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 Action Access authorization gem. #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add Action Access authorization gem. #44

wants to merge 1 commit into from

Conversation

matiasgali
Copy link

Action Access is a very lightweight access control system for Rails that works at controller level focusing on what actions are accessible for the current user instead of messing with models and their attributes. It has a really clear DSL including utilities for thorough control and some useful view helpers.

@hothero
Copy link
Owner

hothero commented Feb 27, 2016

Could you describe the main difference of action_access and pundit?

@matiasgali
Copy link
Author

At plain sight I'd say that Pundit it's much more verbose and less modular, it spreads out setting and checking permissions between policies and controller actions whereas Action Access uses small declarative authorization statements right in the controller. By having everything related to a controller within the controller you get it's logic at a glimpse and it avoids the possibility of leaving stale code after refactoring.

After gem set up the following two examples do exactly the same, allow admin users to edit posts.

Pundit

class PostPolicy
  attr_reader :user

  def initialize(user)
    @user = user
  end

  def update?
    user.admin?
  end
end

class PostsController < ApplicationController
  def update
    @post = Post.find(params[:id])
    authorize @post
    # ...
  end
end

Action Access

class PostsController < ApplicationController
  let :admins, :update

  def update
    # ...
  end
end

Utilities for fine grained control and helpers come out of the box too, please take a quick look at the readme.

@hothero hothero added the review label Mar 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants