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

Detangle Cognito, sources, & group logic on authn #74

Merged
merged 1 commit into from
Jan 10, 2020

Conversation

kairstenfay
Copy link
Contributor

@kairstenfay kairstenfay commented Jan 9, 2020

Centralize the computation of the list of sources visible to the current
user, but using a different property that doesn't conflate Cognito
groups with our internal sources.

Additionally, centralize the authz decisions to stay within the Source
object.

This change was originally requested by Thomas on a recently closed
PR
.

@tsibley tsibley temporarily deployed to nextstrain-s-detangle-c-n0tomi January 9, 2020 20:07 Inactive
@kairstenfay kairstenfay force-pushed the detangle-cognito-from-sources branch from 1768ed8 to 06daa63 Compare January 9, 2020 20:07
@tsibley tsibley temporarily deployed to nextstrain-s-detangle-c-n0tomi January 9, 2020 20:07 Inactive
@@ -9,7 +9,7 @@ const UserGroups = (props) => {

const colors = [...theme.titleColors];

const groupCards = props.user.groups.map((group) => {
const groupCards = props.user.visibleSources.map((group) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

how do we feel about calling the mapping variable group still?

Copy link
Member

Choose a reason for hiding this comment

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

Just commented on that separately before I saw your note here. :-)

@@ -9,7 +9,7 @@ const UserGroups = (props) => {

const colors = [...theme.titleColors];

const groupCards = props.user.groups.map((group) => {
const groupCards = props.user.visibleSources.map((group) => {
Copy link
Member

Choose a reason for hiding this comment

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

There's a conflict of terms here: the array is one of sources, but the map function calls them groups.

It may be that my off-the-cuff suggestion of visibleSources was a poor one and visibleGroups would be better.

user.visibleSources = Array.from(sources.values())
.filter(source => source.visibleToUser(user))
.map(source => source._name)
.filter(source => groups.includes(source));
Copy link
Member

Choose a reason for hiding this comment

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

Is the purpose of this last line to filter out the non-group sources (e.g. CoreSource, CoreStagingSource, and CommunitySource)?

If so, then I think there are more future-proof ways of doing this which delegates that decision to the source itself and avoids deepening the existing hardcoded assumption/conflation that the group name matches the source name exactly.

I don't think ☝️ needs to block merge, but I'll think about it some more and maybe push a commit up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's to remove the groups/tiles that appear as core, staging, and community on nextstrain.org.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm curious to know what a better solution would be.

Copy link
Member

Choose a reason for hiding this comment

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

I'm curious to know what a better solution would be.

Not entirely sure! :-) The equating of group names with source names in this part of the code raises red flags for me, but I think avoiding that here would require broader changes than I think are worth implementing right now. So I would merge this as-is and we can revisit later during other work on Groups if it arises again.

@jameshadfield jameshadfield removed their request for review January 9, 2020 20:32
Centralize the computation of the list of sources visible to the current
user, but using a different property that doesn't conflate Cognito
groups with our internal sources.

Additionally, centralize the authz decisions to stay within the Source
object.

This change was originally [requested by Thomas on a recently closed
PR](1a65e10#commitcomment-36703817).
@kairstenfay kairstenfay force-pushed the detangle-cognito-from-sources branch from 06daa63 to 958d9d3 Compare January 9, 2020 21:50
@tsibley tsibley temporarily deployed to nextstrain-s-detangle-c-n0tomi January 9, 2020 21:50 Inactive
@kairstenfay
Copy link
Contributor Author

@tsibley I renamed visibleSources to visibleGroups.

@kairstenfay kairstenfay requested a review from tsibley January 9, 2020 21:53
@kairstenfay kairstenfay merged commit cff9909 into master Jan 10, 2020
@kairstenfay kairstenfay deleted the detangle-cognito-from-sources branch January 10, 2020 18:55
@tsibley
Copy link
Member

tsibley commented Jan 10, 2020

Ah, sorry, I was doing one last test and ran into an issue:

TypeError: "e.user.visibleGroups is undefined"

@kairstenfay kairstenfay restored the detangle-cognito-from-sources branch January 10, 2020 18:59
@kairstenfay kairstenfay deleted the detangle-cognito-from-sources branch January 10, 2020 19:03
kairstenfay added a commit that referenced this pull request Jan 10, 2020
In further testing of #74, we found an error when a user is logged-out
that prevented the splash page of nextstrain.org from loading.

Fix the error by checking if visibleGroups is defined in addition to
user before rendering the `<UserGroups>` component.
kairstenfay added a commit that referenced this pull request Jan 10, 2020
In further testing of #74, we found an error when a user is logged-out
that prevented the splash page of nextstrain.org from loading.

Fix the error by checking if visibleGroups is defined in addition to
user before rendering the `<UserGroups>` component.
kairstenfay added a commit that referenced this pull request Jan 10, 2020
In further testing of #74, we found an error when a user is logged-out
that prevented the splash page of nextstrain.org from loading.

Move the logic for determining which groups are visible to a user into
the `/whoami` endpoint. Send the resulting `visibleGroups` as an
additional key in the json load sent by this endpoint. Handle the
additional `visibleGroups` object accordingly.
kairstenfay added a commit that referenced this pull request Jan 10, 2020
In further testing of #74, we found an error when a user is logged-out
that prevented the splash page of nextstrain.org from loading.

Move the logic for determining which groups are visible to a user into
the `/whoami` endpoint. Send the resulting `visibleGroups` as an
additional key in the json load sent by this endpoint. Handle the
additional `visibleGroups` object accordingly.
kairstenfay added a commit that referenced this pull request Jan 11, 2020
In further testing of #74, we found an error when a user is logged-out
that prevented the splash page of nextstrain.org from loading.

Move the logic for determining which groups are visible to a user into
the `/whoami` endpoint. Send the resulting `visibleGroups` as an
additional key in the json load sent by this endpoint. Handle the
additional `visibleGroups` object accordingly.
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