Sha256: e368eb7461aa4a5d9ae86f5802859bb649c94bef440db36ecf3ebc67e6a2547a

Contents?: true

Size: 1.02 KB

Versions: 46

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Decidim
  module Surveys
    module Abilities
      # Defines the abilities related to surveys 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 :answer, Survey if authorized?(:answer)
        end

        private

        def authorized?(action)
          return unless feature

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

        def current_settings
          context.fetch(:current_settings, nil)
        end

        def feature_settings
          context.fetch(:feature_settings, nil)
        end

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

          feature
        end
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 2 rubygems

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