diff --git a/app/assets/stylesheets/application.bootstrap.scss b/app/assets/stylesheets/application.bootstrap.scss index d09e0a7..2fe46dd 100644 --- a/app/assets/stylesheets/application.bootstrap.scss +++ b/app/assets/stylesheets/application.bootstrap.scss @@ -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'; @@ -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; } \ No newline at end of file diff --git a/app/controllers/comments/likes_controller.rb b/app/controllers/comments/likes_controller.rb new file mode 100644 index 0000000..d94bd36 --- /dev/null +++ b/app/controllers/comments/likes_controller.rb @@ -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 diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index a821e66..5bc2ade 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -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 diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 1d30a17..5b500fc 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -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 diff --git a/app/controllers/posts/likes_controller.rb b/app/controllers/posts/likes_controller.rb new file mode 100644 index 0000000..b0024a0 --- /dev/null +++ b/app/controllers/posts/likes_controller.rb @@ -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 diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 0b6c706..98f1aa8 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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' @@ -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 diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index e98e0f1..b674c1c 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -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 @@ -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 @@ -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 diff --git a/app/jobs/post_interest_notification_job.rb b/app/jobs/post_interest_notification_job.rb new file mode 100644 index 0000000..14dc1b8 --- /dev/null +++ b/app/jobs/post_interest_notification_job.rb @@ -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 diff --git a/app/models/comment.rb b/app/models/comment.rb index 7a42d29..d0b8121 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/notification.rb b/app/models/notification.rb index 3475ad6..f7fa0aa 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,4 +1,6 @@ class Notification < ApplicationRecord belongs_to :profile belongs_to :notifiable, polymorphic: true + + enum status: { unseen: 0, seen: 5, clicked: 10 } end diff --git a/app/models/post.rb b/app/models/post.rb index 5e7ec8c..832877d 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 } @@ -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 diff --git a/app/models/profile.rb b/app/models/profile.rb index 47ef977..663de5e 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -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( diff --git a/app/models/report.rb b/app/models/report.rb index 621629b..089aab3 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -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) diff --git a/app/views/connections_mailer/notify_follow.html.erb b/app/views/connections_mailer/notify_follow.html.erb index dc3b139..6620377 100644 --- a/app/views/connections_mailer/notify_follow.html.erb +++ b/app/views/connections_mailer/notify_follow.html.erb @@ -1 +1 @@ -

<%= I18n.t('notifications.new_follower_mail', follower_name: @notification.notifiable.follower.full_name) %>

+

<%= @notification.notifiable.follower.full_name %> <%= t('notifications.started_following_you') %>

diff --git a/app/views/notifications/_comment.html.erb b/app/views/notifications/_comment.html.erb index 683889d..2efcfb2 100644 --- a/app/views/notifications/_comment.html.erb +++ b/app/views/notifications/_comment.html.erb @@ -1 +1,11 @@ -

<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> comentou em sua publicação \ No newline at end of file +<% 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 %> \ No newline at end of file diff --git a/app/views/notifications/_connection.html.erb b/app/views/notifications/_connection.html.erb index 4e2666a..0f649a8 100644 --- a/app/views/notifications/_connection.html.erb +++ b/app/views/notifications/_connection.html.erb @@ -1 +1 @@ -

<%= link_to notification.notifiable.follower.user.full_name, profile_path(notification.notifiable.follower) %> começou a te seguir \ No newline at end of file +<%= notification.notifiable.follower.full_name %> <%= t('notifications.started_following_you') %> diff --git a/app/views/notifications/_invitation.html.erb b/app/views/notifications/_invitation.html.erb index b618f6b..311dada 100644 --- a/app/views/notifications/_invitation.html.erb +++ b/app/views/notifications/_invitation.html.erb @@ -1 +1 @@ -

Você recebeu um convite para <%= link_to notification.notifiable.project_title, invitation_path(notification.notifiable) %> \ No newline at end of file +<%= t('notifications.new_invitation_to') %> <%= notification.notifiable.project_title %> diff --git a/app/views/notifications/_like.html.erb b/app/views/notifications/_like.html.erb index 4a428bc..57fae01 100644 --- a/app/views/notifications/_like.html.erb +++ b/app/views/notifications/_like.html.erb @@ -1,5 +1,5 @@ <% if notification.notifiable.likeable.is_a?Post %> -

<%= 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 %> -

<%= 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 %> \ No newline at end of file diff --git a/app/views/notifications/_post.html.erb b/app/views/notifications/_post.html.erb index 9e2e784..5dbc716 100644 --- a/app/views/notifications/_post.html.erb +++ b/app/views/notifications/_post.html.erb @@ -1 +1 @@ -

<%= notification.notifiable.user.full_name %> fez uma <%= link_to 'publicação', post_path(notification.notifiable) %> \ No newline at end of file +<%= notification.notifiable.user.full_name %> <%= t('notifications.published_a_new_post') %> \ No newline at end of file diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index 7d8e41c..4b08d24 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -1,16 +1,18 @@

-

Notificações

- <% if @notifications&.any? %> +

<%= Notification.model_name.human(count: 2) %>

+ <% if @notifications.any? %> + <% else %> -

Nenhuma notificação encontrada

+

<%= t('notifications.no_notification') %>

