mirror of
https://github.com/documize/community.git
synced 2025-08-02 20:15:26 +02:00
parent
4445f41801
commit
4e082b4159
26 changed files with 937 additions and 611 deletions
|
@ -199,6 +199,7 @@ func Authorize(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|||
context.OrgName = org.Title
|
||||
context.Administrator = false
|
||||
context.Editor = false
|
||||
context.Global = false
|
||||
|
||||
// Fetch user permissions for this org
|
||||
if context.Authenticated {
|
||||
|
@ -211,6 +212,7 @@ func Authorize(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|||
|
||||
context.Administrator = user.Admin
|
||||
context.Editor = user.Editor
|
||||
context.Global = user.Global
|
||||
}
|
||||
|
||||
request.SetContext(r, context)
|
||||
|
|
81
core/api/endpoint/global_endpoint.go
Normal file
81
core/api/endpoint/global_endpoint.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/documize/community/core/api/request"
|
||||
"github.com/documize/community/core/api/util"
|
||||
)
|
||||
|
||||
// GetGlobalConfig returns installation-wide settings
|
||||
func GetGlobalConfig(w http.ResponseWriter, r *http.Request) {
|
||||
method := "GetGlobalConfig"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
if !p.Context.Global {
|
||||
writeForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
// SMTP settings
|
||||
config := request.ConfigString("SMTP", "")
|
||||
|
||||
// marshall as JSON
|
||||
var y map[string]interface{}
|
||||
json.Unmarshal([]byte(config), &y)
|
||||
|
||||
json, err := json.Marshal(y)
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "GetGlobalConfig", err)
|
||||
return
|
||||
}
|
||||
|
||||
util.WriteSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
// SaveGlobalConfig persists global configuration.
|
||||
func SaveGlobalConfig(w http.ResponseWriter, r *http.Request) {
|
||||
method := "SaveGlobalConfig"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
if !p.Context.Global {
|
||||
writeForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
defer r.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
writePayloadError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
var config string
|
||||
config = string(body)
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
p.Context.Transaction = tx
|
||||
|
||||
request.ConfigSet("SMTP", config)
|
||||
|
||||
util.WriteSuccessEmptyJSON(w)
|
||||
}
|
|
@ -212,6 +212,10 @@ func init() {
|
|||
log.IfErr(Add(RoutePrefixPrivate, "sections", []string{"POST", "OPTIONS"}, nil, RunSectionCommand))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/refresh", []string{"GET", "OPTIONS"}, nil, RefreshSections))
|
||||
|
||||
// Global installation-wide config
|
||||
log.IfErr(Add(RoutePrefixPrivate, "global", []string{"GET", "OPTIONS"}, nil, GetGlobalConfig))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "global", []string{"PUT", "OPTIONS"}, nil, SaveGlobalConfig))
|
||||
|
||||
// **** configure single page app handler.
|
||||
|
||||
log.IfErr(Add(RoutePrefixRoot, "robots.txt", []string{"GET", "OPTIONS"}, nil, GetRobots))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue