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

feat: Only show "Team Settings" menu for users with teamEditor role #2693

Merged
merged 5 commits into from
Jan 24, 2024

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Jan 23, 2024

What does this PR do?

  • Visually hides "Team Settings" menu for users who do not have the teamEditor or platformAdmin roles
    • Also handle "Global Settings" and "Flow Settings" displaying in the incorrect context
  • Adds route guard for <team>/settings
    • Also added a guard for <team>/<flow>/settings and /global-setting as these were previously missed
  • Correctly sets up Hasura permissions for the teamEditor role

If we decide we want / need a teamAdmin role we can add one in future but this seems fine to me for the moment

TeamEditor
image

Not TeamEditor
image

@DafyddLlyr DafyddLlyr changed the title feat: Only show "Team Settings" menu for user with teamEditor role feat: Only show "Team Settings" menu for users with teamEditor role Jan 23, 2024
Copy link

github-actions bot commented Jan 23, 2024

Removed vultr server and associated DNS entries

@DafyddLlyr DafyddLlyr requested a review from a team January 23, 2024 10:23
@DafyddLlyr DafyddLlyr marked this pull request as ready for review January 23, 2024 10:23
@DafyddLlyr DafyddLlyr marked this pull request as draft January 23, 2024 15:57
Copy link
Contributor

@Mike-Heneghan Mike-Heneghan left a comment

Choose a reason for hiding this comment

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

Working as expected for me on the pizza with regard to hiding of the settings link 👍

As you mentioned I can still access the route but I see that's on the TODO.

Although I was surprised that I think the Hasura permissions still allowed me to edit the forms when I believe I was just a TeamViewer.

I was also able to update other teams design settings.

My user permissions:

"is_platform_admin": false,
"is_staging_only": false,
"teams": [
  {
    "role": "teamEditor",
    "team": {
      "slug": "templates"
    }
  },
  {
    "role": "teamViewer",
    "team": {
      "slug": "doncaster"
    }
  }
]

Is that expected behaviour or maybe I'm making a mistake locally?

I think this will effectively be resolved with the guard clauses I was just surprised 🤔

@Mike-Heneghan
Copy link
Contributor

Working as expected for me on the pizza with regard to hiding of the settings link 👍

As you mentioned I can still access the route but I see that's on the TODO.

Although I was surprised that I think the Hasura permissions still allowed me to edit the forms when I believe I was just a TeamViewer.

I was also able to update other teams design settings.

My user permissions:

"is_platform_admin": false,
"is_staging_only": false,
"teams": [
  {
    "role": "teamEditor",
    "team": {
      "slug": "templates"
    }
  },
  {
    "role": "teamViewer",
    "team": {
      "slug": "doncaster"
    }
  }
]

Is that expected behaviour or maybe I'm making a mistake locally?

I think this will effectively be resolved with the guard clauses I was just surprised 🤔

Sorry @DafyddLlyr I didn't realised this had been swapped to draft.

Copy link

github-actions bot commented Jan 23, 2024

🤖 Hasura Change Summary compared a subset of table metadata including permissions:

Updated Tables (1)

Comment on lines +30 to +34
const isAuthorised = useStore.getState().canUserEditTeam(req.params.team);
if (!isAuthorised)
throw new NotFoundError(
`User does not have access to ${req.originalUrl}`,
);
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 noticed that this was missing and picked up the fix here. On staging and prod you can navigate to <flow>/settings without the proper permissions.

Comment on lines +418 to +425
const isFlowSettingsVisible =
route.data.flow && !route.data.flow && canUserEditTeam(team.slug);

const isTeamSettingsVisible =
route.data.team && !route.data.flow && canUserEditTeam(team.slug);

const isGlobalSettingsVisible =
!route.data.flow && !team.slug && user?.isPlatformAdmin;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A few related fixes / tidy ups to the change made in this PR , apologies for polluting things a little.

Comment on lines +1488 to +1495
filter:
team:
members:
_and:
- user_id:
_eq: x-hasura-user-id
- role:
_eq: teamEditor
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This equates to "teams where the user is a teamEditor"

@DafyddLlyr
Copy link
Contributor Author

@Mike-Heneghan Thanks for taking a look - things should now be resolved 👍

@DafyddLlyr DafyddLlyr marked this pull request as ready for review January 23, 2024 17:01
Copy link
Contributor

@Mike-Heneghan Mike-Heneghan left a comment

Choose a reason for hiding this comment

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

All working as expected for me and thanks for updating the other routes as well!

@DafyddLlyr DafyddLlyr merged commit de43957 into main Jan 24, 2024
12 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/team-themes-permissions branch January 24, 2024 08:33
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