Sha256: ac32b52e8b0b8b8219d43ceaec5df331c2ecf477ae0cded5788b7f050e8109dc
Contents?: true
Size: 1.43 KB
Versions: 2
Compression:
Stored size: 1.43 KB
Contents
# frozen_string_literal: true module Decidim # Default permissions class for all components and spaces. It disauthorizes all # actions by any kind of user. Also works as a default implementation so other # components can inherit from it and get some cenvenience methods. class DefaultPermissions def initialize(user, permission_action, context = {}) @user = user @permission_action = permission_action @context = context end def permissions permission_action end private attr_reader :user, :permission_action, :context def disallow! permission_action.disallow! end def allow! permission_action.allow! end def toggle_allow(condition) condition ? allow! : disallow! end def read_participatory_space_action? permission_action.action == :read && [:participatory_space, :component].include?(permission_action.subject) end def authorized?(permission_action) return unless component ActionAuthorizer.new(user, component, permission_action).authorize.ok? end def current_settings @current_settings ||= context.fetch(:current_settings, nil) end def component_settings @component_settings ||= context.fetch(:component_settings, nil) end def component @component ||= context.fetch(:current_component) end def space @space ||= component.participatory_space end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
decidim-core-0.12.0 | app/permissions/decidim/default_permissions.rb |
decidim-core-0.12.0.pre | app/permissions/decidim/default_permissions.rb |