Module: AeUsers::Acts::Permissioned::InstanceMethods
- Defined in:
- lib/ae_users.rb
Instance Method Summary collapse
- #grant(grantees, permissions = nil) ⇒ Object
- #permitted?(person, permission = nil) ⇒ Boolean
- #permitted_people(permission) ⇒ Object
- #revoke(grantees, permissions = nil) ⇒ Object
Instance Method Details
#grant(grantees, permissions = nil) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/ae_users.rb', line 198 def grant(grantees, =nil) if not grantees.kind_of?(Array) grantees = [grantees] end if not .kind_of?(Array) if .nil? = self.class. else = [] end end grantees.each do |grantee| if grantee.kind_of? Role .each do |perm| if AeUsers. grantee.members.each do |person| AeUsers..invalidate(person, self, perm) end end Permission.create :role => grantee, :permission => perm, :permissioned => self end elsif grantee.kind_of? Person .each do |perm| if AeUsers. AeUsers..invalidate(grantee, self, perm) end Permission.create :person => grantee, :permission => perm, :permissioned => self end end end end |
#permitted?(person, permission = nil) ⇒ Boolean
175 176 177 |
# File 'lib/ae_users.rb', line 175 def permitted?(person, =nil) person.permitted? self, end |
#permitted_people(permission) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/ae_users.rb', line 179 def permitted_people() grants = .select { |perm| perm. == } people = [] grants.collect {|grant| grant.grantee}.each do |grantee| if grantee.kind_of? Person if not people.include? grantee people << grantee end elsif grantee.kind_of? Role grantee.people.each do |person| if not people.include? person people << person end end end end return people end |
#revoke(grantees, permissions = nil) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/ae_users.rb', line 232 def revoke(grantees, =nil) if not grantees.kind_of?(Array) grantees = [grantees] end if not .kind_of?(Array) if .nil? = self.class. else = [] end end grantees.each do |grantee| .each do |perm| existing = if grantee.kind_of? Role if AeUsers. grantee.members.each do |person| AeUsers..invalidate(person, self, perm) end end Permission.(grantee, perm) elsif grantee.kind_of? Person if AeUsers. AeUsers..invalidate(pesron, self, perm) end Permission.(person, perm) end if existing existing.destroy end end end end |