Sha256: 7fbd2c98783a0bd7f258504b7c05b9aa24443cbe569b6998f2e222afb5f8a8bc

Contents?: true

Size: 989 Bytes

Versions: 34

Compression:

Stored size: 989 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Abilities
      # Defines the abilities related to meetings for a logged in user.
      # Intended to be used with `cancancan`.
      class CurrentUserAbility
        include CanCan::Ability

        attr_reader :user, :context

        def initialize(user, context)
          return unless user

          @user = user
          @context = context

          can :join, Meeting do |meeting|
            authorized?(:join) && meeting.registrations_enabled?
          end

          can :leave, Meeting, &:registrations_enabled?
        end

        private

        def authorized?(action)
          return unless feature

          ActionAuthorizer.new(user, feature, action).authorize.ok?
        end

        def feature
          feature = context.fetch(:current_feature, nil)
          return nil unless feature && feature.manifest.name == :meetings

          feature
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
decidim-meetings-0.10.1 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.10.0 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.9.3 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.9.2 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.9.1 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.9.0 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.8.4 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.8.3 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.8.2 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.8.1 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.8.0 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.7.4 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.7.3 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.7.2 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.7.1 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.7.0 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.6.8 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-0.6.8 decidim-meetings/app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-meetings-0.6.7 app/models/decidim/meetings/abilities/current_user_ability.rb
decidim-0.6.7 decidim-meetings/app/models/decidim/meetings/abilities/current_user_ability.rb