Skip to content

Commit d3512b4

Browse files
committed
improved setup wizard redirection
1 parent 8081b60 commit d3512b4

File tree

15 files changed

+670
-661
lines changed

15 files changed

+670
-661
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The mission is to bring software dev inspired features (refactoring, testing, li
88

99
## Latest version
1010

11-
v1.53.1
11+
v1.53.2
1212

1313
## OS Support
1414

core/database/create.go renamed to core/database/endpoint.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"strings"
1919
"time"
2020

21+
"github.com/documize/community/core/api/plugins"
2122
"github.com/documize/community/core/env"
2223
"github.com/documize/community/core/secrets"
2324
"github.com/documize/community/core/stringutil"
@@ -32,8 +33,8 @@ type Handler struct {
3233
Store *domain.Store
3334
}
3435

35-
// Create the tables in a blank database
36-
func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
36+
// Setup the tables in a blank database
37+
func (h *Handler) Setup(w http.ResponseWriter, r *http.Request) {
3738
defer func() {
3839
target := "/setup"
3940
status := http.StatusBadRequest
@@ -45,23 +46,23 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
4546

4647
req, err := http.NewRequest("GET", target, nil)
4748
if err != nil {
48-
h.Runtime.Log.Error("database.Create()'s error in defer ", err)
49+
h.Runtime.Log.Error("database.Setup error in defer ", err)
4950
}
5051

5152
http.Redirect(w, req, target, status)
5253
}()
5354

5455
err := r.ParseForm()
5556
if err != nil {
56-
h.Runtime.Log.Error("database.Create()'s r.ParseForm()", err)
57+
h.Runtime.Log.Error("database.Setup r.ParseForm()", err)
5758
return
5859
}
5960

6061
dbname := r.Form.Get("dbname")
6162
dbhash := r.Form.Get("dbhash")
6263

6364
if dbname != web.SiteInfo.DBname || dbhash != web.SiteInfo.DBhash {
64-
h.Runtime.Log.Error("database.Create()'s security credentials error ", errors.New("bad db name or validation code"))
65+
h.Runtime.Log.Error("database.Setup security credentials error ", errors.New("bad db name or validation code"))
6566
return
6667
}
6768

@@ -84,22 +85,27 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
8485
details.Password == "" ||
8586
details.Firstname == "" ||
8687
details.Lastname == "" {
87-
h.Runtime.Log.Error("database.Create() error ", errors.New("required field in database set-up form blank"))
88+
h.Runtime.Log.Error("database.Setup error ", errors.New("required field in database set-up form blank"))
8889
return
8990
}
9091

9192
if err = Migrate(h.Runtime, false /* no tables exist yet */); err != nil {
92-
h.Runtime.Log.Error("database.Create()", err)
93+
h.Runtime.Log.Error("database.Setup migrate", err)
9394
return
9495
}
9596

9697
err = setupAccount(h.Runtime, details, secrets.GenerateSalt())
9798
if err != nil {
98-
h.Runtime.Log.Error("database.Create()", err)
99+
h.Runtime.Log.Error("database.Setup setup account ", err)
99100
return
100101
}
101102

102103
h.Runtime.Flags.SiteMode = env.SiteModeNormal
104+
105+
err = plugins.Setup(h.Store)
106+
if err != nil {
107+
h.Runtime.Log.Error("database.Setup plugin setup failed", err)
108+
}
103109
}
104110

105111
// The result of completing the onboarding process.

core/database/migrate.go

+2
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,14 @@ func getStatements(bytes []byte) []string {
268268
stripped := regexp.MustCompile("(?s)--.*?\n|/\\*.*?\\*/").ReplaceAll(bytes, []byte("\n"))
269269
sqls := strings.Split(string(stripped), ";")
270270
ret := make([]string, 0, len(sqls))
271+
271272
for _, v := range sqls {
272273
trimmed := strings.TrimSpace(v)
273274
if len(trimmed) > 0 &&
274275
!strings.HasPrefix(strings.ToUpper(trimmed), "USE ") { // make sure we don't USE the wrong database
275276
ret = append(ret, trimmed+";")
276277
}
277278
}
279+
278280
return ret
279281
}

domain/meta/endpoint.go

-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ func (h *Handler) Sitemap(w http.ResponseWriter, r *http.Request) {
175175
response.WriteBytes(w, buffer.Bytes())
176176
}
177177

178-
// sitemapItem provides a means to teleport somewhere else for free.
179-
// What did you think it did?
180178
type sitemapItem struct {
181179
URL string
182180
Date string

domain/organization/mysql/store.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (s Scope) GetOrganization(ctx domain.RequestContext, id string) (org org.Or
7878

7979
// GetOrganizationByDomain returns the organization matching a given URL subdomain.
8080
// No context is required because user might no be authenticated yet.
81-
func (s Scope) GetOrganizationByDomain(subdomain string) (org org.Organization, err error) {
81+
func (s Scope) GetOrganizationByDomain(subdomain string) (o org.Organization, err error) {
8282
err = nil
8383
subdomain = strings.TrimSpace(strings.ToLower(subdomain))
8484

@@ -93,8 +93,7 @@ func (s Scope) GetOrganizationByDomain(subdomain string) (org org.Organization,
9393
return
9494
}
9595

96-
err = stmt.Get(&org, subdomain)
97-
96+
err = stmt.Get(&o, subdomain)
9897
if err != nil && err != sql.ErrNoRows {
9998
err = errors.Wrap(err, fmt.Sprintf("unable to execute select for subdomain %s", subdomain))
10099
return

edition/community.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func main() {
3838
rt.Product = env.ProdInfo{}
3939
rt.Product.Major = "1"
4040
rt.Product.Minor = "53"
41-
rt.Product.Patch = "1"
41+
rt.Product.Patch = "2"
4242
rt.Product.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch)
4343
rt.Product.Edition = "Community"
4444
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition)

embed/bindata_assetfs.go

+619-619
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gui/app/pods/folders/route.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@
1212
import Ember from 'ember';
1313
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
1414

15+
const {
16+
inject: { service }
17+
} = Ember;
18+
1519
export default Ember.Route.extend(AuthenticatedRouteMixin, {
16-
folderService: Ember.inject.service('folder'),
20+
appMeta: service(),
21+
folderService: service('folder'),
22+
localStorage: service(),
23+
24+
beforeModel() {
25+
if (this.get('appMeta.setupMode')) {
26+
this.get('localStorage').clearAll();
27+
this.transitionTo('setup');
28+
}
29+
},
1730

1831
model() {
19-
// if (this.get('appMeta.setupMode')) {
20-
// localStorage.clearAll();
21-
// return;
22-
// }
2332
return this.get('folderService').getAll();
2433
}
2534
});

gui/app/pods/setup/route.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright 2016 Documize Inc. <[email protected]>. All rights reserved.
22
//
3-
// This software (Documize Community Edition) is licensed under
3+
// This software (Documize Community Edition) is licensed under
44
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
55
//
66
// You can operate outside the AGPL restrictions by purchasing
77
// Documize Enterprise Edition and obtaining a commercial license
8-
// by contacting <[email protected]>.
8+
// by contacting <[email protected]>.
99
//
1010
// https://documize.com
1111

@@ -36,6 +36,6 @@ export default Ember.Route.extend({
3636
},
3737

3838
activate() {
39-
document.title = "Setup Documize database '" + document.head.querySelector("[property=dbname]").content + "'";
39+
document.title = "Documize Setup";
4040
}
41-
});
41+
});

gui/app/routes/application.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@ export default Ember.Route.extend(ApplicationRouteMixin, TooltipMixin, {
3131

3232
return this.get('appMeta').boot(transition.targetName, window.location.href).then(data => {
3333
if (sa !== "authenticator:documize" && sa !== "authenticator:keycloak" && data.allowAnonymousAccess) {
34-
if (!this.get('appMeta.setupMode')) {
34+
if (!this.get('appMeta.setupMode') && !this.get('appMeta.secureMode')) {
3535
return this.get('session').authenticate('authenticator:anonymous', data);
36-
// } else {
37-
// this.get('localStorage').clearAll();
3836
}
3937
}
40-
41-
return;
4238
});
4339
},
4440

4541
sessionAuthenticated() {
46-
if (this.get('appMeta.setupMode')) {
42+
if (this.get('appMeta.setupMode') || this.get('appMeta.secureMode')) {
4743
this.get('localStorage').clearAll();
4844
return;
4945
}

gui/app/services/app-meta.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default Ember.Service.extend({
3636
authProvider: constants.AuthProvider.Documize,
3737
authConfig: null,
3838
setupMode: false,
39+
secureMode: false,
3940

4041
invalidLicense() {
4142
return this.valid === false;
@@ -68,7 +69,7 @@ export default Ember.Service.extend({
6869
this.setProperties({
6970
title: htmlSafe("Secure document viewing"),
7071
allowAnonymousAccess: true,
71-
setupMode: true
72+
secureMode: true
7273
});
7374

7475
this.get('localStorage').clearAll();

gui/app/templates/components/documize-setup.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="form-bordered">
33
<div class="form-header">
44
<div class="title">Let's setup Documize</div>
5-
<div class="tip">Database name is <em>{{model.dbname}}</em></div>
5+
<div class="tip">Database: <b>{{model.dbname}}</b></div>
66
</div>
77
<div class="input-control input-transparent">
88
<label>Team</label>

gui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "documize",
3-
"version": "1.53.1",
3+
"version": "1.53.2",
44
"description": "The Document IDE",
55
"private": true,
66
"repository": "",

meta.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"community":
33
{
4-
"version": "1.53.1",
4+
"version": "1.53.2",
55
"major": 1,
66
"minor": 53,
7-
"patch": 1
7+
"patch": 2
88
},
99
"enterprise":
1010
{
11-
"version": "1.55.1",
11+
"version": "1.55.2",
1212
"major": 1,
1313
"minor": 55,
14-
"patch": 1
14+
"patch": 2
1515
}
1616
}

server/server.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ package server
1414
import (
1515
"fmt"
1616
"net/http"
17-
"os"
1817
"strings"
1918

2019
"github.com/codegangsta/negroni"
@@ -38,16 +37,15 @@ func Start(rt *env.Runtime, s *domain.Store, ready chan struct{}) {
3837
case env.SiteModeOffline:
3938
rt.Log.Info("Serving OFFLINE web server")
4039
case env.SiteModeSetup:
41-
dbHandler := database.Handler{Runtime: rt, Store: s}
42-
routing.Add(rt, routing.RoutePrefixPrivate, "setup", []string{"POST", "OPTIONS"}, nil, dbHandler.Create)
4340
rt.Log.Info("Serving SETUP web server")
41+
dbHandler := database.Handler{Runtime: rt, Store: s}
42+
routing.Add(rt, routing.RoutePrefixPrivate, "setup", []string{"POST", "OPTIONS"}, nil, dbHandler.Setup)
4443
case env.SiteModeBadDB:
4544
rt.Log.Info("Serving BAD DATABASE web server")
4645
default:
4746
err := plugins.Setup(s)
4847
if err != nil {
49-
rt.Log.Error("Terminating before running - invalid plugin.json", err)
50-
os.Exit(1)
48+
rt.Log.Error("plugin setup failed", err)
5149
}
5250
rt.Log.Info("Starting web server")
5351
}

0 commit comments

Comments
 (0)