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

UserManager: show proper org domain (#476) #1143

Merged
merged 1 commit into from
Aug 6, 2024
Merged

Conversation

jordigh
Copy link
Contributor

@jordigh jordigh commented Jul 31, 2024

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.

fixes: #476

@jordigh jordigh force-pushed the jordigh/fix-org-display branch from c3c1217 to bda85cf Compare July 31, 2024 21:09
@jordigh jordigh changed the title UserManager: show proper org domain (#476) UserManager: show proper org domain (fixes #476) Jul 31, 2024
@jordigh jordigh changed the title UserManager: show proper org domain (fixes #476) UserManager: show proper org domain Jul 31, 2024
@jordigh jordigh changed the title UserManager: show proper org domain UserManager: show proper org domain (#476) Jul 31, 2024
@berhalak berhalak self-requested a review August 5, 2024 09:32
return [
t('Manage members of team site'),
!resource ? null : cssOrgName(
`${(resource as Organization).name} (`,
cssOrgDomain(`${(resource as Organization).domain}.getgrist.com`),
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously we used .domain prop, and now you calculate it using .baseDomain config.
Can you explain why? And also I see this comment on baseDomain:

  // Base domain for constructing new URLs, should start with "." and not include port, e.g.
  // ".getgrist.com". It should be unset for localhost operation and in single-org mode.

This should be unset looks suspicious. Are you sure it will work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

domain is the subdomain, baseDomain is what was hardcoded as .getgrist.com.

You were right, though, I should be using domain for the orgDisplay not name.

const gristConfig = getGristConfig();
const gristHomeHost = gristConfig.homeUrl ? new URL(gristConfig.homeUrl).host : '';
const baseDomain = gristConfig.baseDomain || gristHomeHost;
const orgName = (resource as Organization).name;
Copy link
Contributor

Choose a reason for hiding this comment

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

Later in the code you have resource ? ... : ... code fragment, which checks if resource is null or not, but here, you ignore this check and just grab the .name prop. Can you refactor it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about this refactoring?

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.
@jordigh jordigh force-pushed the jordigh/fix-org-display branch 2 times, most recently from b0e9174 to e4f85bc Compare August 6, 2024 13:27
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}`;
Copy link
Contributor

@berhalak berhalak Aug 6, 2024

Choose a reason for hiding this comment

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

I don't like the possibility that a baseDomain can be empty, and then gristHomeHost will be something like foo.example.com and then you concatenate it with a domain name which will produce something like catsfoo.example.com without a dot in the middle.

I tried reproducing this with various setups but couldn't - baseDomain was always set, so I think it is fine.

@jordigh jordigh merged commit 9525444 into main Aug 6, 2024
11 checks passed
@jordigh jordigh deleted the jordigh/fix-org-display branch August 6, 2024 18:39
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.

[Minor BUG] Self-hosted grist shows wrong url in "Manage members" dialog
2 participants