mirror of
https://github.com/documize/community.git
synced 2025-08-07 06:25:23 +02:00
Continued MySQL/PostgreSQL store provider refactoring
Refactored, renamed, removed storage related code. Basic smoke test passed for PostgreSQL whilst fully working on MySQL variants as per usual.
This commit is contained in:
parent
b455e5eaf5
commit
97beb3f4d3
81 changed files with 1454 additions and 1497 deletions
|
@ -22,13 +22,14 @@ import (
|
|||
"github.com/documize/community/core/response"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/org"
|
||||
)
|
||||
|
||||
// Handler contains the runtime information such as logging and database.
|
||||
type Handler struct {
|
||||
Runtime *env.Runtime
|
||||
Store *domain.Store
|
||||
Store *store.Store
|
||||
}
|
||||
|
||||
// Get returns the requested organization.
|
||||
|
@ -96,90 +97,3 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
response.WriteJSON(w, org)
|
||||
}
|
||||
|
||||
// GetInstanceSetting returns the requested organization level setting.
|
||||
func (h *Handler) GetInstanceSetting(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
orgID := request.Param(r, "orgID")
|
||||
if orgID != ctx.OrgID || !ctx.Administrator {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
key := request.Query(r, "key")
|
||||
setting, _ := h.Store.Setting.GetUser(orgID, "", key, "")
|
||||
if len(setting) == 0 {
|
||||
setting = "{}"
|
||||
}
|
||||
|
||||
response.WriteJSON(w, setting)
|
||||
}
|
||||
|
||||
// SaveInstanceSetting saves org level setting.
|
||||
func (h *Handler) SaveInstanceSetting(w http.ResponseWriter, r *http.Request) {
|
||||
method := "org.SaveInstanceSetting"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
orgID := request.Param(r, "orgID")
|
||||
if orgID != ctx.OrgID || !ctx.Administrator {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
key := request.Query(r, "key")
|
||||
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
config := string(body)
|
||||
h.Store.Setting.SetUser(orgID, "", key, config)
|
||||
|
||||
response.WriteEmpty(w)
|
||||
}
|
||||
|
||||
// GetGlobalSetting returns the requested organization level setting.
|
||||
func (h *Handler) GetGlobalSetting(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !ctx.GlobalAdmin {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
key := request.Query(r, "key")
|
||||
setting, _ := h.Store.Setting.Get(key, "")
|
||||
|
||||
response.WriteJSON(w, setting)
|
||||
}
|
||||
|
||||
// SaveGlobalSetting saves org level setting.
|
||||
func (h *Handler) SaveGlobalSetting(w http.ResponseWriter, r *http.Request) {
|
||||
method := "org.SaveGlobalSetting"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !ctx.GlobalAdmin {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
key := request.Query(r, "key")
|
||||
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
config := string(body)
|
||||
h.Store.Setting.Set(key, config)
|
||||
|
||||
response.WriteEmpty(w)
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import (
|
|||
// Store provides data access to organization (tenant) information.
|
||||
type Store struct {
|
||||
store.Context
|
||||
domain.OrganizationStorer
|
||||
store.OrganizationStorer
|
||||
}
|
||||
|
||||
// AddOrganization inserts the passed organization record into the organization table.
|
||||
|
@ -94,12 +94,11 @@ func (s Store) GetOrganizationByDomain(subdomain string) (o org.Organization, er
|
|||
coalesce(c_authconfig,`+s.EmptyJSON()+`) AS authconfig, c_maxtags AS maxtags,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_org
|
||||
WHERE c_domain=? AND c_active=1`),
|
||||
WHERE c_domain=? AND c_active=true`),
|
||||
subdomain)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(err)
|
||||
err = nil
|
||||
|
||||
// match on empty domain AS last resort
|
||||
|
@ -110,7 +109,7 @@ func (s Store) GetOrganizationByDomain(subdomain string) (o org.Organization, er
|
|||
coalesce(c_authconfig,`+s.EmptyJSON()+`) AS authconfig, c_maxtags AS maxtags,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_org
|
||||
WHERE c_domain='' AND c_active=1`))
|
||||
WHERE c_domain='' AND c_active=true`))
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
err = errors.Wrap(err, "unable to execute select for empty subdomain")
|
||||
|
@ -143,7 +142,7 @@ func (s Store) DeleteOrganization(ctx domain.RequestContext, orgID string) (rows
|
|||
|
||||
// RemoveOrganization sets the orgID organization to be inactive, thus executing a "soft delete" operation.
|
||||
func (s Store) RemoveOrganization(ctx domain.RequestContext, orgID string) (err error) {
|
||||
_, err = ctx.Transaction.Exec(s.Bind("UPDATE dmz_org SET c_active=0 WHERE c_refid=?"), orgID)
|
||||
_, err = ctx.Transaction.Exec(s.Bind("UPDATE dmz_org SET c_active=false WHERE c_refid=?"), orgID)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute soft delete for org %s", orgID))
|
||||
|
@ -171,7 +170,7 @@ func (s Store) UpdateAuthConfig(ctx domain.RequestContext, org org.Organization)
|
|||
|
||||
// CheckDomain makes sure there is an organisation with the correct domain
|
||||
func (s Store) CheckDomain(ctx domain.RequestContext, domain string) string {
|
||||
row := s.Runtime.Db.QueryRow(s.Bind("SELECT COUNT(*) FROM dmz_org WHERE c_domain=? AND c_active=1"), domain)
|
||||
row := s.Runtime.Db.QueryRow(s.Bind("SELECT COUNT(*) FROM dmz_org WHERE c_domain=? AND c_active=true"), domain)
|
||||
|
||||
var count int
|
||||
err := row.Scan(&count)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue