Class: Goldberg::Credentials
- Defined in:
- lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#controllers ⇒ Object
Returns the value of attribute controllers.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#permission_ids ⇒ Object
Returns the value of attribute permission_ids.
-
#role_id ⇒ Object
Returns the value of attribute role_id.
-
#role_ids ⇒ Object
Returns the value of attribute role_ids.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #action_authorised?(controller, action) ⇒ Boolean
- #controller_authorised?(controller) ⇒ Boolean
-
#initialize(role_id) ⇒ Credentials
constructor
Create a new credentials object for the given role.
- #page_authorised?(page) ⇒ Boolean
Constructor Details
#initialize(role_id) ⇒ Credentials
Create a new credentials object for the given role
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 10 def initialize(role_id) @role_id = role_id role = Role.find(@role_id) @updated_at = role.updated_at roles = role.get_parents @role_ids = Array.new for r in roles do @role_ids << r.id end = Permission.find_for_role(@role_ids) @permission_ids = Array.new for p in do @permission_ids << p.id end if @permission_ids.length < 1 @permission_ids << 0 end actions = ControllerAction.actions_allowed(@permission_ids) @actions = Hash.new for a in actions do @actions[a.site_controller.name] ||= Hash.new if a.allowed.to_i == 1 @actions[a.site_controller.name][a.name] = true else @actions[a.site_controller.name][a.name] = false end end sc = SiteController.table_name controllers = SiteController.find_by_sql ["select sc.*, (case when permission_id in (?) then 1 else 0 end) as allowed from #{sc} sc", @permission_ids] @controllers = Hash.new for c in controllers do if c.allowed.to_i == 1 @controllers[c.name] = true else @controllers[c.name] = false end end cp = ContentPage.table_name pages = ContentPage.find_by_sql ["select id, name, permission_id, (case when permission_id in (?) then 1 else 0 end) as allowed from #{cp}", @permission_ids] @pages = Hash.new for p in pages do if p.allowed.to_i == 1 @pages[p.name] = true else @pages[p.name] = false end end end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
6 7 8 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 6 def actions @actions end |
#controllers ⇒ Object
Returns the value of attribute controllers.
6 7 8 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 6 def controllers @controllers end |
#pages ⇒ Object
Returns the value of attribute pages.
6 7 8 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 6 def pages @pages end |
#permission_ids ⇒ Object
Returns the value of attribute permission_ids.
5 6 7 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 5 def @permission_ids end |
#role_id ⇒ Object
Returns the value of attribute role_id.
4 5 6 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 4 def role_id @role_id end |
#role_ids ⇒ Object
Returns the value of attribute role_ids.
4 5 6 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 4 def role_ids @role_ids end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
4 5 6 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 4 def updated_at @updated_at end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 7 def user @user end |
Instance Method Details
#action_authorised?(controller, action) ⇒ Boolean
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 81 def (controller, action) = false # default check_controller = false # Check if there's a specific permission for an action if @actions.has_key?(controller) if @actions[controller].has_key?(action) if @actions[controller][action] # logger.info "Action: authorised" = true else # logger.info "Action: NOT authorised" end else check_controller = true end else check_controller = true end # Check if there's a general permission for a controller if check_controller = (controller) end # logger.info "Authorised? #{authorised.to_s}" return end |
#controller_authorised?(controller) ⇒ Boolean
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 67 def (controller) = false # default if @controllers.has_key?(controller) if @controllers[controller] # logger.info "Controller: authorised" = true else # logger.info "Controller: NOT authorised" end else end return end |
#page_authorised?(page) ⇒ Boolean
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/credentials.rb', line 110 def (page) = false # default if page and @pages.has_key?(page.to_s) if @pages[page.to_s] == true # logger.info "Page: authorised" = true else # logger.info "Page: NOT authorised" end else # logger.warn "(Unknown page? #{page})" end return end |