mirror of
https://github.com/documize/community.git
synced 2025-08-05 05:25:27 +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
|
@ -21,16 +21,19 @@ import (
|
|||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/event"
|
||||
"github.com/documize/community/core/request"
|
||||
"github.com/documize/community/core/response"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/smtp"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/audit"
|
||||
)
|
||||
|
||||
// Handler contains the runtime information such as logging and database.
|
||||
type Handler struct {
|
||||
Runtime *env.Runtime
|
||||
Store *domain.Store
|
||||
Store *store.Store
|
||||
}
|
||||
|
||||
// SMTP returns installation-wide SMTP settings
|
||||
|
@ -294,3 +297,90 @@ func (h *Handler) SetAuthConfig(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
response.WriteEmpty(w)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ package setting
|
|||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/smtp"
|
||||
"github.com/documize/community/domain/store"
|
||||
)
|
||||
|
||||
// GetSMTPConfig returns SMTP configuration.
|
||||
func GetSMTPConfig(s *domain.Store) (c smtp.Config) {
|
||||
func GetSMTPConfig(s *store.Store) (c smtp.Config) {
|
||||
c = smtp.Config{}
|
||||
|
||||
// server
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -24,14 +23,14 @@ import (
|
|||
// Store provides data access to user permission information.
|
||||
type Store struct {
|
||||
store.Context
|
||||
domain.SettingStorer
|
||||
store.SettingStorer
|
||||
}
|
||||
|
||||
// Get fetches a configuration JSON element from the config table.
|
||||
func (s Store) Get(area, path string) (value string, err error) {
|
||||
qry := fmt.Sprintf("SELECT %s FROM dmz_config WHERE c_key = '%s';", s.GetJSONValue("c_config", path), area)
|
||||
|
||||
var item = make([]uint8, 0)
|
||||
item := []byte{}
|
||||
err = s.Runtime.Db.Get(&item, qry)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -83,7 +82,7 @@ func (s Store) Set(area, json string) (err error) {
|
|||
func (s Store) GetUser(orgID, userID, key, path string) (value string, err error) {
|
||||
var item = make([]uint8, 0)
|
||||
|
||||
qry := fmt.Sprintf("SELECT %s FROM dmz_config WHERE c_key = '%s' AND c_orgid='%s' AND c_userid='%s';",
|
||||
qry := fmt.Sprintf("SELECT %s FROM dmz_user_config WHERE c_key = '%s' AND c_orgid='%s' AND c_userid='%s';",
|
||||
s.GetJSONValue("c_config", path), key, orgID, userID)
|
||||
|
||||
err = s.Runtime.Db.Get(&item, qry)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue