Skip to content

Commit

Permalink
Merge branch 'main' into fix/traducoes
Browse files Browse the repository at this point in the history
  • Loading branch information
Luckvc committed Feb 13, 2024
2 parents 616eb65 + 19a931c commit 1f2529f
Show file tree
Hide file tree
Showing 55 changed files with 600 additions and 153 deletions.
23 changes: 23 additions & 0 deletions app/assets/stylesheets/application.bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ $theme-colors: (
"light": rgba(255, 251, 251, 0.603),
"dark": #1b1b1b
);

$primary: #a130fd;

@import 'bootstrap/scss/bootstrap';
@import 'bootstrap-icons/font/bootstrap-icons';
@import 'actiontext.css';
Expand Down Expand Up @@ -70,4 +73,24 @@ input[type="checkbox"]:checked {

.categories{
width: 35% !important;
}

.highlighted {
transform: scale(1.01s);
background-color: hsla(256, 85%, 82%, 0.2);
box-shadow: 0 0 5px 5px rgba(0, 0, 0, 0.2);
transition:
transform 1.5s ease-in-out,
box-shadow 1.5s ease-in-out,
background-color 1.5s ease-in-out;
}

[id^='comment_'] {
transform: reset;
background-color: reset;
box-shadow: reset;
transition:
transform 1s ease-in-out,
box-shadow 1s ease-in-out,
background-color 1s ease-in-out;
}
12 changes: 12 additions & 0 deletions app/controllers/comments/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Comments
class LikesController < LikesController
before_action :set_likeable

private

def set_likeable
@likeable = Comment.find(params[:comment_id])
@post = @likeable.post
end
end
end
32 changes: 5 additions & 27 deletions app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,18 @@ class LikesController < ApplicationController
before_action :authenticate_user!

def create
likeable, post_id = find_likeable_and_post_id
return unless likeable

like = current_user.likes.build(likeable:)
like = current_user.likes.build(likeable: @likeable)
if like.save
redirect_to post_path(post_id)
redirect_to post_path(@post)
else
redirect_to post_path(post_id), alert: t('.error')
redirect_to post_path(@post), alert: t('.error')
end
end

def destroy
if params[:post_like_id]
like = Like.find(params[:post_like_id])
post_id = like.likeable
elsif params[:comment_like_id]
like = Like.find(params[:comment_like_id])
post_id = like.likeable.post
end

like = current_user.likes.find(params[:id])
like.destroy

redirect_to post_path(post_id)
end

private

def find_likeable_and_post_id
if params[:post_id]
likeable = Post.find(params[:post_id])
[likeable, likeable.id]
elsif params[:comment_id]
likeable = Comment.find(params[:comment_id])
[likeable, likeable.post_id]
end
redirect_to post_path(@post)
end
end
39 changes: 39 additions & 0 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,44 @@ class NotificationsController < ApplicationController

def index
@notifications = current_user.profile.notifications.order(created_at: :desc)
@notifications.map { |n| n.seen! if n.unseen? }
end

def update
@notification = Notification.find(params[:id])
@notification.clicked!
redirect_to_notification
end

private

def redirect_to_notification
return redirect_to_invitation if @notification.notifiable.is_a? Invitation
return redirect_to_comment if @notification.notifiable.is_a? Comment
return redirect_to_connection if @notification.notifiable.is_a? Connection
return redirect_to_post if @notification.notifiable.is_a? Post

redirect_to_like if @notification.notifiable.is_a? Like
end

def redirect_to_invitation
redirect_to invitation_path(@notification.notifiable)
end

def redirect_to_comment
redirect_to post_path(@notification.notifiable.post)
end

def redirect_to_connection
redirect_to profile_path(@notification.notifiable.follower)
end

def redirect_to_post
redirect_to post_path(@notification.notifiable)
end

def redirect_to_like
likeable = @notification.notifiable.likeable
redirect_to post_path(likeable.is_a?(Comment) ? likeable.post : likeable)
end
end
12 changes: 12 additions & 0 deletions app/controllers/posts/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Posts
class LikesController < LikesController
before_action :set_likeable

private

def set_likeable
@likeable = Post.find(params[:post_id])
@post = @likeable
end
end
end
7 changes: 7 additions & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class PostsController < ApplicationController
before_action :set_post, only: %w[show edit update pin]
before_action :authorize!, only: %w[edit update pin]
before_action :blocks_update, only: %w[update]
before_action :redirect_if_removed_content, only: %w[show edit update pin]

require 'image_processing/mini_magick'

Expand Down Expand Up @@ -71,4 +72,10 @@ def authorize!
def blocks_update
redirect_to root_path, alert: t('.error') if @post.published? && @post.published_at && post_params['published_at']
end

def redirect_if_removed_content
return if current_user&.admin?

redirect_to root_path, alert: t('.redirect_alert.invalid_user') if @post.removed?
end
end
20 changes: 17 additions & 3 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ReportsController < ApplicationController
before_action :redirect_unless_published_post
before_action :authorize!, only: %i[index show]
before_action :redirect_if_self_report, only: :create
before_action :set_report, only: %i[reject show remove_content]

def new
set_offences
Expand All @@ -18,13 +19,22 @@ def create

def index
return @reports = Report.granted.all if params[:filter] == 'granted'
return @reports = Report.not_granted.all if params[:filter] == 'not_granted'
return @reports = Report.rejected.all if params[:filter] == 'rejected'

@reports = Report.pending.all
end

def show
@report = Report.find(params[:id])
def show; end

def reject
@report.rejected!
redirect_to @report, notice: t('.success')
end

def remove_content
@report.reportable.removed!
@report.granted!
redirect_to @report, notice: t('.success')
end

private
Expand Down Expand Up @@ -57,6 +67,10 @@ def set_offences
]
end

def set_report
@report = Report.find(params[:id])
end

def post_and_published?
return true unless @reportable.is_a? Post

Expand Down
9 changes: 9 additions & 0 deletions app/jobs/post_interest_notification_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class PostInterestNotificationJob < ApplicationJob
queue_as :default

def perform(comment)
post = comment.post
users = post.comments.map(&:user).uniq.excluding(comment.user, post.user)
users.each { |user| Notification.create!(profile: user.profile, notifiable: comment) }
end
end
9 changes: 8 additions & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ class Comment < ApplicationRecord
belongs_to :user
has_many :likes, as: :likeable, dependent: :destroy
has_many :reports, as: :reportable, dependent: :destroy
has_one :notification, as: :notifiable, dependent: :destroy
has_many :notifications, as: :notifiable, dependent: :destroy

enum status: { published: 0, removed: 20 }

after_create :notify_interested_users
after_create :create_notification

private

def notify_interested_users
PostInterestNotificationJob.perform_later(self)
end

def create_notification
comment_author = user.profile
return if comment_author == post.user.profile
Expand Down
2 changes: 2 additions & 0 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Notification < ApplicationRecord
belongs_to :profile
belongs_to :notifiable, polymorphic: true

enum status: { unseen: 0, seen: 5, clicked: 10 }
end
5 changes: 3 additions & 2 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Post < ApplicationRecord
validate :file_size
validate :validate_published_at

enum status: { published: 0, archived: 5, draft: 10, scheduled: 15 }
enum status: { published: 0, archived: 5, draft: 10, scheduled: 15, removed: 20 }
acts_as_ordered_taggable_on :tags

