1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-02 20:15:26 +02:00

Make API work with new schema

This commit is contained in:
Harvey Kandola 2018-09-19 16:03:29 +01:00
parent 28342fcf5e
commit 4f0cc2f616
48 changed files with 1218 additions and 1097 deletions

View file

@ -38,7 +38,7 @@ func (h *Handler) SMTP(w http.ResponseWriter, r *http.Request) {
method := "setting.SMTP"
ctx := domain.GetRequestContext(r)
if !ctx.Global {
if !ctx.GlobalAdmin {
response.WriteForbiddenError(w)
return
}
@ -63,7 +63,7 @@ func (h *Handler) SetSMTP(w http.ResponseWriter, r *http.Request) {
method := "setting.SetSMTP"
ctx := domain.GetRequestContext(r)
if !ctx.Global {
if !ctx.GlobalAdmin {
response.WriteForbiddenError(w)
return
}
@ -130,7 +130,7 @@ func (h *Handler) SetSMTP(w http.ResponseWriter, r *http.Request) {
func (h *Handler) License(w http.ResponseWriter, r *http.Request) {
ctx := domain.GetRequestContext(r)
if !ctx.Global {
if !ctx.GlobalAdmin {
response.WriteForbiddenError(w)
return
}
@ -164,7 +164,7 @@ func (h *Handler) SetLicense(w http.ResponseWriter, r *http.Request) {
method := "setting.SetLicense"
ctx := domain.GetRequestContext(r)
if !ctx.Global {
if !ctx.GlobalAdmin {
response.WriteForbiddenError(w)
return
}
@ -222,7 +222,7 @@ func (h *Handler) AuthConfig(w http.ResponseWriter, r *http.Request) {
method := "global.auth"
ctx := domain.GetRequestContext(r)
if !ctx.Global {
if !ctx.GlobalAdmin {
response.WriteForbiddenError(w)
return
}
@ -242,7 +242,7 @@ func (h *Handler) SetAuthConfig(w http.ResponseWriter, r *http.Request) {
method := "global.auth.save"
ctx := domain.GetRequestContext(r)
if !ctx.Global {
if !ctx.GlobalAdmin {
response.WriteForbiddenError(w)
return
}

View file

@ -31,7 +31,7 @@ func (s Scope) Get(area, path string) (value string, err error) {
path = "." + path
}
sql := "SELECT JSON_EXTRACT(`config`,'$" + path + "') FROM `config` WHERE `key` = '" + area + "';"
sql := "SELECT JSON_EXTRACT(c_config,'$" + path + "') FROM dmz_config WHERE c_key = '" + area + "';"
var item = make([]uint8, 0)
@ -54,9 +54,9 @@ func (s Scope) Set(area, json string) (err error) {
return errors.New("no area")
}
sql := "INSERT INTO `config` (`key`,`config`) " +
sql := "INSERT INTO dmz_config (c_key,c_config) " +
"VALUES ('" + area + "','" + json +
"') ON DUPLICATE KEY UPDATE `config`='" + json + "';"
"') ON DUPLICATE KEY UPDATE c_config='" + json + "';"
_, err = s.Runtime.Db.Exec(sql)
@ -73,8 +73,8 @@ func (s Scope) GetUser(orgID, userID, key, path string) (value string, err error
path = "." + path
}
qry := "SELECT JSON_EXTRACT(`config`,'$" + path + "') FROM `userconfig` WHERE `key` = '" + key +
"' AND `orgid` = '" + orgID + "' AND `userid` = '" + userID + "';"
qry := "SELECT JSON_EXTRACT(c_config,'$" + path + "') FROM dmz_user_config WHERE c_key = '" + key +
"' AND c_orgid = '" + orgID + "' AND c_userid = '" + userID + "';"
err = s.Runtime.Db.Get(&item, qry)
if err != nil && err != sql.ErrNoRows {
@ -101,13 +101,13 @@ func (s Scope) SetUser(orgID, userID, key, json string) (err error) {
return err
}
_, err = tx.Exec("DELETE FROM userconfig WHERE orgid=? AND userid=? AND `key`=?", orgID, userID, key)
_, err = tx.Exec("DELETE FROM dmz_user_config WHERE c_orgid=? AND c_userid=? AND c_key=?", orgID, userID, key)
if err != nil {
fmt.Println(err)
fmt.Println("ccc")
}
_, err = tx.Exec("INSERT INTO userconfig (orgid, userid, `key`, `config`) VALUES (?, ?, ?, ?)", orgID, userID, key, json)
_, err = tx.Exec("INSERT INTO dmz_user_config (c_orgid, c_userid, c_key, c_config) VALUES (?, ?, ?, ?)", orgID, userID, key, json)
if err != nil {
fmt.Println(err)
fmt.Println("ddd")