1
0
Fork 0
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:
Harvey Kandola 2017-08-27 16:39:09 +01:00
parent 63b24aed3f
commit 8081b60146
23 changed files with 692 additions and 666 deletions

View file

@ -8,7 +8,7 @@ The mission is to bring software dev inspired features (refactoring, testing, li
## Latest version ## Latest version
v1.53.0 v1.53.1
## OS Support ## OS Support

View file

@ -99,7 +99,8 @@ func Setup(s *domain.Store) error {
var json = make([]byte, 0) var json = make([]byte, 0)
if PluginFile == "DB" { if PluginFile == "DB" {
json = []byte(s.Setting.Get("FILEPLUGINS", "")) c, _ := s.Setting.Get("FILEPLUGINS", "")
json = []byte(c)
if len(bytes.TrimSpace(json)) == 0 { if len(bytes.TrimSpace(json)) == 0 {
return nil // don't fail if the DB does not exist yet return nil // don't fail if the DB does not exist yet
} }

View file

@ -60,11 +60,6 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
dbname := r.Form.Get("dbname") dbname := r.Form.Get("dbname")
dbhash := r.Form.Get("dbhash") 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 { 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")) h.Runtime.Log.Error("database.Create()'s security credentials error ", errors.New("bad db name or validation code"))
return return

View file

@ -68,9 +68,11 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
} }
dom := strings.TrimSpace(strings.ToLower(credentials[0])) 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])) email := strings.TrimSpace(strings.ToLower(credentials[1]))
password := credentials[2] 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) h.Runtime.Log.Info("logon attempt " + email + " @ " + dom)
u, err := h.Store.User.GetByDomain(ctx, dom, email) u, err := h.Store.User.GetByDomain(ctx, dom, email)
@ -108,6 +110,8 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
return return
} }
h.Runtime.Log.Info("login " + email + " @ " + dom)
authModel := auth.AuthenticationModel{} authModel := auth.AuthenticationModel{}
authModel.Token = GenerateJWT(h.Runtime, u.RefID, org.RefID, dom) authModel.Token = GenerateJWT(h.Runtime, u.RefID, org.RefID, dom)
authModel.User = u authModel.User = u

View file

@ -64,5 +64,9 @@ func GetRequestContext(r *http.Request) (ctx RequestContext) {
return return
} }
return RequestContext{} ctx = RequestContext{}
ctx.AppURL = r.Host
ctx.SSL = r.TLS != nil
return
} }

View file

@ -96,8 +96,8 @@ func (h *Handler) convert(w http.ResponseWriter, r *http.Request, job, folderID
method := "conversion.upload" method := "conversion.upload"
ctx := domain.GetRequestContext(r) ctx := domain.GetRequestContext(r)
licenseKey := h.Store.Setting.Get("EDITION-LICENSE", "key") licenseKey, _ := h.Store.Setting.Get("EDITION-LICENSE", "key")
licenseSignature := h.Store.Setting.Get("EDITION-LICENSE", "signature") licenseSignature, _ := h.Store.Setting.Get("EDITION-LICENSE", "signature")
k, _ := hex.DecodeString(licenseKey) k, _ := hex.DecodeString(licenseKey)
s, _ := hex.DecodeString(licenseSignature) s, _ := hex.DecodeString(licenseSignature)

View file

@ -291,9 +291,18 @@ func (m *Mailer) GetHost() string {
// LoadCredentials loads up SMTP details from database // LoadCredentials loads up SMTP details from database
func (m *Mailer) LoadCredentials() { func (m *Mailer) LoadCredentials() {
m.Credentials.SMTPuserid = strings.TrimSpace(m.Store.Setting.Get("SMTP", "userid")) userID, _ := m.Store.Setting.Get("SMTP", "userid")
m.Credentials.SMTPpassword = strings.TrimSpace(m.Store.Setting.Get("SMTP", "password")) m.Credentials.SMTPuserid = strings.TrimSpace(userID)
m.Credentials.SMTPhost = strings.TrimSpace(m.Store.Setting.Get("SMTP", "host"))
m.Credentials.SMTPport = strings.TrimSpace(m.Store.Setting.Get("SMTP", "port")) pwd, _ := m.Store.Setting.Get("SMTP", "password")
m.Credentials.SMTPsender = strings.TrimSpace(m.Store.Setting.Get("SMTP", "sender")) 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)
} }

View file

@ -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. // No context is required because user might no be authenticated yet.
func (s Scope) GetOrganizationByDomain(subdomain string) (org org.Organization, err error) { func (s Scope) GetOrganizationByDomain(subdomain string) (org org.Organization, err error) {
err = nil 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 if s.Runtime.Flags.SiteMode == env.SiteModeNormal { // only return an organization when running normally
var stmt *sqlx.Stmt var stmt *sqlx.Stmt

View file

@ -25,16 +25,19 @@ import (
) )
func clientID(ctx domain.RequestContext, s *domain.Store) string { 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 { 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 { func authorizationCallbackURL(ctx domain.RequestContext, s *domain.Store) string {
// NOTE: URL value must have the path and query "/api/public/validate?section=github" // 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 { func validateToken(ctx provider.Context, s *domain.Store, ptoken string) error {

View file

@ -222,7 +222,9 @@ func (c *Context) MarshalSecrets(sec interface{}, s *domain.Store) error {
// Errors return the empty string. // Errors return the empty string.
func (c *Context) GetSecrets(JSONpath string, s *domain.Store) string { func (c *Context) GetSecrets(JSONpath string, s *domain.Store) string {
m := c.prov.Meta() 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. // ErrNoSecrets is returned if no secret is found in the database.

View file

@ -69,7 +69,7 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
} }
config.Clean() 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 { if len(config.AppKey) == 0 {
p.Runtime.Log.Info("missing trello App Key") p.Runtime.Log.Info("missing trello App Key")

View file

@ -41,7 +41,7 @@ func (h *Handler) SMTP(w http.ResponseWriter, r *http.Request) {
return return
} }
config := h.Store.Setting.Get("SMTP", "") config, _ := h.Store.Setting.Get("SMTP", "")
var y map[string]interface{} var y map[string]interface{}
json.Unmarshal([]byte(config), &y) json.Unmarshal([]byte(config), &y)
@ -101,7 +101,7 @@ func (h *Handler) License(w http.ResponseWriter, r *http.Request) {
return return
} }
config := h.Store.Setting.Get("EDITION-LICENSE", "") config, _ := h.Store.Setting.Get("EDITION-LICENSE", "")
if len(config) == 0 { if len(config) == 0 {
config = "{}" config = "{}"
} }

View file

@ -14,7 +14,6 @@ package mysql
import ( import (
"bytes" "bytes"
"database/sql" "database/sql"
"fmt"
"github.com/documize/community/core/env" "github.com/documize/community/core/env"
"github.com/documize/community/core/streamutil" "github.com/documize/community/core/streamutil"
@ -27,7 +26,7 @@ type Scope struct {
} }
// Get fetches a configuration JSON element from the config table. // 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 != "" { if path != "" {
path = "." + path path = "." + path
} }
@ -37,16 +36,14 @@ func (s Scope) Get(area, path string) (value string) {
defer streamutil.Close(stmt) defer streamutil.Close(stmt)
if err != nil { if err != nil {
s.Runtime.Log.Error(fmt.Sprintf("setting.Get %s %s", area, path), err) return "", err
return ""
} }
var item = make([]uint8, 0) var item = make([]uint8, 0)
err = stmt.Get(&item) err = stmt.Get(&item)
if err != nil { if err != nil {
s.Runtime.Log.Error(fmt.Sprintf("setting.Get %s %s", area, path), err) return "", err
return ""
} }
if len(item) > 1 { 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)) value = string(bytes.TrimPrefix(bytes.TrimSuffix(item, q), q))
} }
return value return value, nil
} }
// Set writes a configuration JSON element to the config table. // 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. // 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. // 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 != "" { if path != "" {
path = "." + path path = "." + path
} }
@ -93,15 +90,14 @@ func (s Scope) GetUser(orgID, userID, area, path string) (value string) {
defer streamutil.Close(stmt) defer streamutil.Close(stmt)
if err != nil { if err != nil {
return "" return "", err
} }
var item = make([]uint8, 0) var item = make([]uint8, 0)
err = stmt.Get(&item) err = stmt.Get(&item)
if err != nil && err != sql.ErrNoRows { if err != nil && err != sql.ErrNoRows {
s.Runtime.Log.Error(fmt.Sprintf("setting.GetUser for user %s %s %s", userID, area, path), err) return "", err
return ""
} }
if len(item) > 1 { 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)) 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. // SetUser writes a configuration JSON element to the userconfig table for the current user.

View file

@ -145,9 +145,9 @@ type DocumentStorer interface {
// SettingStorer defines required methods for persisting global and user level settings // SettingStorer defines required methods for persisting global and user level settings
type SettingStorer interface { type SettingStorer interface {
Get(area, path string) string Get(area, path string) (val string, err error)
Set(area, value string) 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 SetUser(orgID, userID, area, json string) error
} }

View file

@ -32,6 +32,7 @@ import (
"github.com/documize/community/core/uniqueid" "github.com/documize/community/core/uniqueid"
"github.com/documize/community/domain" "github.com/documize/community/domain"
"github.com/documize/community/domain/mail" "github.com/documize/community/domain/mail"
"github.com/documize/community/domain/organization"
"github.com/documize/community/model/account" "github.com/documize/community/model/account"
"github.com/documize/community/model/audit" "github.com/documize/community/model/audit"
"github.com/documize/community/model/space" "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) { func (h *Handler) ForgotPassword(w http.ResponseWriter, r *http.Request) {
method := "user.ForgotPassword" method := "user.ForgotPassword"
ctx := domain.GetRequestContext(r) ctx := domain.GetRequestContext(r)
ctx.Subdomain = organization.GetSubdomainFromHost(r)
defer streamutil.Close(r.Body) defer streamutil.Close(r.Body)
body, err := ioutil.ReadAll(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) { func (h *Handler) ResetPassword(w http.ResponseWriter, r *http.Request) {
method := "user.ForgotUserPassword" method := "user.ForgotUserPassword"
ctx := domain.GetRequestContext(r) ctx := domain.GetRequestContext(r)
ctx.Subdomain = organization.GetSubdomainFromHost(r)
token := request.Param(r, "token") token := request.Param(r, "token")
if len(token) == 0 { if len(token) == 0 {

View file

@ -38,7 +38,7 @@ func main() {
rt.Product = env.ProdInfo{} rt.Product = env.ProdInfo{}
rt.Product.Major = "1" rt.Product.Major = "1"
rt.Product.Minor = "53" 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.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch)
rt.Product.Edition = "Community" rt.Product.Edition = "Community"
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition) rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition)

File diff suppressed because one or more lines are too long

View file

@ -16,6 +16,10 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
folderService: Ember.inject.service('folder'), folderService: Ember.inject.service('folder'),
model() { model() {
// if (this.get('appMeta.setupMode')) {
// localStorage.clearAll();
// return;
// }
return this.get('folderService').getAll(); return this.get('folderService').getAll();
} }
}); });

View file

@ -12,6 +12,7 @@
import Ember from 'ember'; import Ember from 'ember';
import NotifierMixin from "../../mixins/notifier"; import NotifierMixin from "../../mixins/notifier";
import Encoding from "../../utils/encoding"; import Encoding from "../../utils/encoding";
import netUtil from '../../utils/net';
export default Ember.Controller.extend(NotifierMixin, { export default Ember.Controller.extend(NotifierMixin, {
@ -24,7 +25,8 @@ export default Ember.Controller.extend(NotifierMixin, {
data: this.model, data: this.model,
dataType: "text", dataType: "text",
}).then(() => { }).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); window.location.href = "/auth/sso/" + encodeURIComponent(credentials);
}).catch((error) => { // eslint-disable-line no-unused-vars }).catch((error) => { // eslint-disable-line no-unused-vars
// TODO notify user of the error within the GUI // TODO notify user of the error within the GUI

View file

@ -33,6 +33,8 @@ export default Ember.Route.extend(ApplicationRouteMixin, TooltipMixin, {
if (sa !== "authenticator:documize" && sa !== "authenticator:keycloak" && data.allowAnonymousAccess) { if (sa !== "authenticator:documize" && sa !== "authenticator:keycloak" && data.allowAnonymousAccess) {
if (!this.get('appMeta.setupMode')) { if (!this.get('appMeta.setupMode')) {
return this.get('session').authenticate('authenticator:anonymous', data); 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() { sessionAuthenticated() {
if (this.get('appMeta.setupMode')) { if (this.get('appMeta.setupMode')) {
this.get('localStorage').clearAll();
return; return;
} }
@ -68,7 +71,7 @@ export default Ember.Route.extend(ApplicationRouteMixin, TooltipMixin, {
console.log(transition); // eslint-disable-line no-console console.log(transition); // eslint-disable-line no-console
if (netUtil.isAjaxAccessError(error) && !this.get('appMeta.setupMode')) { if (netUtil.isAjaxAccessError(error) && !this.get('appMeta.setupMode')) {
localStorage.clear(); localStorage.clearAll();
return this.transitionTo('auth.login'); return this.transitionTo('auth.login');
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "documize", "name": "documize",
"version": "1.53.0", "version": "1.53.1",
"description": "The Document IDE", "description": "The Document IDE",
"private": true, "private": true,
"repository": "", "repository": "",

View file

@ -1,16 +1,16 @@
{ {
"community": "community":
{ {
"version": "1.53.0", "version": "1.53.1",
"major": 1, "major": 1,
"minor": 53, "minor": 53,
"patch": 0 "patch": 1
}, },
"enterprise": "enterprise":
{ {
"version": "1.55.0", "version": "1.55.1",
"major": 1, "major": 1,
"minor": 55, "minor": 55,
"patch": 0 "patch": 1
} }
} }

View file

@ -100,7 +100,7 @@ func Start(rt *env.Runtime, s *domain.Store, ready chan struct{}) {
n.Run(testHost + ":" + rt.Flags.HTTPPort) n.Run(testHost + ":" + rt.Flags.HTTPPort)
} else { } else {
if rt.Flags.ForceHTTPPort2SSL != "" { if rt.Flags.ForceHTTPPort2SSL != "" {
rt.Log.Info("Starting non-SSL server on " + rt.Flags.ForceHTTPPort2SSL + " and redirecting to SSL server on " + rt.Flags.HTTPPort) rt.Log.Info("Starting non-SSL server on " + rt.Flags.ForceHTTPPort2SSL + " and redirecting to SSL server on " + rt.Flags.HTTPPort)
go func() { go func() {
err := http.ListenAndServe(":"+rt.Flags.ForceHTTPPort2SSL, http.HandlerFunc( err := http.ListenAndServe(":"+rt.Flags.ForceHTTPPort2SSL, http.HandlerFunc(