Methods provided by Lockdown
View Helpers
- link_to_open(name, options = {}, html_options = nil)
This is the standard link_to provided by rails. Use this if you don’t want to have Lockdown check for access.
- button_to_open(name, options = {}, html_options = nil)
This is the standard button_to provided by rails. Use this if you don’t want to have Lockdown check for access.
- link_to_or_show(name, options = {}, html_options = nil)
Works just the same as link_to, but if the user doesn’t have access it will output the name without the link.
- links( link_to(‘A’,some_a_url), link_to(‘B’,some_b_url), link_to(‘C’,some_c_url))
Will join links with a pipe (option to change this character in init.rb).
If the user doesn’t have access, the link won’t appear.
example: in the below, if user didn’t have access to ‘B’, you would get:
A | C
Session methods
- add_lockdown_session_values(user = nil)
Will use the user returned by current_user or the user passed into the method. This sets up the session[:access_rights] and session[:current_user_id]
- current_user_id
Returns the id of the current user: session[:current_user_id]
- current_user_is_admin?
Simple enough.
- logged_in?
current_user_id.to_i > 0
- reset_lockdown_session
Nilifies these session values:
[:expiry_time, :current_user_id, :access_rights]
- current_user_access_in_group?(:group_symbol)
Returns true or false if user has access to ANY permission in the group.
It does NOT require that the user has access to ALL permissions associated to the group.
System methods
- Lockdown::System.public_access
Returns the array of public rights (“#{controller}/#{action}”).
- Lockdown::System.access_rights_for_user(user)
Returns the array of rights (“#{controller}/#{action}”) the user has access to.
- Lockdown::System.user_groups_assignable_for_user(user)
Pass in a user object to this method and you’ll get back an array of UserGroup objects the user would be allowed to assign to someone else. This can be used to prevent a user from assigning more power than he/she has. Example in users_controller template.
- Lockdown::System.permissions_assignable_for_user(user)
Pass in a user object to this method and you’ll get back an array of Permission objects the user would be allowed to assign to someone else. This can be used to prevent a user from assigning more power than he/she has. Example in user_groups_controller template.
- Lockdown::System.permissions_for_user_group(user_group)
bq. Pass in a user group object and you’ll get back an array of permission names (as symbols).
- Lockdown::System.access_rights_for_permission(permission_symbol)
Pass in a permission symbol and you’ll get back the array of rights (“#{controller}/#{action}”) for the permission.
- Lockdown::System.get_user_groups
Returns an array of user group names (as symbols) defined in init.rb.
- Lockdown::System.get_permissions
Returns an array of permission names (as symbols) defined in init.rb.
