https://github.com/mithereal/ecto-role
assign roles to your tables
https://github.com/mithereal/ecto-role
elixir elixir-library
Last synced: about 1 year ago
JSON representation
assign roles to your tables
- Host: GitHub
- URL: https://github.com/mithereal/ecto-role
- Owner: mithereal
- License: mit
- Created: 2018-01-10T18:35:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-02-01T23:26:41.000Z (over 7 years ago)
- Last Synced: 2025-03-24T07:39:59.835Z (about 1 year ago)
- Topics: elixir, elixir-library
- Language: Elixir
- Homepage:
- Size: 191 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# EctoRole
[](https://travis-ci.org/mithereal/ecto-role)
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fmithereal%2Fecto-role?ref=badge_shield)
[](http://inch-ci.org/github/mithereal/ecto-role)
** Ecto-Role: Implement Table, Row and Column Locking(ish) via OTP **
Add Role based authentication to your otp app. Ecto-Role Provides a simple way to create and assign roles to users
Ecto-Role creates a few schemas to track roles and entities,
Entities are a object we are assiging the role to, entities have a uuid.
Schemas represent the schema and its fields/filters -- filters is a list of all filters relating to the schema
a filter has a name, which fields are filtered in the result and if create/delete actions can/not happen
we have a few different ways of looking at this:
* Entities have roles which have filters
* Roles have entities and filters
* Schemas have fields (row_names) and filters
* filters explain how to filter data/actions
By using the entity instead of user we can have many different filters/filters for different objects and by holding this information in an otp app we can easily query for the filters on the entity with no need to hit the database
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `ecto_role` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:ecto_role, "~> 0.1.0"}
]
end
```
## How to Use
you can query the otp app to see if the entity has the necessary role to access the db record, and/or filter the result of the query
entity_uuid = "xxx-xxx-xxx-xxx"
role_uuid = "xxx-xxx-xxx-xxx"
role = EctoRole.role?("entity_uuid", role_uuid )
# {:ok,_}, {:error,_}
query_result = %{SCHEMA}
result = case role do
{:ok,_} -> EctoRole.filter("filter_uuid", query_result)
{:error,e} -> {:error,e}
end
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/ecto_role](https://hexdocs.pm/ecto_role).
## License
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fmithereal%2Fecto-role?ref=badge_large)