mirror of
https://github.com/documize/community.git
synced 2025-07-19 13:19:43 +02:00
set defaults for request context
This commit is contained in:
parent
63b24aed3f
commit
8081b60146
23 changed files with 692 additions and 666 deletions
|
@ -8,7 +8,7 @@ The mission is to bring software dev inspired features (refactoring, testing, li
|
|||
|
||||
## Latest version
|
||||
|
||||
v1.53.0
|
||||
v1.53.1
|
||||
|
||||
## OS Support
|
||||
|
||||
|
|
|
@ -99,7 +99,8 @@ func Setup(s *domain.Store) error {
|
|||
|
||||
var json = make([]byte, 0)
|
||||
if PluginFile == "DB" {
|
||||
json = []byte(s.Setting.Get("FILEPLUGINS", ""))
|
||||
c, _ := s.Setting.Get("FILEPLUGINS", "")
|
||||
json = []byte(c)
|
||||
if len(bytes.TrimSpace(json)) == 0 {
|
||||
return nil // don't fail if the DB does not exist yet
|
||||
}
|
||||
|
|
|
@ -60,11 +60,6 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
|||
dbname := r.Form.Get("dbname")
|
||||
dbhash := r.Form.Get("dbhash")
|
||||
|
||||
h.Runtime.Log.Info(dbname)
|
||||
h.Runtime.Log.Info(dbhash)
|
||||
h.Runtime.Log.Info(web.SiteInfo.DBname)
|
||||
h.Runtime.Log.Info(web.SiteInfo.DBhash)
|
||||
|
||||
if dbname != web.SiteInfo.DBname || dbhash != web.SiteInfo.DBhash {
|
||||
h.Runtime.Log.Error("database.Create()'s security credentials error ", errors.New("bad db name or validation code"))
|
||||
return
|
||||
|
|
|
@ -68,9 +68,11 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
dom := strings.TrimSpace(strings.ToLower(credentials[0]))
|
||||
dom = h.Store.Organization.CheckDomain(ctx, dom) // TODO optimize by removing this once js allows empty domains
|
||||
email := strings.TrimSpace(strings.ToLower(credentials[1]))
|
||||
password := credentials[2]
|
||||
|
||||
dom = h.Store.Organization.CheckDomain(ctx, dom) // TODO optimize by removing this once js allows empty domains
|
||||
|
||||
h.Runtime.Log.Info("logon attempt " + email + " @ " + dom)
|
||||
|
||||
u, err := h.Store.User.GetByDomain(ctx, dom, email)
|
||||
|
@ -108,6 +110,8 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
h.Runtime.Log.Info("login " + email + " @ " + dom)
|
||||
|
||||
authModel := auth.AuthenticationModel{}
|
||||
authModel.Token = GenerateJWT(h.Runtime, u.RefID, org.RefID, dom)
|
||||
authModel.User = u
|
||||
|
|
|
@ -64,5 +64,9 @@ func GetRequestContext(r *http.Request) (ctx RequestContext) {
|
|||
return
|
||||
}
|
||||
|
||||
return RequestContext{}
|
||||
ctx = RequestContext{}
|
||||
ctx.AppURL = r.Host
|
||||
ctx.SSL = r.TLS != nil
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -96,8 +96,8 @@ func (h *Handler) convert(w http.ResponseWriter, r *http.Request, job, folderID
|
|||
method := "conversion.upload"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
licenseKey := h.Store.Setting.Get("EDITION-LICENSE", "key")
|
||||
licenseSignature := h.Store.Setting.Get("EDITION-LICENSE", "signature")
|
||||
licenseKey, _ := h.Store.Setting.Get("EDITION-LICENSE", "key")
|
||||
licenseSignature, _ := h.Store.Setting.Get("EDITION-LICENSE", "signature")
|
||||
k, _ := hex.DecodeString(licenseKey)
|
||||
s, _ := hex.DecodeString(licenseSignature)
|
||||
|
||||
|
|
|
@ -291,9 +291,18 @@ func (m *Mailer) GetHost() string {
|
|||
|
||||
// LoadCredentials loads up SMTP details from database
|
||||
func (m *Mailer) LoadCredentials() {
|
||||
m.Credentials.SMTPuserid = strings.TrimSpace(m.Store.Setting.Get("SMTP", "userid"))
|
||||
m.Credentials.SMTPpassword = strings.TrimSpace(m.Store.Setting.Get("SMTP", "password"))
|
||||
m.Credentials.SMTPhost = strings.TrimSpace(m.Store.Setting.Get("SMTP", "host"))
|
||||
m.Credentials.SMTPport = strings.TrimSpace(m.Store.Setting.Get("SMTP", "port"))
|
||||
m.Credentials.SMTPsender = strings.TrimSpace(m.Store.Setting.Get("SMTP", "sender"))
|
||||
userID, _ := m.Store.Setting.Get("SMTP", "userid")
|
||||
m.Credentials.SMTPuserid = strings.TrimSpace(userID)
|
||||
|
||||
pwd, _ := m.Store.Setting.Get("SMTP", "password")
|
||||
m.Credentials.SMTPpassword = strings.TrimSpace(pwd)
|
||||
|
||||
host, _ := m.Store.Setting.Get("SMTP", "host")
|
||||
m.Credentials.SMTPhost = strings.TrimSpace(host)
|
||||
|
||||
port, _ := m.Store.Setting.Get("SMTP", "port")
|
||||
m.Credentials.SMTPport = strings.TrimSpace(port)
|
||||
|
||||
sender, _ := m.Store.Setting.Get("SMTP", "sender")
|
||||
m.Credentials.SMTPsender = strings.TrimSpace(sender)
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ func (s Scope) GetOrganization(ctx domain.RequestContext, id string) (org org.Or
|
|||
// No context is required because user might no be authenticated yet.
|
||||
func (s Scope) GetOrganizationByDomain(subdomain string) (org org.Organization, err error) {
|
||||
err = nil
|
||||
subdomain = strings.ToLower(subdomain)
|
||||
subdomain = strings.TrimSpace(strings.ToLower(subdomain))
|
||||
|
||||
if s.Runtime.Flags.SiteMode == env.SiteModeNormal { // only return an organization when running normally
|
||||
var stmt *sqlx.Stmt
|
||||
|
|
|
@ -25,16 +25,19 @@ import (
|
|||
)
|
||||
|
||||
func clientID(ctx domain.RequestContext, s *domain.Store) string {
|
||||
return s.Setting.Get(meta.ConfigHandle(), "clientID")
|
||||
c, _ := s.Setting.Get(meta.ConfigHandle(), "clientID")
|
||||
return c
|
||||
}
|
||||
|
||||
func clientSecret(ctx domain.RequestContext, s *domain.Store) string {
|
||||
return s.Setting.Get(meta.ConfigHandle(), "clientSecret")
|
||||
c, _ := s.Setting.Get(meta.ConfigHandle(), "clientSecret")
|
||||
return c
|
||||
}
|
||||
|
||||
func authorizationCallbackURL(ctx domain.RequestContext, s *domain.Store) string {
|
||||
// NOTE: URL value must have the path and query "/api/public/validate?section=github"
|
||||
return s.Setting.Get(meta.ConfigHandle(), "authorizationCallbackURL")
|
||||
c, _ := s.Setting.Get(meta.ConfigHandle(), "authorizationCallbackURL")
|
||||
return c
|
||||
}
|
||||
|
||||
func validateToken(ctx provider.Context, s *domain.Store, ptoken string) error {
|
||||
|
|
|
@ -222,7 +222,9 @@ func (c *Context) MarshalSecrets(sec interface{}, s *domain.Store) error {
|
|||
// Errors return the empty string.
|
||||
func (c *Context) GetSecrets(JSONpath string, s *domain.Store) string {
|
||||
m := c.prov.Meta()
|
||||
return s.Setting.GetUser(c.OrgID, c.UserID, m.ContentType, JSONpath)
|
||||
v, _ := s.Setting.GetUser(c.OrgID, c.UserID, m.ContentType, JSONpath)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// ErrNoSecrets is returned if no secret is found in the database.
|
||||
|
|
|
@ -69,7 +69,7 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
|||
}
|
||||
|
||||
config.Clean()
|
||||
config.AppKey = p.Store.Setting.Get(meta.ConfigHandle(), "appKey")
|
||||
config.AppKey, _ = p.Store.Setting.Get(meta.ConfigHandle(), "appKey")
|
||||
|
||||
if len(config.AppKey) == 0 {
|
||||
p.Runtime.Log.Info("missing trello App Key")
|
||||
|
|
|
@ -41,7 +41,7 @@ func (h *Handler) SMTP(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
config := h.Store.Setting.Get("SMTP", "")
|
||||
config, _ := h.Store.Setting.Get("SMTP", "")
|
||||
|
||||
var y map[string]interface{}
|
||||
json.Unmarshal([]byte(config), &y)
|
||||
|
@ -101,7 +101,7 @@ func (h *Handler) License(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
config := h.Store.Setting.Get("EDITION-LICENSE", "")
|
||||
config, _ := h.Store.Setting.Get("EDITION-LICENSE", "")
|
||||
if len(config) == 0 {
|
||||
config = "{}"
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ package mysql
|
|||
import (
|
||||
"bytes"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
|
@ -27,7 +26,7 @@ type Scope struct {
|
|||
}
|
||||
|
||||
// Get fetches a configuration JSON element from the config table.
|
||||
func (s Scope) Get(area, path string) (value string) {
|
||||
func (s Scope) Get(area, path string) (value string, err error) {
|
||||
if path != "" {
|
||||
path = "." + path
|
||||
}
|
||||
|
@ -37,16 +36,14 @@ func (s Scope) Get(area, path string) (value string) {
|
|||
defer streamutil.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
s.Runtime.Log.Error(fmt.Sprintf("setting.Get %s %s", area, path), err)
|
||||
return ""
|
||||
return "", err
|
||||
}
|
||||
|
||||
var item = make([]uint8, 0)
|
||||
|
||||
err = stmt.Get(&item)
|
||||
if err != nil {
|
||||
s.Runtime.Log.Error(fmt.Sprintf("setting.Get %s %s", area, path), err)
|
||||
return ""
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(item) > 1 {
|
||||
|
@ -54,7 +51,7 @@ func (s Scope) Get(area, path string) (value string) {
|
|||
value = string(bytes.TrimPrefix(bytes.TrimSuffix(item, q), q))
|
||||
}
|
||||
|
||||
return value
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// Set writes a configuration JSON element to the config table.
|
||||
|
@ -81,7 +78,7 @@ func (s Scope) Set(area, json string) error {
|
|||
|
||||
// GetUser fetches a configuration JSON element from the userconfig table for a given orgid/userid combination.
|
||||
// Errors return the empty string. A blank path returns the whole JSON object, as JSON.
|
||||
func (s Scope) GetUser(orgID, userID, area, path string) (value string) {
|
||||
func (s Scope) GetUser(orgID, userID, area, path string) (value string, err error) {
|
||||
if path != "" {
|
||||
path = "." + path
|
||||
}
|
||||
|
@ -93,15 +90,14 @@ func (s Scope) GetUser(orgID, userID, area, path string) (value string) {
|
|||
defer streamutil.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
return ""
|
||||
return "", err
|
||||
}
|
||||
|
||||
var item = make([]uint8, 0)
|
||||
|
||||
err = stmt.Get(&item)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
s.Runtime.Log.Error(fmt.Sprintf("setting.GetUser for user %s %s %s", userID, area, path), err)
|
||||
return ""
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(item) > 1 {
|
||||
|
@ -109,7 +105,7 @@ func (s Scope) GetUser(orgID, userID, area, path string) (value string) {
|
|||
value = string(bytes.TrimPrefix(bytes.TrimSuffix(item, q), q))
|
||||
}
|
||||
|
||||
return value
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// SetUser writes a configuration JSON element to the userconfig table for the current user.
|
||||
|
|
|
@ -145,9 +145,9 @@ type DocumentStorer interface {
|
|||
|
||||
// SettingStorer defines required methods for persisting global and user level settings
|
||||
type SettingStorer interface {
|
||||
Get(area, path string) string
|
||||
Get(area, path string) (val string, err error)
|
||||
Set(area, value string) error
|
||||
GetUser(orgID, userID, area, path string) string
|
||||
GetUser(orgID, userID, area, path string) (val string, err error)
|
||||
SetUser(orgID, userID, area, json string) error
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"github.com/documize/community/core/uniqueid"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/mail"
|
||||
"github.com/documize/community/domain/organization"
|
||||
"github.com/documize/community/model/account"
|
||||
"github.com/documize/community/model/audit"
|
||||
"github.com/documize/community/model/space"
|
||||
|
@ -566,6 +567,7 @@ func (h *Handler) UserSpacePermissions(w http.ResponseWriter, r *http.Request) {
|
|||
func (h *Handler) ForgotPassword(w http.ResponseWriter, r *http.Request) {
|
||||
method := "user.ForgotPassword"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
ctx.Subdomain = organization.GetSubdomainFromHost(r)
|
||||
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
|
@ -619,6 +621,7 @@ func (h *Handler) ForgotPassword(w http.ResponseWriter, r *http.Request) {
|
|||
func (h *Handler) ResetPassword(w http.ResponseWriter, r *http.Request) {
|
||||
method := "user.ForgotUserPassword"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
ctx.Subdomain = organization.GetSubdomainFromHost(r)
|
||||
|
||||
token := request.Param(r, "token")
|
||||
if len(token) == 0 {
|
||||
|
|
|
@ -38,7 +38,7 @@ func main() {
|
|||
rt.Product = env.ProdInfo{}
|
||||
rt.Product.Major = "1"
|
||||
rt.Product.Minor = "53"
|
||||
rt.Product.Patch = "0"
|
||||
rt.Product.Patch = "1"
|
||||
rt.Product.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch)
|
||||
rt.Product.Edition = "Community"
|
||||
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition)
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -16,6 +16,10 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
|||
folderService: Ember.inject.service('folder'),
|
||||
|
||||
model() {
|
||||
// if (this.get('appMeta.setupMode')) {
|
||||
// localStorage.clearAll();
|
||||
// return;
|
||||
// }
|
||||
return this.get('folderService').getAll();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
import Ember from 'ember';
|
||||
import NotifierMixin from "../../mixins/notifier";
|
||||
import Encoding from "../../utils/encoding";
|
||||
import netUtil from '../../utils/net';
|
||||
|
||||
export default Ember.Controller.extend(NotifierMixin, {
|
||||
|
||||
|
@ -24,7 +25,8 @@ export default Ember.Controller.extend(NotifierMixin, {
|
|||
data: this.model,
|
||||
dataType: "text",
|
||||
}).then(() => {
|
||||
var credentials = Encoding.Base64.encode(":" + this.model.email + ":" + this.model.password);
|
||||
let dom = netUtil.getSubdomain();
|
||||
var credentials = Encoding.Base64.encode(dom + ":" + this.model.email + ":" + this.model.password);
|
||||
window.location.href = "/auth/sso/" + encodeURIComponent(credentials);
|
||||
}).catch((error) => { // eslint-disable-line no-unused-vars
|
||||
// TODO notify user of the error within the GUI
|
||||
|
|
|
@ -33,6 +33,8 @@ export default Ember.Route.extend(ApplicationRouteMixin, TooltipMixin, {
|
|||
if (sa !== "authenticator:documize" && sa !== "authenticator:keycloak" && data.allowAnonymousAccess) {
|
||||
if (!this.get('appMeta.setupMode')) {
|
||||
return this.get('session').authenticate('authenticator:anonymous', data);
|
||||
// } else {
|
||||
// this.get('localStorage').clearAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +44,7 @@ export default Ember.Route.extend(ApplicationRouteMixin, TooltipMixin, {
|
|||
|
||||
sessionAuthenticated() {
|
||||
if (this.get('appMeta.setupMode')) {
|
||||
this.get('localStorage').clearAll();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -68,7 +71,7 @@ export default Ember.Route.extend(ApplicationRouteMixin, TooltipMixin, {
|
|||
console.log(transition); // eslint-disable-line no-console
|
||||
|
||||
if (netUtil.isAjaxAccessError(error) && !this.get('appMeta.setupMode')) {
|
||||
localStorage.clear();
|
||||
localStorage.clearAll();
|
||||
return this.transitionTo('auth.login');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "documize",
|
||||
"version": "1.53.0",
|
||||
"version": "1.53.1",
|
||||
"description": "The Document IDE",
|
||||
"private": true,
|
||||
"repository": "",
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
{
|
||||
"community":
|
||||
{
|
||||
"version": "1.53.0",
|
||||
"version": "1.53.1",
|
||||
"major": 1,
|
||||
"minor": 53,
|
||||
"patch": 0
|
||||
"patch": 1
|
||||
},
|
||||
"enterprise":
|
||||
{
|
||||
"version": "1.55.0",
|
||||
"version": "1.55.1",
|
||||
"major": 1,
|
||||
"minor": 55,
|
||||
"patch": 0
|
||||
"patch": 1
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue