{"id":22840571,"url":"https://github.com/shouya/cant_cant_cant","last_synced_at":"2025-04-28T10:50:08.392Z","repository":{"id":56843201,"uuid":"69345046","full_name":"shouya/cant_cant_cant","owner":"shouya","description":"Role-based authentication on controller actions, centrally configured","archived":false,"fork":false,"pushed_at":"2017-03-06T07:59:48.000Z","size":77,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T08:58:23.729Z","etag":null,"topics":["authentication","permissions","rails","rubygems"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shouya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-27T10:22:15.000Z","updated_at":"2017-03-06T07:48:37.000Z","dependencies_parsed_at":"2022-09-01T04:40:12.346Z","dependency_job_id":null,"html_url":"https://github.com/shouya/cant_cant_cant","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shouya%2Fcant_cant_cant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shouya%2Fcant_cant_cant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shouya%2Fcant_cant_cant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shouya%2Fcant_cant_cant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shouya","download_url":"https://codeload.github.com/shouya/cant_cant_cant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251299607,"owners_count":21567265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","permissions","rails","rubygems"],"created_at":"2024-12-13T01:12:43.935Z","updated_at":"2025-04-28T10:50:08.371Z","avatar_url":"https://github.com/shouya.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CantCantCant\n\n[![Build Status](https://travis-ci.org/shouya/cant_cant_cant.svg?branch=master)](https://travis-ci.org/shouya/cant_cant_cant)\n[![Gem Version](https://badge.fury.io/rb/cant_cant_cant.svg)](https://rubygems.org/gems/cant_cant_cant)\n[![Ruby Doc](https://img.shields.io/badge/rubydoc-lastest-brightgreen.svg)](http://www.rubydoc.info/gems/cant_cant_cant)\n\nI want an authentication library to:\n\n- be light weight and simple, working in a controllable way;\n- be role based, where roles and users are multiple-to-multiple relation;\n- apply on controller actions;\n- have access control in a single configuration file;\n- be able to export a list of permissions for roles\n\nSo CanCan[Can] just can't satisfy my requirement. And then CantCantCant is the wheel invented for above purposes.\n\n## Installation\n\nAdd the following line to your `Gemfile` and execute `bundle`.\n\n    gem 'cant_cant_cant'\n\nThen run:\n\n    $ rails generate cant_cant_cant:install\n\nto generate the config and the initializer.\n\nTo get authentication works, you have to adjust `config/cant_cant_cant.yml` for your own need.\n\nAfter all you need to tell CantCantCant how to acquire your current role(s). Modify the code in `config/initializers/cant_cant_cant.rb`.\n\nCantCantCant will raise an exception on unauthorized access. In order to handle the error yourself, take a look on the related code in `config/initializers/cant_cant_cant.rb`.\n\n## Usage\n\nYou're done. There is no need to configure more in any of your controllers.\n\n\u003cs\u003eNote that live reloading is not supported yet; it means you'll need to restart your server after modifying your actions/controllers/config to take effect.\u003c/s\u003e Live reloading can be enabled by setting `config.caching = false` to force CantCantCant load your permission file without caching them.\n\nIf you need to acquire a list of actions that given roles have access to, just call `CantCantCant.allowed_actions_for(roles)`.\n\n\n## Configuration\n\nThe configuration is located in `config/cant_cant_cant.yml`. The path to configuration file can be modified in the initializer.\n\nThe configuration is a YAML document that looks like:\n\n```yaml\nuser: \u0026default_permissions\n  test#public: allow\n  test#admin_only: deny\n  test#no_access: deny\n\nadmin:\n  \u003c\u003c: *default_permissions\n  test#admin_only: allow\n```\n\n## Initializer\n\nYou can adjust the initializer as you want, the only thing to notice is that you need to call `CantCantCant.initialize` before making any request, otherwise the authentication won't take effect.\n\nCantCantCant need a `current_roles` method, you should implement it by your own according to the template, either in the initializer or in your own `ApplicationController`. You can also handle the `PermissionDenied` exception in the same way.\n\nUsing `rails generate cant_cant_cant:install`, the template will be generated for you in the initializer.\n\n```ruby\nclass ActionController::Base\n  # Write your own handler\n  rescue_from CantCantCant::PermissionDenied do\n    render plain: 'permission denied', status: 403\n  end\n\n  # Write your own method to return the roles for current user\n  def current_roles\n    return [] unless defined? current_user\n    return [] if current_user.empty?\n\n    current_user.roles\n  end\nend\n```\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshouya%2Fcant_cant_cant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshouya%2Fcant_cant_cant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshouya%2Fcant_cant_cant/lists"}