mirror of
https://github.com/documize/community.git
synced 2025-08-08 06:55:28 +02:00
Minor tweaks and fixes to broken tests
This commit is contained in:
parent
a2bf51d144
commit
df62973eb4
3 changed files with 88 additions and 89 deletions
|
@ -7,10 +7,11 @@ test('visiting / when not authenticated and with { allowAnonymousAccess: true }
|
|||
server.create('meta', { allowAnonymousAccess: true });
|
||||
server.createList('folder', 2);
|
||||
visit('/');
|
||||
// return pauseTest();
|
||||
|
||||
andThen(function() {
|
||||
assert.equal(find('.login').length, 1, 'Login button is displayed');
|
||||
assert.equal(find('.document-card').length, 2, '2 document displayed');
|
||||
assert.equal(find('.documents-list .document').length, 2, '2 document displayed');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard and public spaces are displayed without being signed in');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -36,6 +36,6 @@ test('changing user details and email ', function(assert) {
|
|||
|
||||
andThen(function() {
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
|
||||
assert.equal(find('.name').text().trim(), 'Test User', 'Profile name displayed');
|
||||
assert.equal(find('.content .name').text().trim(), 'Test User', 'Profile name displayed');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,14 +14,8 @@ const Session = Ember.Service.extend({
|
|||
authenticated: false,
|
||||
folderPermissions: null,
|
||||
currentFolder: null,
|
||||
ajax: Ember.inject.service(),
|
||||
|
||||
init: function() {
|
||||
this.set('user', models.UserModel.create());
|
||||
this.appMeta = models.AppMeta.create();
|
||||
|
||||
this.set('isMac', is.mac());
|
||||
this.set('isMobile', is.mobile());
|
||||
},
|
||||
isAdmin: function() {
|
||||
if (this.authenticated && is.not.null(this.user) && this.user.id !== "") {
|
||||
return this.user.admin;
|
||||
|
@ -36,38 +30,57 @@ const Session = Ember.Service.extend({
|
|||
return false;
|
||||
}.property('user'),
|
||||
|
||||
login(credentials) {
|
||||
// TODO: figure out what to do with credentials
|
||||
var self = this;
|
||||
var url = self.appMeta.getUrl('public/authenticate');
|
||||
// Boot up
|
||||
init: function() {
|
||||
this.set('user', models.UserModel.create());
|
||||
this.appMeta = models.AppMeta.create();
|
||||
|
||||
this.set('isMac', is.mac());
|
||||
this.set('isMobile', is.mobile());
|
||||
},
|
||||
|
||||
login: function(credentials) {
|
||||
let url = this.appMeta.getUrl('public/authenticate');
|
||||
let domain = netUtil.getSubdomain();
|
||||
|
||||
this.clearSession();
|
||||
|
||||
return new Ember.RSVP.Promise(function(resolve, reject) {
|
||||
if (is.empty(credentials.email) || is.empty(credentials.password)) {
|
||||
reject("invalid");
|
||||
return;
|
||||
return Ember.RSVP.reject("invalid");
|
||||
}
|
||||
|
||||
var encoded = encodingUtil.Base64.encode(domain + ":" + credentials.email + ":" + credentials.password);
|
||||
var header = {
|
||||
var headers = {
|
||||
'Authorization': 'Basic ' + encoded
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
headers: header,
|
||||
success: function(response) {
|
||||
self.setSession(response.token, models.UserModel.create(response.user));
|
||||
self.get('ready', true);
|
||||
resolve(response);
|
||||
},
|
||||
error: function(reason) {
|
||||
reject(reason);
|
||||
}
|
||||
return this.get('ajax').post(url, {
|
||||
headers
|
||||
}).then((response)=>{
|
||||
this.setSession(response.token, models.UserModel.create(response.user));
|
||||
this.get('ready', true);
|
||||
return response;
|
||||
});
|
||||
},
|
||||
|
||||
sso: function(credentials) {
|
||||
let url = this.appMeta.getUrl('public/authenticate');
|
||||
this.clearSession();
|
||||
|
||||
if (is.empty(credentials.email) || is.empty(credentials.password)) {
|
||||
return Ember.RSVP.reject("invalid");
|
||||
}
|
||||
|
||||
var headers = {
|
||||
'Authorization': 'Basic ' + credentials
|
||||
};
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
headers
|
||||
}).then((response)=>{
|
||||
this.setSession(response.token, models.UserModel.create(response.user));
|
||||
this.get('ready', true);
|
||||
resolve(response);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -84,8 +97,13 @@ const Session = Ember.Service.extend({
|
|||
this.storeSessionItem('token', token);
|
||||
this.storeSessionItem('user', JSON.stringify(user));
|
||||
|
||||
let self = this;
|
||||
|
||||
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
|
||||
// We only tack on auth header for Documize API calls
|
||||
if (is.startWith(options.url, self.get('appMeta.url'))) {
|
||||
jqXHR.setRequestHeader('Authorization', 'Bearer ' + token);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -109,11 +127,6 @@ const Session = Ember.Service.extend({
|
|||
// delete localStorage[key];
|
||||
},
|
||||
|
||||
// boot(){
|
||||
// console.log(this.get('appMeta'));
|
||||
// return new Ember.RSVP.resolve();
|
||||
// },
|
||||
|
||||
boot() {
|
||||
let self = this;
|
||||
let dbhash = "";
|
||||
|
@ -140,60 +153,45 @@ const Session = Ember.Service.extend({
|
|||
});
|
||||
}
|
||||
|
||||
return new Ember.RSVP.Promise(function(resolve) {
|
||||
$.ajax({
|
||||
url: self.get('appMeta').getUrl("public/meta"),
|
||||
type: 'GET',
|
||||
contentType: 'json',
|
||||
success: function(response) {
|
||||
self.get('appMeta').set('orgId', response.orgId);
|
||||
self.get('appMeta').setSafe('title', response.title);
|
||||
self.get('appMeta').set('version', response.version);
|
||||
self.get('appMeta').setSafe('message', response.message);
|
||||
self.get('appMeta').set('allowAnonymousAccess', response.allowAnonymousAccess);
|
||||
// var blockedPopupTest = window.open("http://maintenance.documize.com", "directories=no,height=1,width=1,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no");
|
||||
//
|
||||
// if (!blockedPopupTest) {
|
||||
// this.set('popupBlocked', true);
|
||||
// } else {
|
||||
// blockedPopupTest.close();
|
||||
// this.set('popupBlocked', false);
|
||||
// }
|
||||
|
||||
let token = self.getSessionItem('token');
|
||||
let url = this.get('appMeta').getUrl("public/meta");
|
||||
|
||||
return this.get('ajax').request(url)
|
||||
.then((response) => {
|
||||
this.get('appMeta').set('orgId', response.orgId);
|
||||
this.get('appMeta').setSafe('title', response.title);
|
||||
this.get('appMeta').set('version', response.version);
|
||||
this.get('appMeta').setSafe('message', response.message);
|
||||
this.get('appMeta').set('allowAnonymousAccess', response.allowAnonymousAccess);
|
||||
|
||||
let token = this.getSessionItem('token');
|
||||
|
||||
if (is.not.undefined(token)) {
|
||||
// We now validate current token
|
||||
let tokenCheckUrl = self.get('appMeta').getUrl(`public/validate?token=${token}`);
|
||||
let tokenCheckUrl = this.get('appMeta').getUrl(`public/validate?token=${token}`);
|
||||
|
||||
$.ajax({
|
||||
url: tokenCheckUrl,
|
||||
type: 'GET',
|
||||
contentType: 'json',
|
||||
success: function(user) {
|
||||
self.setSession(token, models.UserModel.create(user));
|
||||
self.set('ready', true);
|
||||
resolve();
|
||||
},
|
||||
error: function(reason) {
|
||||
return this.get('ajax').request(tokenCheckUrl, {
|
||||
method: 'GET',
|
||||
contentType: 'json'
|
||||
}).then((response) => {
|
||||
this.setSession(token, models.UserModel.create(user));
|
||||
this.set('ready', true);
|
||||
}).catch((reason) => {
|
||||
if (reason.status === 401 || reason.status === 403) {
|
||||
localStorage.clear();
|
||||
window.location.href = "/auth/login";
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
self.set('ready', true);
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
error: function(reason) {
|
||||
if (reason.status === 401 || reason.status === 403) {
|
||||
window.location.href = "https://documize.com";
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getSessionItem(key){
|
||||
return this.get(`data.${key}`);
|
||||
},
|
||||
|
||||
sso: function(credentials) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue