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: handle alias redirection #1121

Merged
merged 8 commits into from
Jan 27, 2025
Merged

feat: handle alias redirection #1121

merged 8 commits into from
Jan 27, 2025

Conversation

ChaituVR
Copy link
Member

@ChaituVR ChaituVR commented Jan 24, 2025

Summary

Closes: https://github.com/snapshot-labs/workflow/issues/369

  • Handle alias spaces redirection
  • space's /about should redirect to the space overview page to handle v1's URLs

How to test

  1. http://localhost:8080/#/s:gal.eth should redirect to http://localhost:8080/#/s:g-dao.eth
  2. http://localhost:8080/#/gal.eth should redirect to http://localhost:8080/#/s:g-dao.eth
  3. http://localhost:8080/#/safe.eth should redirect to http://localhost:8080/#/s:safe.eth
  4. http://localhost:8080/#/s:safe.eth/about should redirect to should redirect to http://localhost:8080/#/s:safe
  5. http://localhost:8080/#/safe.eth/about should redirect to should redirect to http://localhost:8080/#/s:safe

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • apps/ui/src/helpers/aliases.json: Language not supported
Comments suppressed due to low confidence (1)

apps/ui/src/routes/index.ts:43

  • Ensure that the new redirection logic for handling aliases is covered by tests.
if (to.matched[0]?.name === 'space') {
@@ -25,6 +25,7 @@ export const spaceChildrenRoutes: RouteRecordRaw[] = [
component: SpaceEditor
},
{ path: '', name: 'space-overview', component: SpaceOverview },
{ path: 'about', redirect: { name: 'space-overview' } },
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? This already direct me to space overview: https://snapshot.org/#/fabien.eth/about

Copy link
Member Author

Choose a reason for hiding this comment

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

This was handled in the previous code (which is changed now to make it more readable)

redirectPath = `/${metadataNetwork}:${domain}`;
if (rest && !/^\/about$/.test(rest)) {
  redirectPath += rest;
}

// Match and redirect paths like "/safe.eth/settings" to "/s:safe.eth/settings"
const domainMatch = to.path.match(/^\/([^:\/]+?\.[^:\/]+)(\/.*)?$/);
if (domainMatch) {
const domain = domainMatch[1];
Copy link
Member

Choose a reason for hiding this comment

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

Can't we just replace the domain here and not change the whole logic? There is plenty of case to test if we change the logic.

Copy link
Member Author

@ChaituVR ChaituVR Jan 24, 2025

Choose a reason for hiding this comment

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

Here we match only if the space doesn't have s: for example URLs like /safe.eth/settings,

Updated code handles both URLs with s:safe.eth and safe.eth and redirects to new aliased space

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 a bit afraid of rewriting the logic like this, it might be hard to find out if we are breaking anything.

Do we need to redirect safe.eth to s:safe.eth? Space should have single canonical URL (aside from hardcoded redirects).

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need to redirect safe.eth to s:safe.eth

Yes, else all existing URLs will break, users reference these URLs on their forums or blogs or Twitter, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have tested most of the cases (also mentioned them in the description)

Also, this is not a complete rewrite but adds one more case to handle aliases and moving /about to routes instead of handling it in this function

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 mostly concerned by whitelist functionality as this code was used for this as well.

@ChaituVR ChaituVR requested a review from bonustrack January 24, 2025 07:53
Copy link
Member

@Sekhmet Sekhmet left a comment

Choose a reason for hiding this comment

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

Whitelist is broken:

WHITE_WHITE_LABEL_MAPPING='127.0.0.1;balancer.eth yarn dev

It redirects to http://127.0.0.1:8080/#/s:

@ChaituVR
Copy link
Member Author

Whitelist is broken:

WHITE_WHITE_LABEL_MAPPING='127.0.0.1;balancer.eth yarn dev

It redirects to http://127.0.0.1:8080/#/s:

Thanks for catching this, It was not handled in this guard before as well so I missed it. now we ignore this gaurd if it is a whitelabel domain

@ChaituVR ChaituVR requested a review from Sekhmet January 24, 2025 16:05
@Sekhmet
Copy link
Member

Sekhmet commented Jan 24, 2025

@wa0x6e would appreciate if you could take a look to see if it doesn't break anything whitelabel related.

Copy link
Member

@Sekhmet Sekhmet left a comment

Choose a reason for hiding this comment

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

tACK

Looks good to me and it seems to work, but not sure if all edge cases for whitelist are handled. Would be good to get approval from @wa0x6e for this.

@bonustrack bonustrack merged commit 97a87e4 into master Jan 27, 2025
1 check passed
@bonustrack bonustrack deleted the alias-space-name branch January 27, 2025 13:05
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.

3 participants