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

message: Fix code checking group mention permission to handle anonymous user groups. #30130

Merged
merged 2 commits into from
May 20, 2024

Conversation

sahil839
Copy link
Collaborator

  • First commit is to fix code to check whether UserGroup object is linked to a NamedUserGroup object.
  • Second commit is a small optimization to check if can_mention_group is everyone group.
Self-review checklist
  • Self-reviewed the changes for clarity and maintainability
    (variable names, code reuse, readability, etc.).

Communicate decisions, questions, and potential concerns.

  • Explains differences from previous plans (e.g., issue description).
  • Highlights technical choices and bugs encountered.
  • Calls out remaining decisions and concerns.
  • Automated tests verify logic where appropriate.

Individual commits are ready for review (see commit discipline).

  • Each commit is a coherent idea.
  • Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

  • Visual appearance of the changes.
  • Responsiveness and internationalization.
  • Strings and tooltips.
  • End-to-end functionality of buttons, interactions and flows.
  • Corner cases, error conditions, and easily imagined bugs.

This commits fixes the code which checks group mention permission
to handle anonymous user groups correctly. Basically we were
not checking whether the UserGroup is linked to a NamedUserGroup
and directly accessing named_user_group which results in an
error.

We also update the error messages to include the group name
which has permission to mention the groups since now there
might be a comnbination of groups and users who has permission
to mention the group.

This commit also adds tests to check sending and editing messages
when can_mention_group is set to a anonymous user group.
This commit updates the code to not call is_user_in_group
function if can_mention_group setting is set to "role:everyone"
group.
"You are not allowed to mention user group '{user_group_name}'. You must be a member of '{can_mention_group_name}' to mention this group."
).format(user_group_name=group.name, can_mention_group_name=can_mention_group_name)
_("You are not allowed to mention user group '{user_group_name}'.").format(
user_group_name=group.name
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that can_mention_group can be a combination of users and groups, we might also want to handle the system bot separately like what should we do if the setting is set to {direct_subgroups: [everyone_group.id], direct_members: [admin.id]}. Obviously including everyone group as subgroup and then having other fields, does not make sense but we do not restrict anyone from doing this, so this might be the case.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need special code for that case; it's a useless configuration, but not a problematic one.... and might even be a useful intermediate state to keep track of some individual permissions when temporarily changing the current permission value to everyone with intent to restrict it again later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so do we want to allow system bots to mention the group in case the setting is set to {direct_subgroups: [everyone_group.id], direct_members: [admin.id]}. We do not allow currently.

user_group.direct_members.set([othello])
user_group.direct_subgroups.set([moderators_system_group])
leadership.can_mention_group = user_group
leadership.save()
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should aim to use higher-level functions than this in tests wherever possible -- there's no reason we shouldn't be able to just call the do_ with the object we want in about the same number of lines of code.

@timabbott timabbott merged commit 2007a58 into zulip:main May 20, 2024
7 checks passed
@timabbott
Copy link
Sponsor Member

Merged, with one comment about test setup patterns that might be best addressed in a follow-up PR anyway; I'm not sure whether you'll find it makes sense to add a new test_classes.py helper or something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants