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: remove onDelete for Placeholder tag for non Platform admiins #3959

Merged
merged 11 commits into from
Nov 20, 2024

Conversation

RODO94
Copy link
Contributor

@RODO94 RODO94 commented Nov 14, 2024

What does this PR do?

This PR adds a role access constraint to the Placeholder tag so only PlatformAdmins can edit it, but everyone can see it.

To do this, I have restricted the renderOption function so it only shows Placeholder tag in the MultiSelect for PlatformAdmin users. I have also added the constraint to the renderTags function, so it removes the onDelete from the Chip component when a user is not a PlatformAdmin

With the changes to TAG_DISPLAY_VALUES we can now use Role types to add further permission layers in future if required. To ensure this happens, new logic would need to be introduced to the canEdit() in ComponentTagSelect()

Copy link

github-actions bot commented Nov 14, 2024

Removed vultr server and associated DNS entries

@RODO94 RODO94 marked this pull request as ready for review November 15, 2024 14:55
@RODO94 RODO94 requested a review from a team November 15, 2024 16:02
Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

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

There might be a more generalisable pattern here than just toggling controls for a single named tag.

Could we set rules in an object, maybe a renamed/repurposed TAG_DISPLAY_VALUES that controls the behaviour?

export const TAG_DISPLAY_VALUES: Record<
  NodeTag,
  { color: keyof Palette["nodeTag"]; displayName: string, isEditable?: boolean }
> = {
  placeholder: {
    color: "blocking",
    displayName: "Placeholder",
    isEditable: useStore.getState().user?.isPlatformAdmin
  },
  ...

I think this would give us a more robust, scalable, and data driven solution.

Also, it would be great to see some tests here describing the change please 🙏

editor.planx.uk/src/ui/editor/ComponentTagSelect.tsx Outdated Show resolved Hide resolved
editor.planx.uk/src/ui/editor/ComponentTagSelect.tsx Outdated Show resolved Hide resolved
@RODO94 RODO94 force-pushed the rory/templates-tag-hide branch from ffa182a to 55c3236 Compare November 15, 2024 16:58
@RODO94 RODO94 requested a review from DafyddLlyr November 18, 2024 16:12
@RODO94 RODO94 requested a review from DafyddLlyr November 19, 2024 15:44
Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

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

This still feels a bit more complex and hard to follow than it needs to be.

I'd really recommend changing the variable name from isEditable (which denotes a boolean) to something more indicative of a Role[] - maybe editableBy?

Have a look at how EditorNavMenu solves a very similar problem.

@RODO94
Copy link
Contributor Author

RODO94 commented Nov 19, 2024

This still feels a bit more complex and hard to follow than it needs to be.

I'd really recommend changing the variable name from isEditable (which denotes a boolean) to something more indicative of a Role[] - maybe editableBy?

Have a look at how EditorNavMenu solves a very similar problem.

Nah you're definitely right, this slipped my mind when making the changes, sorry!

@RODO94 RODO94 force-pushed the rory/templates-tag-hide branch from 943f540 to 518c33f Compare November 19, 2024 17:08
@RODO94 RODO94 requested a review from DafyddLlyr November 19, 2024 17:41
@RODO94 RODO94 merged commit 6647d3a into main Nov 20, 2024
12 checks passed
@RODO94 RODO94 deleted the rory/templates-tag-hide branch November 20, 2024 12:22
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