Class: Warrant::Permission
- Includes:
- WarrantObject
- Defined in:
- lib/warrant/models/permission.rb
Constant Summary collapse
- OBJECT_TYPE =
"permission"
Instance Attribute Summary
Attributes inherited from Object
#created_at, #meta, #object_id, #object_type
Class Method Summary collapse
-
.assign_to_role(role_id, permission_id, relation: "member", options: {}) ⇒ Warrant
Assign a permission to a role.
-
.assign_to_user(user_id, permission_id, relation: "member", options: {}) ⇒ Warrant
Assign a permission to a user.
-
.create(params = {}, options = {}) ⇒ Permission
Creates a permission with the given parameters.
-
.delete(permission_id, options = {}) ⇒ nil
Deletes a permission with given permission id.
-
.get(permission_id, options = {}) ⇒ Permission
Get a permission with the given permission_id.
-
.list(filters = {}, options = {}) ⇒ Array<Permission>
Lists all permissions for your organization.
-
.list_for_role(role_id, filters = {}, options = {}) ⇒ Array<Permission>
List permissions for a role.
-
.list_for_user(user_id, filters = {}, options = {}) ⇒ Array<Permission>
List permissions for a user.
-
.remove_from_role(role_id, permission_id, relation: "member", options: {}) ⇒ nil
Remove a permission from a role.
-
.remove_from_user(user_id, permission_id, relation: "member", options: {}) ⇒ nil
Remove a permission from a user.
-
.update(permission_id, meta, options = {}) ⇒ Permission
Updates a permission with the given role_id and params.
Instance Method Summary collapse
-
#update(meta, options = {}) ⇒ Permission
Updates a permission with the given params.
- #warrant_object_id ⇒ Object
- #warrant_object_type ⇒ Object
Methods inherited from Object
Class Method Details
.assign_to_role(role_id, permission_id, relation: "member", options: {}) ⇒ Warrant
Assign a permission to a role
170 171 172 |
# File 'lib/warrant/models/permission.rb', line 170 def self.assign_to_role(role_id, , relation: "member", options: {}) Warrant.create({ object_type: Permission::OBJECT_TYPE, object_id: }, relation, { object_type: Role::OBJECT_TYPE, object_id: role_id }, nil, ) end |
.assign_to_user(user_id, permission_id, relation: "member", options: {}) ⇒ Warrant
Assign a permission to a user
229 230 231 |
# File 'lib/warrant/models/permission.rb', line 229 def self.assign_to_user(user_id, , relation: "member", options: {}) Warrant.create({ object_type: Permission::OBJECT_TYPE, object_id: }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, ) end |
.create(params = {}, options = {}) ⇒ Permission
Creates a permission with the given parameters
30 31 32 33 |
# File 'lib/warrant/models/permission.rb', line 30 def self.create(params = {}, = {}) object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:permission_id], meta: params[:meta] }, ) return Permission.new(object.object_id, object., object.created_at) end |
.delete(permission_id, options = {}) ⇒ nil
Deletes a permission with given permission id
48 49 50 |
# File 'lib/warrant/models/permission.rb', line 48 def self.delete(, = {}) return Object.delete(OBJECT_TYPE, , ) end |
.get(permission_id, options = {}) ⇒ Permission
Get a permission with the given permission_id
88 89 90 91 |
# File 'lib/warrant/models/permission.rb', line 88 def self.get(, = {}) object = Object.get(OBJECT_TYPE, , ) return Permission.new(object.object_id, object., object.created_at) end |
.list(filters = {}, options = {}) ⇒ Array<Permission>
Lists all permissions for your organization
71 72 73 74 75 76 |
# File 'lib/warrant/models/permission.rb', line 71 def self.list(filters = {}, = {}) filters.merge({ object_type: "permission" }) list_response = Object.list(filters, ) = list_response.results.map{ |object| Permission.new(object.object_id, object., object.created_at)} return ListResponse.new(, list_response.prev_cursor, list_response.next_cursor) end |
.list_for_role(role_id, filters = {}, options = {}) ⇒ Array<Permission>
List permissions for a role
150 151 152 153 154 |
# File 'lib/warrant/models/permission.rb', line 150 def self.list_for_role(role_id, filters = {}, = {}) query_response = Warrant.query("select permission where role:#{role_id} is *", filters: filters, options: ) = query_response.results.map{ |result| Permission.new(result.object_id, result.) } return ListResponse.new(, query_response.prev_cursor, query_response.next_cursor) end |
.list_for_user(user_id, filters = {}, options = {}) ⇒ Array<Permission>
List permissions for a user
209 210 211 212 213 |
# File 'lib/warrant/models/permission.rb', line 209 def self.list_for_user(user_id, filters = {}, = {}) query_response = Warrant.query("select permission where user:#{user_id} is *", filters: filters, options: ) = query_response.results.map{ |result| Permission.new(result.object_id, result.) } return ListResponse.new(, query_response.prev_cursor, query_response.next_cursor) end |
.remove_from_role(role_id, permission_id, relation: "member", options: {}) ⇒ nil
Remove a permission from a role
187 188 189 |
# File 'lib/warrant/models/permission.rb', line 187 def self.remove_from_role(role_id, , relation: "member", options: {}) Warrant.delete({ object_type: Permission::OBJECT_TYPE, object_id: }, relation, { object_type: Role::OBJECT_TYPE, object_id: role_id }, nil, ) end |
.remove_from_user(user_id, permission_id, relation: "member", options: {}) ⇒ nil
Remove a permission from a user
246 247 248 |
# File 'lib/warrant/models/permission.rb', line 246 def self.remove_from_user(user_id, , relation: "member", options: {}) Warrant.delete({ object_type: Permission::OBJECT_TYPE, object_id: }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, ) end |
.update(permission_id, meta, options = {}) ⇒ Permission
Updates a permission with the given role_id and params
108 109 110 111 |
# File 'lib/warrant/models/permission.rb', line 108 def self.update(, , = {}) object = Object.update(OBJECT_TYPE, , , ) return Permission.new(object.object_id, object., object.created_at) end |
Instance Method Details
#update(meta, options = {}) ⇒ Permission
Updates a permission with the given params
128 129 130 |
# File 'lib/warrant/models/permission.rb', line 128 def update(, = {}) return Permission.update(, , ) end |
#warrant_object_id ⇒ Object
254 255 256 |
# File 'lib/warrant/models/permission.rb', line 254 def warrant_object_id end |
#warrant_object_type ⇒ Object
250 251 252 |
# File 'lib/warrant/models/permission.rb', line 250 def warrant_object_type "permission" end |