mirror of
https://github.com/documize/community.git
synced 2025-07-27 17:19:42 +02:00
improved url domain matching for multi-tenant deployments
This commit is contained in:
parent
e92ad317d8
commit
2386dcbd83
3 changed files with 650 additions and 632 deletions
|
@ -41,6 +41,7 @@ func (h *Handler) Meta(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
org, err := h.Store.Organization.GetOrganizationByDomain(data.URL)
|
org, err := h.Store.Organization.GetOrganizationByDomain(data.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
h.Runtime.Log.Error("unable to fetch request meta for "+data.URL, err)
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,9 +82,13 @@ func (s Scope) GetOrganizationByDomain(subdomain string) (o org.Organization, er
|
||||||
err = nil
|
err = nil
|
||||||
subdomain = strings.TrimSpace(strings.ToLower(subdomain))
|
subdomain = strings.TrimSpace(strings.ToLower(subdomain))
|
||||||
|
|
||||||
if s.Runtime.Flags.SiteMode == env.SiteModeNormal { // only return an organization when running normally
|
// only return an organization when running normally
|
||||||
var stmt *sqlx.Stmt
|
if s.Runtime.Flags.SiteMode != env.SiteModeNormal {
|
||||||
|
err = errors.New("database not in normal mode so cannot fetch meta for " + subdomain)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var stmt *sqlx.Stmt
|
||||||
stmt, err = s.Runtime.Db.Preparex("SELECT id, refid, company, title, message, url, domain, service as conversionendpoint, email, serial, active, allowanonymousaccess, authprovider, coalesce(authconfig,JSON_UNQUOTE('{}')) as authconfig, created, revised FROM organization WHERE domain=? AND active=1")
|
stmt, err = s.Runtime.Db.Preparex("SELECT id, refid, company, title, message, url, domain, service as conversionendpoint, email, serial, active, allowanonymousaccess, authprovider, coalesce(authconfig,JSON_UNQUOTE('{}')) as authconfig, created, revised FROM organization WHERE domain=? AND active=1")
|
||||||
defer streamutil.Close(stmt)
|
defer streamutil.Close(stmt)
|
||||||
|
|
||||||
|
@ -94,10 +98,23 @@ func (s Scope) GetOrganizationByDomain(subdomain string) (o org.Organization, er
|
||||||
}
|
}
|
||||||
|
|
||||||
err = stmt.Get(&o, subdomain)
|
err = stmt.Get(&o, subdomain)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err == nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select for subdomain %s", subdomain))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we try to match on empty domain as last resort
|
||||||
|
stmt, err = s.Runtime.Db.Preparex("SELECT id, refid, company, title, message, url, domain, service as conversionendpoint, email, serial, active, allowanonymousaccess, authprovider, coalesce(authconfig,JSON_UNQUOTE('{}')) as authconfig, created, revised FROM organization WHERE domain='' AND active=1")
|
||||||
|
defer streamutil.Close(stmt)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, "unable to prepare select for empty subdomain")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = stmt.Get(&o)
|
||||||
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
err = errors.Wrap(err, "unable to execute select for empty subdomain")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue