Sha256: cb043af02a3892f98d08ffadb48f9bdc0d3b873b4a1fb8884613d59b071e0065

Contents?: true

Size: 1.11 KB

Versions: 79

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic to close a current impersonation session.
    class CloseSessionManagedUser < Rectify::Command
      # Public: Initializes the command.
      #
      # user         - The user impersonated.
      # current_user - The current user doing the impersonation.
      def initialize(user, current_user)
        @user = user
        @current_user = current_user
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the impersonation is not valid.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) if impersonation_log.blank?

        close_session

        broadcast(:ok)
      end

      attr_reader :current_user, :user

      private

      def impersonation_log
        @impersonation_log ||= Decidim::ImpersonationLog.where(admin: current_user, user: user).active.first
      end

      def close_session
        impersonation_log.ended_at = Time.current
        impersonation_log.save!
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
decidim-admin-0.12.0.pre app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.11.1 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.11.0.pre1 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.10.1 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.10.0 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.9.3 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.9.2 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.9.1 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.9.0 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.8.4 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.8.3 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.8.2 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.8.1 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.8.0 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.7.4 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.7.3 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.7.2 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.7.1 app/commands/decidim/admin/close_session_managed_user.rb
decidim-admin-0.7.0 app/commands/decidim/admin/close_session_managed_user.rb