Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CanCanCan for Authorization #28

Open
jendiamond opened this issue Jul 31, 2016 · 1 comment
Open

Add CanCanCan for Authorization #28

jendiamond opened this issue Jul 31, 2016 · 1 comment
Labels

Comments

@jendiamond
Copy link
Owner

jendiamond commented Jul 31, 2016

Pull Request #

http://blog.kangkyu.com/authorization-with-pundit

CanCanCan


SuperAdmin

  • Can Create User
  • Can Modify User
  • Can Delete User
  • Can View Admin Panel
  • Can Make Changes in Admin Panel

Admin

  • Can View Admin Panel

Applicant (Member)

  • Can Edit their own Membership
  • Can Delete their own Membership
  • Can Edit their own User Info
  • Can Delete their own User Info
  • Can Upload Tutorials

Guest

  • Can View Static Pages
@jendiamond jendiamond changed the title When a member uploads a tutorial they should receive a confirmation by email Add CanCanCan for Authorization Jul 31, 2016
@jendiamond jendiamond added the NEXT label Sep 8, 2016
@jendiamond
Copy link
Owner Author

jendiamond commented Sep 8, 2016

Because I am using Rails Admin I am following these directions: https://github.com/sferik/rails_admin/wiki/Authorization

To use an authorization adapter, pass the name of the adapter. For example, to use with CanCanCan, pass it like this.

RailsAdmin.config do |config|
  config.authorize_with :cancan
end

Add gem "cancancan" to Gemfile

$ bundle


Next, run the generator to create an Ability class. This is where authorization rules are defined.

$ rails g cancan:ability
create app/models/ability.rb


CanCanCan with Rails Admin

Add this to config/initializers/rails_admin.rb

RailsAdmin.config do |config|
  config.authorize_with :cancan #TODO add cancancan to rails_admin config
end

Rails Admin & Devise

RailsAdmin.config do |config|

  # == Devise ==
  config.authenticate_with do
    warden.authenticate! scope: :member
  end
  config.current_user_method(&:current_member)

  # == Cancan && Rails Admin https://github.com/sferik/rails_admin/wiki/Base-configuration
  config.authorize_with :cancan

  ## == Gravatar integration ==
  ## To disable Gravatar integration in Navigation Bar set to false
  # config.show_gravatar true

  config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new
    export
    bulk_delete
    show
    edit
    delete
    show_in_app

    ## With an audit adapter, you can add:
    # history_index
    # history_show
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant