Class: Decidim::DecidimAwesome::PaperTrailVersion
- Inherits:
-
PaperTrail::Version
- Object
- PaperTrail::Version
- Decidim::DecidimAwesome::PaperTrailVersion
- Defined in:
- app/models/decidim/decidim_awesome/paper_trail_version.rb
Class Method Summary collapse
- .admin_role_actions(filter = nil) ⇒ Object
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(_auth_object = nil) ⇒ Object
- .safe_admin_role_type(admin_role) ⇒ Object
- .safe_user_roles ⇒ Object
Instance Method Summary collapse
Class Method Details
.admin_role_actions(filter = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/decidim/decidim_awesome/paper_trail_version.rb', line 34 def self.admin_role_actions(filter = nil) base = where(item_type: "Decidim::UserBaseEntity", event: %w(create update)) case filter when nil base.where( "object_changes @> ?::jsonb OR object_changes @> ?::jsonb", { "roles" => [[], []] }.to_json, { "admin" => [false, true] }.to_json ) when "admin" base.where("object_changes @> ?::jsonb", { "admin" => [false, true] }.to_json) else base.where("object_changes @> ?::jsonb", { "roles" => [[], [filter]] }.to_json) end end |
.ransackable_associations(_auth_object = nil) ⇒ Object
125 126 127 |
# File 'app/models/decidim/decidim_awesome/paper_trail_version.rb', line 125 def self.ransackable_associations(_auth_object = nil) ["item"] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
121 122 123 |
# File 'app/models/decidim/decidim_awesome/paper_trail_version.rb', line 121 def self.ransackable_attributes(_auth_object = nil) %w(created_at event id item_id item_type object object_changes participatory_space_type role_type user_email user_name whodunnit) end |
.safe_admin_role_type(admin_role) ⇒ Object
12 13 14 |
# File 'app/models/decidim/decidim_awesome/paper_trail_version.rb', line 12 def self.safe_admin_role_type(admin_role) Decidim.user_roles.find { |role| role == admin_role } end |
.safe_user_roles ⇒ Object
8 9 10 |
# File 'app/models/decidim/decidim_awesome/paper_trail_version.rb', line 8 def self.safe_user_roles DecidimAwesome.participatory_space_roles.filter(&:safe_constantize) end |
Instance Method Details
#present(html: true) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'app/models/decidim/decidim_awesome/paper_trail_version.rb', line 50 def present(html: true) @present ||= if item_type == "Decidim::UserBaseEntity" UserEntityPresenter.new(self, html:) elsif item_type.in?(PaperTrailVersion.safe_user_roles) ParticipatorySpaceRolePresenter.new(self, html:) else self end end |