From 5d10afdf26c4ee278bb5f0104c26562c06558478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 11 Jun 2020 17:53:24 +0200 Subject: [PATCH 1/2] Fix deleting searched managers/moderators/admins We were deleting managers, moderators and administrators based on their user ID, instead of their manager/moderator/administrator ID. --- app/views/admin/administrators/search.html.erb | 2 +- app/views/admin/managers/search.html.erb | 2 +- app/views/admin/moderators/search.html.erb | 2 +- spec/system/admin/administrators_spec.rb | 10 ++++++++++ spec/system/admin/managers_spec.rb | 10 ++++++++++ spec/system/admin/moderators_spec.rb | 10 ++++++++++ 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/views/admin/administrators/search.html.erb b/app/views/admin/administrators/search.html.erb index e8beec208b1..89064f2989b 100644 --- a/app/views/admin/administrators/search.html.erb +++ b/app/views/admin/administrators/search.html.erb @@ -20,7 +20,7 @@ <% if user.administrator? && user.administrator.persisted? %> <%= link_to t("admin.administrators.administrator.delete"), - admin_administrator_path(user), + admin_administrator_path(user.administrator), method: :delete, class: "button hollow alert expanded" %> <% else %> diff --git a/app/views/admin/managers/search.html.erb b/app/views/admin/managers/search.html.erb index a986f61347c..bc6005d42d5 100644 --- a/app/views/admin/managers/search.html.erb +++ b/app/views/admin/managers/search.html.erb @@ -20,7 +20,7 @@ <% if user.manager? && user.manager.persisted? %> <%= link_to t("admin.managers.manager.delete"), - admin_manager_path(user), + admin_manager_path(user.manager), method: :delete, class: "button hollow alert expanded" %> <% else %> diff --git a/app/views/admin/moderators/search.html.erb b/app/views/admin/moderators/search.html.erb index 9f4a8d6a949..358e6704304 100644 --- a/app/views/admin/moderators/search.html.erb +++ b/app/views/admin/moderators/search.html.erb @@ -20,7 +20,7 @@ <% if user.moderator? && user.moderator.persisted? %> <%= link_to t("admin.moderators.moderator.delete"), - admin_moderator_path(user), + admin_moderator_path(user.moderator), method: :delete, class: "button hollow alert expanded" %> <% else %> diff --git a/spec/system/admin/administrators_spec.rb b/spec/system/admin/administrators_spec.rb index ae17dd47850..a97f5d38989 100644 --- a/spec/system/admin/administrators_spec.rb +++ b/spec/system/admin/administrators_spec.rb @@ -98,6 +98,16 @@ expect(page).to have_content(administrator2.email) expect(page).not_to have_content(administrator1.email) end + + scenario "Delete after searching" do + fill_in "Search user by name or email", with: administrator2.email + click_button "Search" + + click_link "Delete" + + expect(page).to have_content(administrator1.email) + expect(page).not_to have_content(administrator2.email) + end end context "Edit" do diff --git a/spec/system/admin/managers_spec.rb b/spec/system/admin/managers_spec.rb index 49bc43b6620..d3b0b30cb38 100644 --- a/spec/system/admin/managers_spec.rb +++ b/spec/system/admin/managers_spec.rb @@ -80,5 +80,15 @@ expect(page).to have_content(manager2.email) expect(page).not_to have_content(manager1.email) end + + scenario "Delete after searching" do + fill_in "Search user by name or email", with: manager2.email + click_button "Search" + + click_link "Delete" + + expect(page).to have_content(manager1.email) + expect(page).not_to have_content(manager2.email) + end end end diff --git a/spec/system/admin/moderators_spec.rb b/spec/system/admin/moderators_spec.rb index 4f984656454..c3e24d800b0 100644 --- a/spec/system/admin/moderators_spec.rb +++ b/spec/system/admin/moderators_spec.rb @@ -80,5 +80,15 @@ expect(page).to have_content(moderator2.email) expect(page).not_to have_content(moderator1.email) end + + scenario "Delete after searching" do + fill_in "Search user by name or email", with: moderator2.email + click_button "Search" + + click_link "Delete" + + expect(page).to have_content(moderator1.email) + expect(page).not_to have_content(moderator2.email) + end end end From 99256adf1368fc5711b633e403773e6e6aefb5b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 12 Jun 2019 00:02:14 +0200 Subject: [PATCH 2/2] Simplify manager/moderator/admin/official tables Originally, the code was shared between the index action and the search action, but since commit fb6dbdf2 that's no longer the case. So in the index action we don't need to check whether a user is a moderator/manager/admin/official or not; they all are. --- app/views/admin/administrators/index.html.erb | 22 ++++++------------- app/views/admin/managers/index.html.erb | 18 ++++----------- app/views/admin/moderators/index.html.erb | 17 ++++---------- app/views/admin/officials/index.html.erb | 2 +- 4 files changed, 16 insertions(+), 43 deletions(-) diff --git a/app/views/admin/administrators/index.html.erb b/app/views/admin/administrators/index.html.erb index 304760c7e03..db08c59332a 100644 --- a/app/views/admin/administrators/index.html.erb +++ b/app/views/admin/administrators/index.html.erb @@ -29,21 +29,13 @@ <%= administrator.description %> - <% if administrator.persisted? %> - <%= link_to t("admin.actions.edit"), - edit_admin_administrator_path(administrator), - class: "button hollow" %> - <%= link_to t("admin.administrators.administrator.delete"), - admin_administrator_path(administrator), - method: :delete, - class: "button hollow alert" %> - <% else %> - <%= link_to t("admin.administrators.administrator.add"), - { controller: "admin/administrators", action: :create, - user_id: administrator.user_id }, - method: :post, - class: "button success expanded" %> - <% end %> + <%= link_to t("admin.actions.edit"), + edit_admin_administrator_path(administrator), + class: "button hollow" %> + <%= link_to t("admin.administrators.administrator.delete"), + admin_administrator_path(administrator), + method: :delete, + class: "button hollow alert" %> <% end %> diff --git a/app/views/admin/managers/index.html.erb b/app/views/admin/managers/index.html.erb index b9121ac8a33..0ff1971c42c 100644 --- a/app/views/admin/managers/index.html.erb +++ b/app/views/admin/managers/index.html.erb @@ -22,20 +22,10 @@ <%= manager.email %> - <% if manager.persisted? %> - <%= link_to t("admin.managers.manager.delete"), - admin_manager_path(manager), - method: :delete, - class: "button hollow alert expanded" - %> - <% else %> - <%= link_to t("admin.managers.manager.add"), - { controller: "admin/managers", - action: :create, - user_id: manager.user_id }, - method: :post, - class: "button success expanded" %> - <% end %> + <%= link_to t("admin.managers.manager.delete"), + admin_manager_path(manager), + method: :delete, + class: "button hollow alert expanded" %> <% end %> diff --git a/app/views/admin/moderators/index.html.erb b/app/views/admin/moderators/index.html.erb index be8eff1ad2d..770fd77c5ed 100644 --- a/app/views/admin/moderators/index.html.erb +++ b/app/views/admin/moderators/index.html.erb @@ -24,19 +24,10 @@ <%= moderator.email %> - <% if moderator.persisted? %> - <%= link_to t("admin.moderators.moderator.delete"), - admin_moderator_path(moderator), - method: :delete, - class: "button hollow alert expanded" - %> - <% else %> - <%= link_to t("admin.moderators.moderator.add"), - { controller: "admin/moderators", action: :create, - user_id: moderator.user_id }, - method: :post, - class: "button success expanded" %> - <% end %> + <%= link_to t("admin.moderators.moderator.delete"), + admin_moderator_path(moderator), + method: :delete, + class: "button hollow alert expanded" %> <% end %> diff --git a/app/views/admin/officials/index.html.erb b/app/views/admin/officials/index.html.erb index 67921d3ab85..3b1e2b7dac3 100644 --- a/app/views/admin/officials/index.html.erb +++ b/app/views/admin/officials/index.html.erb @@ -28,7 +28,7 @@ <%= t("admin.officials.level_#{official.official_level}") %> - <%= link_to official.official? ? t("admin.officials.search.edit_official") : t("admin.officials.search.make_official"), + <%= link_to t("admin.officials.search.edit_official"), edit_admin_official_path(official), class: "button hollow expanded" %>