Sha256: 752dd3a0a65bc2562707cb1e8e40251c359de1eac356b6a0de348a31ea9cfb51

Contents?: true

Size: 781 Bytes

Versions: 44

Compression:

Stored size: 781 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    module TrusteeZone
      class Permissions < Decidim::DefaultPermissions
        def permissions
          return permission_action unless permission_action.scope == :trustee_zone

          case permission_action.subject
          when :trustee, :election
            toggle_allow(trustee_for_user?) if [:view, :update].member?(permission_action.action)
          when :user
            allow! if permission_action.action == :update_profile
          end

          permission_action
        end

        private

        def trustee_for_user?
          trustee && trustee.user == user
        end

        def trustee
          @trustee ||= context.fetch(:trustee, nil)
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-elections-0.28.4 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.27.9 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.28.3 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.27.8 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.28.2 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.27.7 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.28.1 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.27.6 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.26.10 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.26.9 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.28.0 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.27.5 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.28.0.rc5 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.28.0.rc4 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.26.8 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.27.4 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.27.3 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.26.7 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.26.5 app/permissions/decidim/elections/trustee_zone/permissions.rb
decidim-elections-0.27.2 app/permissions/decidim/elections/trustee_zone/permissions.rb