Giter VIP home page Giter VIP logo

Comments (4)

farao avatar farao commented on July 17, 2024

Hm, maybe I should make it clearer. My goal is that:
(a) a user with role "user" can edit/delete/show only his own profile
(b) a user with role "admin" can edit/delete/show all users
I have a pretty standard user_controller & model and only want to add the plugs in the controller so that it represents the behaviour above.

from openmaize.

riverrun avatar riverrun commented on July 17, 2024

You can do this by customizing the authorize_id plug, like this:

Openmaize.AccessControl

plug :authorize, roles: ["admin", "user"]
plug :custom_auth when action in [:show, :edit, :delete]

defp custom_auth(conn, opts) do
  if conn.assigns.current_user.role == "admin" do
    conn
  else
    authorize_id(conn, opts)
  end
end

Thanks for raising the issue. I should add an example like this in the documentation somewhere.
Let me know if you have any further questions.

from openmaize.

riverrun avatar riverrun commented on July 17, 2024

There is now an example of this in the documentation for the AccessControl module.

from openmaize.

farao avatar farao commented on July 17, 2024

Thanks for your help!

from openmaize.

Related Issues (20)

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.