Sha256: 05babb2408c03c0da0e26d0cee7fb7332cab94c242e4df96ad3fece81f721c62

Contents?: true

Size: 1.62 KB

Versions: 19

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

module Decidim
  module AdminLog
    # This class holds the logic to present a `Decidim::User`
    # for the `AdminLog` log.
    #
    # Usage should be automatic and you shouldn't need to call this class
    # directly, but here's an example:
    #
    #    action_log = Decidim::ActionLog.last
    #    view_helpers # => this comes from the views
    #    UserPresenter.new(action_log, view_helpers).present
    class UserPresenter < Decidim::Log::BasePresenter
      private

      def action_string
        case action
        when "invite", "officialize", "remove_from_admin", "unofficialize"
          "decidim.admin_log.user.#{action}"
        else
          super
        end
      end

      def i18n_params
        super.merge(
          role: I18n.t("models.user.fields.roles.#{user_role}", scope: "decidim.admin")
        )
      end

      def user_role
        action_log.extra.dig("extra", "invited_user_role")
      end

      def user_badge
        action_log.extra.dig("extra", "officialized_user_badge") || Hash.new("")
      end

      def previous_user_badge
        action_log.extra.dig("extra", "officialized_user_badge_previous") || Hash.new("")
      end

      # We fake the changeset for officialization actions.
      def changeset
        Decidim::Log::DiffChangesetCalculator.new(
          { badge: [previous_user_badge, user_badge] },
          { badge: :i18n },
          i18n_labels_scope
        ).changeset
      end

      # If the action is officialization, then we want to show the diff
      def has_diff?
        %w(officialize unofficialize).include?(action)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-core-0.15.2 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.15.1 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.15.0 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.14.4 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.14.3 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.14.2 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.14.1 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.13.1 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.12.2 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.13.0 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.12.1 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.13.0.pre1 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.12.0 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.11.2 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.12.0.pre app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.11.1 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.11.0.pre1 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.10.1 app/presenters/decidim/admin_log/user_presenter.rb
decidim-core-0.10.0 app/presenters/decidim/admin_log/user_presenter.rb