Module: Mongoid::ACL::Methods::InstanceMethods
- Defined in:
- lib/mongoid_acl/methods.rb
Instance Method Summary collapse
-
#can_destroy?(identifier) ⇒ Boolean
check if an actor with identifier has the destroy permission (Mongoid::ACL::DESTROY_PERM) on this object.
-
#can_manage?(identifier) ⇒ Boolean
quickly check whether an actor has the read,update and destroy permission on this object.
-
#can_read?(identifier) ⇒ Boolean
check if an actor with identifier has read permission (Mongoid::ACL::READ_PERM) on this object.
-
#can_update?(identifier) ⇒ Boolean
check if an actor with identifier has the update permission (Mongoid::ACL::UPDATE_PERM) on this object.
-
#grant_destroy!(identifier) ⇒ Boolean
quickly add destroy permission for this actor.
-
#grant_manage!(identifier) ⇒ Boolean
quickly add read,update and destroy permission for this actor.
-
#grant_permission_to(permission, identifier) ⇒ Object
add identifier(s) to the given permission(s) in the acl list of this object.
-
#grant_read!(identifier) ⇒ Boolean
quickly add read permission for this actor.
-
#grant_update!(identifier) ⇒ Boolean
quickly add update permission for this actor.
- #has_permission_for(permission, identifier) ⇒ Object
-
#revoke_all_permissions ⇒ Boolean
quickly remove all permissions.
-
#revoke_destroy!(identifier) ⇒ Boolean
quickly remove destroy permission for this actor.
-
#revoke_manage!(identifier) ⇒ Boolean
quickly remove read,update and destroy permission for this actor.
-
#revoke_permission_for(permission, identifier) ⇒ Object
revoke identifier(s) from the given permission(s) in the acl list of this object.
-
#revoke_read(identifier) ⇒ Boolean
quickly remove read permission for this actor.
-
#revoke_update!(identifier) ⇒ Boolean
quickly remove update permission for this actor.
Instance Method Details
#can_destroy?(identifier) ⇒ Boolean
check if an actor with identifier has the destroy permission (Mongoid::ACL::DESTROY_PERM) on this object
25 26 27 |
# File 'lib/mongoid_acl/methods.rb', line 25 def can_destroy?(identifier) self.(Mongoid::ACL::DESTROY_PERM,identifier) end |
#can_manage?(identifier) ⇒ Boolean
quickly check whether an actor has the read,update and destroy permission on this object
32 33 34 |
# File 'lib/mongoid_acl/methods.rb', line 32 def can_manage?(identifier) can_read?(identifier) && can_update?(identifier) && can_destroy?(identifier) end |
#can_read?(identifier) ⇒ Boolean
check if an actor with identifier has read permission (Mongoid::ACL::READ_PERM) on this object
10 11 12 |
# File 'lib/mongoid_acl/methods.rb', line 10 def can_read?(identifier) self.(Mongoid::ACL::READ_PERM,identifier) end |
#can_update?(identifier) ⇒ Boolean
check if an actor with identifier has the update permission (Mongoid::ACL::UPDATE_PERM) on this object
17 18 19 20 |
# File 'lib/mongoid_acl/methods.rb', line 17 def can_update?(identifier) self.(Mongoid::ACL::UPDATE_PERM,identifier) end |
#grant_destroy!(identifier) ⇒ Boolean
quickly add destroy permission for this actor
53 54 55 |
# File 'lib/mongoid_acl/methods.rb', line 53 def grant_destroy!(identifier) self.(Mongoid::ACL::DESTROY_PERM,identifier) end |
#grant_manage!(identifier) ⇒ Boolean
quickly add read,update and destroy permission for this actor
61 62 63 |
# File 'lib/mongoid_acl/methods.rb', line 61 def grant_manage!(identifier) self.([Mongoid::ACL::READ_PERM,Mongoid::ACL::UPDATE_PERM,Mongoid::ACL::DESTROY_PERM],identifier) end |
#grant_permission_to(permission, identifier) ⇒ Object
add identifier(s) to the given permission(s) in the acl list of this object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/mongoid_acl/methods.rb', line 105 def (,identifier) if identifier.kind_of?(Array) identifier = {"$each" => identifier} end if .kind_of?(Array) hash_map = Hash.new .each{ |p| hash_map["acls.#{p}"] = identifier} else hash_map = {"acls.#{}" => identifier} end return self.collection.update({"_id" => self.id}, {"$addToSet" => hash_map }) end |
#grant_read!(identifier) ⇒ Boolean
quickly add read permission for this actor
39 40 41 |
# File 'lib/mongoid_acl/methods.rb', line 39 def grant_read!(identifier) self.(Mongoid::ACL::READ_PERM,identifier) end |
#grant_update!(identifier) ⇒ Boolean
quickly add update permission for this actor
46 47 48 |
# File 'lib/mongoid_acl/methods.rb', line 46 def grant_update!(identifier) self.(Mongoid::ACL::UPDATE_PERM,identifier) end |
#has_permission_for(permission, identifier) ⇒ Object
136 137 138 139 |
# File 'lib/mongoid_acl/methods.rb', line 136 def (,identifier) return false if self.acls.nil? self.acls[].include?(PUBLIC_IDENTIFIER) || self.acls[].include?(identifier) end |
#revoke_all_permissions ⇒ Boolean
quickly remove all permissions
97 98 99 |
# File 'lib/mongoid_acl/methods.rb', line 97 def self.collection.update({"_id" => self.id}, {"$unset" => {"acls"=>1} }) end |
#revoke_destroy!(identifier) ⇒ Boolean
quickly remove destroy permission for this actor
82 83 84 |
# File 'lib/mongoid_acl/methods.rb', line 82 def revoke_destroy!(identifier) self.(Mongoid::ACL::DESTROY_PERM,identifier) end |
#revoke_manage!(identifier) ⇒ Boolean
quickly remove read,update and destroy permission for this actor
90 91 92 |
# File 'lib/mongoid_acl/methods.rb', line 90 def revoke_manage!(identifier) self.([Mongoid::ACL::READ_PERM,Mongoid::ACL::UPDATE_PERM,Mongoid::ACL::DESTROY_PERM],identifier) end |
#revoke_permission_for(permission, identifier) ⇒ Object
revoke identifier(s) from the given permission(s) in the acl list of this object
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/mongoid_acl/methods.rb', line 122 def (,identifier) if !identifier.respond_to?('each') identifier = [identifier] end if .kind_of?(Array) hash_map = Hash.new .each{ |p| hash_map["acls.#{p}"] = identifier} else hash_map = {"acls.#{}" => identifier} end return self.collection.update({"_id" => self.id}, {"$pullAll" => hash_map }) end |
#revoke_read(identifier) ⇒ Boolean
quickly remove read permission for this actor
68 69 70 |
# File 'lib/mongoid_acl/methods.rb', line 68 def revoke_read(identifier) self.(Mongoid::ACL::READ_PERM,identifier) end |
#revoke_update!(identifier) ⇒ Boolean
quickly remove update permission for this actor
75 76 77 |
# File 'lib/mongoid_acl/methods.rb', line 75 def revoke_update!(identifier) self.(Mongoid::ACL::UPDATE_PERM,identifier) end |