Plots2: Switch to logged_in_as(roles) to simplify auth logic!

Created on 25 Mar 2019  Â·  6Comments  Â·  Source: publiclab/plots2

the User model could use some simpler helpers, which would dramatically simplify some template code for showing things only to moderators or admins, like this:

https://github.com/publiclab/plots2/blob/aba49c4378fd94ab3f37de1d398243b75cf90365/app/views/users/list.html.erb#L8-L11

Instead, let's make a user model method like:

user.is_role(:admin)

Then that code could become:

if user.is_role(:admin, :moderator)

But we need to be able to specify if it's AND or OR -- any ideas?

Maybe:

user.is_one_of_roles(:admin, :moderator)

We could also simplify by making an application_helper method like:

user_has_role(:admin, :moderator)

where we also check if there is a current_user, further simplifying the code!

We'd love some help with this, and ideally the new methods would be tested as well! Thanks!

Ruby fto-candidate help wanted multiple-use

All 6 comments

Reposting from part of #268

Ack! We actually have this! So this issue could be for switching to this system:

https://github.com/publiclab/plots2/blob/aba49c4378fd94ab3f37de1d398243b75cf90365/app/helpers/application_helper.rb#L3-L13

This could be broken into many first-timers-only issues using search results from this:

https://github.com/publiclab/plots2/search?q=%22current_user.role+%3D%3D%22&unscoped_q=%22current_user.role+%3D%3D%22


This has been marked as a good candidate for becoming a first-timers-only issue like these, meaning that it's simple, self-contained, and with some extra formatting, could be a great entry point for a new contributor. If you're familiar enough with this code, please consider reformatting or reposting it as a first-timers-only issue, and then ping @publiclab/reviewers to get it labelled. Or, if this is not your first time, try to solve it yourself!

Made https://github.com/publiclab/plots2/issues/5306 for admin_controller.rb!

@jywarren I am a ROR developer and I am new to open source. I would like to work on this.

We will love to have your help

On Fri, Apr 19, 2019, 4:53 AM Srinandan Pai notifications@github.com
wrote:

@jywarren https://github.com/jywarren I am a ROR developer and I am new
to open source. I would like to work on this.

—
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/5259#issuecomment-484721123,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFAAEQZENCA5DGQDLLAG4LDPRD7H7ANCNFSM4HA6BSOQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

keshavsethi picture keshavsethi  Â·  3Comments

jywarren picture jywarren  Â·  3Comments

bronwen9 picture bronwen9  Â·  3Comments

keshavsethi picture keshavsethi  Â·  3Comments

grvsachdeva picture grvsachdeva  Â·  3Comments