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

whoami: List public group memberships (take 2) #780

Merged
merged 4 commits into from
Apr 22, 2024
Merged

Conversation

victorlin
Copy link
Member

@victorlin victorlin commented Jan 10, 2024

Description of proposed changes

See commit messages.

Related issue(s)

Checklist

  • Checks pass
  • Local testing: public testing env group memberships are listed
  • Post-merge: public production env group memberships are listed on canary site

@victorlin victorlin requested a review from a team January 10, 2024 22:25
@victorlin victorlin self-assigned this Jan 10, 2024
@nextstrain-bot nextstrain-bot temporarily deployed to nextstrain-s-victorlin--i1jip8 January 10, 2024 22:25 Inactive
@tsibley tsibley self-requested a review January 10, 2024 22:28
src/endpoints/users.js Outdated Show resolved Hide resolved
Copy link
Member

@tsibley tsibley left a comment

Choose a reason for hiding this comment

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

This needs rebasing for the Gatsby → Next.js switch.

src/endpoints/users.js Show resolved Hide resolved
The reference was removed in "splash page redesign" (fab5217).
The two exported values are independent of user information, so remove
'user' from the filename.
This is a re-attempt at ab569ec, which
was reverted in 6e61054.

Previously, there was no way to identify which public groups a user has
membership in on any nextstrain.org page. This change makes that
possible on the whoami page.

Notes on implementation:

1. The visibleGroups variable cannot be used here because it provides no
   way to distinguish a member of a public group with view-only
   permission and an external user that has the same view-only
   permission. Those can only be distinguished by inspecting the user's
   authorization roles, which is exposed through a new variable
   groupMemberships.
2. There is some overlap between visibleGroups and groupMemberships, but
   they serve different purposes. An alternative to bring the two
   together would be to update the group listing page to show group
   memberships and other public groups separately, but that is a bigger
   change.
membershipRoles is internal and not used by the frontend.

Future-proofs against any unintentional leaking of new properties.
@victorlin victorlin merged commit cb82f3c into master Apr 22, 2024
4 checks passed
@victorlin victorlin deleted the victorlin/whoami branch April 22, 2024 22:50
* the Group class.
*/
const groupMemberships = (user) => user?.groups
?.map(name => new Group(name))
Copy link
Member

Choose a reason for hiding this comment

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

This ended up breaking /whoami for me (noticed in production just now) because my Cognito user is a member of Cognito groups for which there are no corresponding Nextstrain groups. This is a historical artifact and likely only affects me (and maybe one or two other devs), but it'd still be better to be robust in the face of unexpected input.

I noticed the issue in the web, where /whoami 404s for me when JSON is requested, but reproduced it below with curl for an example:

$ nextstrain whoami
# Logged into https://nextstrain.org as…
username: trs
email: tsibley@fredhutch.org
groups: 
  - !flags/canary
  - blab-private/editors
  - blab/editors
  - seattleflu/editors
  - test/editors
  - trs-test/owners

$ curl -s https://nextstrain.org/whoami -H 'Accept: application/json' -H @<(nextstrain authorization)
{"error":"unknown group: test"}

Copy link
Member

Choose a reason for hiding this comment

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

I'd previously said:

Longer term, it probably makes sense to convert req.user.groups to Group objects in the authn code rather than here. There can also be some additional error/edge-case handling (e.g. group names reported by Cognito that the server doesn't know about).

and I guess I shouldn't have said "Longer term"!

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, fixing in #839

@victorlin victorlin mentioned this pull request Apr 25, 2024
2 tasks
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.

3 participants