From acc84d6541080ef89edcfc60ea54bd1a9f15bb4c Mon Sep 17 00:00:00 2001 From: Anna Topalidi Date: Fri, 13 Jan 2023 13:55:45 +0100 Subject: [PATCH 1/8] add new section, add new controller, add view index --- .../admin/admin_actions_controller.rb | 20 +++++++++++++++++++ .../admin/admin_actions/index.html.erb | 8 ++++++++ config/locales/en.yml | 1 + lib/decidim/decidim_awesome/admin_engine.rb | 11 ++++++++++ 4 files changed, 40 insertions(+) create mode 100644 app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb create mode 100644 app/views/decidim/decidim_awesome/admin/admin_actions/index.html.erb diff --git a/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb b/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb new file mode 100644 index 000000000..bef39c158 --- /dev/null +++ b/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Decidim + module DecidimAwesome + module Admin + class AdminActionsController < DecidimAwesome::Admin::ApplicationController + include ConfigConstraintsHelpers + helper ConfigConstraintsHelpers + + layout "decidim/admin/users" + + def index; end + + def export_xls + # TODO: export to xls + end + end + end + end +end diff --git a/app/views/decidim/decidim_awesome/admin/admin_actions/index.html.erb b/app/views/decidim/decidim_awesome/admin/admin_actions/index.html.erb new file mode 100644 index 000000000..076d9cc31 --- /dev/null +++ b/app/views/decidim/decidim_awesome/admin/admin_actions/index.html.erb @@ -0,0 +1,8 @@ +
+
+

<%= t("menu.admin_accountability", scope: "decidim.admin", default: "Admin accountability") %>

+
+
+

List of admin actions

+
+
diff --git a/config/locales/en.yml b/config/locales/en.yml index 32f4a5124..750189738 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -60,6 +60,7 @@ en: decidim: admin: menu: + admin_accountability: Admin accountability decidim_awesome: Decidim awesome components: awesome_iframe: diff --git a/lib/decidim/decidim_awesome/admin_engine.rb b/lib/decidim/decidim_awesome/admin_engine.rb index d9c9f5818..9fec3e776 100644 --- a/lib/decidim/decidim_awesome/admin_engine.rb +++ b/lib/decidim/decidim_awesome/admin_engine.rb @@ -22,6 +22,7 @@ class AdminEngine < ::Rails::Engine resources :scoped_styles, param: :var, only: [:create, :destroy] resources :proposal_custom_fields, param: :var, only: [:create, :destroy] resources :scoped_admins, param: :var, only: [:create, :destroy] + resources :admin_actions, only: [:index, :export_xls] get :users, to: "config#users" post :rename_scope_label, to: "config#rename_scope_label" get :checks, to: "checks#index" @@ -47,6 +48,16 @@ class AdminEngine < ::Rails::Engine end end + initializer "decidim_awesome.admin_menu" do + Decidim.menu :admin_user_menu do |menu| + menu.add_item :admin_accountability, + I18n.t("menu.admin_accountability", scope: "decidim.admin", default: "Admin accountability"), + decidim_admin_decidim_awesome.admin_actions_path, + active: is_active_link?(decidim_admin_decidim_awesome.admin_actions_path, :inclusive), + position: 7 + end + end + def load_seed nil end From 7b080efb416e66a07c0fa952812310c525302f14 Mon Sep 17 00:00:00 2001 From: Anna Topalidi Date: Fri, 13 Jan 2023 15:22:04 +0100 Subject: [PATCH 2/8] add permissions to index action --- .../decidim_awesome/admin/admin_actions_controller.rb | 7 ++++--- .../decidim/decidim_awesome/admin/permissions.rb | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb b/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb index bef39c158..a49bd4a28 100644 --- a/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb +++ b/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb @@ -4,12 +4,13 @@ module Decidim module DecidimAwesome module Admin class AdminActionsController < DecidimAwesome::Admin::ApplicationController - include ConfigConstraintsHelpers - helper ConfigConstraintsHelpers + include NeedsAwesomeConfig layout "decidim/admin/users" - def index; end + def index + enforce_permission_to :index, :admin_action + end def export_xls # TODO: export to xls diff --git a/app/permissions/decidim/decidim_awesome/admin/permissions.rb b/app/permissions/decidim/decidim_awesome/admin/permissions.rb index 00bda6d58..6143593cc 100644 --- a/app/permissions/decidim/decidim_awesome/admin/permissions.rb +++ b/app/permissions/decidim/decidim_awesome/admin/permissions.rb @@ -11,6 +11,8 @@ def permissions return permission_action unless user return permission_action if user.read_attribute("admin").blank? + allow! if permission_action.action == :index && permission_action.subject == :admin_action + toggle_allow(config_enabled?(permission_action.subject)) if permission_action.action == :edit_config permission_action From 8866d2f3e2f9f9b1cb1adc552bd69ee87c36fb12 Mon Sep 17 00:00:00 2001 From: Anna Topalidi Date: Fri, 13 Jan 2023 16:15:01 +0100 Subject: [PATCH 3/8] add rspec tests --- .../admin/admin_actions_controller_spec.rb | 26 +++++++++++++++++ .../system/admin/admin_accountability_spec.rb | 29 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 spec/controllers/admin/admin_actions_controller_spec.rb create mode 100644 spec/system/admin/admin_accountability_spec.rb diff --git a/spec/controllers/admin/admin_actions_controller_spec.rb b/spec/controllers/admin/admin_actions_controller_spec.rb new file mode 100644 index 000000000..f77fb9897 --- /dev/null +++ b/spec/controllers/admin/admin_actions_controller_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim::DecidimAwesome + module Admin + describe AdminActionsController, type: :controller do + routes { Decidim::DecidimAwesome::AdminEngine.routes } + + let(:user) { create(:user, :confirmed, :admin, organization: organization) } + let(:organization) { create(:organization) } + + before do + request.env["decidim.current_organization"] = user.organization + sign_in user, scope: :user + end + + describe "GET #index" do + it "returns http success" do + get :index, params: {} + expect(response).to have_http_status(:success) + end + end + end + end +end diff --git a/spec/system/admin/admin_accountability_spec.rb b/spec/system/admin/admin_accountability_spec.rb new file mode 100644 index 000000000..6bbc9499d --- /dev/null +++ b/spec/system/admin/admin_accountability_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "Admin accountability", type: :system do + let(:organization) { create :organization } + let!(:user) { create :user, :admin, :confirmed, organization: organization } + + before do + switch_to_host(organization.host) + login_as user, scope: :user + + visit decidim_admin.root_path + click_link "Participants" + end + + context "when admin goes to 'Participants' page" do + it "shows 'Admin accountability' submenu" do + expect(page).to have_link("Admin accountability") + end + end + + context "when admin clicks on 'Admin accountability' submenu" do + it "has title page" do + click_link "Admin accountability" + expect(page).to have_css("h2", class: "card-title", text: "Admin accountability") + end + end +end From 33393578d409743593328f96de52dee4fc198fa1 Mon Sep 17 00:00:00 2001 From: Anna Topalidi Date: Mon, 16 Jan 2023 12:31:28 +0100 Subject: [PATCH 4/8] add var to config and rspec --- .../decidim_awesome/admin/permissions.rb | 13 +++++++-- lib/decidim/decidim_awesome/admin_engine.rb | 2 ++ lib/decidim/decidim_awesome/awesome.rb | 5 ++++ .../admin/admin_actions_controller_spec.rb | 20 +++++++++++-- spec/permissions/admin/permissions_spec.rb | 28 +++++++++++++++++++ .../system/admin/admin_accountability_spec.rb | 22 +++++++++------ 6 files changed, 77 insertions(+), 13 deletions(-) diff --git a/app/permissions/decidim/decidim_awesome/admin/permissions.rb b/app/permissions/decidim/decidim_awesome/admin/permissions.rb index 6143593cc..6b8c0c2a5 100644 --- a/app/permissions/decidim/decidim_awesome/admin/permissions.rb +++ b/app/permissions/decidim/decidim_awesome/admin/permissions.rb @@ -11,12 +11,21 @@ def permissions return permission_action unless user return permission_action if user.read_attribute("admin").blank? - allow! if permission_action.action == :index && permission_action.subject == :admin_action - toggle_allow(config_enabled?(permission_action.subject)) if permission_action.action == :edit_config + case permission_action.action + when :index + admin_accountability_enabled? + end + permission_action end + + private + + def admin_accountability_enabled? + toggle_allow(Decidim::DecidimAwesome.allow_admin_accountability) + end end end end diff --git a/lib/decidim/decidim_awesome/admin_engine.rb b/lib/decidim/decidim_awesome/admin_engine.rb index 9fec3e776..f10e80f92 100644 --- a/lib/decidim/decidim_awesome/admin_engine.rb +++ b/lib/decidim/decidim_awesome/admin_engine.rb @@ -49,6 +49,8 @@ class AdminEngine < ::Rails::Engine end initializer "decidim_awesome.admin_menu" do + return unless Decidim::DecidimAwesome.allow_admin_accountability + Decidim.menu :admin_user_menu do |menu| menu.add_item :admin_accountability, I18n.t("menu.admin_accountability", scope: "decidim.admin", default: "Admin accountability"), diff --git a/lib/decidim/decidim_awesome/awesome.rb b/lib/decidim/decidim_awesome/awesome.rb index 10219e02c..29a35ae4e 100644 --- a/lib/decidim/decidim_awesome/awesome.rb +++ b/lib/decidim/decidim_awesome/awesome.rb @@ -221,6 +221,11 @@ module DecidimAwesome } end + # allows to enable admin_accountability if true + config_accessor :allow_admin_accountability do + true + end + # # HELPERS # diff --git a/spec/controllers/admin/admin_actions_controller_spec.rb b/spec/controllers/admin/admin_actions_controller_spec.rb index f77fb9897..071008ec9 100644 --- a/spec/controllers/admin/admin_actions_controller_spec.rb +++ b/spec/controllers/admin/admin_actions_controller_spec.rb @@ -9,16 +9,30 @@ module Admin let(:user) { create(:user, :confirmed, :admin, organization: organization) } let(:organization) { create(:organization) } + let(:allow_admin_accountability) { true } before do request.env["decidim.current_organization"] = user.organization sign_in user, scope: :user + + allow(Decidim::DecidimAwesome.config).to receive(:allow_admin_accountability).and_return(allow_admin_accountability) end describe "GET #index" do - it "returns http success" do - get :index, params: {} - expect(response).to have_http_status(:success) + context "when admin accountability is enabled" do + it "returns http success" do + get :index, params: {} + expect(response).to have_http_status(:success) + end + end + + context "when admin accountability is disabled" do + let!(:allow_admin_accountability) { false } + + it "returns http success" do + get :index, params: {} + expect(response).to have_http_status(:found) + end end end end diff --git a/spec/permissions/admin/permissions_spec.rb b/spec/permissions/admin/permissions_spec.rb index eeb219417..6febe0529 100644 --- a/spec/permissions/admin/permissions_spec.rb +++ b/spec/permissions/admin/permissions_spec.rb @@ -63,5 +63,33 @@ module Decidim::DecidimAwesome::Admin it_behaves_like "permission is not set" end + + context "when admin_accountability is enabled" do + before do + allow(Decidim::DecidimAwesome.config).to receive(:allow_admin_accountability).and_return(true) + end + + context "when action is index" do + let(:action) do + { scope: :admin, action: :index, subject: :admin_actions } + end + + it { is_expected.to eq true } + end + end + + context "when admin_accountability is disabled" do + before do + allow(Decidim::DecidimAwesome.config).to receive(:allow_admin_accountability).and_return(false) + end + + context "when action is index" do + let(:action) do + { scope: :admin, action: :index, subject: :admin_actions } + end + + it { is_expected.to eq false } + end + end end end diff --git a/spec/system/admin/admin_accountability_spec.rb b/spec/system/admin/admin_accountability_spec.rb index 6bbc9499d..3a3c28aee 100644 --- a/spec/system/admin/admin_accountability_spec.rb +++ b/spec/system/admin/admin_accountability_spec.rb @@ -11,19 +11,25 @@ login_as user, scope: :user visit decidim_admin.root_path - click_link "Participants" end - context "when admin goes to 'Participants' page" do - it "shows 'Admin accountability' submenu" do - expect(page).to have_link("Admin accountability") + context "when admin accountability is enabled" do + it "shows the admin accountability link" do + click_link "Participants" + + expect(page).to have_content("Admin accountability") end end - context "when admin clicks on 'Admin accountability' submenu" do - it "has title page" do - click_link "Admin accountability" - expect(page).to have_css("h2", class: "card-title", text: "Admin accountability") + context "when admin accountability is disabled" do + before do + allow(Decidim::DecidimAwesome).to receive(:allow_admin_accountability).and_return(false) + end + + it "does not show the admin accountability link" do + click_link "Participants" + + expect(page).not_to have_content("Admin accountability") end end end From 5c93319f9b07fc6ca6a81ab25f495477252be2f3 Mon Sep 17 00:00:00 2001 From: Anna Topalidi Date: Mon, 16 Jan 2023 12:46:32 +0100 Subject: [PATCH 5/8] fix initializer --- lib/decidim/decidim_awesome/admin_engine.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/decidim/decidim_awesome/admin_engine.rb b/lib/decidim/decidim_awesome/admin_engine.rb index f10e80f92..ee4d17d5f 100644 --- a/lib/decidim/decidim_awesome/admin_engine.rb +++ b/lib/decidim/decidim_awesome/admin_engine.rb @@ -49,14 +49,14 @@ class AdminEngine < ::Rails::Engine end initializer "decidim_awesome.admin_menu" do - return unless Decidim::DecidimAwesome.allow_admin_accountability - - Decidim.menu :admin_user_menu do |menu| - menu.add_item :admin_accountability, - I18n.t("menu.admin_accountability", scope: "decidim.admin", default: "Admin accountability"), - decidim_admin_decidim_awesome.admin_actions_path, - active: is_active_link?(decidim_admin_decidim_awesome.admin_actions_path, :inclusive), - position: 7 + Decidim.menu :admin_user_menu do |menu| + if Decidim::DecidimAwesome.allow_admin_accountability + menu.add_item :admin_accountability, + I18n.t("menu.admin_accountability", scope: "decidim.admin", default: "Admin accountability"), + decidim_admin_decidim_awesome.admin_actions_path, + active: is_active_link?(decidim_admin_decidim_awesome.admin_actions_path, :inclusive), + position: 7 + end end end From a3eed45c8b22148b3758c6d6d64547ba26e5f980 Mon Sep 17 00:00:00 2001 From: Anna Topalidi Date: Mon, 16 Jan 2023 12:47:35 +0100 Subject: [PATCH 6/8] fix lint --- lib/decidim/decidim_awesome/admin_engine.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/decidim/decidim_awesome/admin_engine.rb b/lib/decidim/decidim_awesome/admin_engine.rb index ee4d17d5f..445873cba 100644 --- a/lib/decidim/decidim_awesome/admin_engine.rb +++ b/lib/decidim/decidim_awesome/admin_engine.rb @@ -49,8 +49,8 @@ class AdminEngine < ::Rails::Engine end initializer "decidim_awesome.admin_menu" do - Decidim.menu :admin_user_menu do |menu| - if Decidim::DecidimAwesome.allow_admin_accountability + Decidim.menu :admin_user_menu do |menu| + if Decidim::DecidimAwesome.allow_admin_accountability menu.add_item :admin_accountability, I18n.t("menu.admin_accountability", scope: "decidim.admin", default: "Admin accountability"), decidim_admin_decidim_awesome.admin_actions_path, From 475612c83da6a9a9e39ae2b9523541adc038bb4b Mon Sep 17 00:00:00 2001 From: Anna Topalidi Date: Mon, 16 Jan 2023 14:10:36 +0100 Subject: [PATCH 7/8] fix permissions --- .../decidim_awesome/admin/admin_actions_controller.rb | 2 +- .../decidim/decidim_awesome/admin/permissions.rb | 6 +++--- lib/decidim/decidim_awesome/admin_engine.rb | 4 ++-- lib/decidim/decidim_awesome/awesome.rb | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb b/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb index a49bd4a28..3191b56f5 100644 --- a/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb +++ b/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb @@ -9,7 +9,7 @@ class AdminActionsController < DecidimAwesome::Admin::ApplicationController layout "decidim/admin/users" def index - enforce_permission_to :index, :admin_action + enforce_permission_to :index, :admin_accountability end def export_xls diff --git a/app/permissions/decidim/decidim_awesome/admin/permissions.rb b/app/permissions/decidim/decidim_awesome/admin/permissions.rb index 6b8c0c2a5..942fc6bee 100644 --- a/app/permissions/decidim/decidim_awesome/admin/permissions.rb +++ b/app/permissions/decidim/decidim_awesome/admin/permissions.rb @@ -13,8 +13,8 @@ def permissions toggle_allow(config_enabled?(permission_action.subject)) if permission_action.action == :edit_config - case permission_action.action - when :index + case permission_action.subject + when :admin_accountability admin_accountability_enabled? end @@ -24,7 +24,7 @@ def permissions private def admin_accountability_enabled? - toggle_allow(Decidim::DecidimAwesome.allow_admin_accountability) + toggle_allow(Decidim::DecidimAwesome.allow_admin_accountability == true) end end end diff --git a/lib/decidim/decidim_awesome/admin_engine.rb b/lib/decidim/decidim_awesome/admin_engine.rb index 445873cba..70af4bdf6 100644 --- a/lib/decidim/decidim_awesome/admin_engine.rb +++ b/lib/decidim/decidim_awesome/admin_engine.rb @@ -49,8 +49,8 @@ class AdminEngine < ::Rails::Engine end initializer "decidim_awesome.admin_menu" do - Decidim.menu :admin_user_menu do |menu| - if Decidim::DecidimAwesome.allow_admin_accountability + if Decidim::DecidimAwesome.allow_admin_accountability + Decidim.menu :admin_user_menu do |menu| menu.add_item :admin_accountability, I18n.t("menu.admin_accountability", scope: "decidim.admin", default: "Admin accountability"), decidim_admin_decidim_awesome.admin_actions_path, diff --git a/lib/decidim/decidim_awesome/awesome.rb b/lib/decidim/decidim_awesome/awesome.rb index 29a35ae4e..3bfdbb60d 100644 --- a/lib/decidim/decidim_awesome/awesome.rb +++ b/lib/decidim/decidim_awesome/awesome.rb @@ -221,7 +221,7 @@ module DecidimAwesome } end - # allows to enable admin_accountability if true + # If true, enables a new section in "Participants" where to audit all the admin roles that have been enabled/disabled historically in Decidim config_accessor :allow_admin_accountability do true end From b4ae9d8c88ada05cd337664b80526fb33512e82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Mon, 16 Jan 2023 14:38:07 +0100 Subject: [PATCH 8/8] refactor permissions handling --- .../admin/admin_actions_controller.rb | 7 +++-- .../decidim_awesome/admin/permissions.rb | 11 ------- lib/decidim/decidim_awesome/admin_engine.rb | 4 +-- lib/decidim/decidim_awesome/awesome.rb | 1 + .../admin/admin_actions_controller_spec.rb | 2 +- spec/permissions/admin/permissions_spec.rb | 29 ++++++------------- .../system/admin/admin_accountability_spec.rb | 6 ++-- 7 files changed, 20 insertions(+), 40 deletions(-) diff --git a/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb b/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb index 3191b56f5..62d813531 100644 --- a/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb +++ b/app/controllers/decidim/decidim_awesome/admin/admin_actions_controller.rb @@ -7,11 +7,12 @@ class AdminActionsController < DecidimAwesome::Admin::ApplicationController include NeedsAwesomeConfig layout "decidim/admin/users" - - def index - enforce_permission_to :index, :admin_accountability + before_action do + enforce_permission_to :edit_config, :allow_admin_accountability end + def index; end + def export_xls # TODO: export to xls end diff --git a/app/permissions/decidim/decidim_awesome/admin/permissions.rb b/app/permissions/decidim/decidim_awesome/admin/permissions.rb index 942fc6bee..00bda6d58 100644 --- a/app/permissions/decidim/decidim_awesome/admin/permissions.rb +++ b/app/permissions/decidim/decidim_awesome/admin/permissions.rb @@ -13,19 +13,8 @@ def permissions toggle_allow(config_enabled?(permission_action.subject)) if permission_action.action == :edit_config - case permission_action.subject - when :admin_accountability - admin_accountability_enabled? - end - permission_action end - - private - - def admin_accountability_enabled? - toggle_allow(Decidim::DecidimAwesome.allow_admin_accountability == true) - end end end end diff --git a/lib/decidim/decidim_awesome/admin_engine.rb b/lib/decidim/decidim_awesome/admin_engine.rb index 70af4bdf6..6ddc91fa6 100644 --- a/lib/decidim/decidim_awesome/admin_engine.rb +++ b/lib/decidim/decidim_awesome/admin_engine.rb @@ -49,8 +49,8 @@ class AdminEngine < ::Rails::Engine end initializer "decidim_awesome.admin_menu" do - if Decidim::DecidimAwesome.allow_admin_accountability - Decidim.menu :admin_user_menu do |menu| + Decidim.menu :admin_user_menu do |menu| + if DecidimAwesome.enabled? :allow_admin_accountability menu.add_item :admin_accountability, I18n.t("menu.admin_accountability", scope: "decidim.admin", default: "Admin accountability"), decidim_admin_decidim_awesome.admin_actions_path, diff --git a/lib/decidim/decidim_awesome/awesome.rb b/lib/decidim/decidim_awesome/awesome.rb index 3bfdbb60d..b993285df 100644 --- a/lib/decidim/decidim_awesome/awesome.rb +++ b/lib/decidim/decidim_awesome/awesome.rb @@ -222,6 +222,7 @@ module DecidimAwesome end # If true, enables a new section in "Participants" where to audit all the admin roles that have been enabled/disabled historically in Decidim + # Set to :disabled to completly remove this feature config_accessor :allow_admin_accountability do true end diff --git a/spec/controllers/admin/admin_actions_controller_spec.rb b/spec/controllers/admin/admin_actions_controller_spec.rb index 071008ec9..776bb9d67 100644 --- a/spec/controllers/admin/admin_actions_controller_spec.rb +++ b/spec/controllers/admin/admin_actions_controller_spec.rb @@ -27,7 +27,7 @@ module Admin end context "when admin accountability is disabled" do - let!(:allow_admin_accountability) { false } + let!(:allow_admin_accountability) { :disabled } it "returns http success" do get :index, params: {} diff --git a/spec/permissions/admin/permissions_spec.rb b/spec/permissions/admin/permissions_spec.rb index 6febe0529..819465f53 100644 --- a/spec/permissions/admin/permissions_spec.rb +++ b/spec/permissions/admin/permissions_spec.rb @@ -64,31 +64,20 @@ module Decidim::DecidimAwesome::Admin it_behaves_like "permission is not set" end - context "when admin_accountability is enabled" do - before do - allow(Decidim::DecidimAwesome.config).to receive(:allow_admin_accountability).and_return(true) - end - - context "when action is index" do - let(:action) do - { scope: :admin, action: :index, subject: :admin_actions } - end - - it { is_expected.to eq true } - end - end + context "when accessing admin_accountability" do + let(:feature) { :allow_admin_accountability } + let(:status) { true } - context "when admin_accountability is disabled" do before do - allow(Decidim::DecidimAwesome.config).to receive(:allow_admin_accountability).and_return(false) + allow(Decidim::DecidimAwesome.config).to receive(:allow_admin_accountability).and_return(status) end - context "when action is index" do - let(:action) do - { scope: :admin, action: :index, subject: :admin_actions } - end + it { is_expected.to eq true } + + context "when admin_accountability is disabled" do + let(:status) { :disabled } - it { is_expected.to eq false } + it_behaves_like "permission is not set" end end end diff --git a/spec/system/admin/admin_accountability_spec.rb b/spec/system/admin/admin_accountability_spec.rb index 3a3c28aee..6cc450b50 100644 --- a/spec/system/admin/admin_accountability_spec.rb +++ b/spec/system/admin/admin_accountability_spec.rb @@ -5,8 +5,10 @@ describe "Admin accountability", type: :system do let(:organization) { create :organization } let!(:user) { create :user, :admin, :confirmed, organization: organization } + let(:status) { true } before do + allow(Decidim::DecidimAwesome.config).to receive(:allow_admin_accountability).and_return(status) switch_to_host(organization.host) login_as user, scope: :user @@ -22,9 +24,7 @@ end context "when admin accountability is disabled" do - before do - allow(Decidim::DecidimAwesome).to receive(:allow_admin_accountability).and_return(false) - end + let(:status) { :disabled } it "does not show the admin accountability link" do click_link "Participants"