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))
|
||||
|
|
|
@ -45,6 +45,7 @@ type User struct {
|
|||
Active bool `json:"active"`
|
||||
Editor bool `json:"editor"`
|
||||
Admin bool `json:"admin"`
|
||||
Global bool `json:"global"`
|
||||
Password string `json:"-"`
|
||||
Salt string `json:"-"`
|
||||
Reset string `json:"-"`
|
||||
|
|
|
@ -32,6 +32,7 @@ type Context struct {
|
|||
Administrator bool
|
||||
Guest bool
|
||||
Editor bool
|
||||
Global bool
|
||||
UserID string
|
||||
OrgID string
|
||||
OrgName string
|
||||
|
|
|
@ -55,7 +55,7 @@ func (p *Persister) AddUser(user entity.User) (err error) {
|
|||
|
||||
// GetUser returns the user record for the given id.
|
||||
func (p *Persister) GetUser(id string) (user entity.User, err error) {
|
||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, password, salt, reset, active, created, revised FROM user WHERE refid=?")
|
||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, active, created, revised FROM user WHERE refid=?")
|
||||
defer utility.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
|
@ -77,7 +77,7 @@ func (p *Persister) GetUser(id string) (user entity.User, err error) {
|
|||
func (p *Persister) GetUserByEmail(email string) (user entity.User, err error) {
|
||||
email = strings.TrimSpace(strings.ToLower(email))
|
||||
|
||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, password, salt, reset, active, created, revised FROM user WHERE TRIM(LOWER(email))=?")
|
||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, active, created, revised FROM user WHERE TRIM(LOWER(email))=?")
|
||||
defer utility.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
|
@ -99,7 +99,7 @@ func (p *Persister) GetUserByEmail(email string) (user entity.User, err error) {
|
|||
func (p *Persister) GetUserByDomain(domain, email string) (user entity.User, err error) {
|
||||
email = strings.TrimSpace(strings.ToLower(email))
|
||||
|
||||
stmt, err := Db.Preparex("SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.active, u.created, u.revised FROM user u, account a, organization o WHERE TRIM(LOWER(u.email))=? AND u.refid=a.userid AND a.orgid=o.refid AND TRIM(LOWER(o.domain))=?")
|
||||
stmt, err := Db.Preparex("SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.global, u.password, u.salt, u.reset, u.active, u.created, u.revised FROM user u, account a, organization o WHERE TRIM(LOWER(u.email))=? AND u.refid=a.userid AND a.orgid=o.refid AND TRIM(LOWER(o.domain))=?")
|
||||
defer utility.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
|
@ -119,7 +119,7 @@ func (p *Persister) GetUserByDomain(domain, email string) (user entity.User, err
|
|||
|
||||
// GetUserByToken returns a user record given a reset token value.
|
||||
func (p *Persister) GetUserByToken(token string) (user entity.User, err error) {
|
||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, password, salt, reset, active, created, revised FROM user WHERE reset=?")
|
||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, active, created, revised FROM user WHERE reset=?")
|
||||
defer utility.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
|
@ -141,7 +141,7 @@ func (p *Persister) GetUserByToken(token string) (user entity.User, err error) {
|
|||
// This occurs when we you share a folder with a new user and they have to complete
|
||||
// the onboarding process.
|
||||
func (p *Persister) GetUserBySerial(serial string) (user entity.User, err error) {
|
||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, password, salt, reset, active, created, revised FROM user WHERE salt=?")
|
||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, active, created, revised FROM user WHERE salt=?")
|
||||
defer utility.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -164,7 +164,7 @@ func setupAccount(completion onboardRequest, serial string) (err error) {
|
|||
|
||||
userID := util.UniqueID()
|
||||
|
||||
sql = fmt.Sprintf("insert into user (refid, firstname, lastname, email, initials, salt, password) values (\"%s\",\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")",
|
||||
sql = fmt.Sprintf("insert into user (refid, firstname, lastname, email, initials, salt, password, global) values (\"%s\",\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", 1)",
|
||||
userID, completion.Firstname, completion.Lastname, completion.Email, utility.MakeInitials(completion.Firstname, completion.Lastname), salt, password)
|
||||
_, err = runSQL(sql)
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS `user` (
|
|||
`lastname` NVARCHAR(500) NOT NULL,
|
||||
`email` NVARCHAR(250) NOT NULL UNIQUE,
|
||||
`initials` NVARCHAR(10) NOT NULL DEFAULT "",
|
||||
`global` BOOL NOT NULL DEFAULT 0,
|
||||
`password` NVARCHAR(500) NOT NULL DEFAULT "",
|
||||
`salt` NVARCHAR(100) NOT NULL DEFAULT "",
|
||||
`reset` NVARCHAR(100) NOT NULL DEFAULT "",
|
||||
|
|
2
core/database/scripts/autobuild/db_00003.sql
Normal file
2
core/database/scripts/autobuild/db_00003.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
/* community edition */
|
||||
ALTER TABLE user ADD COLUMN `global` BOOL NOT NULL DEFAULT 0 AFTER `initials`;
|
|
@ -26,8 +26,8 @@ type ProdInfo struct {
|
|||
// Product returns product edition details
|
||||
func Product() (p ProdInfo) {
|
||||
p.Major = "0"
|
||||
p.Minor = "26"
|
||||
p.Patch = "1"
|
||||
p.Minor = "27"
|
||||
p.Patch = "0"
|
||||
p.Version = fmt.Sprintf("%s.%s.%s", p.Major, p.Minor, p.Patch)
|
||||
p.Edition = "Community"
|
||||
p.Title = fmt.Sprintf("%s Edition", p.Edition)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue