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.
This commit is contained in:
Jordi Gutiérrez Hermoso 2024-08-05 14:51:47 -04:00 committed by jordigh
parent 95189158c0
commit 952544432e

View File

@ -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 ?