<% end %> -
\ No newline at end of file + diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 29bbe5a..721ecee 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -46,13 +46,13 @@ <%= @likes_count %> <%= Like.model_name.human(count: @likes_count) %> <% if @liked %> - <%= button_to like_path(post_like_id: @liked), method: :delete, class: 'btn btn-sm', id: 'unlike' do %> - <%= image_tag 'thumbs-up-solid', width: '20rem' %> - <% end %> + <%= button_to post_like_path(@post, @liked), method: :delete, class: 'btn btn-sm', id: 'unlike' do %> + <%= image_tag 'thumbs-up-solid', width: '20rem' %> + <% end %> <% else %> - <%= button_to likes_path(post_id: @post), method: :post, class: 'btn btn-sm', id: 'like' do %> - <%= image_tag 'thumbs-up-regular', width: '20rem' %> - <% end %> + <%= button_to post_likes_path(@post), method: :post, class: 'btn btn-sm', id: 'like' do %> + <%= image_tag 'thumbs-up-regular', width: '20rem' %> + <% end %> <% end %> @@ -69,40 +69,63 @@ <%= @post.comments.count %> <%= Comment.model_name.human(count: @post.comments.count) %> <% @post.comments.each do |comment| %> -
-
-

<%= comment.message %>

-
- <%= link_to comment.user.full_name, comment.user.profile %> <%= '(autor)' if comment.user == @post.user %> -
-
+
+ <% if comment.removed?%> +

<%= t('comments.removed_content') %>

+ <% else %> +
+

<%= comment.message %>

+
+ <%= link_to comment.user.full_name, comment.user.profile %> <%= '(autor)' if comment.user == @post.user %> +
+
- <% if comment.user.deleted_at.nil? %> -
-
-
- <%= comment.likes.count %> <%= Like.model_name.human(count: comment.likes.count) %> -
-
- <% if user_signed_in? && comment.likes.where(user_id: current_user.id).any? %> - <% like = comment.likes.find_by(user_id: current_user.id) %> - <%= button_to like_path(comment_like_id: like.id), method: :delete, class: 'btn btn-sm', id: 'unlike' do %> - <%= image_tag 'thumbs-up-solid', width: '20rem', class: 'mb-4' %> - <% end %> - <% else %> - <%= button_to likes_path(comment_id: comment.id), method: :post, class: 'btn btn-sm', id: 'like' do %> - <%= image_tag 'thumbs-up-regular', width: '20rem', class: 'mb-2' %> + <% if comment.user.deleted_at.nil? %> +
+
+
+ <%= comment.likes.count %> <%= Like.model_name.human(count: comment.likes.count) %> +
+ +
+ <% if user_signed_in? && comment.likes.where(user_id: current_user.id).any? %> + <% like = comment.likes.find_by(user_id: current_user.id) %> + <%= button_to comment_like_path(comment, like), method: :delete, class: 'btn btn-sm', id: 'unlike' do %> + <%= image_tag 'thumbs-up-solid', width: '20rem', class: 'mb-4' %> + <% end %> + <% else %> + <%= button_to comment_likes_path(comment), method: :post, class: 'btn btn-sm', id: 'like' do %> + <%= image_tag 'thumbs-up-regular', width: '20rem', class: 'mb-2' %> + <% end %> <% end %> - <% end %> +
+ + <% if current_user != comment.user %> + + <% end %>
- <% if current_user != comment.user %> - - <% end %> -
+ <% end %> <% end %>
<% end %> -
\ No newline at end of file +
+ + diff --git a/app/views/profiles/show.html.erb b/app/views/profiles/show.html.erb index 4a73fe7..b300f79 100644 --- a/app/views/profiles/show.html.erb +++ b/app/views/profiles/show.html.erb @@ -57,7 +57,7 @@ <% end %>
- <%= link_to t('reports.report_btn'), new_report_path(reportable: @profile.id, reportable_type: @profile.class), class: 'btn btn-dark btn-sm' %> + <%= link_to t('reports.report_btn'), new_report_path(reportable: @profile.id, reportable_type: @profile.class), class: 'btn btn-secondary btn-sm' %>
<% end %> diff --git a/app/views/reports/_post.html.erb b/app/views/reports/_post.html.erb index 99637a9..7718a6d 100644 --- a/app/views/reports/_post.html.erb +++ b/app/views/reports/_post.html.erb @@ -1,6 +1,6 @@
-

<%= post.title %>

+

<%= link_to post.title, post_path(post) %>

<%= t('posts.show.authored_by', author_name: post.user.full_name) %>
diff --git a/app/views/reports/index.html.erb b/app/views/reports/index.html.erb index 518cc56..642282a 100644 --- a/app/views/reports/index.html.erb +++ b/app/views/reports/index.html.erb @@ -6,7 +6,7 @@
@@ -15,8 +15,8 @@ <% if @reports.empty? %>

<%= t('.empty_state') %>

<% else %> - - +
+ diff --git a/app/views/reports/show.html.erb b/app/views/reports/show.html.erb index cdf5c0c..b75a42e 100644 --- a/app/views/reports/show.html.erb +++ b/app/views/reports/show.html.erb @@ -37,6 +37,23 @@

<%= I18n.t('.reporting_profile') %>: <%= link_to @report.profile.full_name, profile_path(@report.profile) %>

+ <% if @report.pending? %> +
+ <% unless @report.reportable.is_a? Profile %> + <%= button_to t('reports.remove_content_btn'), remove_content_report_path(@report), class:'card-btn flex-column btn btn-danger btn-lg' %> + <% end %> + <%= button_to t('reports.reject_btn'), reject_report_path(@report), class:'card-btn flex-column btn btn-secondary btn-lg ml-2' %> +
+ <% else %> +
+

+ <%= I18n.t('reports.rejected') if @report.rejected? %> +

+

+ <%= I18n.t('reports.granted') if @report.granted? %> +

+
+ <% end %> diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index bc4eb49..9f54c3e 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -44,7 +44,12 @@ <% if current_user.admin? %> diff --git a/config/locales/models/comments.pt-BR.yml b/config/locales/models/comments.pt-BR.yml index e82f751..7257e3c 100644 --- a/config/locales/models/comments.pt-BR.yml +++ b/config/locales/models/comments.pt-BR.yml @@ -12,4 +12,5 @@ pt-BR: create: success: Comentário enviado com sucesso error: Não foi possível fazer o comentário - comment_btn: Comentar \ No newline at end of file + comment_btn: Comentar + removed_content: Comentário removido pela administração diff --git a/config/locales/models/likes.pt-BR.yml b/config/locales/models/likes.pt-BR.yml index 29a120e..6546783 100644 --- a/config/locales/models/likes.pt-BR.yml +++ b/config/locales/models/likes.pt-BR.yml @@ -22,4 +22,3 @@ pt-BR: most_liked_comment: O seu comentário mais curtido foi %{comment} na publicação access_profile: para acessar seu perfil e continuar interagindo. regards: Abraços - diff --git a/config/locales/models/notifications.pt-BR.yml b/config/locales/models/notifications.pt-BR.yml index 77f9b52..6b7c5a6 100644 --- a/config/locales/models/notifications.pt-BR.yml +++ b/config/locales/models/notifications.pt-BR.yml @@ -4,7 +4,13 @@ pt-BR: notification: one: 'Notificação' other: 'Notificações' - notifications: - new_follower_mail: '%{follower_name} te seguiu' - new_notificaiton: 'Você recebeu uma nova notificação!' \ No newline at end of file + no_notification: 'Nenhuma notificação' + published_a_new_post: 'fez uma publicação' + liked_your_post: 'curtiu sua publicação' + liked_your_comment: 'curtiu seu comentário' + commented_on_your_post: 'comentou em sua publicação:' + commented_on_post: 'comentou na publicação:' + started_following_you: 'começou a seguir você' + new_invitation_to: 'Você recebeu um convite para' + time_ago: 'há %{time}' \ No newline at end of file diff --git a/config/locales/models/posts.pt-BR.yml b/config/locales/models/posts.pt-BR.yml index 7ee871f..b24e09b 100644 --- a/config/locales/models/posts.pt-BR.yml +++ b/config/locales/models/posts.pt-BR.yml @@ -21,7 +21,7 @@ pt-BR: status_published: Publicada posts: redirect_alert: - invalid_user: Você não pode realizar essa ação + invalid_user: Você não pode acessar este conteúdo ou realizar esta ação create: success: "Publicação %{status} com sucesso!" error: Não foi possível criar sua publicação diff --git a/config/locales/models/reports.pt-BR.yml b/config/locales/models/reports.pt-BR.yml index 03b1849..ba0c85f 100644 --- a/config/locales/models/reports.pt-BR.yml +++ b/config/locales/models/reports.pt-BR.yml @@ -17,14 +17,21 @@ pt-BR: not_published_post: Essa publicação não está disponível. new: not_published_post: Essa publicação não está disponível. + reject: + success: Denúncia rejeitada com sucesso + remove_content: + success: Conteúdo removido com sucesso comment: see_post: Ver publicação show: reporting_profile: Denunciado por + reject_btn: Rejeitar denúncia + remove_content_btn: Remover conteúdo index: pending: Pendente - granted: Deferido - not_granted: Indeferido + granted: Conteúdo removido + rejected: Denúncia rejeitada + rejected_tab: Denúncias rejeitadas empty_state: Nenhuma denúncia encontrada action: Ver mais reported_when: Denunciado em @@ -35,4 +42,4 @@ pt-BR: racism: Racismo spam: Spam disturbin_content: Conteúdo pertubador - harassment: Abuso/Perseguição \ No newline at end of file + harassment: Abuso/Perseguição diff --git a/config/routes.rb b/config/routes.rb index 6d68a5e..e814e3d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,14 +14,24 @@ post '/projects', to: 'projects#create_invitation_request', as: 'invitation_request' resources :job_categories, only: %i[index create destroy] - resources :notifications, only: %i[index] + resources :notifications, only: %i[index update] resources :posts, only: %i[new create] do resources :comments, only: %i[create] post 'pin', on: :member end - resources :reports, only: %i[index new create show] + resources :reports, only: %i[index new create show] do + post 'reject', 'remove_content', on: :member + end + + resources :posts, only: %i[] do + resources :likes, only: %i[create destroy], module: :posts + + end + resources :comments, only: %i[] do + resources :likes, only: %i[create destroy], module: :comments + end resources :users, only: [] do resources :posts, shallow: true, only: %i[show edit update] @@ -38,7 +48,6 @@ delete 'delete_account', controller: :settings patch 'deactivate_profile', 'work_unavailable', 'open_to_work', 'change_privacy', controller: :settings - resources :likes, only: %i[create destroy] resources :job_categories, only: %i[index create] resource :profile, only: %i[edit update], controller: :profile, as: :user_profile do resources :professional_infos, shallow: true, only: %i[new create edit update] @@ -53,7 +62,7 @@ resources :job_categories, only: %i[index show] resources :profiles, only: %i[show index] resources :invitations, only: %i[create update] - + get 'projects/request_invitation', controller: :projects end end diff --git a/config/solid_queue.yml b/config/solid_queue.yml index 814c327..00d08d0 100644 --- a/config/solid_queue.yml +++ b/config/solid_queue.yml @@ -4,9 +4,9 @@ default: &default batch_size: 500 workers: - queues: "*" - threads: 5 + threads: 1 processes: 1 - polling_interval: 0.1 + polling_interval: 1 development: <<: *default diff --git a/db/migrate/20240209191251_add_status_to_comment.rb b/db/migrate/20240209191251_add_status_to_comment.rb new file mode 100644 index 0000000..594ee35 --- /dev/null +++ b/db/migrate/20240209191251_add_status_to_comment.rb @@ -0,0 +1,5 @@ +class AddStatusToComment < ActiveRecord::Migration[7.1] + def change + add_column :comments, :status, :integer, default: 0 + end +end diff --git a/db/migrate/20240212195517_add_status_to_notifications.rb b/db/migrate/20240212195517_add_status_to_notifications.rb new file mode 100644 index 0000000..dada613 --- /dev/null +++ b/db/migrate/20240212195517_add_status_to_notifications.rb @@ -0,0 +1,5 @@ +class AddStatusToNotifications < ActiveRecord::Migration[7.1] + def change + add_column :notifications, :status, :integer, default: 0 + end +end diff --git a/db/migrate/20240212195603_remove_read_from_notifications.rb b/db/migrate/20240212195603_remove_read_from_notifications.rb new file mode 100644 index 0000000..cacac2b --- /dev/null +++ b/db/migrate/20240212195603_remove_read_from_notifications.rb @@ -0,0 +1,5 @@ +class RemoveReadFromNotifications < ActiveRecord::Migration[7.1] + def change + remove_column :notifications, :read, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index a2b6db2..84dde84 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_12_172630) do +ActiveRecord::Schema[7.1].define(version: 2024_02_12_195603) do create_table "action_text_rich_texts", force: :cascade do |t| t.string "name", null: false t.text "body" @@ -134,7 +134,7 @@ t.integer "notifiable_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.boolean "read", default: false + t.integer "status", default: 0 t.index ["notifiable_type", "notifiable_id"], name: "index_notifications_on_notifiable" t.index ["profile_id"], name: "index_notifications_on_profile_id" end @@ -161,7 +161,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "pin", default: 0 - t.datetime "edited_at", default: "2024-02-06 12:28:03" + t.datetime "edited_at", default: "2024-02-13 03:11:57" t.integer "status", default: 0 t.datetime "published_at" t.string "old_status" diff --git a/db/seeds.rb b/db/seeds.rb index 1dc75d4..8546816 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,27 +7,27 @@ image_post_one = ActiveStorage::Blob.create_and_upload!(io: File.open(Rails.root.join('app', 'assets', 'images', 'seeds', 'turma_11.jpeg')), filename: 'turma_11.jpeg') html_post_one = %() -post_joao_1 = joao.posts.create(title: 'Turma 11', content: "A melhor turma de todas
#{html_post_one}", tag_list: ['treinadev', 'tdd']) +post_joao_1 = joao.posts.create(published_at: Time.zone.now, title: 'Turma 11', content: "A melhor turma de todas
#{html_post_one}", tag_list: ['treinadev', 'tdd']) -post_joao_2 = joao.posts.create(title: 'Warehouses', content: "Vamos aprender a fazer um app de gestão de galpões
", tag_list: ['tdd']) +post_joao_2 = joao.posts.create(published_at: Time.zone.now, title: 'Warehouses', content: "Vamos aprender a fazer um app de gestão de galpões
", tag_list: ['tdd']) -post_joao_3 = joao.posts.create(title: 'Rubocop: devo usar?', content: "No começo, tem que aprender na marra.
", tag_list: ['rubocop']) +post_joao_3 = joao.posts.create(published_at: Time.zone.now, title: 'Rubocop: devo usar?', content: "No começo, tem que aprender na marra.
", tag_list: ['rubocop']) image_post_two = ActiveStorage::Blob.create_and_upload!(io: File.open(Rails.root.join('app', 'assets', 'images', 'seeds', 'git_github.jpg')), filename: 'git_github.jpg') html_post_two = %() -post_andre_1 = andre.posts.create(title: 'Pull Request', content: "Façam o Pull Request na main antes de usar o código nas branches dos outros
#{html_post_two}", tag_list: ['git']) +post_andre_1 = andre.posts.create(published_at: Time.zone.now, title: 'Pull Request', content: "Façam o Pull Request na main antes de usar o código nas branches dos outros
#{html_post_two}", tag_list: ['git']) -post_andre_2 = andre.posts.create(title: 'Desafios Exclusivos', content: "Eu fiz o batalha naval mesmo para desafiar a galera
", tag_list: ['desafios']) +post_andre_2 = andre.posts.create(published_at: Time.zone.now, title: 'Desafios Exclusivos', content: "Eu fiz o batalha naval mesmo para desafiar a galera
", tag_list: ['desafios']) -post_andre_3 = andre.posts.create(title: 'SOLID', content: "Hoje, vamos falar sobre boas prática de desenvolvimento de código
", tag_list: ['solid', 'boaspraticas']) +post_andre_3 = andre.posts.create(published_at: Time.zone.now, title: 'SOLID', content: "Hoje, vamos falar sobre boas prática de desenvolvimento de código
", tag_list: ['solid', 'boaspraticas']) image_post_three = ActiveStorage::Blob.create_and_upload!(io: File.open(Rails.root.join('app', 'assets', 'images', 'seeds', 'vue_js.jpg')), filename: 'vue_js.jpg') html_post_three = %() -post_gabriel_1 = gabriel.posts.create(title: 'Como fazer uma app Vue', content: "Não esqueça de usar o app.mount
#{html_post_three}", tag_list: ['vue']) +post_gabriel_1 = gabriel.posts.create(published_at: Time.zone.now, title: 'Como fazer uma app Vue', content: "Não esqueça de usar o app.mount
#{html_post_three}", tag_list: ['vue']) -post_gabriel_2 = gabriel.posts.create(title: 'Boas práticas em Zoom', content: "Hoje vamos falar sobre breakout rooms!
", tag_list: ['zoom']) +post_gabriel_2 = gabriel.posts.create(published_at: Time.zone.now, title: 'Boas práticas em Zoom', content: "Hoje vamos falar sobre breakout rooms!
", tag_list: ['zoom']) -post_gabriel_3 = gabriel.posts.create(title: 'Robô Saltitante: como resolver?', content: "Vamos falar sobre a tarefa mais complexa do Code Saga!
", tag_list: ['codesaga']) +post_gabriel_3 = gabriel.posts.create(published_at: Time.zone.now, title: 'Robô Saltitante: como resolver?', content: "Vamos falar sobre a tarefa mais complexa do Code Saga!
", tag_list: ['codesaga']) joao.profile.update(cover_letter: 'Sou profissional organizado, esforçado e apaixonado pelo que faço', work_status: 'unavailable') andre.profile.update(cover_letter: 'Sou profissional organizado, esforçado e apaixonado pelo que faço', work_status: 'open_to_work') diff --git a/spec/jobs/notify_posts_of_interests_spec.rb b/spec/jobs/notify_posts_of_interests_spec.rb new file mode 100644 index 0000000..bb8b8bb --- /dev/null +++ b/spec/jobs/notify_posts_of_interests_spec.rb @@ -0,0 +1,47 @@ +require 'rails_helper' + +RSpec.describe PostInterestNotificationJob, type: :job do + include ActiveJob::TestHelper + context '.perform' do + it 'envia notificações aos usuários que comentaram em um post' do + post_author = create(:user) + interested_user_one = create(:user) + interested_user_two = create(:user) + + no_related_user = create(:user) + commenter_user = create(:user) + post = create(:post, user: post_author) + create(:comment, post:, user: interested_user_one) + create(:comment, post:, user: interested_user_two) + + comment = build(:comment, post:, user: commenter_user) + + PostInterestNotificationJob.perform_now(comment) + + expect(interested_user_one.reload.profile.notifications.count).to eq 1 + expect(interested_user_one.profile.notifications.first.notifiable).to be_a Comment + + expect(interested_user_two.reload.profile.notifications.count).to eq 1 + expect(interested_user_two.profile.notifications.first.notifiable).to be_a Comment + + expect(commenter_user.reload.profile.notifications).to be_empty + expect(no_related_user.reload.profile.notifications).to be_empty + expect(post_author.reload.profile.notifications.count).to eq 3 + end + + it 'não envia notificação ao autor do post quando ele tem comentário no próprio post' do + post_author = create(:user) + + commenter_user = create(:user) + post = create(:post, user: post_author) + + create(:comment, post:, user: post_author) + + comment = build(:comment, post:, user: commenter_user) + + PostInterestNotificationJob.perform_now(comment) + + expect(post_author.reload.profile.notifications).to be_empty + end + end +end diff --git a/spec/mailer/connections_mailer_spec.rb b/spec/mailer/connections_mailer_spec.rb index 8c59276..9656f87 100644 --- a/spec/mailer/connections_mailer_spec.rb +++ b/spec/mailer/connections_mailer_spec.rb @@ -14,7 +14,7 @@ expect(mail.subject).to include 'Alguém seguiu seu perfil' expect(mail.to).to eq [followed_profile.email] expect(mail.from).to eq ['notifications@portfoliorrr.com'] - expect(mail.body).to include 'Danilo Martins te seguiu' + expect(mail.body).to include 'Danilo Martins começou a seguir você' end end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 21d9eca..f26c77d 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -25,7 +25,7 @@ context 'data de publicação' do it 'não deve ser no passado' do user = create(:user) - post = build(:post, user:, published_at: Time.zone.yesterday) + post = build(:post, user:, published_at: Time.zone.yesterday, status: :scheduled) expect(post).not_to be_valid expect(post.errors[:published_at]).to include('não pode estar no passado') diff --git a/spec/requests/likes/user_likes_spec.rb b/spec/requests/likes/user_likes_spec.rb index 6860b84..f80c204 100644 --- a/spec/requests/likes/user_likes_spec.rb +++ b/spec/requests/likes/user_likes_spec.rb @@ -3,25 +3,30 @@ describe 'Usuário curte uma publicação ou comentário' do context 'não esta logado' do it 'e tenta curtir' do - post likes_path + post = create(:post) + + post post_likes_path(post) expect(response).to redirect_to(new_user_session_path) + expect(Like.count).to eq 0 end it 'e tenta descurtir uma publicação' do like = create(:like, :for_post) - delete like_path(like) + delete post_like_path(like.likeable, like) expect(response).to redirect_to(new_user_session_path) + expect(Like.count).to eq 1 end it 'e tenta descurtir um comentário' do like = create(:like, :for_comment) - delete like_path(like) + delete comment_like_path(like.likeable, like) expect(response).to redirect_to(new_user_session_path) + expect(Like.count).to eq 1 end end @@ -30,9 +35,10 @@ login_as like.user - post likes_path, params: { post_id: like.likeable.id } + post post_likes_path(like.likeable) expect(response).to redirect_to(post_path(like.likeable)) expect(flash[:alert]).to eq 'Você já curtiu isso' + expect(Like.count).to eq 1 end end diff --git a/spec/requests/posts/user_edit_post_status_pin_spec.rb b/spec/requests/posts/user_edit_post_status_pin_spec.rb index 0935747..3edd648 100644 --- a/spec/requests/posts/user_edit_post_status_pin_spec.rb +++ b/spec/requests/posts/user_edit_post_status_pin_spec.rb @@ -10,7 +10,7 @@ post pin_post_path(post) expect(response).to redirect_to(root_path) - expect(flash[:alert]).to eq('Você não pode realizar essa ação') + expect(flash[:alert]).to eq('Você não pode acessar este conteúdo ou realizar esta ação') expect(post.reload.pinned?).to eq(false) end end diff --git a/spec/requests/reports/user_reports_spec.rb b/spec/requests/reports/user_reports_spec.rb index 36e5252..92745a9 100644 --- a/spec/requests/reports/user_reports_spec.rb +++ b/spec/requests/reports/user_reports_spec.rb @@ -40,7 +40,7 @@ it 'mas post está agendado' do user = create(:user) - post = create(:post, status: :scheduled, published_at: Time.current) + post = create(:post, status: :scheduled, published_at: Time.current + 5.seconds) login_as user post reports_path, params: { diff --git a/spec/system/notifications/user_is_notified_about_post_of_interest_spec.rb b/spec/system/notifications/user_is_notified_about_post_of_interest_spec.rb new file mode 100644 index 0000000..f99519c --- /dev/null +++ b/spec/system/notifications/user_is_notified_about_post_of_interest_spec.rb @@ -0,0 +1,50 @@ +require 'rails_helper' + +describe 'Usuário é notificado' do + context 'sobre posts em que ele comentou' do + it 'quando alguém comenta nele' do + post_author = create(:user) + interested_user = create(:user) + commenter_user = create(:user) + + post = create(:post, user: post_author, title: 'Meu primeiro post') + create(:comment, post:, user: interested_user) + + post_interest_notification_job_spy = spy(PostInterestNotificationJob) + stub_const('PostInterestNotificationJob', post_interest_notification_job_spy) + + create(:comment, post:, user: commenter_user) + + expect(post_interest_notification_job_spy).to have_received(:perform_later) + end + + it 'e vê a notificação na página de Notificações' do + post_author = create(:user) + interested_user = create(:user) + + commenter_user = create(:user, full_name: 'Gabriel') + + post_one = create(:post, user: post_author, title: 'Meu primeiro post') + post_two = create(:post, user: post_author, title: 'Meu segundo post') + + create(:comment, post: post_one, user: interested_user, created_at: 2.days.ago) + create(:comment, post: post_two, user: interested_user, created_at: 2.days.ago) + + comment_one = build(:comment, post: post_one, user: commenter_user, + message: 'Meu primerio comentário', created_at: 10.hours.ago) + comment_two = build(:comment, post: post_two, user: commenter_user, + message: 'Meu segundo comentário', created_at: 10.minutes.ago) + + PostInterestNotificationJob.perform_now(comment_one) + PostInterestNotificationJob.perform_now(comment_two) + + login_as interested_user + visit notifications_path + + expect(page).to have_content 'Gabriel comentou na publicação: Meu segundo post há 10 minutos' + expect(page).to have_content 'Gabriel comentou na publicação: Meu primeiro post há aproximadamente 10 horas' + expect(page).to have_link post_one.title, href: post_path(post_one, anchor: "comment_#{comment_one.id}") + expect(page).to have_link post_two.title, href: post_path(post_two, anchor: "comment_#{comment_two.id}") + end + end +end diff --git a/spec/system/notifications/user_sees_comments_notification_spec.rb b/spec/system/notifications/user_sees_comments_notification_spec.rb index 1180386..bc2e27b 100644 --- a/spec/system/notifications/user_sees_comments_notification_spec.rb +++ b/spec/system/notifications/user_sees_comments_notification_spec.rb @@ -5,15 +5,14 @@ user = create(:user) post = create(:post, user:) other_user = create(:user) - comment = create(:comment, post:, user: other_user) + create(:comment, post:, user: other_user) login_as user visit notifications_path expect(Notification.count).to eq 1 expect(page).to have_current_path notifications_path - expect(page).to have_content 'comentou em sua publicação' - expect(page).to have_link comment.user.profile.full_name, href: profile_path(comment.user.profile) + expect(page).to have_content "#{other_user.full_name} comentou em sua publicação: #{post.title}" end it 'e não vê notificação de seu comentário' do @@ -43,8 +42,8 @@ end expect(page).to have_current_path notifications_path - expect(page).to have_content 'curtiu seu comentário' - expect(page).to have_link like.user.profile.full_name, href: profile_path(like.user.profile) + expect(page).to have_content "#{like.user.full_name} curtiu seu comentário" + expect(Notification.last).to be_seen end it 'e não recebe ao curtir seu próprio comentário' do @@ -63,4 +62,37 @@ expect(page).not_to have_content 'curtiu seu comentário' expect(page).not_to have_link like.user.profile.full_name, href: profile_path(like.user.profile) end + + context 'ao clicar na notificação' do + it 'de comentário é redirecionado para a página do post' do + user = create(:user) + post = create(:post, user:) + comment = create(:comment, post:) + + login_as user + visit notifications_path + click_on comment.user.full_name + + expect(page).to have_current_path post_path(post) + expect(page).to have_content post.title + expect(page).to have_content comment.message + expect(Notification.last).to be_clicked + end + + it 'de curtida é redirecionado para a página do post' do + user = create(:user) + post = create(:post) + comment = create(:comment, post:, user:) + like = create(:like, likeable: comment) + + login_as user + visit notifications_path + click_on like.user.full_name + + expect(page).to have_current_path post_path(post) + expect(page).to have_content post.title + expect(page).to have_content comment.message + expect(Notification.last).to be_clicked + end + end end diff --git a/spec/system/notifications/user_sees_invitation_notification_spec.rb b/spec/system/notifications/user_sees_invitation_notification_spec.rb index 6bca12c..760f2bb 100644 --- a/spec/system/notifications/user_sees_invitation_notification_spec.rb +++ b/spec/system/notifications/user_sees_invitation_notification_spec.rb @@ -10,7 +10,6 @@ expect(page).to have_current_path notifications_path expect(page).to have_content "Você recebeu um convite para #{invitation.project_title} há 1 dia" - expect(page).to have_link invitation.project_title, href: invitation_path(invitation) end it 'e não vê convites de outros usuários' do @@ -28,7 +27,7 @@ expect(page).to_not have_content "Você recebeu um convite para #{other_user_invitation.project_title}" end - it 'ao clicar na notificação é redirecionado para a página de convites' do + it 'ao clicar na notificação é redirecionado para a página do convite' do user = create(:user) invitation = create(:invitation, profile: user.profile) @@ -38,5 +37,6 @@ expect(page).to have_current_path invitation_path(invitation) expect(page).to have_content invitation.project_title + expect(Notification.last).to be_clicked end end diff --git a/spec/system/notifications/user_sees_new_follower_notification_spec.rb b/spec/system/notifications/user_sees_new_follower_notification_spec.rb index 9970da4..2e78d64 100644 --- a/spec/system/notifications/user_sees_new_follower_notification_spec.rb +++ b/spec/system/notifications/user_sees_new_follower_notification_spec.rb @@ -10,7 +10,19 @@ visit notifications_path expect(page).to have_current_path notifications_path - expect(page).to have_content 'Paulo começou a te seguir' - expect(page).to have_link follower.full_name, href: profile_path(follower) + expect(page).to have_content 'Paulo começou a seguir você' + end + + it 'ao clicar na notificação redireciona para o perfil do seguidor' do + follower = create(:user, full_name: 'Paulo') + followed = create(:user, full_name: 'Ana') + Connection.create!(followed_profile: followed.profile, follower: follower.profile) + + login_as followed + visit notifications_path + click_on 'Paulo começou a seguir você' + + expect(page).to have_current_path profile_path(follower) + expect(Notification.last).to be_clicked end end diff --git a/spec/system/notifications/user_sees_notifications_spec.rb b/spec/system/notifications/user_sees_notifications_spec.rb index 5e739a1..e713708 100644 --- a/spec/system/notifications/user_sees_notifications_spec.rb +++ b/spec/system/notifications/user_sees_notifications_spec.rb @@ -28,12 +28,12 @@ expect(page).to have_current_path notifications_path expect(new_post_notification_job_spy).to have_received(:perform_later) expect(user.profile.notifications.count).to eq 5 - expect(page).to have_content 'começou a te seguir' + expect(page).to have_content 'começou a seguir você' expect(page).to have_content 'curtiu sua publicação' expect(page).to have_content 'comentou em sua publicação' expect(page).to have_content 'curtiu seu comentário' expect(page).to have_content 'Você recebeu um convite' - expect(page.body.index('começou a te seguir')).to be > page.body.index('curtiu sua publicação') + expect(page.body.index('começou a seguir você')).to be > page.body.index('curtiu sua publicação') expect(page.body.index('curtiu sua publicação')).to be > page.body.index('comentou em sua publicação') expect(page.body.index('comentou em sua publicação')).to be > page.body.index('curtiu seu comentário') expect(page.body.index('curtiu seu comentário')).to be > page.body.index('Você recebeu um convite') @@ -55,4 +55,17 @@ expect(page).to have_content 'Nenhuma notificação' expect(Notification.count).to eq 0 end + + it 'contagem de notificações muda ao ir para página de notificações' do + user = create(:user) + create(:invitation, profile: user.profile) + + login_as user + visit notifications_path + click_button class: 'dropdown-toggle' + + expect(page).not_to have_content 'Notificações 1' + expect(page).to have_content 'Notificações' + expect(user.profile.notifications.count).to eq 1 + end end diff --git a/spec/system/notifications/user_sees_post_notification_spec.rb b/spec/system/notifications/user_sees_post_notification_spec.rb index 28de556..f242c81 100644 --- a/spec/system/notifications/user_sees_post_notification_spec.rb +++ b/spec/system/notifications/user_sees_post_notification_spec.rb @@ -13,7 +13,7 @@ visit notifications_path expect(page).to have_content 'Ana fez uma publicação' - expect(page).to have_link 'publicação', href: post_path(post) + expect(Notification.last).to be_seen end context 'nova publicação notifica seguidores' do @@ -39,8 +39,7 @@ visit notifications_path expect(page).to have_current_path notifications_path - expect(page).to have_content 'curtiu sua publicação' - expect(page).to have_link like.user.full_name, href: profile_path(like.user.profile) + expect(page).to have_content "#{like.user.full_name} curtiu sua publicação" end it 'e não recebe quando curte sua própria publicação' do @@ -54,5 +53,34 @@ expect(page).not_to have_content 'curtiu sua publicação' expect(page).not_to have_link like.user.profile.full_name, href: profile_path(like.user.profile) end + + it 'ao clicar na notificação é redirecionado para a publicação' do + user = create(:user) + post = create(:post, user:) + like = create(:like, likeable: post) + + login_as user + visit notifications_path + click_on "#{like.user.full_name} curtiu sua publicação" + + expect(page).to have_current_path post_path(post) + expect(Notification.last).to be_clicked + end + end + + it 'ao clicar na notificação é redirecionado para a publicação' do + follower = create(:user, full_name: 'Paulo') + followed = create(:user, full_name: 'Ana') + Connection.create!(followed_profile: followed.profile, follower: follower.profile) + post = create(:post, user: followed) + + NewPostNotificationJob.perform_now(post) + + login_as follower + visit notifications_path + click_on 'Ana fez uma publicação' + + expect(page).to have_current_path post_path(post) + expect(Notification.last).to be_clicked end end diff --git a/spec/system/posts/user_edits_post_spec.rb b/spec/system/posts/user_edits_post_spec.rb index 27926a4..6ef49a4 100644 --- a/spec/system/posts/user_edits_post_spec.rb +++ b/spec/system/posts/user_edits_post_spec.rb @@ -38,7 +38,7 @@ visit edit_post_path(post) expect(current_path).to eq root_path - expect(page).to have_content 'Você não pode realizar essa ação' + expect(page).to have_content 'Você não pode acessar este conteúdo ou realizar esta ação' end it 'mas não vê o link de editar caso não seja seu post' do diff --git a/spec/system/posts/visitor_views_post_spec.rb b/spec/system/posts/visitor_views_post_spec.rb index 5ca1484..23aa44f 100644 --- a/spec/system/posts/visitor_views_post_spec.rb +++ b/spec/system/posts/visitor_views_post_spec.rb @@ -18,7 +18,7 @@ visit post_path(post) expect(page).to have_current_path(root_path) - expect(page).to have_content 'Você não pode realizar essa ação' + expect(page).to have_content 'Você não pode acessar este conteúdo ou realizar esta ação' end it 'e não vê rascunho' do @@ -27,6 +27,34 @@ visit post_path(post) expect(page).to have_current_path(root_path) - expect(page).to have_content 'Você não pode realizar essa ação' + expect(page).to have_content 'Você não pode acessar este conteúdo ou realizar esta ação' + end + + it 'e não vê post removido' do + post = create(:post, title: 'Título do post', content: 'Conteúdo do post', status: 'removed') + + visit post_path(post) + + expect(page).to have_current_path(root_path) + expect(page).to have_content 'Você não pode acessar este conteúdo ou realizar esta ação' + end + + it 'e nâo vê comentário removido' do + user = create(:user) + post = create(:post, title: 'Título do post', content: 'Conteúdo do post', + status: 'published', published_at: Time.zone.now) + create(:comment, post:, status: :published, message: 'Primeiro comentário') + create(:comment, post:, status: :removed, message: 'Segundo comentário') + create(:comment, post:, status: :published, message: 'Terceiro comentário') + + login_as user + visit post_path(post) + + within '#comments' do + expect(page).to have_content 'Primeiro comentário' + expect(page).not_to have_content 'Segundo comentário' + expect(page).to have_content 'Terceiro comentário' + expect(page).to have_content 'Comentário removido pela administração' + end end end diff --git a/spec/system/reports/admin_rules_report_spec.rb b/spec/system/reports/admin_rules_report_spec.rb new file mode 100644 index 0000000..301c7fd --- /dev/null +++ b/spec/system/reports/admin_rules_report_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +describe 'Admin avalia denúncia' do + it 'decidindo rejeitar a denúncia' do + admin = create(:user, :admin) + create(:report, :for_post) + create(:report, :for_profile) + + login_as admin + visit reports_path + page.all('.see_more').to_a.second.click + click_on 'Rejeitar denúncia' + + expect(Report.first).to be_pending + expect(Report.second).to be_rejected + expect(page).to have_content 'Denúncia rejeitada com sucesso' + end + + it 'decidindo remover o conteúdo' do + admin = create(:user, :admin) + post = create(:post, :published) + create(:report, reportable: post) + create(:report, :for_comment) + + login_as admin + visit reports_path + page.all('.see_more').to_a.first.click + click_on 'Remover conteúdo' + + expect(Report.first).to be_granted + expect(Report.second).to be_pending + expect(page).to have_content 'Conteúdo removido com sucesso' + end +end diff --git a/spec/system/reports/admin_sees_reports_listing_page_spec.rb b/spec/system/reports/admin_sees_reports_listing_page_spec.rb index e0c0bf3..8fd5b7b 100644 --- a/spec/system/reports/admin_sees_reports_listing_page_spec.rb +++ b/spec/system/reports/admin_sees_reports_listing_page_spec.rb @@ -34,7 +34,7 @@ visit root_path click_button class: 'dropdown-toggle' click_on 'Denúncias' - click_on 'Deferido' + click_on 'Conteúdo removido' expect(page).not_to have_content report.truncated_message expect(page).not_to have_content 'Discurso de ódio' @@ -50,7 +50,7 @@ it 'e visualiza denúncias indeferidas' do admin = create(:user, :admin) - report = create(:report, :for_post, offence_type: 'Discurso de ódio', status: :not_granted) + report = create(:report, :for_post, offence_type: 'Discurso de ódio', status: :rejected) other_report = create(:report, :for_comment, offence_type: 'Abuso/Perseguição') another_report = create(:report, :for_profile, offence_type: 'Spam') @@ -58,7 +58,7 @@ visit root_path click_button class: 'dropdown-toggle' click_on 'Denúncias' - click_on 'Indeferido' + click_on 'Denúncias rejeitadas' expect(page).to have_content report.truncated_message expect(page).to have_content 'Discurso de ódio' @@ -69,7 +69,7 @@ expect(page).not_to have_content another_report.truncated_message expect(page).not_to have_content 'Spam' expect(page).not_to have_content 'Perfil' - expect(page).to have_current_path reports_path({ filter: 'not_granted' }) + expect(page).to have_current_path reports_path({ filter: 'rejected' }) end it 'e não há denúncias disponíveis' do diff --git a/spec/system/reports/user_report_spec.rb b/spec/system/reports/user_report_spec.rb index 98e6814..86f3746 100644 --- a/spec/system/reports/user_report_spec.rb +++ b/spec/system/reports/user_report_spec.rb @@ -97,7 +97,7 @@ visit post_path(post) within '#comments' do - expect(page.all('.report-link-wrapper').size).to eq 2 + expect(page).to have_link('Denunciar').twice end expect(page.all('.comment').to_a.second).not_to have_link 'Denunciar' end
<%= Report.human_attribute_name :offence_type %> <%= Report.human_attribute_name :message %>