enum pin: { unpinned: 0, pinned: 10 }
Expand Down Expand Up @@ -89,7 +89,8 @@ def validate_attachment_size(attachment, content_type, size_limit, error_message

def validate_published_at
return if published_at.nil?
return unless scheduled?

errors.add(:published_at, I18n.t('posts.model.invalid_date')) if published_at < (Time.zone.now - 1.second)
errors.add(:published_at, I18n.t('posts.model.invalid_date')) if published_at < Time.zone.now
end
end
3 changes: 1 addition & 2 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class Profile < ApplicationRecord
enum privacy: { private_profile: 0, public_profile: 10 }
enum status: { inactive: 0, active: 5 }

delegate :full_name, to: :user
delegate :email, to: :user
delegate :full_name, :email, to: :user

def self.advanced_search(search_query)
left_outer_joins(:job_categories, :personal_info, :user).where(
Expand Down
2 changes: 1 addition & 1 deletion app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Report < ApplicationRecord
belongs_to :profile
belongs_to :reportable, polymorphic: true

enum status: { pending: 0, granted: 5, not_granted: 9 }
enum status: { pending: 0, granted: 5, rejected: 9 }

def truncated_message
message.truncate(50)
Expand Down
2 changes: 1 addition & 1 deletion app/views/connections_mailer/notify_follow.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p><%= I18n.t('notifications.new_follower_mail', follower_name: @notification.notifiable.follower.full_name) %></p>
<p><%= @notification.notifiable.follower.full_name %> <%= t('notifications.started_following_you') %></p>
12 changes: 11 additions & 1 deletion app/views/notifications/_comment.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
<p><%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> comentou em sua publicação
<% if notification.notifiable.post.user == current_user %>
<%= notification.notifiable.user.full_name %>
<%= t('notifications.commented_on_your_post') %>
<%= notification.notifiable.post.title %>
<% else %>
<%= notification.notifiable.user.full_name %>
<%= t('notifications.commented_on_post') %>
<%= link_to notification.notifiable.post.title,
post_path(notification.notifiable.post,
anchor: "comment_#{notification.notifiable.id}") %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/notifications/_connection.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p><%= link_to notification.notifiable.follower.user.full_name, profile_path(notification.notifiable.follower) %> começou a te seguir
<%= notification.notifiable.follower.full_name %> <%= t('notifications.started_following_you') %>
2 changes: 1 addition & 1 deletion app/views/notifications/_invitation.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>Você recebeu um convite para <%= link_to notification.notifiable.project_title, invitation_path(notification.notifiable) %>
<%= t('notifications.new_invitation_to') %> <%= notification.notifiable.project_title %>
4 changes: 2 additions & 2 deletions app/views/notifications/_like.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if notification.notifiable.likeable.is_a?Post %>
<p><%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu sua publicação
<%= notification.notifiable.user.full_name %> <%= t('notifications.liked_your_post') %>
<% else %>
<p><%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu seu comentário
<%= notification.notifiable.user.full_name %> <%= t('notifications.liked_your_comment') %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/notifications/_post.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p><%= notification.notifiable.user.full_name %> fez uma <%= link_to 'publicação', post_path(notification.notifiable) %>
<%= notification.notifiable.user.full_name %> <%= t('notifications.published_a_new_post') %>
24 changes: 13 additions & 11 deletions app/views/notifications/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<div class="container d-flex flex-column align-items-center">
<h2>Notificações</h2>
<% if @notifications&.any? %>
<h2><%= Notification.model_name.human(count: 2) %></h2>
<% if @notifications.any? %>
<ul class="list-group list-group-action">
<% @notifications.each do |notification| %>
<div class="list-group">
<%= render(
partial: "#{notification.notifiable.class.name.downcase}" ,
locals: { notification: notification }
)%>
<%= distance_of_time_in_words_to_now(notification.notifiable.created_at) %></p>
</div>
<li class="list-group-item <%= 'list-group-item-primary' if notification.seen? %> ">
<%= button_to notification_path(notification), method: :patch, class: 'btn btn-link' do %>
<%= render( partial: "#{notification.notifiable.class.name.downcase}",
locals: { notification: notification } ) %>
<%= t('notifications.time_ago', time: time_ago_in_words(notification.notifiable.created_at)) %>
<% end %>
</li>
<% end %>
</ul>
<% else %>
<p>Nenhuma notificação encontrada</p>
<p><%= t('notifications.no_notification') %></p>
<% end %>
</div>
</div>
Loading

0 comments on commit 1f2529f

Please sign in to comment.