mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +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)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("unable to fetch request meta for "+data.URL, err)
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -82,22 +82,39 @@ func (s Scope) GetOrganizationByDomain(subdomain string) (o org.Organization, er
|
|||
err = nil
|
||||
subdomain = strings.TrimSpace(strings.ToLower(subdomain))
|
||||
|
||||
if s.Runtime.Flags.SiteMode == env.SiteModeNormal { // only return an organization when running normally
|
||||
var stmt *sqlx.Stmt
|
||||
// only return an organization when running normally
|
||||
if s.Runtime.Flags.SiteMode != env.SiteModeNormal {
|
||||
err = errors.New("database not in normal mode so cannot fetch meta for " + subdomain)
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
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")
|
||||
defer streamutil.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare select for subdomain %s", subdomain))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare select for subdomain %s", subdomain))
|
||||
return
|
||||
}
|
||||
|
||||
err = stmt.Get(&o, subdomain)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select for subdomain %s", subdomain))
|
||||
return
|
||||
}
|
||||
err = stmt.Get(&o, subdomain)
|
||||
if err == nil {
|
||||
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
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue