Coder Social home page Coder Social logo

exelord / monarchy Goto Github PK

View Code? Open in Web Editor NEW
49.0 3.0 6.0 11.67 MB

Hierarchical access management system with advanced roles inheritance. ๐Ÿฆ‹

Home Page: https://exelord.github.io/Monarchy/

License: MIT License

Ruby 95.83% JavaScript 0.40% CSS 0.46% HTML 3.25% Shell 0.08%
roles-inheritance ruby monarchy rails authorization roles access-control access

monarchy's Introduction

Sublime's custom image

Monarchy is a ruby gem offering a complete solution to manage an authorization access in Ruby on Rails applications. A hierarchical structure as well as built-in roles inheritance options make it the most powerful tool to control access to application data resources.

Thanks to closure_tree - a gem used to manage binary trees - Monarchy can deliver the best-in-class algorithmic performance and enables developers to forget about hierarchies and complicated structures.

If you feel limited while using rolify, feel free to use Monarchy with its advanced capacity to inherit roles and collect all accessible resources with just one method.

Usage Example

After Monarchy setup you can enjoy with roles inheritance and accessible resources.

# Create roles
admin_role = Monarchy.role_class.create(name: :admin, level: 5, inherited: true)
manager_role = Monarchy.role_class.create(name: :manager, level: 4, inherited_role: admin_role, inherited: true)

# Create resources
project1 = Project.create()
project2 = Project.create(parent: project1)
project3 = Project.create(parent: project2)
project4 = Project.create(parent: project1)

# Grant user
user.grant(:manager, project2)

# Accessible projects
Project.accessible_for(user)  # returns [project1, project2, project3]

# User inherited roles
user.roles_for(project1) # returns a default role eg. [guest_role]
user.roles_for(project2) # returns [manager_role]
user.roles_for(project3) # returns [admin_role]
user.roles_for(project4) # returns empty array []

# Graphical visualization

#                              project1 (default role, eg. guest)
#                                 |
#                                 |
#   (granted as manager) project2   project4 (no access)
#                           |
#                           |
#                        project3 (admin | inherited role from manager_role)

Requirements

Monarchy requires:

  • Ruby 2.3

Documentation

We are preparing an official website with documentation. Meanwhile you can look to the docs directory for actual documentation.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/exelord/Monarchy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

This version of the gem is available as open source under the terms of the MIT License.

monarchy's People

Contributors

dependabot[bot] avatar exelord avatar poslinskinet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

monarchy's Issues

Debug mode ability

Ability to get more detailed information where we run Monarchy methods, so for example if we run in Monarchy.debug = true we will see stack trace with corresponding application code, so we can easier track potential performance issues (for example) or even better if we can somehow connect it with bullet log/warning.

Dynamic relationships

Register and generate automatically all relationships for all resources.

  has_many :accounts, through: :hierarchies, class_name: 'Account', source: 'resource', source_type: 'Account'
  has_many :projects, through: :hierarchies, class_name: 'Project', source: 'resource', source_type: 'Project'
  has_many :memos, through: :hierarchies, class_name: 'Memo', source: 'resource', source_type: 'Memo'

Probably missing tests

TODO:

  • Default role is granted automatically?
  • roles: [ owner, guest(default) ] - When revoking owner: access is still granted? (due to guest role?)
  • What happening in case of revoking role that not exist?

Rework on roles_for

User #roles_for method should returns an array wth all accessible role with highest level

Custom Up and down roles inheritence

Some roles have to have downgraded level after down inheritance.
Eg.
When you grant user to a resource A as Owner and then create a child for resource A as resource B you want to inherit role from A to B but with downgraded level eg. as manager.

In fact in resource A user will be owner and in resource B will be manager

TODO:

  • create a column named downgraded_role and set as nil by default
  • rework on role_for method to obtain a correct downgraded role if exist
  • write tests

And think about upgraded_role... Maybe there will be also some use cases.

Better revoking roles

Make second method revoke_role! for force revoking access to resource in case when role that was revoked was the last one. (Works like current method revoke_role)

Rework on revoke_role:

  • when role that was revoked was the last one grant default role and keep access to resource

Rise warnings

Rise warning eg when you grant user a role that doesn't exist

Extend `parent_as` method

Extend parent_as method to receive also an array with models names and propagate the parent method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.