Class: Access::User
Overview
Access::User Use nil-oid if you don’t want the object to be stored.
Defined Under Namespace
Modules: Base
Instance Attribute Summary collapse
-
#credentials ⇒ Object
The credentials of the user (password).
-
#meta ⇒ Object
Metadata - anything you want.
-
#oid ⇒ Object
readonly
The record-id.
-
#privileges ⇒ Object
readonly
Privileges of the user (Privileges instance).
-
#roles ⇒ Object
readonly
Roles the user is in (Roles instance).
Attributes included from Savable
Instance Method Summary collapse
-
#activate ⇒ Object
Activate a user.
-
#active=(value) ⇒ Object
Set active state to value.
-
#active? ⇒ Boolean
Check if user is activated (deactivated users have no privileges).
-
#admin? ⇒ Boolean
Check if user is admin.
-
#authorized?(*args) ⇒ Boolean
Same as privileged? but also takes active? and logged? into consideration.
-
#deactivate ⇒ Object
Deactivate a user (deactivated users have no privileges).
-
#eql?(other) ⇒ Boolean
(also: #==)
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#inactive? ⇒ Boolean
Check if user is deactivated (deactivated users have no privileges).
-
#initialize(access, base, oid, credentials, meta = nil, admin = false, other = {}) ⇒ User
constructor
access: the access-instance the user is tied to (necessary for storing) oid: a string/integer, identifying the user credentials: (if not subclassed) a string authenticating the user, will be hashed before storing.
-
#inspect ⇒ Object
:nodoc:.
-
#logged=(value) ⇒ Object
Set the logged? status of the user.
-
#logged? ⇒ Boolean
Whether the user is logged in or not.
-
#login ⇒ Object
Set the logged? status of the user to true.
-
#logout ⇒ Object
Set the logged? status of the user to false.
-
#privileged?(privilege, parameters = nil) ⇒ Boolean
Check if a user has sufficient privileges to be allowed for certain privilege with certain restriction parameters.
-
#storable ⇒ Object
The data needed to restore a user.
Methods included from Savable
Constructor Details
#initialize(access, base, oid, credentials, meta = nil, admin = false, other = {}) ⇒ User
access: the access-instance the user is tied to (necessary for storing) oid: a string/integer, identifying the user credentials: (if not subclassed) a string authenticating the user, will be hashed before storing. meta: meta data about the user admin: admin’s have all privileges granted
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/access/user.rb', line 85 def initialize(access, base, oid, credentials, =nil, admin=false, other={}) @access = access @base = base @oid = oid @credentials = credentials @admin = admin @active = other.has_key?(:active) ? other[:active] : false @meta = @roles = RoleList.new(self, other[:roles]) @privileges = PrivilegeList.new(self, other[:privileges]) @logged = false extend(Admin) if @admin end |
Instance Attribute Details
#credentials ⇒ Object
The credentials of the user (password)
55 56 57 |
# File 'lib/access/user.rb', line 55 def credentials @credentials end |
#meta ⇒ Object
Metadata - anything you want
64 65 66 |
# File 'lib/access/user.rb', line 64 def @meta end |
#oid ⇒ Object (readonly)
The record-id
52 53 54 |
# File 'lib/access/user.rb', line 52 def oid @oid end |
#privileges ⇒ Object (readonly)
Privileges of the user (Privileges instance)
58 59 60 |
# File 'lib/access/user.rb', line 58 def privileges @privileges end |
#roles ⇒ Object (readonly)
Roles the user is in (Roles instance)
61 62 63 |
# File 'lib/access/user.rb', line 61 def roles @roles end |
Instance Method Details
#activate ⇒ Object
Activate a user
139 140 141 142 |
# File 'lib/access/user.rb', line 139 def activate @active = true save end |
#active=(value) ⇒ Object
Set active state to value
151 152 153 154 |
# File 'lib/access/user.rb', line 151 def active=(value) @active = value save end |
#active? ⇒ Boolean
Check if user is activated (deactivated users have no privileges)
129 130 131 |
# File 'lib/access/user.rb', line 129 def active? @active end |
#admin? ⇒ Boolean
Check if user is admin
124 125 126 |
# File 'lib/access/user.rb', line 124 def admin? false end |
#authorized?(*args) ⇒ Boolean
Same as privileged? but also takes active? and logged? into consideration. I.e. if a user is inactive or not logged in, he is not authorized for anything.
119 120 121 |
# File 'lib/access/user.rb', line 119 def (*args) @active && @logged && privileged?(*args) end |
#deactivate ⇒ Object
Deactivate a user (deactivated users have no privileges)
145 146 147 148 |
# File 'lib/access/user.rb', line 145 def deactivate @active = false save end |
#eql?(other) ⇒ Boolean Also known as: ==
:nodoc:
177 178 179 |
# File 'lib/access/user.rb', line 177 def eql?(other) self.class == other.class && @oid.eql?(other.oid) end |
#hash ⇒ Object
:nodoc:
183 184 185 |
# File 'lib/access/user.rb', line 183 def hash @oid.hash end |
#inactive? ⇒ Boolean
Check if user is deactivated (deactivated users have no privileges)
134 135 136 |
# File 'lib/access/user.rb', line 134 def inactive? !@active end |
#inspect ⇒ Object
:nodoc:
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/access/user.rb', line 188 def inspect "#<%s:0x%08x base: %s oid: %s credentials: %s %s%s%s>" % [ self.class, object_id << 1, "#{@base.class}(#{(class <<@base; self; end).ancestors.first})", @oid.inspect, @credentials, @active ? 'active' : 'inactive', admin? ? ' admin' : '', logged? ? ' logged' : '' ] end |
#logged=(value) ⇒ Object
Set the logged? status of the user
167 168 169 |
# File 'lib/access/user.rb', line 167 def logged=(value) @logged = !!value end |
#logged? ⇒ Boolean
Whether the user is logged in or not
172 173 174 |
# File 'lib/access/user.rb', line 172 def logged? @logged end |
#login ⇒ Object
Set the logged? status of the user to true
157 158 159 |
# File 'lib/access/user.rb', line 157 def login @logged = true end |
#logout ⇒ Object
Set the logged? status of the user to false
162 163 164 |
# File 'lib/access/user.rb', line 162 def logout @logged = false end |
#privileged?(privilege, parameters = nil) ⇒ Boolean
Check if a user has sufficient privileges to be allowed for certain privilege with certain restriction parameters. WARNING! This method does not care about login- nor active-state. Use authorized? to do that
113 114 115 |
# File 'lib/access/user.rb', line 113 def privileged?(privilege, parameters=nil) @privileges.allow?(privilege, parameters) || @roles.allow?(privilege, parameters) end |
#storable ⇒ Object
The data needed to restore a user. Simplified to hashes and scalar values.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/access/user.rb', line 68 def storable { :oid => @oid, :credentials => @credentials, :meta => @meta, :admin => @admin, :active => @active, :privileges => @privileges.storable, :roles => @roles.storable, } end |