-
Notifications
You must be signed in to change notification settings - Fork 8.6k
DEV: Remove now-redundant is_staff check in can_invite_to_forum #33742
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
Conversation
return false if !@user.in_any_groups?(SiteSetting.invite_allowed_groups_map) | ||
return false if !SiteSetting.max_invites_per_day.to_i.positive? && !is_staff? | ||
|
||
groups.blank? || groups.all? { |g| can_edit_group?(g) } |
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.
is_admin?
is already checked for in can_edit_group?
, no need to leak the logic into here.
(is_admin? || groups.blank? || groups.all? { |g| can_edit_group?(g) }) | ||
return false if !authenticated? | ||
return false if !@user.in_any_groups?(SiteSetting.invite_allowed_groups_map) | ||
return false if !SiteSetting.max_invites_per_day.to_i.positive? && !is_staff? |
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'm not sure this escape hatch for staff works in practice, because I didn't see any conditional in the rate-limiting logic, but leaving it here for now and can investigate separately.
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 also unfurled this one long conditional into multiple guard clauses.
Thank you! 🙏
af6e0de
to
59ce6ed
Compare
5592d5e
to
7c827d3
Compare
eee6853
to
5dd2c53
Compare
5dd2c53
to
bd8d4ec
Compare
What is this change?
We check for membership in
invite_allowed_groups
, which hasadmins
andmoderators
as a mandatory value, so it's redundant to checkis_staff?
as well.I also unfurled this one long conditional into multiple guard clauses.
The refactoring is covered by existing tests in
invite_guardian_spec.rb
.