mirror of
				https://github.com/gristlabs/grist-core.git
				synced 2025-06-13 20:53:59 +00:00 
			
		
		
		
	(core) make SELF_HYPERLINK urls cleaner
Summary: This cleans up a few things about SELF_HYPERLINK urls: * Use `urlId` rather than `docId`. * Correctly merge personal org subdomain. * In dev environment, use clearer port number. Test Plan: updated test Reviewers: alexmojaki, dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2841
This commit is contained in:
		
							parent
							
								
									37698f9cb5
								
							
						
					
					
						commit
						c6265335af
					
				@ -2277,15 +2277,24 @@ export class HomeDBManager extends EventEmitter {
 | 
			
		||||
  public normalizeOrgDomain(orgId: number, domain: string|null,
 | 
			
		||||
                            ownerId: number|undefined, mergePersonalOrgs: boolean = true,
 | 
			
		||||
                            suppressDomain: boolean = false): string {
 | 
			
		||||
    if (!domain) {
 | 
			
		||||
      if (ownerId) {
 | 
			
		||||
        // This is an org with no domain set, and an owner set.
 | 
			
		||||
        domain = mergePersonalOrgs ? this.mergedOrgDomain() : `docs-${this._idPrefix}${ownerId}`;
 | 
			
		||||
      } else {
 | 
			
		||||
        // This is an org with no domain or owner set.
 | 
			
		||||
        domain = `o-${this._idPrefix}${orgId}`;
 | 
			
		||||
    if (ownerId) {
 | 
			
		||||
      // An org with an ownerId set is a personal org.  Historically, those orgs
 | 
			
		||||
      // have a subdomain like docs-NN where NN is the user ID.
 | 
			
		||||
      const personalDomain = `docs-${this._idPrefix}${ownerId}`;
 | 
			
		||||
      // In most cases now we pool all personal orgs as a single virtual org.
 | 
			
		||||
      // So when mergePersonalOrgs is on, and the subdomain is either not set
 | 
			
		||||
      // (as it is in the database for personal orgs) or set to something
 | 
			
		||||
      // like docs-NN (as it is in the API), normalization should just return the
 | 
			
		||||
      // single merged org ("docs" or "docs-s").
 | 
			
		||||
      if (mergePersonalOrgs && (!domain || domain === personalDomain)) {
 | 
			
		||||
        domain = this.mergedOrgDomain();
 | 
			
		||||
      }
 | 
			
		||||
    } else if (suppressDomain)  {
 | 
			
		||||
      if (!domain) {
 | 
			
		||||
        domain = personalDomain;
 | 
			
		||||
      }
 | 
			
		||||
    } else if (suppressDomain || !domain) {
 | 
			
		||||
      // If no subdomain is set, or custom subdomains or forbidden, return something
 | 
			
		||||
      // uninspiring but unique, like o-NN where NN is the org ID.
 | 
			
		||||
      domain = `o-${this._idPrefix}${orgId}`;
 | 
			
		||||
    }
 | 
			
		||||
    return domain;
 | 
			
		||||
 | 
			
		||||
@ -88,9 +88,16 @@ export async function main() {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // The home server and web server(s) are effectively identical in Grist deployments
 | 
			
		||||
  // now, but remain distinct in some test setups.
 | 
			
		||||
  const homeServerPort = getPort("HOME_PORT", 9000);
 | 
			
		||||
  const webServerPort = getPort("PORT", 8080);
 | 
			
		||||
  if (!process.env.APP_HOME_URL) {
 | 
			
		||||
    process.env.APP_HOME_URL = `http://localhost:${homeServerPort}`;
 | 
			
		||||
    // All servers need to know a "main" URL for Grist.  This is generally
 | 
			
		||||
    // that of the web server.  In some test setups, the web server port is left
 | 
			
		||||
    // at 0 to be auto-allocated, but for those tests it suffices to use the home
 | 
			
		||||
    // server port.
 | 
			
		||||
    process.env.APP_HOME_URL = `http://localhost:${webServerPort || homeServerPort}`;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Bring up the static resource server
 | 
			
		||||
@ -107,7 +114,6 @@ export async function main() {
 | 
			
		||||
 | 
			
		||||
  // If a distinct webServerPort is specified, we listen also on that port, though serving
 | 
			
		||||
  // exactly the same content.  This is handy for testing CORS issues.
 | 
			
		||||
  const webServerPort = getPort("PORT", 8080);
 | 
			
		||||
  if (webServerPort !== 0 && webServerPort !== homeServerPort) {
 | 
			
		||||
    await home.startCopy('webServer', webServerPort);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -1147,7 +1147,7 @@ export class FlexServer implements GristServer {
 | 
			
		||||
      state.ws = resource.id;
 | 
			
		||||
    } else {
 | 
			
		||||
      org = resource.workspace.org;
 | 
			
		||||
      state.doc = resource.id;
 | 
			
		||||
      state.doc = resource.urlId || resource.id;
 | 
			
		||||
      state.slug = getSlugIfNeeded(resource);
 | 
			
		||||
    }
 | 
			
		||||
    state.org = this.dbManager.normalizeOrgDomain(org.id, org.domain, org.ownerId);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user