-
Notifications
You must be signed in to change notification settings - Fork 138
Temp Fix to restrict access for unconfirmed users #992
Conversation
- Update specs, update shared contexts, update controller texts and leave some comments for things that should be addressed later, if still relevant
@@ -69,6 +71,7 @@ | |||
allow(user).to receive(:confirmed?).and_return(false) | |||
end | |||
it 'allows to see not hidden email address' do | |||
pending "Fails. Unconfirmed user has no access" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??? This spec is failing, but I am not sure if we even want it to pass for this conditions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. You're right. All an unconfirmed user should, in theory, be able to do is edit their email address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we keep it pending for now? I expect that it will solve itself in the upcoming Overhaul steps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. Is there a way to mark this as a TODO? Or is the pending
enough, do you reckon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am currently collecting all the todo's, and will add them when we have finished the discussion in #991 . Don't want to add too much detail to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point!
CC fails on complexity of the body of Ability#initialize. AFAIK this is quite inevitable. Can I ignore it? |
@pgaspar @klappradla @ramonh Can you take a look please? |
can :crud, User, id: user.id | ||
can :crud, User if user.admin? | ||
can :read, User | ||
can :update, User, id: user.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understood correctly, but admins seem to be losing the ability to update users here. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the failing spec comes from here. Is there a reason we're removing admin access from crud
'ing users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Admin can still crud User, it has moved to line 38.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies! Dunno how I missed that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the admin call is guarded behind a if user.confirmed?
. I feel we should keep the current behaviour. If anything, we want admins to be able to fix a user's typo'd email address as a response to a support request ticket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if user.confirmed?
checks here if the admin user is confirmed. Which they should be, right?- I added very verbose expectations to check if an admin user can crud everyone.
- And I tested manually if an admin user can update someone else's account. They can, and the new specs cover that now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @F3PiX, looks good!
Just a question on my end, and otherwise good to go, I'd say.
can :crud, User, id: user.id | ||
can :crud, User if user.admin? | ||
can :read, User | ||
can :update, User, id: user.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the failing spec comes from here. Is there a reason we're removing admin access from crud
'ing users?
app/models/ability.rb
Outdated
def on_team_for_season?(user, season) | ||
season && user.roles.student.joins(:team).pluck(:season_id).include?(season.id) | ||
end | ||
can :crud, :comments if user.admin? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related to this PR specifically, and we should probably open a separate issue for this: it seems we're not testing this ability in the project comments (or anywhere I could find).
We used to have this in the teams show page, but it was removed meanwhile:
rgsoc-teams/app/views/teams/show.html.slim
Lines 17 to 22 in 4fc8dfd
- if can? :crud, :comments | |
.comments | |
a href='#' Hide comments | |
= render partial: 'comments/form', object: @team, as: :team | |
ul | |
= render @team.comments, as: :comment |
I've not used CanCanCan a lot in the past.. do we usually use the controller helpers or just view helpers?
Should I create the issue or do we want to fix it in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use both helpers ( PR #993 is all about the controller helpers :-) )
If it's okay with you, I'd prefer to keep the PR's as clean as possible. And collect issues for every step layed out in the Overhaul: Breakdown (#991) . So we can use that as a reference all the way.
The crud comments issue
will be part of the CommentsController Overhaul (listed in nr 5 in 991). Or afterwards, in the restructuring of the Ability. I'll add it. Thanks!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course! Thank you for your patience - I'm still figuring out how we structure things! 😊
I like these changes 👍 I didn't do a lot of testing, but I think the changes make sense so far! I'm not sure how thoroughly we use these abilities though, there seem to be some that are not checked anywhere - which means unconfirmed users can do some things (I didn't test much other than the comments, but that's one that users can use even before confirmation). Not sure if we should make an effort to see if thee abilities are used or not (in a separate issue, I assume) or if it's too much trouble. |
I don't have authority in CodeClimate to set the warning to 'wontfix'. Can someone disable the warning please? (@ramonh ?) |
Oh! Sure! I thought it might've been a comment. I'll take a look, as this PR otherwise looks solid to me. Thanks @F3PiX |
@F3PiX I marked the CC issue as wontfix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @F3PiX – actually, I think CC has a point about the complexity 🙃 : I noticed that the helper methods are all inlined into the constructor … which is valid ruby, but not very readable and not needed, either.
This is probably also the reason for the diff being so noisy and making me lose track of which line was moved where. Can you move the helper functions back to the bottom of the file please?
can :crud, User, id: user.id | ||
can :crud, User if user.admin? | ||
can :read, User | ||
can :update, User, id: user.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the admin call is guarded behind a if user.confirmed?
. I feel we should keep the current behaviour. If anything, we want admins to be able to fix a user's typo'd email address as a response to a support request ticket.
In the user factory a user has a confirmed_at date, so we treat users as `confirmed` by default. Adding the trait makes it explicit if we are testing an unconfirmed user.
With extra checks to make sure we are testing what we intend to test.
Specs are flickering because of a vailidation error on the Factory.
@carpodaster THANKS! and sorry for the mess.
|
This is covered now by #997 rgsoc-teams/spec/models/ability/admin_spec.rb Lines 14 to 24 in 9d685da
Closing this. |
Related issue #991 (Break Down step 2)
We need to restrict access for unconfirmed users but let them update their email address nevertheless.
Note: I would appreciate help with the feature tests. This is a first attempt.
Follow up issues:
can :read, :feed_entry
, or else remove itscan?
check in views. (Public activities shouldn't be restricted at all.)