From 952544432e3deb84b9e3996d93c9ef72d88c6e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Guti=C3=A9rrez=20Hermoso?= Date: Mon, 5 Aug 2024 14:51:47 -0400 Subject: [PATCH] UserManager: show proper org domain (#476) We had `getgrist.com` hardcoded here, which only works for SaaS. The base domain as well as the way that orgs are encoded in the URL can be different in other circumstances. If we are encoding orgs in the domain name, that's easy. We just do `orgname.base.domain.name`. If we are not, then we first try a base domain, and if that isn't set, we'll use the domain of the home server. --- app/client/ui/UserManager.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/app/client/ui/UserManager.ts b/app/client/ui/UserManager.ts index b615608b..42fb0909 100644 --- a/app/client/ui/UserManager.ts +++ b/app/client/ui/UserManager.ts @@ -6,8 +6,9 @@ * It can be instantiated by calling showUserManagerModal with the UserAPI and IUserManagerOptions. */ import { makeT } from 'app/client/lib/localization'; -import {commonUrls} from 'app/common/gristUrls'; +import {commonUrls, isOrgInPathOnly} from 'app/common/gristUrls'; import {capitalizeFirstWord, isLongerThan} from 'app/common/gutil'; +import {getGristConfig} from 'app/common/urlUtils'; import {FullUser} from 'app/common/LoginSessionAPI'; import * as roles from 'app/common/roles'; import {Organization, PermissionData, UserAPI} from 'app/common/UserAPI'; @@ -816,15 +817,25 @@ const cssMemberPublicAccess = styled(cssMemberSecondary, ` function renderTitle(resourceType: ResourceType, resource?: Resource, personal?: boolean) { switch (resourceType) { case 'organization': { - if (personal) { return t('Your role for this team site'); } - return [ - t('Manage members of team site'), - !resource ? null : cssOrgName( - `${(resource as Organization).name} (`, - cssOrgDomain(`${(resource as Organization).domain}.getgrist.com`), - ')', - ) - ]; + if (personal) { + return t('Your role for this team site'); + } + + function getOrgDisplay() { + if (!resource) { + return null; + } + + const org = resource as Organization; + const gristConfig = getGristConfig(); + const gristHomeHost = gristConfig.homeUrl ? new URL(gristConfig.homeUrl).host : ''; + const baseDomain = gristConfig.baseDomain || gristHomeHost; + const orgDisplay = isOrgInPathOnly() ? `${baseDomain}/o/${org.domain}` : `${org.domain}${baseDomain}`; + + return cssOrgName(`${org.name} (`, cssOrgDomain(orgDisplay), ')'); + } + + return [t('Manage members of team site'), getOrgDisplay()]; } default: { return personal ?