SecureX.Roles (SecureX v0.3.5) View Source

Contains CRUD For Roles.

Link to this section Summary

Functions

Add a Role. You can send either Atom Map or String Map to add 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 Role. It will automatically update that role_id in UserRoles and Permissions table, if you intend to update any role.

Link to this section Functions

Specs

add(map()) :: struct()

Add a Role. You can send either Atom Map or String Map to add Role. If you have existing resources, it will create default permissions against this role

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().

Specs

delete(map()) :: struct()

Delete a Role. All Permissions and UserRoles will be removed against this role.

Examples

iex> delete(%{"id" => "admin")
%Role{
  id: admin,
  name: "Admin",
  permissions: :successfully_removed_permissions,
  user_roles: :successfully_removed_user_roles
}

Specs

get(map()) :: struct()

Get a Role.

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"}
    ...
  ]
}

Specs

list() :: [...]

Get list of Roles with Permissions.

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"}
    ...
  ]
}

]

Specs

update(map()) :: struct()

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 Role. It will automatically update that role_id in UserRoles and Permissions table, if you intend to update any role.

Examples

iex> update(%{"id" => "super_admin", "role" => "Admin", "permissions" => [%{"resource_id" => "users", "permission" => 4}]})
%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.