Class: RsUserPolicy::User
- Inherits:
-
Object
- Object
- RsUserPolicy::User
- Defined in:
- lib/rs_user_policy/user.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
Instance Method Summary collapse
-
#add_permission(account_href, permission) ⇒ Object
Adds a single permission for a single RightScale account.
-
#clear_permissions(account_href, client, options = {}) ⇒ Hash
Removes all permissions for the user in the specified rightscale account using the supplied client.
-
#get_api_permissions(account_href) ⇒ Array<RightApi::ResourceDetail>
Returns the RightScale permissions the user has for the specified account href.
-
#initialize(user) ⇒ User
constructor
Initializes read only attributes for an RsUserPolicy::User.
-
#set_api_permissions(permissions, account_href, client, options = {}) ⇒ Hash
Removes and adds permissions as appropriate so that the users current permissions reflect the desired set passed in as “permissions”.
-
#to_hash ⇒ Object
Converts this object to a hash which can be serialized.
Constructor Details
#initialize(user) ⇒ User
Initializes read only attributes for an RsUserPolicy::User
29 30 31 32 33 34 |
# File 'lib/rs_user_policy/user.rb', line 29 def initialize(user) @email = user.email @href = user.href @user = user @permissions = {} end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
24 25 26 |
# File 'lib/rs_user_policy/user.rb', line 24 def email @email end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
24 25 26 |
# File 'lib/rs_user_policy/user.rb', line 24 def href @href end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
24 25 26 |
# File 'lib/rs_user_policy/user.rb', line 24 def @permissions end |
Instance Method Details
#add_permission(account_href, permission) ⇒ Object
Adds a single permission for a single RightScale account
51 52 53 54 |
# File 'lib/rs_user_policy/user.rb', line 51 def (account_href, ) @permissions[account_href] ||= [] @permissions[account_href] << end |
#clear_permissions(account_href, client, options = {}) ⇒ Hash
Removes all permissions for the user in the specified rightscale account using the supplied client
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rs_user_policy/user.rb', line 75 def (account_href, client, ={}) = {:dry_run => false}.merge() = (account_href) if [:dry_run] Hash[.map{|p| [p.href, p.role_title]}] else retval = RsUserPolicy::RightApi::PermissionUtilities.( , client ) @permissions.delete(account_href) retval end end |
#get_api_permissions(account_href) ⇒ Array<RightApi::ResourceDetail>
Returns the RightScale permissions the user has for the specified account href
61 62 63 |
# File 'lib/rs_user_policy/user.rb', line 61 def (account_href) @permissions[account_href] || [] end |
#set_api_permissions(permissions, account_href, client, options = {}) ⇒ Hash
Removes and adds permissions as appropriate so that the users current permissions reflect the desired set passed in as “permissions”
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rs_user_policy/user.rb', line 102 def (, account_href, client, ={}) = {:dry_run => false}.merge() = (account_href) = Hash[.map{|p| [p.role_title, p] }] if .length == 0 removed = (account_href, client, ) @permissions.delete(account_href) return removed, {} else = (.keys - ).map{|p| [p]} remove_response = Hash[.map{|p| [p.href, p.role_title]}] unless [:dry_run] remove_response = RsUserPolicy::RightApi::PermissionUtilities.(, client) end = { @href => Hash[( - .keys).map{|p| [p,nil]}] } add_response = {} if [:dry_run] href_idx = 0 add_response = { @href => Hash[( - .keys).map{|p| [p,(href_idx += 1)]}] } else add_response = RsUserPolicy::RightApi::PermissionUtilities.(, client) end @permissions[account_href] = client..index(:filter => ["user_href==#{@href}"]) unless [:dry_run] return remove_response, Hash[add_response[@href].keys.map{|p| [add_response[@href][p],p]}] end end |
#to_hash ⇒ Object
Converts this object to a hash which can be serialized
37 38 39 40 41 42 43 44 45 |
# File 'lib/rs_user_policy/user.rb', line 37 def to_hash() rethash = { "permissions" => @permissions } (@user.attributes - [:links]).each do |attr_sym| rethash[attr_sym.to_s] = @user.send(attr_sym.to_s) end rethash end |