Skip to content

Comments

Adds owner of a group as member of that group#261

Merged
lucaspar merged 5 commits intomasterfrom
lp/wip
Feb 24, 2026
Merged

Adds owner of a group as member of that group#261
lucaspar merged 5 commits intomasterfrom
lp/wip

Conversation

@lucaspar
Copy link
Member

@lucaspar lucaspar commented Feb 23, 2026

This makes sure the owner and creator of a group is added as one of its members.

It was strange seeing a group with "0 members" after creation, even if internally, it always had an owner.

It's currently not possible to add yourself to the member list, so the user is not able to "fix" this scenario themselves. nvm, it is. But I think the change is still valid.

For more predictable data, this also prevents user removal from group when:

  • The user is the group owner.
  • The user is the last member.

The migration retroactively adds the owner of all existing groups as one of their members.

New test requirement: individual shares (non-group ones) must survive a group-access revocation.

Currently, individual access is revoked if the group access is revoked. This, combined with the change above, could cause this scenario to fail:

  1. The owner (U2) grants U1 and U2 personal (non-group) access to X.
  2. The owner also shares X with group G (which contains U1 and U2).
    Both users' existing permissions gain G in share_groups.
  3. The owner revokes group G's access to X.
  4. U1 and U2 must still have access through their individual shares.
  5. The owner must still have access via dataset ownership.

To make this work, there's a migration that creates a UserSharePermission.is_individual_share flag to keep track of how an item was shared. If this flag is present, that individual access is not revoked by revoking access to a group the user belongs to: the user must be explicitly removed instead.

@lucaspar lucaspar self-assigned this Feb 23, 2026
Copilot AI review requested due to automatic review settings February 23, 2026 20:56
@semanticdiff-com
Copy link

semanticdiff-com bot commented Feb 23, 2026

@lucaspar lucaspar added bug Something isn't working gateway Gateway component migrations Code changes that require data or schema migrations in the database. labels Feb 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR establishes a new invariant for ShareGroup functionality: group owners are always members of their own groups. This addresses the confusing UX of seeing "0 members" after creating a group, and prevents users from being unable to add themselves to their own groups.

Changes:

  • Group creation now automatically adds the owner as a member, with an initial member count of 1
  • User removal validation now prevents removing the group owner and prevents removing the last member
  • A data migration retroactively adds owners as members to all existing non-deleted groups

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
gateway/sds_gateway/users/views.py Updated _create_share_group to add owner as member; updated _process_user_removal to validate owner and last-member removal attempts
gateway/sds_gateway/users/tests/test_group_sharing.py Added tests for the new owner-as-member behavior and removal validation
gateway/sds_gateway/api_methods/migrations/0020_add_group_owner_as_member.py Data migration to retroactively add owners as members to existing groups
gateway/sds_gateway/api_methods/migrations/max_migration.txt Updated to reference the new migration
gateway/.envs/example/django.prod-example.env Corrected example domain from nd.edu to mit.edu for Haystack reference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@klpoland klpoland left a comment

Choose a reason for hiding this comment

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

Okay, yeah, I think the changes to add an extra check for individual vs group share origination should fix the issue I described. Thanks!

@lucaspar lucaspar merged commit 407bdef into master Feb 24, 2026
2 checks passed
@lucaspar lucaspar deleted the lp/wip branch February 24, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working gateway Gateway component migrations Code changes that require data or schema migrations in the database.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants