1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-08 15:05:28 +02:00

Minor tweaks and fixes to broken tests

This commit is contained in:
zinyando 2016-06-09 16:12:10 +02:00
parent a2bf51d144
commit df62973eb4
3 changed files with 88 additions and 89 deletions

View file

@ -7,10 +7,11 @@ test('visiting / when not authenticated and with { allowAnonymousAccess: true }
server.create('meta', { allowAnonymousAccess: true }); server.create('meta', { allowAnonymousAccess: true });
server.createList('folder', 2); server.createList('folder', 2);
visit('/'); visit('/');
// return pauseTest();
andThen(function() { andThen(function() {
assert.equal(find('.login').length, 1, 'Login button is displayed'); 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'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard and public spaces are displayed without being signed in');
}); });
}); });

View file

@ -36,6 +36,6 @@ test('changing user details and email ', function(assert) {
andThen(function() { andThen(function() {
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); 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');
}); });
}); });

View file

@ -14,14 +14,8 @@ const Session = Ember.Service.extend({
authenticated: false, authenticated: false,
folderPermissions: null, folderPermissions: null,
currentFolder: 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() { isAdmin: function() {
if (this.authenticated && is.not.null(this.user) && this.user.id !== "") { if (this.authenticated && is.not.null(this.user) && this.user.id !== "") {
return this.user.admin; return this.user.admin;
@ -36,38 +30,57 @@ const Session = Ember.Service.extend({
return false; return false;
}.property('user'), }.property('user'),
login(credentials) { // Boot up
// TODO: figure out what to do with credentials init: function() {
var self = this; this.set('user', models.UserModel.create());
var url = self.appMeta.getUrl('public/authenticate'); 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(); let domain = netUtil.getSubdomain();
this.clearSession(); this.clearSession();
return new Ember.RSVP.Promise(function(resolve, reject) { if (is.empty(credentials.email) || is.empty(credentials.password)) {
if (is.empty(credentials.email) || is.empty(credentials.password)) { return Ember.RSVP.reject("invalid");
reject("invalid"); }
return;
}
var encoded = encodingUtil.Base64.encode(domain + ":" + credentials.email + ":" + credentials.password); var encoded = encodingUtil.Base64.encode(domain + ":" + credentials.email + ":" + credentials.password);
var header = { var headers = {
'Authorization': 'Basic ' + encoded 'Authorization': 'Basic ' + encoded
}; };
$.ajax({ return this.get('ajax').post(url, {
url: url, headers
type: 'POST', }).then((response)=>{
headers: header, this.setSession(response.token, models.UserModel.create(response.user));
success: function(response) { this.get('ready', true);
self.setSession(response.token, models.UserModel.create(response.user)); return response;
self.get('ready', true); });
resolve(response); },
},
error: function(reason) { sso: function(credentials) {
reject(reason); 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('token', token);
this.storeSessionItem('user', JSON.stringify(user)); this.storeSessionItem('user', JSON.stringify(user));
let self = this;
$.ajaxPrefilter(function(options, originalOptions, jqXHR) { $.ajaxPrefilter(function(options, originalOptions, jqXHR) {
jqXHR.setRequestHeader('Authorization', 'Bearer ' + token); // 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]; // delete localStorage[key];
}, },
// boot(){
// console.log(this.get('appMeta'));
// return new Ember.RSVP.resolve();
// },
boot() { boot() {
let self = this; let self = this;
let dbhash = ""; let dbhash = "";
@ -140,60 +153,45 @@ const Session = Ember.Service.extend({
}); });
} }
return new Ember.RSVP.Promise(function(resolve) { // 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");
$.ajax({ //
url: self.get('appMeta').getUrl("public/meta"), // if (!blockedPopupTest) {
type: 'GET', // this.set('popupBlocked', true);
contentType: 'json', // } else {
success: function(response) { // blockedPopupTest.close();
self.get('appMeta').set('orgId', response.orgId); // this.set('popupBlocked', false);
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);
let token = self.getSessionItem('token'); let url = this.get('appMeta').getUrl("public/meta");
if (is.not.undefined(token)) { return this.get('ajax').request(url)
// We now validate current token .then((response) => {
let tokenCheckUrl = self.get('appMeta').getUrl(`public/validate?token=${token}`); 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);
$.ajax({ let token = this.getSessionItem('token');
url: tokenCheckUrl,
type: 'GET', if (is.not.undefined(token)) {
contentType: 'json', // We now validate current token
success: function(user) { let tokenCheckUrl = this.get('appMeta').getUrl(`public/validate?token=${token}`);
self.setSession(token, models.UserModel.create(user));
self.set('ready', true); return this.get('ajax').request(tokenCheckUrl, {
resolve(); method: 'GET',
}, contentType: 'json'
error: function(reason) { }).then((response) => {
if (reason.status === 401 || reason.status === 403) { this.setSession(token, models.UserModel.create(user));
localStorage.clear(); this.set('ready', true);
window.location.href = "/auth/login"; }).catch((reason) => {
}
}
});
} else {
self.set('ready', true);
resolve();
}
},
error: function(reason) {
if (reason.status === 401 || reason.status === 403) { if (reason.status === 401 || reason.status === 403) {
window.location.href = "https://documize.com"; localStorage.clear();
window.location.href = "/auth/login";
} }
} });
}); }
}); });
},
getSessionItem(key){
return this.get(`data.${key}`);
},
sso: function(credentials) {
} }
}); });