View Source SecureX.Roles (SecureX v1.0.2)
Contains CRUD For Roles.
Link to this section Summary
Functions
Add a Role. You can send either Atom Map or String Map to add a Role. If you have existing resources,
it will create default permissions against this role.
Delete a Role. All Permissions and UserRoles will be removed against this role.
Get a Role.
Get list of Roles with Permissions.
Update a Role. You can update any role along with its permissions if you want, if you pass :permissions
in your params. You can send either Atom Map or String Map to update sRole. It will automatically
update that role_id in UserRoles and Permissions table, if you intend to update any role.
Link to this section Functions
Add a Role. You can send either Atom Map or String Map to add a Role. If you have existing resources,
it will create default permissions against this role.
examples
Examples
iex> add(%{"role" => "Super Admin"})
%Role{
id: "super_admin",
name: "Super Admin",
permission: [
%{resource_id: "users", permission: -1, role_id: "super_admin"},
%{resource_id: "employees", permission: -1, role_id: "super_admin"},
%{resource_id: "customer", permission: -1, role_id: "super_admin"}
]
}Your will get Role struct() with all permissions created for the resources if they exist.
list()of permissions you will get in simple map().
Delete a Role. All Permissions and UserRoles will be removed against this role.
examples
Examples
iex> delete(%{"id" => "admin")
%Role{
id: admin,
name: "Admin",
permissions: :successfully_removed_permissions,
user_roles: :successfully_removed_user_roles
}
Get a Role.
examples
Examples
iex> get(%{"role" => "super_admin"})
%Role{
id: "super_admin",
name: "Super Admin",
permission: [
%{resource_id: "users", permission: -1, role_id: "super_admin"},
%{resource_id: "employees", permission: -1, role_id: "super_admin"},
%{resource_id: "customer", permission: -1, role_id: "super_admin"}
]
}
@spec list() :: tuple()
Get list of Roles with Permissions.
examples
Examples
iex> list()
[
%Role{
id: "super_admin",
name: "Super Admin",
permission: [
%{resource_id: "users", permission: -1, role_id: "super_admin"},
%{resource_id: "employees", permission: -1, role_id: "super_admin"},
%{resource_id: "customer", permission: -1, role_id: "super_admin"}
]
}]
Update a Role. You can update any role along with its permissions if you want, if you pass :permissions
in your params. You can send either Atom Map or String Map to update sRole. It will automatically
update that role_id in UserRoles and Permissions table, if you intend to update any role.
examples
Examples
iex> update(%{"id" => "super_admin", "role" => "Admin", "permissions" => [%{"resource_id" => "users", "permission" => 4}]})
{:ok, %Role{
id: admin,
name: "Admin",
permission: [%{resource_id: "users", permission: 4, role_id: "admin"}]
}
}It will return with permissions that you sent in params to change.