Module: Card::Set::Right::Roles

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod011-card-mod-account/right/roles.rb,
card/tmpsets/set/mod010-card-mod-account/right/roles.rb

Overview

Set: All “+Roles” cards

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'card/tmpsets/set/mod011-card-mod-account/right/roles.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-account/set/right/roles.rb"; end

Instance Method Details

#event: validate_permission_to_assign_rolesObject



8
9
10
11
12
13
14
# File 'card/tmpsets/set/mod011-card-mod-account/right/roles.rb', line 8

event :validate_permission_to_assign_roles, :validate, on: :save do
  return unless (fr = forbidden_roles).present?

  errors.add :permission_denied,
             "You don't have permission to assign the role#{'s' if fr.size > 1} "\
             "#{fr.map(&:name).to_sentence}"   # LOCALIZE
end

#forbidden_rolesObject



16
17
18
19
20
21
22
23
# File 'card/tmpsets/set/mod011-card-mod-account/right/roles.rb', line 16

def forbidden_roles
  # restore old roles for permission check
  with_old_role_permissions do |new_roles|
    new_roles.select do |card|
      !Card.fetch(card, "*members").ok? :update
    end
  end
end

#with_old_role_permissionsObject



25
26
27
28
29
30
31
32
33
34
# File 'card/tmpsets/set/mod011-card-mod-account/right/roles.rb', line 25

def with_old_role_permissions
  new_roles = item_cards
  new_content = content
  left.clear_roles
  Auth.update_always_cache Card::Auth.as_id, nil
  self.content = db_content_before_act
  yield new_roles
ensure
  self.content = new_content
end