From 31268b9d68714ca8a916e2afde6805f9411814d8 Mon Sep 17 00:00:00 2001 From: Rosemilson Date: Fri, 9 Feb 2024 17:59:26 -0300 Subject: [PATCH 1/3] =?UTF-8?q?Feat/Admin=20remove=20conte=C3=BAdo=20denun?= =?UTF-8?q?ciado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Admin agora tem opções para remover conteúdo ou rejeitar denúncia Posts removidos não podem mais ser acessados Comentários removidos são substituídos por uma mensagem Co-authored-by: Lucas Vasques --- app/controllers/posts_controller.rb | 7 +++ app/controllers/reports_controller.rb | 20 ++++++-- app/models/comment.rb | 2 + app/models/post.rb | 5 +- app/models/report.rb | 2 +- app/views/posts/show.html.erb | 51 ++++++++++--------- app/views/profiles/show.html.erb | 2 +- app/views/reports/_post.html.erb | 2 +- app/views/reports/index.html.erb | 14 ++--- app/views/reports/show.html.erb | 17 +++++++ config/locales/comments.pt-BR.yml | 3 +- config/locales/posts.pt-BR.yml | 2 +- config/locales/reports.pt-BR.yml | 15 +++++- config/routes.rb | 7 ++- .../20240209191251_add_status_to_comment.rb | 5 ++ db/schema.rb | 5 +- db/seeds.rb | 18 +++---- spec/models/post_spec.rb | 10 ---- .../posts/user_edit_post_status_pin_spec.rb | 2 +- spec/system/posts/user_edits_post_spec.rb | 2 +- spec/system/posts/visitor_views_post_spec.rb | 32 +++++++++++- .../system/reports/admin_rules_report_spec.rb | 34 +++++++++++++ .../admin_sees_reports_listing_page_spec.rb | 8 +-- spec/system/reports/user_report_spec.rb | 2 +- 24 files changed, 192 insertions(+), 75 deletions(-) create mode 100644 db/migrate/20240209191251_add_status_to_comment.rb create mode 100644 spec/system/reports/admin_rules_report_spec.rb 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 1758daf..f5e9689 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/models/comment.rb b/app/models/comment.rb index d8f18d1..6a67b68 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -4,4 +4,6 @@ class Comment < ApplicationRecord belongs_to :user has_many :likes, as: :likeable, dependent: :destroy has_many :reports, as: :reportable, dependent: :destroy + + enum status: { published: 0, removed: 20 } end diff --git a/app/models/post.rb b/app/models/post.rb index 95f5b96..0a287a2 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -9,7 +9,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 } @@ -83,7 +83,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, 'não pode estar no passado') if published_at < (Time.zone.now - 1.second) + errors.add(:published_at, 'não pode estar no passado') if published_at < Time.zone.now end end 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/posts/show.html.erb b/app/views/posts/show.html.erb index 95b1540..a50650c 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -65,34 +65,37 @@ <%= @post.comments.count %> <%= Comment.model_name.human(count: @post.comments.count) %> <% @post.comments.each do |comment| %> -
-
-

<%= comment.message %>

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

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

+ <% else %> +
+

<%= comment.message %>

+
+ <%= comment.user.full_name %> <%= '(autor)' if comment.user == @post.user %> +
+
-
-
- <%= comment.likes.count %> <%= Like.model_name.human(count: comment.likes.count) %> -
+
+
+ <%= 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 'Descurtir', like_path(comment_like_id: like.id), method: :delete, class: 'btn btn-danger btn-sm' %> - <% else %> - <%= button_to 'Curtir', likes_path(comment_id: comment.id), method: :post, class: 'btn btn-primary btn-sm' %> - <% end %> -
+
+ <% 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 'Descurtir', like_path(comment_like_id: like.id), method: :delete, class: 'btn btn-danger btn-sm' %> + <% else %> + <%= button_to 'Curtir', likes_path(comment_id: comment.id), method: :post, class: 'btn btn-primary btn-sm' %> + <% end %> +
- <% if current_user != comment.user %> - +
+ <% 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 e955f7b..aa39150 100644 --- a/app/views/profiles/show.html.erb +++ b/app/views/profiles/show.html.erb @@ -76,7 +76,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 53740d6..1eafbef 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.views.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 05fbd98..ba684a6 100644 --- a/app/views/reports/index.html.erb +++ b/app/views/reports/index.html.erb @@ -6,7 +6,7 @@
@@ -15,13 +15,13 @@ <% if @reports.empty? %>

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

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

<%= I18n.t('reports.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/config/locales/comments.pt-BR.yml b/config/locales/comments.pt-BR.yml index e614aad..8494c12 100644 --- a/config/locales/comments.pt-BR.yml +++ b/config/locales/comments.pt-BR.yml @@ -11,4 +11,5 @@ pt-BR: comments: create: success: Comentário enviado com sucesso - error: Não foi possível fazer o comentário \ No newline at end of file + error: Não foi possível fazer o comentário + removed_content: Comentário removido pela administração \ No newline at end of file diff --git a/config/locales/posts.pt-BR.yml b/config/locales/posts.pt-BR.yml index 736ed35..6193795 100644 --- a/config/locales/posts.pt-BR.yml +++ b/config/locales/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: 2 create: success: "Publicação %{status} com sucesso!" error: Não foi possível criar sua publicação diff --git a/config/locales/reports.pt-BR.yml b/config/locales/reports.pt-BR.yml index 0330062..cf7162d 100644 --- a/config/locales/reports.pt-BR.yml +++ b/config/locales/reports.pt-BR.yml @@ -15,13 +15,24 @@ 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 + reject_btn: Rejeitar denúncia report_btn: Denunciar 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 reporting_profile: Denunciado por reported_when: Denunciado em see_post: Ver publicação self_report: Você não pode denúnciar sí mesmo ou o próprio conteúdo. + remove_content_btn: Remover conteúdo + + pending: Pendente + granted: Conteúdo removido + rejected: Denúncia rejeitada \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 14816a5..b0be728 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,13 +13,16 @@ resources :job_categories, only: %i[index create destroy] resources :notifications, only: %i[index] - + 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', on: :member + post 'remove_content', on: :member + end resources :users, only: [] do resources :posts, shallow: true, only: %i[show edit update] 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/schema.rb b/db/schema.rb index 2eaa5a1..b47ca3c 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_08_132247) do +ActiveRecord::Schema[7.1].define(version: 2024_02_09_191251) do create_table "action_text_rich_texts", force: :cascade do |t| t.string "name", null: false t.text "body" @@ -55,6 +55,7 @@ t.integer "user_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "status", default: 0 t.index ["post_id"], name: "index_comments_on_post_id" t.index ["user_id"], name: "index_comments_on_user_id" end @@ -158,7 +159,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-08 16:06:05" + t.datetime "edited_at", default: "2024-02-09 19:41:51" t.integer "status", default: 0 t.datetime "published_at" t.index ["user_id"], name: "index_posts_on_user_id" 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/models/post_spec.rb b/spec/models/post_spec.rb index 21d9eca..f5283ef 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -21,16 +21,6 @@ expect(post.valid?).to eq false end end - - 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) - - expect(post).not_to be_valid - expect(post.errors[:published_at]).to include('não pode estar no passado') - end - end end describe 'self.get_sample' do 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/system/posts/user_edits_post_spec.rb b/spec/system/posts/user_edits_post_spec.rb index 81d6395..e0c68f2 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 5efb205..cfdc956 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 5e40ae4..ded02d7 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 8abdd29..8a14daa 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.all('.reporting-button').size).to eq 2 end expect(page.all('.comment').to_a.second).not_to have_link 'Denunciar' end From 37cacbbfdc4e6ca97fe27cb314d589bf81ee1f20 Mon Sep 17 00:00:00 2001 From: Rosemilson Date: Fri, 9 Feb 2024 18:08:06 -0300 Subject: [PATCH 2/3] =?UTF-8?q?Fix/Corrige=20mensagem=20de=20usu=C3=A1rio?= =?UTF-8?q?=20inv=C3=A1lido?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lucas Vasques --- config/locales/posts.pt-BR.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/posts.pt-BR.yml b/config/locales/posts.pt-BR.yml index 6193795..e4e3365 100644 --- a/config/locales/posts.pt-BR.yml +++ b/config/locales/posts.pt-BR.yml @@ -21,7 +21,7 @@ pt-BR: status_published: Publicada posts: redirect_alert: - invalid_user: 2 + 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 From 8719d42e324f414d4d9ea01c02bfd4b778a71d77 Mon Sep 17 00:00:00 2001 From: Lucas Vasques Date: Tue, 13 Feb 2024 15:38:22 -0300 Subject: [PATCH 3/3] Realiza ajustes pedidos na PR --- config/routes.rb | 3 +-- spec/models/post_spec.rb | 10 ++++++++++ spec/system/reports/user_report_spec.rb | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index d797c9f..6aa8fe2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,8 +20,7 @@ end resources :reports, only: %i[index new create show] do - post 'reject', on: :member - post 'remove_content', on: :member + post 'reject', 'remove_content', on: :member end resources :users, only: [] do diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index f5283ef..f26c77d 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -21,6 +21,16 @@ expect(post.valid?).to eq false end end + + 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, status: :scheduled) + + expect(post).not_to be_valid + expect(post.errors[:published_at]).to include('não pode estar no passado') + end + end end describe 'self.get_sample' do diff --git a/spec/system/reports/user_report_spec.rb b/spec/system/reports/user_report_spec.rb index 95d04a8..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('.reporting-button').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 %><%= Report.human_attribute_name :reportable_type %><%= t('reports.action') %><%= Report.human_attribute_name :offence_type %><%= Report.human_attribute_name :message %><%= Report.human_attribute_name :reportable_type %><%= t('reports.action') %>