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

Org page improvements #888

Merged
merged 48 commits into from
Jul 4, 2024
Merged

Org page improvements #888

merged 48 commits into from
Jul 4, 2024

Conversation

rmunn
Copy link
Contributor

@rmunn rmunn commented Jun 14, 2024

Fixes #881.

  • Org page now shows "Leave org" button only to members
  • Org page now shows Settings tab only to members or site admins
  • Members list on org page hides email/username column if you're not an org admin (or site admin)
  • Members list on org page only shows org admins if a non-member is viewing it
  • Projects list on org page only shows public projects, or projects you yourself are a member of
    • This rule applies to both members and non-members equally
  • Org admins can still see all projects (and site admins too)
  • Org admins can click on any org member to see all his details
    • Works like admin dashboard, but restricted to only viewing org members

Screenshots:

Org page members list as seen by non-member (shows only org admins):

image

Org page members list as seen by org admin (shows all members, but not emails since only site admins can see emails):

image

Org page members list as seen by site admin (shows emails, also shows all members even though site admin isn't an org member):

image

Copy link

github-actions bot commented Jun 14, 2024

UI unit Tests

11 tests  ±0   11 ✅ ±0   0s ⏱️ ±0s
 3 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit b62400f. ± Comparison against base commit baaa496.

♻️ This comment has been updated with latest results.

@rmunn rmunn self-assigned this Jun 14, 2024
Copy link

github-actions bot commented Jun 17, 2024

C# Unit Tests

52 tests   52 ✅  5s ⏱️
10 suites   0 💤
 1 files     0 ❌

Results for commit b62400f.

♻️ This comment has been updated with latest results.

@rmunn rmunn mentioned this pull request Jun 18, 2024
@rmunn rmunn marked this pull request as ready for review June 18, 2024 08:04
@rmunn rmunn requested a review from myieye June 18, 2024 08:04
myieye
myieye previously requested changes Jun 18, 2024
Copy link
Contributor

@myieye myieye left a comment

Choose a reason for hiding this comment

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

There's a lot of tricky stuff in here. Keep it up! 👍

@myieye
Copy link
Contributor

myieye commented Jun 19, 2024

I don't have time to think this through right now, but...I think we likely have a problem here.

The project refresh middleware works by assuming that a user will only query projects that it is a member of.
If there's a mismatch between the JWT and the project being queried, then we refresh.

I'm only just realizing this, so I haven't analyzed wether you've considered this or not, but...I'm guessing the logic's not quite right.
We'll presumably also need to adapt quite a bit for public projects.

I'm guessing the Exception you got was, because your code refreshes the JWT much more often than desired.

@rmunn
Copy link
Contributor Author

rmunn commented Jun 19, 2024

@myieye - Commit ae4c382 has the frontend code we discussed at the meeting, which I'm struggling to get the right Typescript types for.

@rmunn
Copy link
Contributor Author

rmunn commented Jun 19, 2024

I don't have time to think this through right now, but...I think we likely have a problem here.

The project refresh middleware works by assuming that a user will only query projects that it is a member of. If there's a mismatch between the JWT and the project being queried, then we refresh.

Right: this might cause refreshes more often than needed. But it limits itself to one refresh per query, at least. Still, that's more work than truly needed, you're right. I don't have time to rethink this today, though.

@myieye
Copy link
Contributor

myieye commented Jun 19, 2024

@rmunn I got the GQL query working in 084cca1. I just live off of copy/paste 😆

@rmunn
Copy link
Contributor Author

rmunn commented Jun 20, 2024

Rebasing on top of new develop now that #865 has been merged.

@rmunn rmunn force-pushed the feat/org-page-improvements branch 2 times, most recently from 7f5bdfc to eaf6e8b Compare June 20, 2024 08:31
@rmunn rmunn mentioned this pull request Jun 20, 2024
2 tasks
@rmunn rmunn dismissed myieye’s stale review June 26, 2024 09:20

Dismissing Tim's review as he's away for three months; will request re-review from Kevin.

@rmunn rmunn requested a review from hahn-kev June 26, 2024 09:20
@hahn-kev
Copy link
Collaborator

hahn-kev commented Jul 1, 2024

@rmunn I've made some changes to how we're returning orgs for permission issues. When querying the org list (default handling) only admins can query projects and members.
The orgById query has special handling so it can return more data, and the expectation is that the data will be filtered in the method based on user permissions, that is still todo for the PR. Keep in mind that the user may not query members or projects, so be sure to handle that case.

Also per Tim's comment, we need to rework the logic of the refresh jwt code as a query returning an org does not mean the user should now have access to it, the way it's setup now I think it'll refresh any time a user visits the org list page.

@rmunn
Copy link
Contributor Author

rmunn commented Jul 1, 2024

The new OrgPermissionTests all pass now. But look at commit 19eabe4, which is a deliberate bug. That change should have caused a test to fail, but it didn't. In order to make this change fail, we'll need a third project in our seeding data, one that is confidential but that the "editor" user is not a member of. Then that test will fail until commit 19eabe4 is reverted, thereby proving that the tests can catch the bug I deliberately introduced in 19eabe4.

@rmunn
Copy link
Contributor Author

rmunn commented Jul 1, 2024

For the third project, it would be useful for it to be an empty project. I suggest we zip up the backend/LexBoxApi/Services/HgEmptyRepo/ directory and put it on Google Drive, then download it the same way we download sena-3.zip and elawa.zip. We would also need to modify deployment/init-repos/hg-deployment-patch.yaml to create the directory for the empty project, and the Taskfile.yml file as well.

Actually, I'm starting to think that this should be tracked as its own issue.

@rmunn rmunn mentioned this pull request Jul 1, 2024
@rmunn rmunn linked an issue Jul 2, 2024 that may be closed by this pull request
@rmunn rmunn force-pushed the feat/org-page-improvements branch from 1c8567d to fdf965b Compare July 2, 2024 05:21
@rmunn
Copy link
Contributor Author

rmunn commented Jul 2, 2024

After #900 was merged, there was (as expected) a merge conflict in Taskfile.yml, so I rebased on top of the new state of develop to fix the conflict.

rmunn added 5 commits July 2, 2024 13:24
Site admins can view any org page, but shouldn't see a "Leave Org"
button unless they're actually members of the org.
Commented out for now because "orgs can own projects" PR needs to be
merged before this will compile.
This will be useful for enforcing GQL permissions such as "non-members
can only see the list of admins, members can see other members".
rmunn added 9 commits July 2, 2024 13:30
Public projects have isConfidential *false*, not true.
The "editor" user is a member of the test org; this test wants a
non-member.
This proves that the test will catch this bug.
This proves that the test suite is now catching the bug.
Also include unit tests to prove that non-managers cannot see usernames.
The org members table doesn't need to show the "user is locked" or
"email not verified" icons; those can be left on the admin dashboard.
But we do want the org managers to be able to see members' usernames,
since there may very well be guest users in the org with usernames but
no email addresses, and org managers should be able to help them get
Send/Receive configuration set up properly.
@rmunn rmunn force-pushed the feat/org-page-improvements branch from 7b12448 to 8cc5e01 Compare July 2, 2024 06:30
@rmunn
Copy link
Contributor Author

rmunn commented Jul 2, 2024

Currently I'm seeing a single unit test failure on my machine (as opposed to the three failing tests in the GHA workflow checks): Testing.ApiTests.AuthTests.CanUseBearerAuth fails with a 401 Unauthorized error. The logs show the following:

LexBoxApi.Auth.Requirements.AudienceRequirementHandler[0]
Token does not have the required audience: [(null)] not in LexboxApi
Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
Authorization failed. Fail() was explicitly called.
OpenIddict.Validation.OpenIddictValidationDispatcher[0]
The response was successfully returned as a challenge response: {
  "error": "invalid_token",
  "error_description": "The signing key associated to the specified token was not found.",
  "error_uri": "https://documentation.openiddict.com/errors/ID2090"
}.

Parsing the jwt that the test is handling shows "aud": "LexboxApi" in the JWT, so I don't kow why the audience is null by the time it's reaching the AudienceRequirementHandler.

However, the same failure occurs when I run the tests on develop, so this failure is unconnected to this PR. (Which doesn't touch anything related to signing keys for JWT or token audiences, so it would have surprised me if the PR was actually causing the test failure).

rmunn added 2 commits July 2, 2024 14:25
Org page show shows the email/username column to org managers/admins,
because we have decided that they're allowed to see it and have
implemented GraphQL rules to that effect.
Org managers, like admins, should be able to see who created a guest
user's account. We expose this in the UserModal by adding createdBy to
the orgMemberById query.
@rmunn rmunn requested review from hahn-kev and removed request for hahn-kev July 2, 2024 07:37
@rmunn
Copy link
Contributor Author

rmunn commented Jul 2, 2024

Adding a third test project exposed a bug: if the org manager hovers over a confidential project that he's not a member of, then the GraphQL query for the project page will fail and it will show an error popup. After discussing this with @hahn-kev we decided that we're going to edit the project page query permissions to allow org admins to view projects owned by their org, at which point the error popup will no longer show. So we'll leave this bug in place for now, as we're going to fix it soon in a separate PR.

@hahn-kev, I believe this is ready for a final review now.

@rmunn rmunn mentioned this pull request Jul 2, 2024
7 tasks
@rmunn
Copy link
Contributor Author

rmunn commented Jul 2, 2024

... if the org manager hovers over a confidential project that he's not a member of, then the GraphQL query for the project page will fail ...

This is now tracked in #915, which I will work on next.

Copy link
Collaborator

@hahn-kev hahn-kev left a comment

Choose a reason for hiding this comment

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

I requested a change which actually ends up simplifying some of the code.

backend/LexBoxApi/GraphQL/LexQueries.cs Outdated Show resolved Hide resolved
backend/LexBoxApi/GraphQL/LexQueries.cs Outdated Show resolved Hide resolved
backend/LexBoxApi/GraphQL/LexQueries.cs Outdated Show resolved Hide resolved
rmunn added 3 commits July 3, 2024 13:48
We have that logic in PermissionService now, so let's use it.
We decided that people who aren't org members can still see the projects
that they themselves are a member of, which means the rule for projects
is the same for both members and non-members so the code gets simpler.
Copy link
Collaborator

@hahn-kev hahn-kev left a comment

Choose a reason for hiding this comment

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

looks good to me. There's still an unresolved conversation that requires a change. There's also some failing tests so you should look into those too, they're working on develop, so I'm not sure why they're failing here.

rmunn added 2 commits July 4, 2024 12:47
Now there's a single source of truth for the two middleware classes that
need to reference it.
The LoginAs method needs to be virtual so that it can be mocked when
non-integration tests are running, otherwise the mock will still try to
log in to a server that isn't there.
@rmunn rmunn merged commit a928b89 into develop Jul 4, 2024
14 checks passed
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.

New empty test project Org page permission improvements
3 participants