Class: Decidim::DecidimAwesome::UserEntityPresenter
- Inherits:
-
RoleBasePresenter
- Object
- PaperTrailBasePresenter
- RoleBasePresenter
- Decidim::DecidimAwesome::UserEntityPresenter
- Defined in:
- app/presenters/decidim/decidim_awesome/user_entity_presenter.rb
Instance Attribute Summary
Attributes inherited from PaperTrailBasePresenter
Instance Method Summary collapse
-
#destroy_entry ⇒ Object
Finds the destroyed entry if exists.
- #role_name ⇒ Object
- #roles ⇒ Object
- #user ⇒ Object
Methods inherited from RoleBasePresenter
#created_at, #created_date, #destroy_item, #destroyed_at, #last_sign_in_date, #participatory_space, #participatory_space_name, #participatory_space_path, #participatory_space_type, #removal_date, #user_email, #user_name
Methods inherited from PaperTrailBasePresenter
#initialize, #item, #item_id, #item_type
Constructor Details
This class inherits a constructor from Decidim::DecidimAwesome::PaperTrailBasePresenter
Instance Method Details
#destroy_entry ⇒ Object
Finds the destroyed entry if exists
7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/presenters/decidim/decidim_awesome/user_entity_presenter.rb', line 7 def destroy_entry @destroy_entry ||= begin query = PaperTrail::Version.where(item_type:, event: "update", item_id:) .where("id > ?", entry.id) if roles.include? "admin" query.where("object_changes LIKE '%\nadmin:\n- true\n- false%'").first else query.where("object_changes LIKE '%\nroles:\n- - %'").first end end end |
#role_name ⇒ Object
27 28 29 30 31 32 |
# File 'app/presenters/decidim/decidim_awesome/user_entity_presenter.rb', line 27 def role_name types = roles.index_with { |role| I18n.t(role, scope: "decidim.decidim_awesome.admin.admin_accountability.admin_roles", default: role) } return types.values.join(", ") unless html types.map { |role, type| "<span class=\"#{role_class(role)}\">#{type}</span>" }.join(" ").html_safe end |
#roles ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/presenters/decidim/decidim_awesome/user_entity_presenter.rb', line 19 def roles @roles ||= begin rls = entry.changeset["roles"]&.last || [] rls << "admin" if entry.changeset["admin"]&.last rls end end |
#user ⇒ Object
34 35 36 |
# File 'app/presenters/decidim/decidim_awesome/user_entity_presenter.rb', line 34 def user @user ||= entry&.item || Decidim::User.find_by(id: entry.changeset["id"]&.last) end |