Sha256: 39ce08cdd1d7d676c4ed4e799dac529b165160384da68b6bfae7c9b79a2f2ccb

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

# 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:, event: "destroy", 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-decidim_awesome-0.11.2 app/presenters/decidim/decidim_awesome/participatory_space_role_presenter.rb
decidim-decidim_awesome-0.11.1 app/presenters/decidim/decidim_awesome/participatory_space_role_presenter.rb