Skip to content

Commit 6f98db5

Browse files
committed
authConfig persistence bug, session vars bug
1 parent 585c446 commit 6f98db5

File tree

8 files changed

+693
-660
lines changed

8 files changed

+693
-660
lines changed

app/app/pods/customize/auth/route.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,20 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
3030
authConfig: null,
3131
};
3232

33-
switch (data.authProvider) {
34-
case constants.AuthProvider.Keycloak:
35-
data.authConfig = this.get('appMeta.authConfig');
36-
break;
37-
case constants.AuthProvider.Documize:
38-
data.authConfig = '';
39-
break;
40-
}
33+
return new Ember.RSVP.Promise((resolve) => {
34+
this.get('global').getAuthConfig().then((config) => {
35+
switch (data.authProvider) {
36+
case constants.AuthProvider.Keycloak:
37+
data.authConfig = config;
38+
break;
39+
case constants.AuthProvider.Documize:
40+
data.authConfig = '';
41+
break;
42+
}
4143

42-
return data;
44+
resolve(data);
45+
});
46+
});
4347
},
4448

4549
activate() {

app/app/services/global.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ export default Ember.Service.extend({
6565
}
6666
},
6767

68+
// Returns auth config for Documize instance.
69+
getAuthConfig() {
70+
if(this.get('sessionService.isGlobalAdmin')) {
71+
return this.get('ajax').request(`global/auth`, {
72+
method: 'GET'
73+
}).then((response) => {
74+
return response;
75+
});
76+
}
77+
},
78+
6879
// Saves auth config for Documize instance.
6980
saveAuthConfig(config) {
7081
if(this.get('sessionService.isGlobalAdmin')) {

app/app/services/session.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,25 @@ export default SimpleAuthSession.extend({
2626
currentFolder: null,
2727
isMac: false,
2828
isMobile: false,
29-
authenticated: computed('user.id', function () {
30-
return this.get('user.id') !== '0';
29+
30+
user: computed('isAuthenticated', 'session.content.authenticated.user', function () {
31+
if (this.get('isAuthenticated')) {
32+
let user = this.get('session.content.authenticated.user') || { id: '' };
33+
let data = this.get('store').normalize('user', user);
34+
return this.get('store').push(data);
35+
}
36+
}),
37+
authenticated: computed('session.content.authenticated.user', function () {
38+
return this.get('session.content.authenticated.user.id') !== '0';
3139
}),
32-
isAdmin: computed('user', function () {
33-
let data = this.get('user');
34-
return data.get('admin');
40+
isAdmin: computed('session.content.authenticated.user', function () {
41+
return this.get('session.content.authenticated.user.admin') === true;
3542
}),
36-
isEditor: computed('user', function () {
37-
let data = this.get('user');
38-
return data.get('editor');
43+
isEditor: computed('session.content.authenticated.user', function () {
44+
return this.get('session.content.authenticated.user.editor') === true;
3945
}),
40-
isGlobalAdmin: computed('user', function () {
41-
let data = this.get('user');
42-
return data.get('global');
46+
isGlobalAdmin: computed('session.content.authenticated.user', function () {
47+
return this.get('session.content.authenticated.user.global') === true;
4348
}),
4449

4550
init() {
@@ -49,14 +54,6 @@ export default SimpleAuthSession.extend({
4954
this.set('isMobile', is.mobile());
5055
},
5156

52-
user: computed('isAuthenticated', 'session.content.authenticated.user', function () {
53-
if (this.get('isAuthenticated')) {
54-
let user = this.get('session.content.authenticated.user') || { id: '' };
55-
let data = this.get('store').normalize('user', user);
56-
return this.get('store').push(data);
57-
}
58-
}),
59-
6057
logout() {
6158
this.get('localStorage').clearAll();
6259
}

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"ember-export-application-global": "^1.0.5",
4141
"ember-load-initializers": "^0.6.0",
4242
"ember-resolver": "^2.0.3",
43-
"ember-simple-auth": "1.2.0",
43+
"ember-simple-auth": "1.2.2",
4444
"ember-source": "~2.12.0",
4545
"loader.js": "^4.2.3"
4646
},

core/api/endpoint/global_endpoint.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,21 @@ type authData struct {
233233
AuthProvider string `json:"authProvider"`
234234
AuthConfig string `json:"authConfig"`
235235
}
236+
237+
// GetAuthConfig returns installation-wide auth configuration
238+
func GetAuthConfig(w http.ResponseWriter, r *http.Request) {
239+
p := request.GetPersister(r)
240+
241+
if !p.Context.Global {
242+
writeForbiddenError(w)
243+
return
244+
}
245+
246+
org, err := p.GetOrganization(p.Context.OrgID)
247+
if err != nil {
248+
writeForbiddenError(w)
249+
return
250+
}
251+
252+
util.WriteJSON(w, org.AuthConfig)
253+
}

core/api/endpoint/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func init() {
236236
log.IfErr(Add(RoutePrefixPrivate, "global/smtp", []string{"PUT", "OPTIONS"}, nil, SaveSMTPConfig))
237237
log.IfErr(Add(RoutePrefixPrivate, "global/license", []string{"GET", "OPTIONS"}, nil, GetLicense))
238238
log.IfErr(Add(RoutePrefixPrivate, "global/license", []string{"PUT", "OPTIONS"}, nil, SaveLicense))
239+
log.IfErr(Add(RoutePrefixPrivate, "global/auth", []string{"GET", "OPTIONS"}, nil, GetAuthConfig))
239240
log.IfErr(Add(RoutePrefixPrivate, "global/auth", []string{"PUT", "OPTIONS"}, nil, SaveAuthConfig))
240241

241242
// Pinned items

core/api/endpoint/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ func cors(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
165165
w.Header().Set("Access-Control-Expose-Headers", "x-documize-version")
166166

167167
if r.Method == "OPTIONS" {
168+
w.Header().Add("X-Documize-Version", Product.Version)
169+
w.Header().Add("Cache-Control", "no-cache")
170+
168171
if _, err := w.Write([]byte("")); err != nil {
169172
log.Error("cors", err)
170173
}
@@ -177,7 +180,6 @@ func cors(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
177180
func metrics(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
178181
w.Header().Add("X-Documize-Version", Product.Version)
179182
w.Header().Add("Cache-Control", "no-cache")
180-
181183
// Prevent page from being displayed in an iframe
182184
w.Header().Add("X-Frame-Options", "DENY")
183185

embed/bindata_assetfs.go

Lines changed: 630 additions & 630 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)