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

Querying Memberships Fix: ensure distinct memberships when querying for ones own public memberships #4333

Merged

Conversation

yuenmichelle1
Copy link
Collaborator

Bug found while working on User Groups Features

Correspondence on issue found in this Slack thread here: https://zooniverse.slack.com/archives/C010QAPB67J/p1715888434468079?thread_ts=1715813389.436219&cid=C010QAPB67J

TL;DR; of the issue is that when doing a GET request to /memberships (either via /memberships?user_id=_user_group_id=_ or via /memberships/id) to one's own public membership, response responds with duplicates.

  • The reason is that when querying memberships (in membership policy) we add a union of any public memberships. This leads to duplicates when one is querying one's own public membership.
  • Because of this duplicates issue, we cannot deactivate memberships through DELETE because ETag headers will never match the precondition (due to response of GET request having dupes). Which results in 412 Precondition Failed error.

Changes:

  • Ensure distinct memberships returned in query
  • Updating membership policy specs to ensure duplicates are not return using a contains_exactly rspec matching array method vs includes match

Review checklist

  • First, the most important one: is this PR small enough that you can actually review it? Feel free to just reject a branch if the changes are hard to review due to the length of the diff.
  • If there are any migrations, will they the previous version of the app work correctly after they've been run (e.g. the don't remove columns still known about by ActiveRecord).
  • If anything changed with regards to the public API, are those changes also documented in the apiary.apib file?
  • Are all the changes covered by tests? Think about any possible edge cases that might be left untested.

@yuenmichelle1 yuenmichelle1 changed the title Querying Memberships Fix: ensure unique memberships when querying for ones own public memberships Querying Memberships Fix: ensure distinct memberships when querying for ones own public memberships May 17, 2024
Copy link
Member

@zwolf zwolf left a comment

Choose a reason for hiding this comment

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

LGTM, just a comment on the readability of those long argument lists.

spec/policies/membership_policy_spec.rb Outdated Show resolved Hide resolved
spec/policies/membership_policy_spec.rb Outdated Show resolved Hide resolved
@yuenmichelle1 yuenmichelle1 merged commit 2bc2583 into master May 20, 2024
8 checks passed
@yuenmichelle1 yuenmichelle1 deleted the fix-get-membership-when-querying-public-memberships branch May 20, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants