forked from decidim-ice/decidim-module-decidim_awesome
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show superadmins in admin accountability (#12)
* refactor initializer & presenter clasess * complete space role test * differentiate admins from space admins * add user presenter specs * fix filters * add tests for super admins * fix tests * fix permissions * Add readme instructions * update version * fix readme
- Loading branch information
1 parent
1a97b89
commit 10958f9
Showing
31 changed files
with
905 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...trollers/concerns/decidim/decidim_awesome/admin_accountability/admin/filterable_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module DecidimAwesome | ||
module AdminAccountability | ||
module Admin | ||
module FilterableHelper | ||
def extra_dropdown_submenu_options_items(_filter, _i18n_scope) | ||
Decidim.user_roles.sort.map do |role_type| | ||
link_to(I18n.t(role_type, scope: "decidim.decidim_awesome.admin.admin_accountability.admin_roles"), | ||
url_for(export_params.merge({ admin_role_type: role_type }))) | ||
end | ||
end | ||
|
||
def applied_filters_tags(i18n_ctx) | ||
if global? && params[:admin_role_type].present? | ||
content_tag(:span, class: "label secondary") do | ||
concat "#{i18n_filter_label(:admin_role_type, filterable_i18n_scope_from_ctx(i18n_ctx))}: " | ||
concat t("decidim.decidim_awesome.admin.admin_accountability.admin_roles.#{params[:admin_role_type]}", default: params[:admin_role_type]) | ||
concat icon_link_to( | ||
"circle-x", | ||
url_for(export_params.except(:admin_role_type)), | ||
t("decidim.admin.actions.cancel"), | ||
class: "action-icon--remove" | ||
) | ||
end | ||
else | ||
ransack_params.slice(*filters).map do |filter, value| | ||
applied_filter_tag(filter, value, filterable_i18n_scope_from_ctx(i18n_ctx)) | ||
end.join.html_safe | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/presenters/decidim/decidim_awesome/paper_trail_base_presenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module DecidimAwesome | ||
class PaperTrailBasePresenter | ||
attr_reader :entry, :html | ||
|
||
def initialize(entry, html: true) | ||
@entry = entry | ||
@html = html | ||
end | ||
|
||
# try to use the object in the database if exists | ||
# Note that "reify" does not work on "create" events | ||
def item | ||
@item ||= entry&.item | ||
end | ||
|
||
def item_type | ||
@item_type ||= entry&.item_type | ||
end | ||
|
||
def item_id | ||
@item_id ||= entry&.item_id | ||
end | ||
end | ||
end | ||
end |
45 changes: 45 additions & 0 deletions
45
app/presenters/decidim/decidim_awesome/participatory_space_role_presenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module DecidimAwesome | ||
class ParticipatorySpaceRolePresenter < RoleBasePresenter | ||
# Finds the destroyed entry if exists | ||
def destroy_entry | ||
@destroy_entry ||= PaperTrail::Version.find_by(item_type: item_type, event: "destroy", item_id: item_id) | ||
end | ||
|
||
# roles are in the destroyed event if the role has been removed | ||
def role | ||
@role ||= destroy_item&.role || item&.role | ||
end | ||
|
||
def role_name | ||
type = I18n.t(role, scope: "decidim.decidim_awesome.admin.admin_accountability.roles", default: role) | ||
return type unless html && role_class | ||
|
||
"<span class=\"#{role_class}\">#{type}</span>".html_safe | ||
end | ||
|
||
def user | ||
@user ||= Decidim::User.find_by(id: entry.changeset["decidim_user_id"]&.last) | ||
end | ||
|
||
# participatory spaces is in the normal entry if the role hasn't been removed | ||
# otherwise is in the removed role log entry | ||
def participatory_space | ||
item&.participatory_space || destroy_item&.participatory_space | ||
end | ||
|
||
private | ||
|
||
def role_class | ||
case role | ||
when "admin" | ||
"text-alert" | ||
when "valuator" | ||
"text-secondary" | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.