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 a handle_authorize hook which is executed on all actions (before logic) #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Commits on Nov 5, 2016

  1. Add a handle_authorize hook which is executed on all actions (before …

    …anything).
    
    This way I can simply add authorization on the record that's properly
    loaded and scoped by ja_resource for all routes at once.
    
    Show, delete and update will call the method with the actual model to be
    operated on (but before anything is done to the model!). index and create
    actions will pass in the model() module instead (since we're operating
    on a collection/adding a record not yet in the db).
    
    This was intended for integration with bodyguard. I had to do the
    following:
    
      def records(conn) do
        scope(conn, model())
      end
    
      # this solves the auth for show, update and delete (but not index or create)
      def record(conn, id) do
        r = super(conn, id)
        authorize!(conn, r, policy: Midori.Bot.Policy)
        r
      end
    
      def handle_index(conn, attributes) do
        authorize!(conn, Bot)
        super(conn, attributes)
      end
    
      def handle_create(conn, attributes) do
        authorize!(conn, Bot)
        super(conn, attributes)
      end
    
    I wanted a solution that would take care of index and create as well,
    because having to do it manually action by action is error-prone.
    archseer committed Nov 5, 2016
    Configuration menu
    Copy the full SHA
    4a8e976 View commit details
    Browse the repository at this point in the history

Commits on Nov 11, 2016

  1. Configuration menu
    Copy the full SHA
    7cf0520 View commit details
    Browse the repository at this point in the history

Commits on Nov 14, 2016

  1. Configuration menu
    Copy the full SHA
    aac8cf2 View commit details
    Browse the repository at this point in the history