Class: Cbac::CbacPristine::PristineRole
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cbac::CbacPristine::PristineRole
- Defined in:
- lib/cbac/cbac_pristine/pristine_role.rb
Class Method Summary collapse
Instance Method Summary collapse
- #known_permission_type ⇒ Object
-
#to_yml_fixture(fixture_id = nil) ⇒ Object
convert this cbac role to a yml statement which can be used to create a yml fixtures file executing this statement will result in one cbac_generic_role in the DB.
Class Method Details
.admin_role(use_db = true) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/cbac/cbac_pristine/pristine_role.rb', line 35 def self.admin_role(use_db = true) admin_role = use_db ? PristineRole.where(role_type: PristineRole.ROLE_TYPES[:admin]).first : nil admin_role || PristineRole.new do |role| role.role_id = 1 role.role_type = PristineRole.ROLE_TYPES[:admin] role.name = "administrator" end end |
.ROLE_TYPES ⇒ Object
8 9 10 |
# File 'lib/cbac/cbac_pristine/pristine_role.rb', line 8 def self.ROLE_TYPES {:context => "context", :generic => "generic", :admin => "administrator"} end |
Instance Method Details
#known_permission_type ⇒ Object
28 29 30 31 32 33 |
# File 'lib/cbac/cbac_pristine/pristine_role.rb', line 28 def # NOTE: known permissions use different type definitions than pristine roles. # They only use the file type to determine if it is a generic or context role. # Context roles include the admin role (same file) while pristine roles use a different type role_type == PristineRole.ROLE_TYPES[:generic] ? Cbac::KnownPermission.PERMISSION_TYPES[:generic] : Cbac::KnownPermission.PERMISSION_TYPES[:context] end |
#to_yml_fixture(fixture_id = nil) ⇒ Object
convert this cbac role to a yml statement which can be used to create a yml fixtures file executing this statement will result in one cbac_generic_role in the DB
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cbac/cbac_pristine/pristine_role.rb', line 14 def to_yml_fixture(fixture_id = nil) fixture_id = role_id if fixture_id.nil? return '' if role_type == Cbac::CbacPristine::PristineRole.ROLE_TYPES[:context] raise ArgumentError, "cannot convert role #{id.to_s} to yml, because it has no name" if name.blank? yml = "cbac_generic_role_00" << fixture_id.to_s << ":\n" yml << " id: " << fixture_id.to_s << "\n" yml << " name: " << name << "\n" yml << " created_at: " << Time.now.strftime("%Y-%m-%d %H:%M:%S") << "\n" yml << " updated_at: " << Time.now.strftime("%Y-%m-%d %H:%M:%S") << "\n" yml << "\n" end |