mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue