Class: RsUserPolicy::RightApi::PermissionUtilities
- Inherits:
-
Object
- Object
- RsUserPolicy::RightApi::PermissionUtilities
- Defined in:
- lib/rs_user_policy/right_api/permission_utilities.rb
Overview
A set of utility methods for manipulating permissions using the RightScale right_api_client gem
Allows bulk actions on permissions without worrying about the complexity of retrying, creating/deleting in the correct order, and the like.
Constant Summary collapse
- @@permission_delete_order =
[ 'enterprise_manager', 'admin', 'security_manager', 'actor', 'billing', 'server_superuser', 'server_login', 'publisher', 'designer', 'library', 'lite_user', 'observer' ]
Class Method Summary collapse
-
.create_permissions(permissions, client) ⇒ Hash
Creates all the passed in permissions using the supplied client.
-
.destroy_permissions(permissions, client) ⇒ Hash
Destroys all passed in permissions with the specified client.
Class Method Details
.create_permissions(permissions, client) ⇒ Hash
Creates all the passed in permissions using the supplied client. This method handles creating permissions with “observer” first in order to avoide the dreaded; RightApi::ApiError: Error: HTTP Code: 422, Response body: A user must have the observer role.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rs_user_policy/right_api/permission_utilities.rb', line 112 def self.(, client) .each do |user_href,perm_ary| user_perms_hash = Hash[perm_ary.keys.map{|p| [p, user_href]}] RsUserPolicy::Utilities.yield_on_keys_in_order(['observer'], user_perms_hash) do |role_title,user_href| = client..create( { 'permission[user_href]' => user_href, 'permission[role_title]' => role_title } ) [user_href][role_title] = .href end end end |
.destroy_permissions(permissions, client) ⇒ Hash
Destroys all passed in permissions with the specified client. This method handles deleting permissions in the appropriate order to avoid the dreaded; RightApi::ApiError: Error: HTTP Code: 422, Response body: A user must have the observer role. TODO: Handle a 422 resulting from calling delete too quickly and attempting to remove “observer” when other deletes have not been committed
60 61 62 63 64 65 66 67 |
# File 'lib/rs_user_policy/right_api/permission_utilities.rb', line 60 def self.(, client) perms_hash = {} .each{|p| perms_hash[p.href] = p.role_title } RsUserPolicy::Utilities.yield_on_values_in_order(@@permission_delete_order, perms_hash) do |perm_href,role_title| client.(:id => RsUserPolicy::Utilities.id_from_href(perm_href)).destroy() end perms_hash end |