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: introduce temporary admin mode for site config #1033

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dcshzj
Copy link
Contributor

@dcshzj dcshzj commented Jan 24, 2025

Problem

Ops load on engineers is quite high for editing the site config, navbar and footer.

Solution

Breaking Changes

  • Yes - this PR contains breaking changes
  • No - this PR is backwards compatible

Features:

  • Add a new /admin route for Isomer Admins to directly modify the site's config, theme, navbar and footer items.
    • Access to this feature is gated for just Isomer Admins, all other users will not know of its existence and even if they do, they will not have the permission to access the form to edit.

Before & After Screenshots

View for Isomer Admins:

image

View for unauthorised users:

image

Tests

  • Log in to Studio as a whitelisted Isomer Admin (your email should be whitelisted inside Growthbook).
  • Go to any site.
  • Verify that a star icon appears on the navigation bar on the left side.
  • Click on the star icon, verify that you are able to see the form to change the site configurations.
  • Change any configuration and save, verify that you are able to save successfully.
  • Navigate to any page and verify that those changes have persisted (or change another configuration that is more visible, such as the navigation bar or footer).
  • Log in to Studio as a non-whitelisted user.
  • Go to any site, verify that there are only 2 icons on the navigation bar on the left side.
  • Append /admin to the URL and navigate to the page.
  • Verify that the page shows that you do not have permission to access the page.

@dcshzj dcshzj requested a review from a team as a code owner January 24, 2025 02:31
@datadog-opengovsg
Copy link

datadog-opengovsg bot commented Jan 24, 2025

Datadog Report

Branch report: feat/site-config-admin
Commit report: e47e08d
Test service: isomer-studio

✅ 0 Failed, 261 Passed, 36 Skipped, 47.08s Total Time
➡️ Test Sessions change in coverage: 1 no change

seaerchin
seaerchin previously approved these changes Jan 24, 2025
@seaerchin seaerchin dismissed their stale review January 24, 2025 09:13

missed something oopsie

Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

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

minor issue - not too sure what the useEffect is doing! i think because this affects end user sites (and the site wide config), we might want to sanitise the json object to make sure it's valid (cos we're just parsing to make sure it's valid json, but not that the jsonobject matches what we expect - eg: {siteNavItems: [...]} vs {siteNavItem: [...]}

but no actionable re: the second point of matching - onlyi want to make sure the useEffect isn't sussy

Comment on lines +123 to +140
useEffect(() => {
const handleRouteChange = (url: string) => {
if (isDirty) {
router.events.off("routeChangeStart", handleRouteChange)
setNextUrl(url)
router.events.emit("routeChangeError")
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw "Error to abort router route change. Ignore this!"
}
}

if (!isOpen) {
router.events.on("routeChangeStart", handleRouteChange)
}
return () => {
router.events.off("routeChangeStart", handleRouteChange)
}
}, [isOpen, router.events, isDirty])
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not quiet sure what this useEffect does? if the modal is closed + there are changes, we unsub to routeChangeStart (so this iwll only ever fire once) -> and we set the next url

why wouldn't we use the nextUrl of the unsaved settings modal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm this was taken directly from the settings.tsx file, mainly to trigger the unsaved settings modal if the form is dirty and the user is attempting to change to a different route (e.g. clicking on the pages icon to go back to the site dashboard). This useEffect will prevent that.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, sounds good! this honestly look abit sus but given that it's used on settings.tsx , i think it's ok.

i think it might be worth to double-check the function is cleaning up properly; just based off what i see here, we turn off the events if isDirty then we setNextUrl, but we only turn on the event when the modal is closed again? wondering if it's possible for our users to bypass the !isOpen and for routeChangeStart to be off permanently

based off what i know i don't think so, because any closing of the modal will trigger the state change, but just wanted to be sure

Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

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

mostly lgtm - i think blind spots for me are the useEffect, which is actually pretty confusing

the router method can be updated but not a real blocker, given that it's narrowly used and easy to infer from context

@@ -136,4 +144,51 @@ export const siteRouter = router({

return input
}),
setSiteConfigAdmin: protectedProcedure
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: i think this might be better named as setSiteConfigByAdmin or setAdminSiteConfig but very minor

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