Module: Lockdown::Access
- Defined in:
- lib/lockdown/access.rb
Instance Method Summary collapse
-
#configure ⇒ Object
Method called by Lockdown::Delivery to trigger parsing of class methods.
-
#permission(name) {|Lockdown::Permission.new(name)| ... } ⇒ Object
Define permision that defines how your application is accessed.
-
#protected_access(*permissions) ⇒ Object
Define which permissions are accessible to everyone protected_access :my_account, :site_administration.
-
#public_access(*permissions) ⇒ Object
Define which permissions are accessible to everyone public_access :site, :user_registration.
-
#user_group(name, *permissions) ⇒ Object
Create user group by giving it a name and a list of permission names.
Instance Method Details
#configure ⇒ Object
Method called by Lockdown::Delivery to trigger parsing of class methods
92 93 94 95 96 97 |
# File 'lib/lockdown/access.rb', line 92 def configure unless Lockdown::Configuration.configured Lockdown::Database.sync_with_db unless Lockdown::Configuration.skip_sync? Lockdown::Configuration.configured = true end end |
#permission(name) {|Lockdown::Permission.new(name)| ... } ⇒ Object
Define permision that defines how your application is accessed.
# All methods on the site resource will be open to users who have
# this permission.
:public_pages do
resource :site
end
# Can use multiple resource statements
:public_pages do
resource :site
resource :posts
end
# Only methods show, edit and update on the users resource will
# be open to users who have this permission.
:my_account_pages do
resource :users do
only :show, :edit, :update
end
end
# All methods except destroy on the users resource will be
# open to users who have this permission.
:manage_users do
resource :users do
except :destroy
end
end
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lockdown/access.rb', line 36 def (name, &block) = Lockdown::Permission.new(name) if block_given? .instance_eval(&block) else .resource(.name) end unless Lockdown::Configuration.() Lockdown::Configuration. << end end |
#protected_access(*permissions) ⇒ Object
Define which permissions are accessible to everyone
protected_access :my_account, :site_administration
67 68 69 70 71 72 73 |
# File 'lib/lockdown/access.rb', line 67 def protected_access(*) .each do |name| Lockdown::Configuration.(name) end Lockdown::Configuration.protected_access = regexes() end |
#public_access(*permissions) ⇒ Object
Define which permissions are accessible to everyone
public_access :site, :user_registration
55 56 57 58 59 60 61 |
# File 'lib/lockdown/access.rb', line 55 def public_access(*) .each do |name| Lockdown::Configuration.(name) end Lockdown::Configuration.public_access = regexes() end |
#user_group(name, *permissions) ⇒ Object
Create user group by giving it a name and a list of permission names.
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/lockdown/access.rb', line 77 def user_group(name, *) return if .empty? name = name.to_s ug = Lockdown::Configuration.find_or_create_user_group(name) .each do |name| if (perm = Lockdown::Configuration.(name)) ug. << perm unless ug..include?(perm) end end Lockdown::Configuration.maybe_add_user_group(ug) end |