mirror of
https://github.com/documize/community.git
synced 2025-08-08 06:55:28 +02:00
Merge pull request #14 from documize/ember-simple-auth
Ember simple auth
This commit is contained in:
commit
d8e61c2743
62 changed files with 1460 additions and 1545 deletions
15
app/app/authenticators/anonymous.js
Normal file
15
app/app/authenticators/anonymous.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import Ember from 'ember';
|
||||
import Base from 'ember-simple-auth/authenticators/base';
|
||||
|
||||
const {
|
||||
RSVP: { resolve }
|
||||
} = Ember;
|
||||
|
||||
export default Base.extend({
|
||||
restore(data) {
|
||||
return resolve(data);
|
||||
},
|
||||
authenticate(data) {
|
||||
return resolve(data);
|
||||
}
|
||||
});
|
59
app/app/authenticators/documize.js
Normal file
59
app/app/authenticators/documize.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
import Ember from 'ember';
|
||||
import Base from 'ember-simple-auth/authenticators/base';
|
||||
import encodingUtil from '../utils/encoding';
|
||||
import netUtil from '../utils/net';
|
||||
import models from '../utils/model';
|
||||
|
||||
const {
|
||||
isPresent,
|
||||
RSVP: { resolve, reject },
|
||||
inject: { service }
|
||||
} = Ember;
|
||||
|
||||
export default Base.extend({
|
||||
|
||||
ajax: service(),
|
||||
appMeta: service(),
|
||||
|
||||
restore(data) {
|
||||
// TODO: verify authentication data
|
||||
if (data) {
|
||||
return resolve(data);
|
||||
}
|
||||
return reject();
|
||||
},
|
||||
|
||||
authenticate(credentials) {
|
||||
let domain = netUtil.getSubdomain();
|
||||
|
||||
let encoded;
|
||||
|
||||
if (typeof credentials === 'object') {
|
||||
|
||||
let { password, email } = credentials;
|
||||
|
||||
if (!isPresent(password) || !isPresent(email)) {
|
||||
return Ember.RSVP.reject("invalid");
|
||||
}
|
||||
|
||||
encoded = encodingUtil.Base64.encode(`${domain}:${email}:${password}`);
|
||||
} else if (typeof credentials === 'string') {
|
||||
encoded = credentials;
|
||||
} else {
|
||||
return Ember.RSVP.reject("invalid");
|
||||
|
||||
}
|
||||
|
||||
var headers = {
|
||||
'Authorization': 'Basic ' + encoded
|
||||
};
|
||||
|
||||
return this.get('ajax').post('public/authenticate', {
|
||||
headers
|
||||
});
|
||||
},
|
||||
|
||||
invalidate() {
|
||||
return resolve();
|
||||
}
|
||||
});
|
|
@ -15,6 +15,7 @@ import TooltipMixin from '../../mixins/tooltip';
|
|||
|
||||
export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
||||
userService: Ember.inject.service('user'),
|
||||
localStorage: Ember.inject.service(),
|
||||
drop: null,
|
||||
users: [],
|
||||
saveTemplate: {
|
||||
|
@ -43,11 +44,12 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
if (this.get('isEditor')) {
|
||||
let self = this;
|
||||
let documentId = this.get('document.id');
|
||||
let uploadUrl = this.session.appMeta.getUrl(`documents/${documentId}/attachments`);
|
||||
let url = this.get('appMeta.url');
|
||||
let uploadUrl = `${url}/documents/${documentId}/attachments`;
|
||||
|
||||
let dzone = new Dropzone("#attachment-button > i", {
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + self.session.getSessionItem('token')
|
||||
'Authorization': 'Bearer ' + self.get('localStorage').getSessionItem('session.session.authenticated.token')
|
||||
},
|
||||
url: uploadUrl,
|
||||
method: "post",
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
|
@ -14,149 +14,150 @@ import NotifierMixin from '../../mixins/notifier';
|
|||
import TooltipMixin from '../../mixins/tooltip';
|
||||
|
||||
export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
||||
documentService: Ember.inject.service('document'),
|
||||
sectionService: Ember.inject.service('section'),
|
||||
/* Parameters */
|
||||
document: null,
|
||||
// pages: [],
|
||||
attachments: [],
|
||||
folder: null,
|
||||
folders: [],
|
||||
isEditor: false,
|
||||
/* Internal */
|
||||
drop: null,
|
||||
deleteAttachment: {
|
||||
id: "",
|
||||
name: "",
|
||||
},
|
||||
deletePage: {
|
||||
id: "",
|
||||
title: "",
|
||||
children: false
|
||||
},
|
||||
documentService: Ember.inject.service('document'),
|
||||
sectionService: Ember.inject.service('section'),
|
||||
appMeta: Ember.inject.service(),
|
||||
/* Parameters */
|
||||
document: null,
|
||||
// pages: [],
|
||||
attachments: [],
|
||||
folder: null,
|
||||
folders: [],
|
||||
isEditor: false,
|
||||
/* Internal */
|
||||
drop: null,
|
||||
deleteAttachment: {
|
||||
id: "",
|
||||
name: "",
|
||||
},
|
||||
deletePage: {
|
||||
id: "",
|
||||
title: "",
|
||||
children: false
|
||||
},
|
||||
|
||||
noSections: Ember.computed('pages', function() {
|
||||
return this.get('pages.length') === 0;
|
||||
}),
|
||||
noSections: Ember.computed('pages', function () {
|
||||
return this.get('pages.length') === 0;
|
||||
}),
|
||||
|
||||
didInsertElement() {
|
||||
let self = this;
|
||||
didInsertElement() {
|
||||
let self = this;
|
||||
|
||||
this.get('sectionService').refresh(this.get('document.id')).then(function(changes) {
|
||||
changes.forEach(function(newPage) {
|
||||
let oldPage = self.get('pages').findBy('id', newPage.get('id'));
|
||||
if (is.not.undefined(oldPage)) {
|
||||
oldPage.set('body', newPage.body);
|
||||
oldPage.set('revised', newPage.revised);
|
||||
self.showNotification(`Refreshed ${oldPage.title}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
this.get('sectionService').refresh(this.get('document.id')).then(function (changes) {
|
||||
changes.forEach(function (newPage) {
|
||||
let oldPage = self.get('pages').findBy('id', newPage.get('id'));
|
||||
if (is.not.undefined(oldPage)) {
|
||||
oldPage.set('body', newPage.body);
|
||||
oldPage.set('revised', newPage.revised);
|
||||
self.showNotification(`Refreshed ${oldPage.title}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
willDestroyElement() {
|
||||
this.destroyTooltips();
|
||||
willDestroyElement() {
|
||||
this.destroyTooltips();
|
||||
|
||||
let drop = this.get('drop');
|
||||
let drop = this.get('drop');
|
||||
|
||||
if (is.not.null(drop)) {
|
||||
drop.destroy();
|
||||
}
|
||||
},
|
||||
if (is.not.null(drop)) {
|
||||
drop.destroy();
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
confirmDeleteAttachment(id, name) {
|
||||
this.set('deleteAttachment', {
|
||||
id: id,
|
||||
name: name
|
||||
});
|
||||
actions: {
|
||||
confirmDeleteAttachment(id, name) {
|
||||
this.set('deleteAttachment', {
|
||||
id: id,
|
||||
name: name
|
||||
});
|
||||
|
||||
$(".delete-attachment-dialog").css("display", "block");
|
||||
$(".delete-attachment-dialog").css("display", "block");
|
||||
|
||||
let drop = new Drop({
|
||||
target: $(".delete-attachment-" + id)[0],
|
||||
content: $(".delete-attachment-dialog")[0],
|
||||
classes: 'drop-theme-basic',
|
||||
position: "bottom right",
|
||||
openOn: "always",
|
||||
tetherOptions: {
|
||||
offset: "5px 0",
|
||||
targetOffset: "10px 0"
|
||||
},
|
||||
remove: false
|
||||
});
|
||||
let drop = new Drop({
|
||||
target: $(".delete-attachment-" + id)[0],
|
||||
content: $(".delete-attachment-dialog")[0],
|
||||
classes: 'drop-theme-basic',
|
||||
position: "bottom right",
|
||||
openOn: "always",
|
||||
tetherOptions: {
|
||||
offset: "5px 0",
|
||||
targetOffset: "10px 0"
|
||||
},
|
||||
remove: false
|
||||
});
|
||||
|
||||
this.set('drop', drop);
|
||||
},
|
||||
this.set('drop', drop);
|
||||
},
|
||||
|
||||
cancel() {
|
||||
let drop = this.get('drop');
|
||||
drop.close();
|
||||
cancel() {
|
||||
let drop = this.get('drop');
|
||||
drop.close();
|
||||
|
||||
this.set('deleteAttachment', {
|
||||
id: "",
|
||||
name: ""
|
||||
});
|
||||
},
|
||||
this.set('deleteAttachment', {
|
||||
id: "",
|
||||
name: ""
|
||||
});
|
||||
},
|
||||
|
||||
deleteAttachment() {
|
||||
let attachment = this.get('deleteAttachment');
|
||||
let drop = this.get('drop');
|
||||
drop.close();
|
||||
deleteAttachment() {
|
||||
let attachment = this.get('deleteAttachment');
|
||||
let drop = this.get('drop');
|
||||
drop.close();
|
||||
|
||||
this.showNotification(`Deleted ${attachment.name}`);
|
||||
this.attrs.onAttachmentDeleted(this.get('deleteAttachment').id);
|
||||
this.set('deleteAttachment', {
|
||||
id: "",
|
||||
name: ""
|
||||
});
|
||||
this.showNotification(`Deleted ${attachment.name}`);
|
||||
this.attrs.onAttachmentDeleted(this.get('deleteAttachment').id);
|
||||
this.set('deleteAttachment', {
|
||||
id: "",
|
||||
name: ""
|
||||
});
|
||||
|
||||
return true;
|
||||
},
|
||||
return true;
|
||||
},
|
||||
|
||||
onDeletePage(id) {
|
||||
let page = this.get('pages').findBy("id", id);
|
||||
onDeletePage(id) {
|
||||
let page = this.get('pages').findBy("id", id);
|
||||
|
||||
if (is.undefined(page)) {
|
||||
return;
|
||||
}
|
||||
if (is.undefined(page)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.set('deletePage', {
|
||||
id: id,
|
||||
title: page.get('title'),
|
||||
children: false
|
||||
});
|
||||
this.set('deletePage', {
|
||||
id: id,
|
||||
title: page.get('title'),
|
||||
children: false
|
||||
});
|
||||
|
||||
$(".delete-page-dialog").css("display", "block");
|
||||
$(".delete-page-dialog").css("display", "block");
|
||||
|
||||
let drop = new Drop({
|
||||
target: $("#page-toolbar-" + id)[0],
|
||||
content: $(".delete-page-dialog")[0],
|
||||
classes: 'drop-theme-basic',
|
||||
position: "bottom right",
|
||||
openOn: "always",
|
||||
tetherOptions: {
|
||||
offset: "5px 0",
|
||||
targetOffset: "10px 0"
|
||||
},
|
||||
remove: false
|
||||
});
|
||||
let drop = new Drop({
|
||||
target: $("#page-toolbar-" + id)[0],
|
||||
content: $(".delete-page-dialog")[0],
|
||||
classes: 'drop-theme-basic',
|
||||
position: "bottom right",
|
||||
openOn: "always",
|
||||
tetherOptions: {
|
||||
offset: "5px 0",
|
||||
targetOffset: "10px 0"
|
||||
},
|
||||
remove: false
|
||||
});
|
||||
|
||||
this.set('drop', drop);
|
||||
},
|
||||
this.set('drop', drop);
|
||||
},
|
||||
|
||||
deletePage() {
|
||||
let drop = this.get('drop');
|
||||
drop.close();
|
||||
deletePage() {
|
||||
let drop = this.get('drop');
|
||||
drop.close();
|
||||
|
||||
this.attrs.onDeletePage(this.deletePage);
|
||||
},
|
||||
this.attrs.onDeletePage(this.deletePage);
|
||||
},
|
||||
|
||||
// onTagChange event emitted from document/tag-editor component
|
||||
onTagChange(tags) {
|
||||
let doc = this.get('document');
|
||||
doc.set('tags', tags);
|
||||
this.get('documentService').save(doc);
|
||||
}
|
||||
}
|
||||
// onTagChange event emitted from document/tag-editor component
|
||||
onTagChange(tags) {
|
||||
let doc = this.get('document');
|
||||
doc.set('tags', tags);
|
||||
this.get('documentService').save(doc);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
|
@ -13,6 +13,7 @@ import Ember from 'ember';
|
|||
|
||||
export default Ember.Component.extend({
|
||||
folderService: Ember.inject.service('folder'),
|
||||
appMeta: Ember.inject.service(),
|
||||
users: [],
|
||||
folders: [],
|
||||
folder: {},
|
||||
|
@ -23,7 +24,7 @@ export default Ember.Component.extend({
|
|||
permissions: {},
|
||||
|
||||
getDefaultInvitationMessage() {
|
||||
return "Hey there, I am sharing the " + this.folder.get('name') + " (in " + this.session.appMeta.title + ") with you so we can both access the same documents.";
|
||||
return "Hey there, I am sharing the " + this.folder.get('name') + " (in " + this.get("appMeta.title") + ") with you so we can both access the same documents.";
|
||||
},
|
||||
|
||||
willRender() {
|
||||
|
@ -106,4 +107,4 @@ export default Ember.Component.extend({
|
|||
this.sendAction("onPermission", this.get('folder'), message, this.get('permissions'));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,20 +13,25 @@ import Ember from 'ember';
|
|||
import NotifierMixin from '../../mixins/notifier';
|
||||
import TooltipMixin from '../../mixins/tooltip';
|
||||
|
||||
const {
|
||||
computed
|
||||
} = Ember;
|
||||
|
||||
export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
||||
documentService: Ember.inject.service('document'),
|
||||
templateService: Ember.inject.service('template'),
|
||||
folderService: Ember.inject.service('folder'),
|
||||
session: Ember.inject.service(),
|
||||
|
||||
folder: {},
|
||||
busy: false,
|
||||
importedDocuments: [],
|
||||
savedTemplates: [],
|
||||
isFolderOwner: false,
|
||||
isFolderOwner: computed.equal('folder.userId', 'session.user.id'),
|
||||
moveFolderId: "",
|
||||
|
||||
didReceiveAttrs() {
|
||||
this.set('isFolderOwner', this.get('folder.userId') === this.session.user.id);
|
||||
this.set('isFolderOwner', this.get('folder.userId') === this.get("session.user.id"));
|
||||
|
||||
let self = this;
|
||||
|
||||
|
|
|
@ -13,12 +13,14 @@ import Ember from 'ember';
|
|||
import NotifierMixin from '../../mixins/notifier';
|
||||
|
||||
export default Ember.Component.extend(NotifierMixin, {
|
||||
localStorage: Ember.inject.service(),
|
||||
tagName: 'span',
|
||||
selectedTemplate: {
|
||||
id: "0"
|
||||
},
|
||||
canEditTemplate: "",
|
||||
drop: null,
|
||||
appMeta: Ember.inject.service(),
|
||||
|
||||
didReceiveAttrs() {
|
||||
this.send('setTemplate', this.get('savedTemplates')[0]);
|
||||
|
@ -71,13 +73,14 @@ export default Ember.Component.extend(NotifierMixin, {
|
|||
|
||||
let self = this;
|
||||
let folderId = this.get('folder.id');
|
||||
let importUrl = this.session.appMeta.getUrl('import/folder/' + folderId);
|
||||
let url = this.get('appMeta.url');
|
||||
let importUrl = `${url}/import/folder/${folderId}`;
|
||||
|
||||
Dropzone.options.uploadDocuments = false;
|
||||
|
||||
let dzone = new Dropzone("#upload-documents", {
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + self.session.getSessionItem('token')
|
||||
'Authorization': 'Bearer ' + self.get('localStorage').getSessionItem('session.session.authenticated.token')
|
||||
},
|
||||
url: importUrl,
|
||||
method: "post",
|
||||
|
|
|
@ -15,15 +15,16 @@ import netUtil from '../../utils/net';
|
|||
export default Ember.Component.extend({
|
||||
folderService: Ember.inject.service('folder'),
|
||||
folder: null,
|
||||
appMeta: Ember.inject.service(),
|
||||
|
||||
didInitAttrs() {
|
||||
let self = this;
|
||||
if (this.session.authenticated) {
|
||||
this.session.user.accounts.forEach(function(account) {
|
||||
account.active = account.orgId === self.session.appMeta.orgId;
|
||||
});
|
||||
}
|
||||
},
|
||||
didInitAttrs() {
|
||||
if (this.get("session.authenticated")) {
|
||||
this.get("session.user.accounts").forEach((account)=>{
|
||||
// TODO: do not mutate account.active here
|
||||
account.active = account.orgId === this.get("appMeta.orgId");
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
didReceiveAttrs() {
|
||||
if (this.get('folder') === null) {
|
||||
|
@ -31,10 +32,10 @@ export default Ember.Component.extend({
|
|||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
switchAccount(domain) {
|
||||
this.audit.record('switched-account');
|
||||
window.location.href = netUtil.getAppUrl(domain);
|
||||
}
|
||||
}
|
||||
actions: {
|
||||
switchAccount(domain) {
|
||||
this.audit.record('switched-account');
|
||||
window.location.href = netUtil.getAppUrl(domain);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
|
@ -13,6 +13,7 @@ import Ember from 'ember';
|
|||
|
||||
export default Ember.Component.extend({
|
||||
pageBody: "",
|
||||
appMeta: Ember.inject.service(),
|
||||
|
||||
didReceiveAttrs() {
|
||||
this.set('pageBody', this.get('meta.rawBody'));
|
||||
|
@ -76,7 +77,7 @@ export default Ember.Component.extend({
|
|||
};
|
||||
|
||||
if (typeof tinymce === 'undefined') {
|
||||
$.getScript(this.session.appMeta.getBaseUrl("tinymce/tinymce.min.js?v=430"), function() {
|
||||
$.getScript(this.get("appMeta").getBaseUrl("tinymce/tinymce.min.js?v=430"), function() {
|
||||
window.tinymce.dom.Event.domLoaded = true;
|
||||
tinymce.baseURL = "//" + window.location.host + "/tinymce";
|
||||
tinymce.suffix = ".min";
|
||||
|
@ -110,4 +111,4 @@ export default Ember.Component.extend({
|
|||
this.attrs.onAction(page, meta);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
|
@ -15,9 +15,15 @@ export default Ember.Mixin.create({
|
|||
tooltips: [],
|
||||
|
||||
addTooltip(elem) {
|
||||
|
||||
if(elem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let t = new Tooltip({
|
||||
target: elem
|
||||
});
|
||||
|
||||
let tt = this.get('tooltips');
|
||||
tt.push(t);
|
||||
},
|
||||
|
@ -33,4 +39,4 @@ export default Ember.Mixin.create({
|
|||
|
||||
this.set('tooltips', tt);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,6 +4,8 @@ export default Ember.Controller.extend({
|
|||
email: "",
|
||||
password: "",
|
||||
invalidCredentials: false,
|
||||
session: Ember.inject.service('session'),
|
||||
audit: Ember.inject.service('audit'),
|
||||
|
||||
reset() {
|
||||
this.setProperties({
|
||||
|
@ -20,24 +22,16 @@ export default Ember.Controller.extend({
|
|||
|
||||
actions: {
|
||||
login() {
|
||||
let self = this;
|
||||
let creds = this.getProperties('email', 'password');
|
||||
|
||||
this.session.login(creds).then(function() {
|
||||
self.set('invalidCredentials', false);
|
||||
self.audit.record("logged-in");
|
||||
|
||||
var previousTransition = self.session.get('previousTransition');
|
||||
|
||||
if (previousTransition) {
|
||||
previousTransition.retry();
|
||||
self.session.set('previousTransition', null);
|
||||
} else {
|
||||
self.transitionToRoute('folders.folder');
|
||||
}
|
||||
}, function() {
|
||||
self.set('invalidCredentials', true);
|
||||
});
|
||||
this.get('session').authenticate('authenticator:documize', creds)
|
||||
.then((response) => {
|
||||
this.get('audit').record("logged-in");
|
||||
this.transitionToRoute('folders.folder');
|
||||
return response;
|
||||
}).catch(() => {
|
||||
this.set('invalidCredentials', true);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,14 +2,17 @@ import Ember from 'ember';
|
|||
import config from 'documize/config/environment';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
session: Ember.inject.service(),
|
||||
appMeta: Ember.inject.service(),
|
||||
|
||||
activate: function(){
|
||||
this.session.logout();
|
||||
this.get('session').invalidate();
|
||||
this.audit.record("logged-in");
|
||||
this.audit.stop();
|
||||
if (config.environment === 'test') {
|
||||
this.transitionTo('auth.login');
|
||||
}else{
|
||||
window.document.location = this.session.appMeta.allowAnonymousAccess ? "/" : "/auth/login";
|
||||
window.document.location = this.get("appMeta.allowAnonymousAccess") ? "/" : "/auth/login";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
model: function(params) {
|
||||
this.set('folderId', params.id);
|
||||
this.set('slug', params.slug);
|
||||
|
|
|
@ -1,24 +1,15 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
beforeModel() {
|
||||
this.session.clearSession();
|
||||
},
|
||||
session: Ember.inject.service(),
|
||||
|
||||
model(params) {
|
||||
let token = params.token;
|
||||
|
||||
if (is.undefined(token) || is.null(token) || token.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let self = this;
|
||||
|
||||
this.session.sso(decodeURIComponent(token)).then(function() {
|
||||
self.transitionTo('folders.folder');
|
||||
}, function() {
|
||||
self.transitionTo('auth.login');
|
||||
console.log(">>>>> Documize SSO failure");
|
||||
});
|
||||
},
|
||||
});
|
||||
model({ token }) {
|
||||
this.get("session").authenticate('authenticator:documize', token)
|
||||
.then(() => {
|
||||
this.transitionTo('folders.folder');
|
||||
}, () => {
|
||||
this.transitionTo('auth.login');
|
||||
console.log(">>>>> Documize SSO failure");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
folderService: Ember.inject.service('folder'),
|
||||
|
||||
beforeModel() {
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
orgService: Ember.inject.service('organization'),
|
||||
appMeta: Ember.inject.service(),
|
||||
session: Ember.inject.service(),
|
||||
|
||||
beforeModel() {
|
||||
if (!this.session.isAdmin) {
|
||||
if (!this.get("session.isAdmin")) {
|
||||
this.transitionTo('auth.login');
|
||||
}
|
||||
},
|
||||
|
||||
model() {
|
||||
return this.get('orgService').getOrg(this.session.appMeta.get('orgId'));
|
||||
let orgId = this.get("appMeta.orgId");
|
||||
return this.get('orgService').getOrg(orgId);
|
||||
},
|
||||
|
||||
activate() {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*global is*/
|
||||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(
|
||||
{
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
beforeModel: function(transition)
|
||||
{
|
||||
if (is.equal(transition.targetName, 'customize.index')) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
userService: Ember.inject.service('user'),
|
||||
|
||||
beforeModel: function() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
documentService: Ember.inject.service('document'),
|
||||
folderService: Ember.inject.service('folder'),
|
||||
|
||||
|
@ -16,4 +17,4 @@ export default Ember.Route.extend({
|
|||
meta: self.get('documentService').getPageMeta(self.paramsFor('document').document_id, params.page_id)
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
// import models from '../../../utils/model';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
documentService: Ember.inject.service('document'),
|
||||
folderService: Ember.inject.service('folder'),
|
||||
userService: Ember.inject.service('user'),
|
||||
|
@ -106,4 +107,4 @@ export default Ember.Route.extend({
|
|||
deactivate() {
|
||||
Ember.$('html').removeClass('background-color-white');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
documentService: Ember.inject.service('document'),
|
||||
|
||||
model: function(params) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
documentService: Ember.inject.service('document'),
|
||||
folderService: Ember.inject.service('folder'),
|
||||
sectionService: Ember.inject.service('section'),
|
||||
|
|
|
@ -3,8 +3,8 @@ import NotifierMixin from '../../../mixins/notifier';
|
|||
|
||||
export default Ember.Controller.extend(NotifierMixin, {
|
||||
documentService: Ember.inject.service('document'),
|
||||
folderService: Ember.inject.service('folder'),
|
||||
hasSelectedDocuments: false,
|
||||
folderService: Ember.inject.service('folder'),
|
||||
hasSelectedDocuments: false,
|
||||
selectedDocuments: [],
|
||||
|
||||
actions: {
|
||||
|
@ -12,56 +12,56 @@ export default Ember.Controller.extend(NotifierMixin, {
|
|||
this.get('target.router').refresh();
|
||||
},
|
||||
|
||||
onDocumentsChecked(documents) {
|
||||
onDocumentsChecked(documents) {
|
||||
this.set('selectedDocuments', documents);
|
||||
this.set('hasSelectedDocuments', documents.length > 0);
|
||||
},
|
||||
|
||||
onMoveDocument(folder) {
|
||||
let self = this;
|
||||
let documents = this.get('selectedDocuments');
|
||||
let documents = this.get('selectedDocuments');
|
||||
|
||||
documents.forEach(function(documentId) {
|
||||
self.get('documentService').getDocument(documentId).then(function(doc) {
|
||||
documents.forEach(function (documentId) {
|
||||
self.get('documentService').getDocument(documentId).then(function (doc) {
|
||||
doc.set('folderId', folder);
|
||||
self.get('documentService').save(doc).then(function() {
|
||||
self.get('documentService').save(doc).then(function () {
|
||||
self.get('target.router').refresh();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
this.set('selectedDocuments', []);
|
||||
this.set('hasSelectedDocuments', false);
|
||||
this.send("showNotification", "Moved");
|
||||
this.set('selectedDocuments', []);
|
||||
this.set('hasSelectedDocuments', false);
|
||||
this.send("showNotification", "Moved");
|
||||
},
|
||||
|
||||
onDeleteDocument() {
|
||||
let documents = this.get('selectedDocuments');
|
||||
let self = this;
|
||||
onDeleteDocument() {
|
||||
let documents = this.get('selectedDocuments');
|
||||
let self = this;
|
||||
|
||||
documents.forEach(function(document) {
|
||||
self.get('documentService').deleteDocument(document).then(function() {
|
||||
self.get('target.router').refresh();
|
||||
});
|
||||
});
|
||||
documents.forEach(function (document) {
|
||||
self.get('documentService').deleteDocument(document).then(function () {
|
||||
self.get('target.router').refresh();
|
||||
});
|
||||
});
|
||||
|
||||
this.set('selectedDocuments', []);
|
||||
this.set('hasSelectedDocuments', false);
|
||||
this.send("showNotification", "Deleted");
|
||||
},
|
||||
this.set('selectedDocuments', []);
|
||||
this.set('hasSelectedDocuments', false);
|
||||
this.send("showNotification", "Deleted");
|
||||
},
|
||||
|
||||
showDocument(folder, document) {
|
||||
this.transitionToRoute('document', folder.get('id'), folder.get('slug'), document.get('id'), document.get('slug'));
|
||||
},
|
||||
|
||||
onFolderAdd(folder) {
|
||||
let self = this;
|
||||
this.showNotification("Added");
|
||||
onFolderAdd(folder) {
|
||||
let self = this;
|
||||
this.showNotification("Added");
|
||||
|
||||
this.get('folderService').add({ name: folder }).then(function(newFolder) {
|
||||
this.get('folderService').add({ name: folder }).then(function (newFolder) {
|
||||
self.get('folderService').setCurrentFolder(newFolder);
|
||||
self.transitionToRoute('folders.folder', newFolder.get('id'), newFolder.get('slug'));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,6 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
documentService: Ember.inject.service('document'),
|
||||
folderService: Ember.inject.service('folder'),
|
||||
|
||||
|
|
|
@ -1,61 +1,71 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
folderService: Ember.inject.service('folder'),
|
||||
folder: {},
|
||||
const {
|
||||
isPresent
|
||||
} = Ember;
|
||||
|
||||
model: function() {
|
||||
return this.get('folderService').getAll();
|
||||
},
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
folderService: Ember.inject.service('folder'),
|
||||
localStorage: Ember.inject.service(),
|
||||
folder: {},
|
||||
|
||||
afterModel: function(model) {
|
||||
let self = this;
|
||||
model: function () {
|
||||
return this.get('folderService').getAll();
|
||||
},
|
||||
|
||||
if (is.empty(this.paramsFor('folders.folder'))) {
|
||||
var lastFolder = this.session.getSessionItem("folder");
|
||||
afterModel: function (model) {
|
||||
|
||||
if (is.not.undefined(lastFolder)) {
|
||||
this.get('folderService').getFolder(lastFolder).then(function(folder) {
|
||||
if (is.undefined(folder) || is.null(folder)) {
|
||||
self.transitionTo('auth.login');
|
||||
}
|
||||
self.folder = folder;
|
||||
self.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
}, function() {
|
||||
if (model.length > 0) {
|
||||
var folder = model[0];
|
||||
self.folder = folder;
|
||||
self.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
} else {
|
||||
self.transitionTo('auth.login');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (model.length > 0) {
|
||||
var folder = model[0];
|
||||
self.folder = folder;
|
||||
self.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
} else
|
||||
{
|
||||
// has no folders, create default folder
|
||||
this.get('folderService').add({ name: "My Space" }).then(function(folder) {
|
||||
self.folder = folder;
|
||||
self.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var folderId = this.paramsFor('folders.folder').folder_id;
|
||||
this.get('folderService').getFolder(folderId).then(function(folder) {
|
||||
self.folder = folder;
|
||||
});
|
||||
}
|
||||
let params = this.paramsFor('folders.folder');
|
||||
|
||||
this.browser.setMetaDescription();
|
||||
},
|
||||
if (is.empty(params)) {
|
||||
let lastFolder = this.get('localStorage').getSessionItem("folder");
|
||||
|
||||
setupController(controller, model) {
|
||||
controller.set('model', model);
|
||||
controller.set('folder', this.folder);
|
||||
}
|
||||
//If folder lastFolder is defined
|
||||
if (isPresent(lastFolder)) {
|
||||
return this.get('folderService').getFolder(lastFolder).then((folder) => {
|
||||
//if Response is null or undefined redirect to login else transitionTo dashboard
|
||||
if (Ember.isNone(folder)) {
|
||||
this.transitionTo('auth.login');
|
||||
}
|
||||
|
||||
Ember.set(this, 'folder', folder);
|
||||
this.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
}).catch(() => {
|
||||
//if there was an error redirect to login
|
||||
this.transitionTo('auth.login');
|
||||
});
|
||||
}
|
||||
|
||||
// If model has any folders redirect to dashboard
|
||||
if (model.length > 0) {
|
||||
let folder = model[0];
|
||||
Ember.set(this, 'folder', folder);
|
||||
this.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
}
|
||||
|
||||
// has no folders, create default folder
|
||||
return this.get('folderService').add({ name: "My Space" }).then((folder) => {
|
||||
Ember.set(this, 'folder', folder);
|
||||
this.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
});
|
||||
}
|
||||
|
||||
//If folder route has params
|
||||
if (isPresent(params)) {
|
||||
|
||||
let folderId = this.paramsFor('folders.folder').folder_id;
|
||||
|
||||
return this.get('folderService').getFolder(folderId).then((folder) => {
|
||||
Ember.set(this, 'folder', folder);
|
||||
});
|
||||
}
|
||||
|
||||
this.browser.setMetaDescription();
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
controller.set('model', model);
|
||||
controller.set('folder', this.folder);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import Ember from 'ember';
|
||||
import models from '../../../utils/model';
|
||||
import NotifierMixin from '../../../mixins/notifier';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(NotifierMixin, {
|
||||
folderService: Ember.inject.service('folder'),
|
||||
userService: Ember.inject.service('user'),
|
||||
folder: {},
|
||||
tab: "",
|
||||
tab: "",
|
||||
|
||||
beforeModel: function(transition) {
|
||||
beforeModel: function (transition) {
|
||||
this.tab = is.not.undefined(transition.queryParams.tab) ? transition.queryParams.tab : "tabGeneral";
|
||||
},
|
||||
|
||||
model(params) {
|
||||
return this.get('folderService').getFolder(params.folder_id);
|
||||
return this.get('folderService').getFolder(params.folder_id);
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
|
@ -21,17 +22,17 @@ export default Ember.Route.extend(NotifierMixin, {
|
|||
this.folder = model;
|
||||
controller.set('model', model);
|
||||
|
||||
controller.set('tabGeneral', false);
|
||||
controller.set('tabShare', false);
|
||||
controller.set('tabPermissions', false);
|
||||
controller.set('tabDelete', false);
|
||||
controller.set(this.get('tab'), true);
|
||||
controller.set('tabGeneral', false);
|
||||
controller.set('tabShare', false);
|
||||
controller.set('tabPermissions', false);
|
||||
controller.set('tabDelete', false);
|
||||
controller.set(this.get('tab'), true);
|
||||
|
||||
this.get('folderService').getAll().then(function(folders) {
|
||||
this.get('folderService').getAll().then(function (folders) {
|
||||
controller.set('folders', folders.rejectBy('id', model.get('id')));
|
||||
});
|
||||
|
||||
this.get('userService').getAll().then(function(users) {
|
||||
this.get('userService').getAll().then(function (users) {
|
||||
controller.set('users', users);
|
||||
|
||||
var folderPermissions = [];
|
||||
|
@ -47,7 +48,7 @@ export default Ember.Route.extend(NotifierMixin, {
|
|||
|
||||
folderPermissions.pushObject(u);
|
||||
|
||||
users.forEach(function(user, index) /* jshint ignore:line */ {
|
||||
users.forEach(function (user, index) /* jshint ignore:line */ {
|
||||
if (user.get('active')) {
|
||||
var u = models.FolderPermissionModel.create({
|
||||
userId: user.get('id'),
|
||||
|
@ -63,8 +64,8 @@ export default Ember.Route.extend(NotifierMixin, {
|
|||
}
|
||||
});
|
||||
|
||||
self.get('folderService').getPermissions(model.id).then(function(permissions) {
|
||||
permissions.forEach(function(permission, index) /* jshint ignore:line */ {
|
||||
self.get('folderService').getPermissions(model.id).then(function (permissions) {
|
||||
permissions.forEach(function (permission, index) /* jshint ignore:line */ {
|
||||
var folderPermission = folderPermissions.findBy('userId', permission.userId);
|
||||
if (is.not.undefined(folderPermission)) {
|
||||
Ember.set(folderPermission, 'orgId', permission.orgId);
|
||||
|
@ -81,45 +82,46 @@ export default Ember.Route.extend(NotifierMixin, {
|
|||
},
|
||||
|
||||
actions: {
|
||||
onRename: function(folder) {
|
||||
let self = this;
|
||||
this.get('folderService').save(folder).then(function() {
|
||||
self.showNotification("Renamed");
|
||||
});
|
||||
onRename: function (folder) {
|
||||
let self = this;
|
||||
this.get('folderService').save(folder).then(function () {
|
||||
self.showNotification("Renamed");
|
||||
});
|
||||
},
|
||||
|
||||
onRemove(moveId) {
|
||||
let self = this;
|
||||
|
||||
this.get('folderService').remove(this.folder.get('id'), moveId).then(function() { /* jshint ignore:line */
|
||||
this.get('folderService').remove(this.folder.get('id'), moveId).then(function () { /* jshint ignore:line */
|
||||
self.showNotification("Deleted");
|
||||
self.session.clearSessionItem('folder');
|
||||
|
||||
self.get('folderService').getFolder(moveId).then(function(folder) {
|
||||
self.get('folderService').getFolder(moveId).then(function (folder) {
|
||||
self.get('folderService').setCurrentFolder(folder);
|
||||
self.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
onShare: function(invitation) {
|
||||
onShare: function (invitation) {
|
||||
let self = this;
|
||||
|
||||
this.get('folderService').share(this.folder.get('id'), invitation).then(function() {
|
||||
self.showNotification("Shared");
|
||||
this.get('folderService').share(this.folder.get('id'), invitation).then(function () {
|
||||
self.showNotification("Shared");
|
||||
});
|
||||
},
|
||||
|
||||
onPermission: function(folder, message, permissions) {
|
||||
onPermission: function (folder, message, permissions) {
|
||||
var self = this;
|
||||
var data = permissions.map(function(obj){ return obj.getProperties('orgId', 'folderId' , 'userId', 'canEdit', 'canView'); });
|
||||
var data = permissions.map(function (obj) {
|
||||
return obj.getProperties('orgId', 'folderId', 'userId', 'canEdit', 'canView'); });
|
||||
var payload = { Message: message, Roles: data };
|
||||
|
||||
this.get('folderService').savePermissions(folder.get('id'), payload).then(function() {
|
||||
self.showNotification("Saved");
|
||||
this.get('folderService').savePermissions(folder.get('id'), payload).then(function () {
|
||||
self.showNotification("Saved");
|
||||
});
|
||||
|
||||
var hasEveryone = _.find(data, function(permission) {
|
||||
var hasEveryone = _.find(data, function (permission) {
|
||||
return permission.userId === "" && (permission.canView || permission.canEdit);
|
||||
});
|
||||
|
||||
|
@ -133,7 +135,7 @@ export default Ember.Route.extend(NotifierMixin, {
|
|||
}
|
||||
}
|
||||
|
||||
this.get('folderService').save(folder).then(function() {
|
||||
this.get('folderService').save(folder).then(function () {
|
||||
// window.location.href = "/folder/" + folder.get('id') + "/" + folder.get('slug');
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
|
||||
beforeModel: function() {
|
||||
this.transitionTo('folders');
|
||||
|
|
|
@ -3,6 +3,7 @@ import Ember from 'ember';
|
|||
export default Ember.Controller.extend({
|
||||
userService: Ember.inject.service('user'),
|
||||
password: { password: "", confirmation: ""},
|
||||
session: Ember.inject.service(),
|
||||
|
||||
actions: {
|
||||
save: function() {
|
||||
|
|
|
@ -1,25 +1,29 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
userService: Ember.inject.service('user'),
|
||||
folderService: Ember.inject.service('folder'),
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
userService: Ember.inject.service('user'),
|
||||
folderService: Ember.inject.service('folder'),
|
||||
session: Ember.inject.service(),
|
||||
|
||||
beforeModel: function() {
|
||||
if (!this.session.authenticated) {
|
||||
this.transitionTo('auth.login');
|
||||
}
|
||||
},
|
||||
|
||||
model: function() {
|
||||
return this.get('userService').getUser(this.session.user.id);
|
||||
},
|
||||
|
||||
afterModel: function(model) {
|
||||
this.browser.setTitleWithoutSuffix(model.get('fullname'));
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
controller.set('model', model);
|
||||
controller.set("folder", this.get('folderService.currentFolder'));
|
||||
beforeModel: function() {
|
||||
if (!this.get("session").authenticated) {
|
||||
this.transitionTo('auth.login');
|
||||
}
|
||||
},
|
||||
|
||||
model: function() {
|
||||
return this.get('userService').getUser(this.get("session.session.authenticated.user.id"));
|
||||
debugger;
|
||||
},
|
||||
|
||||
afterModel: function(model) {
|
||||
this.browser.setTitleWithoutSuffix(model.get('fullname'));
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
controller.set('model', model);
|
||||
controller.set("folder", this.get('folderService.currentFolder'));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (c) 2015 Documize Inc.
|
||||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
});
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin);
|
||||
|
|
|
@ -29,4 +29,4 @@ export default Ember.Route.extend({
|
|||
activate() {
|
||||
document.title = "Setup Documize database '" + document.head.querySelector("[property=dbname]").content + "'";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
});
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin);
|
||||
|
|
|
@ -16,10 +16,10 @@ var Router = Ember.Router.extend({
|
|||
location: config.locationType
|
||||
});
|
||||
|
||||
export default Router.map(function() {
|
||||
export default Router.map(function () {
|
||||
this.route('folders', {
|
||||
path: '/'
|
||||
}, function() {
|
||||
}, function () {
|
||||
this.route('folder', {
|
||||
path: 's/:folder_id/:folder_slug'
|
||||
});
|
||||
|
@ -30,7 +30,7 @@ export default Router.map(function() {
|
|||
|
||||
this.route('document', {
|
||||
path: 's/:folder_id/:folder_slug/d/:document_id/:document_slug'
|
||||
}, function() {
|
||||
}, function () {
|
||||
this.route('edit', {
|
||||
path: 'edit/:page_id'
|
||||
});
|
||||
|
@ -41,7 +41,7 @@ export default Router.map(function() {
|
|||
|
||||
this.route('customize', {
|
||||
path: 'settings'
|
||||
}, function() {
|
||||
}, function () {
|
||||
this.route('general', {
|
||||
path: 'general'
|
||||
});
|
||||
|
@ -59,7 +59,7 @@ export default Router.map(function() {
|
|||
|
||||
this.route('auth', {
|
||||
path: 'auth'
|
||||
}, function() {
|
||||
}, function () {
|
||||
this.route('sso', {
|
||||
path: 'sso/:token'
|
||||
});
|
||||
|
@ -98,5 +98,5 @@ export default Router.map(function() {
|
|||
path: '/*wildcard'
|
||||
});
|
||||
|
||||
this.route('pods', function() {});
|
||||
this.route('pods', function () {});
|
||||
});
|
||||
|
|
|
@ -10,57 +10,49 @@
|
|||
// https://documize.com
|
||||
|
||||
import Ember from 'ember';
|
||||
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
|
||||
import netUtil from '../utils/net';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
userService: Ember.inject.service('user'),
|
||||
sessionService: Ember.inject.service('session'),
|
||||
transitioning: false,
|
||||
const {
|
||||
inject: { service }
|
||||
} = Ember;
|
||||
|
||||
beforeModel: function(transition) {
|
||||
let self = this;
|
||||
let session = this.get('sessionService');
|
||||
export default Ember.Route.extend(ApplicationRouteMixin, {
|
||||
appMeta: service(),
|
||||
session: service(),
|
||||
beforeModel() {
|
||||
return this.get('appMeta').boot().then(data => {
|
||||
if (data.allowAnonymousAccess) {
|
||||
return this.get('session').authenticate('authenticator:anonymous', data);
|
||||
}
|
||||
return;
|
||||
});
|
||||
},
|
||||
|
||||
// Session ready?
|
||||
return session.boot().then(function() {
|
||||
// Need to authenticate?
|
||||
if (!session.get("appMeta.allowAnonymousAccess") && !session.get("authenticated") &&
|
||||
is.not.startWith(transition.targetName, 'auth.')) {
|
||||
if (!self.transitioning) {
|
||||
session.set('previousTransition', transition);
|
||||
self.set('transitioning', true);
|
||||
}
|
||||
|
||||
transition.abort();
|
||||
self.transitionTo('auth.login');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
willTransition: function( /*transition*/ ) {
|
||||
actions: {
|
||||
willTransition: function ( /*transition*/ ) {
|
||||
$("#zone-sidebar").css('height', 'auto');
|
||||
Mousetrap.reset();
|
||||
},
|
||||
Mousetrap.reset();
|
||||
},
|
||||
|
||||
didTransition() {
|
||||
Ember.run.schedule("afterRender",this,function() {
|
||||
Ember.run.schedule("afterRender", this, function () {
|
||||
$("#zone-sidebar").css('height', $(document).height() - $("#zone-navigation").height() - $("#zone-header").height() - 35);
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
error(error, transition) { // jshint ignore: line
|
||||
if (error) {
|
||||
error(error, transition) { // jshint ignore: line
|
||||
if (error) {
|
||||
if (netUtil.isAjaxAccessError(error)) {
|
||||
localStorage.clear();
|
||||
return this.transitionTo('auth.login');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return true to bubble this event to any parent route.
|
||||
return true;
|
||||
}
|
||||
},
|
||||
// Return true to bubble this event to any parent route.
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
25
app/app/services/ajax.js
Normal file
25
app/app/services/ajax.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
import AjaxService from 'ember-ajax/services/ajax';
|
||||
import config from '../config/environment';
|
||||
|
||||
const {
|
||||
computed,
|
||||
inject: { service }
|
||||
} = Ember;
|
||||
|
||||
export default AjaxService.extend({
|
||||
session: service(),
|
||||
host: config.apiHost,
|
||||
namespace: config.apiNamespace,
|
||||
|
||||
headers: Ember.computed('session.session.content.authenticated.token', {
|
||||
get() {
|
||||
let headers = {};
|
||||
const token = this.get('session.session.content.authenticated.token');
|
||||
if (token) {
|
||||
headers['authorization'] = token;
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
})
|
||||
});
|
45
app/app/services/app-meta.js
Normal file
45
app/app/services/app-meta.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
import Ember from 'ember';
|
||||
import config from '../config/environment';
|
||||
|
||||
const {
|
||||
String: { htmlSafe },
|
||||
RSVP: { resolve },
|
||||
inject: { service }
|
||||
} = Ember;
|
||||
|
||||
export default Ember.Service.extend({
|
||||
ajax: service(),
|
||||
|
||||
url: `${config.apiHost}/${config.apiNamespace}`,
|
||||
orgId: '',
|
||||
title: '',
|
||||
version: '',
|
||||
message: '',
|
||||
allowAnonymousAccess: false,
|
||||
|
||||
getBaseUrl(endpoint) {
|
||||
return [this.get('host'), endpoint].join('/');
|
||||
},
|
||||
|
||||
boot() {
|
||||
let dbhash;
|
||||
if (is.not.null(document.head.querySelector("[property=dbhash]"))) {
|
||||
dbhash = document.head.querySelector("[property=dbhash]").content;
|
||||
}
|
||||
|
||||
let isInSetupMode = dbhash && dbhash !== "{{.DBhash}}";
|
||||
if (isInSetupMode) {
|
||||
this.setProperites({
|
||||
title: htmlSafe("Documize Setup"),
|
||||
allowAnonymousAccess: false
|
||||
});
|
||||
return resolve();
|
||||
}
|
||||
|
||||
return this.get('ajax').request('public/meta')
|
||||
.then((response) => {
|
||||
this.setProperties(response);
|
||||
return response;
|
||||
});
|
||||
}
|
||||
});
|
|
@ -18,9 +18,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// Returns document model for specified document id.
|
||||
getDocument(documentId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents/${documentId}`, {
|
||||
method: "GET"
|
||||
}).then((response) => {
|
||||
return models.DocumentModel.create(response);
|
||||
|
@ -29,10 +27,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// Returns all documents for specified folder.
|
||||
getAllByFolder(folderId) {
|
||||
let appMeta = this.get('sessionService.appMeta');
|
||||
let url = appMeta.getUrl(`documents?folder=${folderId}`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents?folder=${folderId}`, {
|
||||
method: "GET"
|
||||
}).then((response) => {
|
||||
let documents = Ember.ArrayProxy.create({
|
||||
|
@ -50,9 +45,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// getDocumentsByTag returns all documents for specified tag (not folder!).
|
||||
getAllByTag(tag) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`documents?filter=tag&tag=${tag}`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents?filter=tag&tag=${tag}`, {
|
||||
method: "GET"
|
||||
}).then((response) => {
|
||||
let documents = Ember.ArrayProxy.create({
|
||||
|
@ -71,16 +64,15 @@ export default Ember.Service.extend({
|
|||
// saveDocument updates an existing document record.
|
||||
save(doc) {
|
||||
let id = doc.get('id');
|
||||
let url = this.get('sessionService').appMeta.getUrl(`documents/${id}`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents/${id}`, {
|
||||
method: 'PUT',
|
||||
data: JSON.stringify(doc)
|
||||
});
|
||||
},
|
||||
|
||||
getBatchedPages: function(documentId, payload) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/batch");
|
||||
let url = `documents/${documentId}/pages/batch`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'POST',
|
||||
|
@ -95,7 +87,7 @@ export default Ember.Service.extend({
|
|||
},
|
||||
|
||||
changePageSequence: function(documentId, payload) {
|
||||
var url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/sequence");
|
||||
let url = `documents/${documentId}/pages/sequence`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
|
@ -104,7 +96,7 @@ export default Ember.Service.extend({
|
|||
},
|
||||
|
||||
changePageLevel(documentId, payload) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/level");
|
||||
let url = `documents/${documentId}/pages/level`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
|
@ -113,7 +105,7 @@ export default Ember.Service.extend({
|
|||
},
|
||||
|
||||
deleteDocument: function(documentId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId);
|
||||
let url = `documents/${documentId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'DELETE'
|
||||
|
@ -122,7 +114,7 @@ export default Ember.Service.extend({
|
|||
|
||||
updatePage: function(documentId, pageId, payload, skipRevision) {
|
||||
var revision = skipRevision ? "?r=true" : "?r=false";
|
||||
let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + revision);
|
||||
let url = `documents/${documentId}/pages/${pageId}${revision}`
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'PUT',
|
||||
|
@ -133,7 +125,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// addPage inserts new page to an existing document.
|
||||
addPage: function(documentId, payload) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages");
|
||||
let url = `documents/${documentId}/pages`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
|
@ -143,7 +135,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// Nukes multiple pages from the document.
|
||||
deletePages: function(documentId, pageId, payload) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId);
|
||||
let url = `documents/${documentId}/pages/${pageId}`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
|
@ -153,7 +145,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// Nukes a single page from the document.
|
||||
deletePage: function(documentId, pageId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId);
|
||||
let url = `documents/${documentId}/pages/${pageId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'DELETE'
|
||||
|
@ -161,7 +153,7 @@ export default Ember.Service.extend({
|
|||
},
|
||||
|
||||
getPageRevisions(documentId, pageId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions");
|
||||
let url = `documents/${documentId}/pages/${pageId}/revisions`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "GET"
|
||||
|
@ -169,7 +161,7 @@ export default Ember.Service.extend({
|
|||
},
|
||||
|
||||
getPageRevisionDiff(documentId, pageId, revisionId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions/" + revisionId);
|
||||
let url = `documents/${documentId}/pages/${pageId}/revisions/${revisionId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "GET",
|
||||
|
@ -178,7 +170,7 @@ export default Ember.Service.extend({
|
|||
},
|
||||
|
||||
rollbackPage(documentId, pageId, revisionId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions/" + revisionId);
|
||||
let url = `documents/${documentId}/pages/${pageId}/revisions/${revisionId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "POST"
|
||||
|
@ -187,18 +179,16 @@ export default Ember.Service.extend({
|
|||
|
||||
// document meta referes to number of views, edits, approvals, etc.
|
||||
getMeta(documentId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/meta`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents/${documentId}/meta`, {
|
||||
method: "GET"
|
||||
});
|
||||
},
|
||||
|
||||
// Returns all pages without the content
|
||||
getTableOfContents(documentId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages?content=0`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents/${documentId}/pages?content=0`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
|
@ -212,9 +202,8 @@ export default Ember.Service.extend({
|
|||
|
||||
// Returns all document pages with content
|
||||
getPages(documentId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents/${documentId}/pages`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let pages = [];
|
||||
|
@ -229,9 +218,8 @@ export default Ember.Service.extend({
|
|||
|
||||
// Returns document page with content
|
||||
getPage(documentId, pageId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages/${pageId}`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents/${documentId}/pages/${pageId}`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let page = models.PageModel.create(response);
|
||||
|
@ -241,9 +229,8 @@ export default Ember.Service.extend({
|
|||
|
||||
// Returns document page meta object
|
||||
getPageMeta(documentId, pageId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages/${pageId}/meta`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents/${documentId}/pages/${pageId}/meta`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let meta = models.PageMetaModel.create(response);
|
||||
|
@ -253,9 +240,8 @@ export default Ember.Service.extend({
|
|||
|
||||
// document attachments without the actual content
|
||||
getAttachments(documentId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/attachments`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents/${documentId}/attachments`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
|
@ -268,9 +254,8 @@ export default Ember.Service.extend({
|
|||
|
||||
// nuke an attachment
|
||||
deleteAttachment(documentId, attachmentId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/attachments/${attachmentId}`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`documents/${documentId}/attachments/${attachmentId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
},
|
||||
|
|
|
@ -13,9 +13,15 @@ import Ember from 'ember';
|
|||
import models from '../utils/model';
|
||||
import BaseService from '../services/base';
|
||||
|
||||
const {
|
||||
get
|
||||
} = Ember;
|
||||
|
||||
export default BaseService.extend({
|
||||
sessionService: Ember.inject.service('session'),
|
||||
ajax: Ember.inject.service(),
|
||||
localStorage: Ember.inject.service(),
|
||||
|
||||
|
||||
// selected folder
|
||||
currentFolder: null,
|
||||
|
@ -23,10 +29,8 @@ export default BaseService.extend({
|
|||
|
||||
// Add a new folder.
|
||||
add(folder) {
|
||||
let appMeta = this.get('sessionService.appMeta');
|
||||
let url = appMeta.getUrl(`folders`);
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
return this.get('ajax').post(`folders`, {
|
||||
contentType: 'json',
|
||||
data: JSON.stringify(folder)
|
||||
}).then((folder)=>{
|
||||
|
@ -37,10 +41,8 @@ export default BaseService.extend({
|
|||
|
||||
// Returns folder model for specified folder id.
|
||||
getFolder(id) {
|
||||
let appMeta = this.get('sessionService.appMeta');
|
||||
let url = appMeta.getUrl(`folders/${id}`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`folders/${id}`, {
|
||||
method: 'GET'
|
||||
}).then((response)=>{
|
||||
let folder = models.FolderModel.create(response);
|
||||
|
@ -64,9 +66,8 @@ export default BaseService.extend({
|
|||
// Updates an existing folder record.
|
||||
save(folder) {
|
||||
let id = folder.get('id');
|
||||
let url = this.get('sessionService').appMeta.getUrl(`folders/${id}`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`folders/${id}`, {
|
||||
method: 'PUT',
|
||||
contentType: 'json',
|
||||
data: JSON.stringify(folder)
|
||||
|
@ -74,7 +75,7 @@ export default BaseService.extend({
|
|||
},
|
||||
|
||||
remove: function(folderId, moveToId) {
|
||||
var url = this.get('sessionService').appMeta.getUrl('folders/' + folderId + "/move/" + moveToId);
|
||||
let url = `folders/${folderId}/move/${moveToId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'DELETE'
|
||||
|
@ -82,7 +83,7 @@ export default BaseService.extend({
|
|||
},
|
||||
|
||||
onboard: function(folderId, payload) {
|
||||
var url = this.get('sessionService').appMeta.getUrl('public/share/' + folderId);
|
||||
let url = `public/share/${folderId}`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
contentType: "application/json",
|
||||
|
@ -92,9 +93,7 @@ export default BaseService.extend({
|
|||
|
||||
// getProtectedFolderInfo returns non-private folders and who has access to them.
|
||||
getProtectedFolderInfo: function() {
|
||||
var url = this.get('sessionService').appMeta.getUrl('folders?filter=viewers');
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`folders?filter=viewers`, {
|
||||
method: "GET"
|
||||
}).then((response)=>{
|
||||
let data = [];
|
||||
|
@ -108,10 +107,8 @@ export default BaseService.extend({
|
|||
|
||||
// reloads and caches folders.
|
||||
reload() {
|
||||
let appMeta = this.get('sessionService.appMeta');
|
||||
let url = appMeta.getUrl(`folders`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`folders`, {
|
||||
method: "GET"
|
||||
}).then((response)=>{
|
||||
let data = [];
|
||||
|
@ -125,9 +122,8 @@ export default BaseService.extend({
|
|||
|
||||
// so who can see/edit this folder?
|
||||
getPermissions(folderId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`folders/${folderId}/permissions`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`folders/${folderId}/permissions`, {
|
||||
method: "GET"
|
||||
}).then((response)=>{
|
||||
let data = [];
|
||||
|
@ -141,9 +137,8 @@ export default BaseService.extend({
|
|||
|
||||
// persist folder permissions
|
||||
savePermissions(folderId, payload) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`folders/${folderId}/permissions`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`folders/${folderId}/permissions`, {
|
||||
method: 'PUT',
|
||||
contentType: 'json',
|
||||
data: JSON.stringify(payload)
|
||||
|
@ -152,9 +147,8 @@ export default BaseService.extend({
|
|||
|
||||
// share this folder with new users!
|
||||
share(folderId, invitation) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`folders/${folderId}/invitation`);
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
return this.get('ajax').post(`folders/${folderId}/invitation`, {
|
||||
contentType: 'json',
|
||||
data: JSON.stringify(invitation)
|
||||
});
|
||||
|
@ -167,15 +161,15 @@ export default BaseService.extend({
|
|||
}
|
||||
|
||||
this.set('currentFolder', folder);
|
||||
this.get('sessionService').storeSessionItem("folder", folder.get('id'));
|
||||
this.get('localStorage').storeSessionItem("folder", get(folder, 'id'));
|
||||
this.set('canEditCurrentFolder', false);
|
||||
|
||||
let userId = this.get('sessionService').user.get('id');
|
||||
let userId = this.get('sessionService.user.id');
|
||||
if (userId === "") {
|
||||
userId = "0";
|
||||
}
|
||||
|
||||
let url = this.get('sessionService').appMeta.getUrl('users/' + userId + "/permissions");
|
||||
let url = `users/${userId}/permissions`;
|
||||
|
||||
return this.get('ajax').request(url).then((folderPermissions) => {
|
||||
// safety check
|
||||
|
@ -206,7 +200,7 @@ export default BaseService.extend({
|
|||
}
|
||||
});
|
||||
Ember.run(() => {
|
||||
this.set('canEditCurrentFolder', canEdit && this.get('sessionService').authenticated);
|
||||
this.set('canEditCurrentFolder', canEdit && this.get('sessionService.authenticated'));
|
||||
});
|
||||
});
|
||||
},
|
||||
|
|
16
app/app/services/local-storage.js
Normal file
16
app/app/services/local-storage.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Service.extend({
|
||||
|
||||
storeSessionItem: function (key, data) {
|
||||
localStorage[key] = data;
|
||||
},
|
||||
|
||||
getSessionItem: function (key) {
|
||||
return localStorage[key];
|
||||
},
|
||||
|
||||
clearSessionItem: function (key) {
|
||||
delete localStorage[key];
|
||||
}
|
||||
});
|
|
@ -15,12 +15,11 @@ import models from '../utils/model';
|
|||
export default Ember.Service.extend({
|
||||
sessionService: Ember.inject.service('session'),
|
||||
ajax: Ember.inject.service(),
|
||||
appMeta: Ember.inject.service(),
|
||||
|
||||
// Returns attributes for specified org id.
|
||||
getOrg(id) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`organizations/${id}`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`organizations/${id}`, {
|
||||
method: 'GET'
|
||||
}).then((response) =>{
|
||||
let org = models.OrganizationModel.create(response);
|
||||
|
@ -31,13 +30,13 @@ export default Ember.Service.extend({
|
|||
// Updates an existing organization record.
|
||||
save(org) {
|
||||
let id = org.get('id');
|
||||
let url = this.get('sessionService').appMeta.getUrl(`organizations/${id}`);
|
||||
|
||||
// refresh on-screen data
|
||||
this.get('sessionService').get('appMeta').setSafe('message', org.message);
|
||||
this.get('sessionService').get('appMeta').setSafe('title', org.title);
|
||||
this.get('appMeta').setProperties({
|
||||
message: org.message,
|
||||
title: org.title
|
||||
});
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`organizations/${id}`, {
|
||||
method: 'PUT',
|
||||
data: JSON.stringify(org)
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// getUsers returns all users for organization.
|
||||
find(keywords) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("search?keywords=" + encodeURIComponent(keywords));
|
||||
let url = "search?keywords=" + encodeURIComponent(keywords);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "GET"
|
||||
|
|
|
@ -19,9 +19,7 @@ export default BaseService.extend({
|
|||
|
||||
// Returns all available sections.
|
||||
getAll() {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`sections`);
|
||||
|
||||
return this.get('ajax').request(url,{
|
||||
return this.get('ajax').request(`sections`,{
|
||||
method: 'GET'
|
||||
}).then((response)=>{
|
||||
let data = [];
|
||||
|
@ -38,8 +36,7 @@ export default BaseService.extend({
|
|||
fetch(page, method, data) {
|
||||
let documentId = page.get('documentId');
|
||||
let section = page.get('contentType');
|
||||
let endpoint = `sections?documentID=${documentId}§ion=${section}&method=${method}`;
|
||||
let url = this.get('sessionService').appMeta.getUrl(endpoint);
|
||||
let url = `sections?documentID=${documentId}§ion=${section}&method=${method}`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(data),
|
||||
|
@ -49,7 +46,7 @@ export default BaseService.extend({
|
|||
|
||||
// Did any dynamic sections change? Fetch and send up for rendering?
|
||||
refresh(documentId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`sections/refresh?documentID=${documentId}`);
|
||||
let url = `sections/refresh?documentID=${documentId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'GET'
|
||||
|
|
|
@ -10,189 +10,38 @@
|
|||
// https://documize.com
|
||||
|
||||
import Ember from 'ember';
|
||||
import encodingUtil from '../utils/encoding';
|
||||
import netUtil from '../utils/net';
|
||||
import models from '../utils/model';
|
||||
import SimpleAuthSession from 'ember-simple-auth/services/session';
|
||||
|
||||
export default Ember.Service.extend({
|
||||
ready: false,
|
||||
appMeta: null,
|
||||
isMac: false,
|
||||
isMobile: false,
|
||||
previousTransition: null,
|
||||
user: null,
|
||||
authenticated: false,
|
||||
folderPermissions: null,
|
||||
currentFolder: null,
|
||||
ajax: Ember.inject.service(),
|
||||
const {
|
||||
inject: { service },
|
||||
computed: { oneWay, or, notEmpty },
|
||||
computed
|
||||
} = Ember;
|
||||
|
||||
isAdmin: function() {
|
||||
if (this.authenticated && is.not.null(this.user) && this.user.id !== "") {
|
||||
return this.user.admin;
|
||||
}
|
||||
return false;
|
||||
}.property('user'),
|
||||
export default SimpleAuthSession.extend({
|
||||
ajax: service(),
|
||||
appMeta: service(),
|
||||
|
||||
isEditor: function() {
|
||||
if (this.authenticated && is.not.null(this.user) && this.user.id !== "") {
|
||||
return this.user.editor || this.user.admin;
|
||||
}
|
||||
return false;
|
||||
}.property('user'),
|
||||
isMac: false,
|
||||
isMobile: false,
|
||||
authenticated: notEmpty('user.id'),
|
||||
isAdmin: oneWay('user.admin'),
|
||||
isEditor: or('user.admin', 'user.editor'),
|
||||
|
||||
// Boot up
|
||||
init: function() {
|
||||
this.set('user', models.UserModel.create());
|
||||
this.appMeta = models.AppMeta.create();
|
||||
init: function () {
|
||||
this.set('isMac', is.mac());
|
||||
this.set('isMobile', is.mobile());
|
||||
},
|
||||
|
||||
this.set('isMac', is.mac());
|
||||
this.set('isMobile', is.mobile());
|
||||
},
|
||||
user: computed('isAuthenticated', 'session.content.authenticated.user', function () {
|
||||
if (this.get('isAuthenticated')) {
|
||||
let user = this.get('session.content.authenticated.user') || { id: '' };
|
||||
return models.UserModel.create(user);
|
||||
}
|
||||
|
||||
// Authentication
|
||||
login: function(credentials) {
|
||||
let url = this.appMeta.getUrl('public/authenticate');
|
||||
let domain = netUtil.getSubdomain();
|
||||
}),
|
||||
|
||||
this.clearSession();
|
||||
|
||||
if (is.empty(credentials.email) || is.empty(credentials.password)) {
|
||||
return Ember.RSVP.reject("invalid");
|
||||
}
|
||||
|
||||
var encoded = encodingUtil.Base64.encode(domain + ":" + credentials.email + ":" + credentials.password);
|
||||
var headers = {
|
||||
'Authorization': 'Basic ' + encoded
|
||||
};
|
||||
|
||||
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 in the form of 'domain:email:password'
|
||||
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);
|
||||
return response;
|
||||
});
|
||||
},
|
||||
|
||||
// Goodbye
|
||||
logout: function() {
|
||||
this.clearSession();
|
||||
},
|
||||
|
||||
// Session management
|
||||
setSession: function(token, user) {
|
||||
this.set('user', user);
|
||||
this.set('authenticated', true);
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
clearSession: function() {
|
||||
this.set('user', null);
|
||||
this.set('authenticated', false);
|
||||
localStorage.clear();
|
||||
},
|
||||
|
||||
storeSessionItem: function(key, data) {
|
||||
localStorage[key] = data;
|
||||
},
|
||||
|
||||
getSessionItem: function(key) {
|
||||
return localStorage[key];
|
||||
},
|
||||
|
||||
clearSessionItem: function(key) {
|
||||
delete localStorage[key];
|
||||
},
|
||||
|
||||
// Application boot process
|
||||
boot() {
|
||||
let self = this;
|
||||
let dbhash = "";
|
||||
|
||||
if (is.not.null(document.head.querySelector("[property=dbhash]"))) {
|
||||
dbhash = document.head.querySelector("[property=dbhash]").content;
|
||||
}
|
||||
|
||||
if (dbhash.length > 0 && dbhash !== "{{.DBhash}}") {
|
||||
self.get('appMeta').set('orgId', "response.orgId");
|
||||
self.get('appMeta').setSafe('title', "Documize Setup");
|
||||
self.get('appMeta').set('version', "response.version");
|
||||
self.get('appMeta').setSafe('message', "response.message");
|
||||
self.get('appMeta').set('allowAnonymousAccess', false);
|
||||
self.set('ready', true);
|
||||
return new Ember.RSVP.Promise(function(resolve) {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
if (this.get('ready')) {
|
||||
return new Ember.RSVP.Promise(function(resolve) {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
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 = this.get('appMeta').getUrl(`public/validate?token=${token}`);
|
||||
|
||||
return this.get('ajax').request(tokenCheckUrl, {
|
||||
method: 'GET',
|
||||
contentType: 'json'
|
||||
}).then((user) => {
|
||||
this.setSession(token, models.UserModel.create(user));
|
||||
this.set('ready', true);
|
||||
}).catch((reason) => {
|
||||
if (netUtil.isAjaxAccessError(reason)) {
|
||||
localStorage.clear();
|
||||
window.location.href = "/auth/login";
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
folderPermissions: null,
|
||||
currentFolder: null
|
||||
});
|
||||
|
|
|
@ -17,8 +17,7 @@ export default Ember.Service.extend({
|
|||
ajax: Ember.inject.service(),
|
||||
|
||||
importStockTemplate: function(folderId, templateId) {
|
||||
|
||||
let url = this.get('sessionService').appMeta.getUrl("templates/" + templateId + "/folder/" + folderId + "?type=stock");
|
||||
let url = `templates/${templateId}/folder/${folderId}?type=stock`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "POST"
|
||||
|
@ -26,7 +25,7 @@ export default Ember.Service.extend({
|
|||
},
|
||||
|
||||
importSavedTemplate: function(folderId, templateId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("templates/" + templateId + "/folder/" + folderId + "?type=saved");
|
||||
let url = `templates/${templateId}/folder/${folderId}?type=saved`;
|
||||
|
||||
return this.get('ajax').post(url).then((doc)=>{
|
||||
let docModel = models.DocumentModel.create(doc);
|
||||
|
@ -35,9 +34,7 @@ export default Ember.Service.extend({
|
|||
},
|
||||
|
||||
getSavedTemplates() {
|
||||
let url = this.get('sessionService').appMeta.getUrl("templates");
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`templates`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
if (is.not.array(response)) {
|
||||
|
@ -57,22 +54,19 @@ export default Ember.Service.extend({
|
|||
},
|
||||
|
||||
getStockTemplates() {
|
||||
let url = this.get('sessionService').appMeta.getUrl("templates/stock");
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`templates/stock`, {
|
||||
method: 'GET'
|
||||
});
|
||||
},
|
||||
|
||||
saveAsTemplate(documentId, name, excerpt) {
|
||||
let url = this.get('sessionService').appMeta.getUrl("templates");
|
||||
let payload = {
|
||||
DocumentID: documentId,
|
||||
Name: name,
|
||||
Excerpt: excerpt
|
||||
};
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`templates`, {
|
||||
method: 'POST',
|
||||
data: JSON.stringify(payload)
|
||||
}).then(() => {
|
||||
|
|
|
@ -18,9 +18,8 @@ export default Ember.Service.extend({
|
|||
|
||||
// Adds a new user.
|
||||
add(user) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`users`);
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
return this.get('ajax').request(`users`, {
|
||||
type: 'POST',
|
||||
data: JSON.stringify(user),
|
||||
contentType: 'json'
|
||||
|
@ -31,7 +30,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// Returns user model for specified user id.
|
||||
getUser(userId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`users/${userId}`);
|
||||
let url = `users/${userId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
type: 'GET'
|
||||
|
@ -42,9 +41,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// Returns all users for organization.
|
||||
getAll() {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`users`);
|
||||
|
||||
return this.get('ajax').request(url).then((response) => {
|
||||
return this.get('ajax').request(`users`).then((response) => {
|
||||
return response.map(function(obj){
|
||||
return models.UserModel.create(obj);
|
||||
});
|
||||
|
@ -53,7 +50,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// Returns all users that can see folder.
|
||||
getFolderUsers(folderId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`users/folder/${folderId}`);
|
||||
let url = `users/folder/${folderId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "GET"
|
||||
|
@ -70,7 +67,7 @@ export default Ember.Service.extend({
|
|||
// Updates an existing user record.
|
||||
save(user) {
|
||||
let userId = user.get('id');
|
||||
let url = this.get('sessionService').appMeta.getUrl(`users/${userId}`);
|
||||
let url = `users/${userId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
type: 'PUT',
|
||||
|
@ -81,7 +78,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// updatePassword changes the password for the specified user.
|
||||
updatePassword(userId, password) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`users/${userId}/password`);
|
||||
let url = `users/${userId}/password`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: password
|
||||
|
@ -90,7 +87,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// Removes the specified user.
|
||||
remove(userId) {
|
||||
let url = this.get('sessionService').appMeta.getUrl(`users/${userId}`);
|
||||
let url = `users/${userId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'DELETE'
|
||||
|
@ -99,7 +96,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// Request password reset.
|
||||
forgotPassword(email) {
|
||||
let url = this.get('sessionService').appMeta.getUrl('public/forgot');
|
||||
let url = `public/forgot`;
|
||||
|
||||
if (is.empty(email)) {
|
||||
return Ember.RSVP.reject("invalid");
|
||||
|
@ -118,7 +115,7 @@ export default Ember.Service.extend({
|
|||
|
||||
// Set new password.
|
||||
resetPassword(token, password) {
|
||||
var url = this.get('sessionService').appMeta.getUrl('public/reset/' + token);
|
||||
var url = `public/reset/${token}`;
|
||||
|
||||
if (is.empty(token) || is.empty(password)) {
|
||||
return Ember.RSVP.reject("invalid");
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
{{#each attachments key="id" as |a index|}}
|
||||
<li class="item">
|
||||
<img class="icon" src="assets/img/attachments/{{document/file-icon a.extension}}" />
|
||||
<a href="{{ session.appMeta.apiUrl }}api/public/attachments/{{ session.appMeta.orgId }}/{{ a.job }}/{{ a.fileId }}">
|
||||
<a href="{{ appMeta.apiUrl }}api/public/attachments/{{ appMeta.orgId }}/{{ a.job }}/{{ a.fileId }}">
|
||||
<span class="file">{{ a.filename }}</span>
|
||||
</a>
|
||||
{{#if isEditor}}
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
</div>
|
||||
{{else}}
|
||||
{{#link-to 'application' class='title'}}
|
||||
<div class="header-button" title=session.appMeta.title>
|
||||
<div class="header-button" title=appMeta.title>
|
||||
<i class="material-icons">apps</i>
|
||||
</div>
|
||||
{{/link-to}}
|
||||
{{/if}}
|
||||
{{#link-to 'application' class='title'}}
|
||||
{{session.appMeta.title}}
|
||||
{{appMeta.title}}
|
||||
{{/link-to}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -11,84 +11,90 @@
|
|||
|
||||
/* jshint node: true */
|
||||
|
||||
module.exports = function(environment) {
|
||||
module.exports = function (environment) {
|
||||
|
||||
var ENV = {
|
||||
modulePrefix: 'documize',
|
||||
podModulePrefix: 'documize/pods',
|
||||
locationType: 'auto',
|
||||
environment: environment,
|
||||
baseURL: '/',
|
||||
apiHost: '',
|
||||
apiNamespace: '',
|
||||
contentSecurityPolicyHeader: 'Content-Security-Policy-Report-Only',
|
||||
var ENV = {
|
||||
modulePrefix: 'documize',
|
||||
podModulePrefix: 'documize/pods',
|
||||
locationType: 'auto',
|
||||
environment: environment,
|
||||
baseURL: '/',
|
||||
apiHost: '',
|
||||
apiNamespace: '',
|
||||
contentSecurityPolicyHeader: 'Content-Security-Policy-Report-Only',
|
||||
|
||||
EmberENV: {
|
||||
FEATURES: {}
|
||||
},
|
||||
"ember-cli-mirage": {
|
||||
enabled: false
|
||||
},
|
||||
APP: {
|
||||
// Allows to disable audit service in tests
|
||||
auditEnabled: true,
|
||||
intercomKey: ""
|
||||
}
|
||||
};
|
||||
EmberENV: {
|
||||
FEATURES: {}
|
||||
},
|
||||
"ember-cli-mirage": {
|
||||
enabled: false
|
||||
},
|
||||
'ember-simple-auth': {
|
||||
authenticationRoute: 'auth.login',
|
||||
routeAfterAuthentication: 'folders.folder',
|
||||
routeIfAlreadyAuthenticated: 'folders.folder'
|
||||
},
|
||||
APP: {
|
||||
// Allows to disable audit service in tests
|
||||
auditEnabled: true,
|
||||
intercomKey: ""
|
||||
}
|
||||
};
|
||||
|
||||
if (environment === 'development') {
|
||||
ENV.APP.LOG_TRANSITIONS = true;
|
||||
ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
|
||||
ENV['ember-cli-mirage'] = {
|
||||
enabled: false
|
||||
};
|
||||
if (environment === 'development') {
|
||||
ENV.APP.LOG_TRANSITIONS = true;
|
||||
ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
|
||||
ENV['ember-cli-mirage'] = {
|
||||
enabled: false
|
||||
};
|
||||
|
||||
ENV.apiHost = "https://localhost:5001";
|
||||
}
|
||||
ENV.apiHost = "https://localhost:5001";
|
||||
ENV.apiNamespace = "api";
|
||||
}
|
||||
|
||||
if (environment === 'test') {
|
||||
ENV.APP.LOG_RESOLVER = false;
|
||||
ENV.APP.LOG_ACTIVE_GENERATION = false;
|
||||
ENV.APP.LOG_VIEW_LOOKUPS = false;
|
||||
// ENV.APP.LOG_TRANSITIONS = false;
|
||||
// ENV.APP.LOG_TRANSITIONS_INTERNAL = false;
|
||||
if (environment === 'test') {
|
||||
ENV.APP.LOG_RESOLVER = false;
|
||||
ENV.APP.LOG_ACTIVE_GENERATION = false;
|
||||
ENV.APP.LOG_VIEW_LOOKUPS = false;
|
||||
ENV.APP.LOG_TRANSITIONS = true;
|
||||
// ENV.APP.LOG_TRANSITIONS_INTERNAL = false;
|
||||
|
||||
ENV.baseURL = '/';
|
||||
ENV.locationType = 'none';
|
||||
ENV.APP.rootElement = '#ember-testing';
|
||||
ENV['ember-cli-mirage'] = {
|
||||
enabled: true
|
||||
};
|
||||
ENV.APP.auditEnabled = false;
|
||||
ENV.baseURL = '/';
|
||||
ENV.locationType = 'none';
|
||||
ENV.APP.rootElement = '#ember-testing';
|
||||
ENV['ember-cli-mirage'] = {
|
||||
enabled: true
|
||||
};
|
||||
ENV.APP.auditEnabled = false;
|
||||
|
||||
ENV.apiHost = "https://localhost:5001";
|
||||
}
|
||||
ENV.apiHost = "https://localhost:5001";
|
||||
}
|
||||
|
||||
if (environment === 'production') {
|
||||
ENV.APP.LOG_RESOLVER = false;
|
||||
ENV.APP.LOG_ACTIVE_GENERATION = false;
|
||||
ENV.APP.LOG_VIEW_LOOKUPS = false;
|
||||
ENV.APP.LOG_TRANSITIONS = false;
|
||||
ENV.APP.LOG_TRANSITIONS_INTERNAL = false;
|
||||
if (environment === 'production') {
|
||||
ENV.APP.LOG_RESOLVER = false;
|
||||
ENV.APP.LOG_ACTIVE_GENERATION = false;
|
||||
ENV.APP.LOG_VIEW_LOOKUPS = false;
|
||||
ENV.APP.LOG_TRANSITIONS = false;
|
||||
ENV.APP.LOG_TRANSITIONS_INTERNAL = false;
|
||||
|
||||
ENV.apiHost = "";
|
||||
}
|
||||
ENV.apiHost = "";
|
||||
}
|
||||
|
||||
process.argv.forEach(function(element) {
|
||||
if (element !== undefined) {
|
||||
if (element.startsWith("intercom=")) {
|
||||
element = element.replace("intercom=", "");
|
||||
ENV.APP.intercomKey = element;
|
||||
}
|
||||
if (element.startsWith("apiHost=")) {
|
||||
element = element.replace("apiHost=", "");
|
||||
ENV.apiHost = element;
|
||||
}
|
||||
}
|
||||
});
|
||||
process.argv.forEach(function (element) {
|
||||
if (element !== undefined) {
|
||||
if (element.startsWith("intercom=")) {
|
||||
element = element.replace("intercom=", "");
|
||||
ENV.APP.intercomKey = element;
|
||||
}
|
||||
if (element.startsWith("apiHost=")) {
|
||||
element = element.replace("apiHost=", "");
|
||||
ENV.apiHost = element;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ENV.apiNamespace = "api";
|
||||
ENV.contentSecurityPolicy = null;
|
||||
ENV.apiNamespace = "api";
|
||||
ENV.contentSecurityPolicy = null;
|
||||
|
||||
return ENV;
|
||||
};
|
||||
return ENV;
|
||||
};
|
||||
|
|
|
@ -1,421 +1,448 @@
|
|||
export default function() {
|
||||
import Mirage from 'ember-cli-mirage';
|
||||
|
||||
this.passthrough('https://widget.intercom.io/widget/%7Bapp_id%7D');
|
||||
this.urlPrefix = 'https://localhost:5001'; // make this `http://localhost:8080`, for example, if your API is on a different server
|
||||
this.namespace = 'api'; // make this `api`, for example, if your API is namespaced
|
||||
// this.timing = 400; // delay for each request, automatically set to 0 during testing
|
||||
export default function () {
|
||||
|
||||
this.get('/public/meta', function(schema) {
|
||||
return schema.db.meta[0];
|
||||
});
|
||||
this.passthrough('https://widget.intercom.io/widget/%7Bapp_id%7D');
|
||||
this.urlPrefix = 'https://localhost:5001'; // make this `http://localhost:8080`, for example, if your API is on a different server
|
||||
this.namespace = 'api'; // make this `api`, for example, if your API is namespaced
|
||||
// this.timing = 400; // delay for each request, automatically set to 0 during testing
|
||||
|
||||
this.get('/public/validate', function(schema, request) {
|
||||
let serverToken = request.queryParams.token;
|
||||
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0";
|
||||
this.logging = true;
|
||||
|
||||
if (token = serverToken) {
|
||||
return {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
};
|
||||
}
|
||||
});
|
||||
this.get('/public/meta', function (schema) {
|
||||
return schema.db.meta[0];
|
||||
});
|
||||
|
||||
this.get('/users/0/permissions', function() {
|
||||
return [{
|
||||
"folderId": "VzMygEw_3WrtFzto",
|
||||
"userId": "",
|
||||
"canView": true,
|
||||
"canEdit": false
|
||||
}];
|
||||
});
|
||||
this.get('/public/validate', function (schema, request) {
|
||||
let serverToken = request.queryParams.token;
|
||||
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0";
|
||||
|
||||
this.get('/templates', function() {
|
||||
return [];
|
||||
});
|
||||
if (token = serverToken) {
|
||||
return {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
this.get('/documents', function(schema, request) {
|
||||
let folder_id = request.queryParams.folder;
|
||||
this.get('/users/0/permissions', function () {
|
||||
return [{
|
||||
"folderId": "VzMygEw_3WrtFzto",
|
||||
"userId": "",
|
||||
"canView": true,
|
||||
"canEdit": false
|
||||
}];
|
||||
});
|
||||
|
||||
if (folder_id = "VzMuyEw_3WqiafcG") {
|
||||
return [{
|
||||
"id": "VzMwX0w_3WrtFztd",
|
||||
"created": "2016-05-11T13:15:11Z",
|
||||
"revised": "2016-05-11T13:22:16Z",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"folderId": "VzMuyEw_3WqiafcG",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"job": "",
|
||||
"location": "template-0",
|
||||
"name": "Empty Document",
|
||||
"excerpt": "My test document",
|
||||
"tags": "",
|
||||
"template": false
|
||||
}, {
|
||||
"id": "VzMvJEw_3WqiafcI",
|
||||
"created": "2016-05-11T13:09:56Z",
|
||||
"revised": "2016-05-11T13:09:56Z",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"folderId": "VzMuyEw_3WqiafcG",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"job": "0bf9b076-cb74-4e8e-75be-8ee2d24a8171",
|
||||
"location": "/var/folders/d6/kr81d2fs5bsbm8rz2p092fy80000gn/T/documize/_uploads/0bf9b076-cb74-4e8e-75be-8ee2d24a8171/README.md",
|
||||
"name": "README",
|
||||
"excerpt": "To Document/ Instructions. GO. go- bindata- assetsfs. SSL.",
|
||||
"tags": "",
|
||||
"template": false
|
||||
}];
|
||||
} else if (folder_id = "VzMygEw_3WrtFzto") {
|
||||
return {
|
||||
"id": "VzMygEw_3WrtFzto",
|
||||
"created": "2016-05-11T13:24:17Z",
|
||||
"revised": "2016-05-11T13:25:51Z",
|
||||
"name": "Test",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"folderType": 1
|
||||
};
|
||||
} else if (folder_id = 'V0Vy5Uw_3QeDAMW9'){
|
||||
return null;
|
||||
}
|
||||
});
|
||||
this.get('/templates', function () {
|
||||
return [];
|
||||
});
|
||||
|
||||
this.get('/folders', function(schema) {
|
||||
return schema.db.folders;
|
||||
});
|
||||
this.get('/documents', function (schema, request) {
|
||||
let folder_id = request.queryParams.folder;
|
||||
|
||||
this.post('/folders', function(schema, request) {
|
||||
var name = JSON.parse(request.requestBody).name;
|
||||
let newFolder = {
|
||||
"id":"V0Vy5Uw_3QeDAMW9",
|
||||
"created":"2016-05-25T09:39:49Z",
|
||||
"revised":"2016-05-25T09:39:49Z",
|
||||
"name":name,
|
||||
"orgId":"VzMuyEw_3WqiafcD",
|
||||
"userId":"VzMuyEw_3WqiafcE",
|
||||
"folderType":2
|
||||
};
|
||||
if (folder_id = "VzMuyEw_3WqiafcG") {
|
||||
return [{
|
||||
"id": "VzMwX0w_3WrtFztd",
|
||||
"created": "2016-05-11T13:15:11Z",
|
||||
"revised": "2016-05-11T13:22:16Z",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"folderId": "VzMuyEw_3WqiafcG",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"job": "",
|
||||
"location": "template-0",
|
||||
"name": "Empty Document",
|
||||
"excerpt": "My test document",
|
||||
"tags": "",
|
||||
"template": false
|
||||
}, {
|
||||
"id": "VzMvJEw_3WqiafcI",
|
||||
"created": "2016-05-11T13:09:56Z",
|
||||
"revised": "2016-05-11T13:09:56Z",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"folderId": "VzMuyEw_3WqiafcG",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"job": "0bf9b076-cb74-4e8e-75be-8ee2d24a8171",
|
||||
"location": "/var/folders/d6/kr81d2fs5bsbm8rz2p092fy80000gn/T/documize/_uploads/0bf9b076-cb74-4e8e-75be-8ee2d24a8171/README.md",
|
||||
"name": "README",
|
||||
"excerpt": "To Document/ Instructions. GO. go- bindata- assetsfs. SSL.",
|
||||
"tags": "",
|
||||
"template": false
|
||||
}];
|
||||
} else if (folder_id = "VzMygEw_3WrtFzto") {
|
||||
return {
|
||||
"id": "VzMygEw_3WrtFzto",
|
||||
"created": "2016-05-11T13:24:17Z",
|
||||
"revised": "2016-05-11T13:25:51Z",
|
||||
"name": "Test",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"folderType": 1
|
||||
};
|
||||
} else if (folder_id = 'V0Vy5Uw_3QeDAMW9') {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
let folder = schema.db.folders.insert(newFolder);
|
||||
return folder;
|
||||
});
|
||||
this.get('/folders', function (schema) {
|
||||
return schema.db.folders;
|
||||
});
|
||||
|
||||
this.post('/public/authenticate', () => {
|
||||
return {
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
|
||||
"user": {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
}
|
||||
};
|
||||
});
|
||||
this.post('/folders', function (schema, request) {
|
||||
var name = JSON.parse(request.requestBody).name;
|
||||
let newFolder = {
|
||||
"id": "V0Vy5Uw_3QeDAMW9",
|
||||
"created": "2016-05-25T09:39:49Z",
|
||||
"revised": "2016-05-25T09:39:49Z",
|
||||
"name": name,
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"folderType": 2
|
||||
};
|
||||
|
||||
this.get('/users/VzMuyEw_3WqiafcE/permissions', (schema) => {
|
||||
return schema.db.permissions;
|
||||
});
|
||||
let folder = schema.db.folders.insert(newFolder);
|
||||
return folder;
|
||||
});
|
||||
|
||||
this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => {
|
||||
return [
|
||||
{
|
||||
"folderId":"VzMuyEw_3WqiafcG",
|
||||
"userId":"VzMuyEw_3WqiafcE",
|
||||
"canView":true,
|
||||
"canEdit":true
|
||||
}
|
||||
];
|
||||
});
|
||||
this.post('/public/authenticate', (schema, request) => {
|
||||
let authorization = request.requestHeaders.Authorization;
|
||||
let expectedAuthorization = "Basic OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw==";
|
||||
|
||||
this.put('/folders/VzMygEw_3WrtFzto/permissions', () => {
|
||||
return [
|
||||
{
|
||||
"orgId":"VzMuyEw_3WqiafcD",
|
||||
"folderId":"VzMygEw_3WrtFzto",
|
||||
"userId":"",
|
||||
"canEdit":true,
|
||||
"canView":true
|
||||
},{
|
||||
"orgId":"VzMuyEw_3WqiafcD",
|
||||
"folderId":"VzMygEw_3WrtFzto",
|
||||
"userId":"VzMyp0w_3WrtFztq",
|
||||
"canEdit":false,
|
||||
"canView":false
|
||||
},{
|
||||
"orgId":"",
|
||||
"folderId":"VzMygEw_3WrtFzto",
|
||||
"userId":"VzMuyEw_3WqiafcE",
|
||||
"canEdit":true,
|
||||
"canView":true
|
||||
}
|
||||
];
|
||||
});
|
||||
if (expectedAuthorization == authorization) {
|
||||
console.log("SSO login success");
|
||||
return {
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
|
||||
"user": {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.get('/folders/VzMygEw_3WrtFzto/permissions', () => {
|
||||
return [
|
||||
{
|
||||
"folderId":"VzMygEw_3WrtFzto",
|
||||
"userId":"VzMuyEw_3WqiafcE",
|
||||
"canView":true,
|
||||
"canEdit":true
|
||||
}
|
||||
];
|
||||
});
|
||||
if (expectedAuthorization != authorization) {
|
||||
return new Mirage.Response(401, { 'Content-Type': 'application/json' }, { message: 'Bad Request' });
|
||||
}
|
||||
|
||||
this.put('/folders/:id', (schema, request) => {
|
||||
let id = request.params.id;
|
||||
let attrs = JSON.parse(request.requestBody);
|
||||
let folder = schema.db.folders.update(id, attrs);
|
||||
return folder;
|
||||
});
|
||||
return {
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
|
||||
"user": {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
||||
this.put('/folders/V0Vy5Uw_3QeDAMW9', () => {
|
||||
return {
|
||||
"id":"V0Vy5Uw_3QeDAMW9",
|
||||
"created":"2016-05-25T09:39:49Z",
|
||||
"revised":"2016-05-25T09:39:49Z",
|
||||
"name":"Test Folder",
|
||||
"orgId":"VzMuyEw_3WqiafcD",
|
||||
"userId":"VzMuyEw_3WqiafcE",
|
||||
"folderType":2
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
this.get('folders/:id', (schema, request) => {
|
||||
let id = request.params.id;
|
||||
return schema.db.folders.find(id);
|
||||
});
|
||||
this.get('/users/VzMuyEw_3WqiafcE/permissions', (schema) => {
|
||||
return schema.db.permissions;
|
||||
});
|
||||
|
||||
this.get('/organizations/VzMuyEw_3WqiafcD', () => {
|
||||
return {
|
||||
"id": "VzMuyEw_3WqiafcD",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-23T11:23:20Z",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"url": "",
|
||||
"domain": "",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"allowAnonymousAccess": false
|
||||
};
|
||||
});
|
||||
this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => {
|
||||
return [{
|
||||
"folderId": "VzMuyEw_3WqiafcG",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"canView": true,
|
||||
"canEdit": true
|
||||
}];
|
||||
});
|
||||
|
||||
this.put('/organizations/VzMuyEw_3WqiafcD', (schema, request) => {
|
||||
let title = JSON.parse(request.requestBody).title;
|
||||
let message = JSON.parse(request.requestBody).title;
|
||||
let allowAnonymousAccess = JSON.parse(request.requestBody).allowAnonymousAccess;
|
||||
this.put('/folders/VzMygEw_3WrtFzto/permissions', () => {
|
||||
return [{
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"folderId": "VzMygEw_3WrtFzto",
|
||||
"userId": "",
|
||||
"canEdit": true,
|
||||
"canView": true
|
||||
}, {
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"folderId": "VzMygEw_3WrtFzto",
|
||||
"userId": "VzMyp0w_3WrtFztq",
|
||||
"canEdit": false,
|
||||
"canView": false
|
||||
}, {
|
||||
"orgId": "",
|
||||
"folderId": "VzMygEw_3WrtFzto",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"canEdit": true,
|
||||
"canView": true
|
||||
}];
|
||||
});
|
||||
|
||||
return {
|
||||
"id": "VzMuyEw_3WqiafcD",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-23T11:23:20Z",
|
||||
"title": `${title}`,
|
||||
"message": `${message}`,
|
||||
"url": "",
|
||||
"domain": "",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"allowAnonymousAccess": `${allowAnonymousAccess}`
|
||||
};
|
||||
});
|
||||
this.get('/folders/VzMygEw_3WrtFzto/permissions', () => {
|
||||
return [{
|
||||
"folderId": "VzMygEw_3WrtFzto",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"canView": true,
|
||||
"canEdit": true
|
||||
}];
|
||||
});
|
||||
|
||||
this.get('/users', () => {
|
||||
return [{
|
||||
"id": "VzMyp0w_3WrtFztq",
|
||||
"created": "2016-05-11T13:24:55Z",
|
||||
"revised": "2016-05-11T13:33:47Z",
|
||||
"firstname": "Len",
|
||||
"lastname": "Random",
|
||||
"email": "zinyando@gmail.com",
|
||||
"initials": "LR",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": false,
|
||||
"accounts": [{
|
||||
"id": "VzMyp0w_3WrtFztr",
|
||||
"created": "2016-05-11T13:24:55Z",
|
||||
"revised": "2016-05-11T13:24:55Z",
|
||||
"admin": false,
|
||||
"editor": true,
|
||||
"userId": "VzMyp0w_3WrtFztq",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
}, {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
}];
|
||||
});
|
||||
this.put('/folders/:id', (schema, request) => {
|
||||
let id = request.params.id;
|
||||
let attrs = JSON.parse(request.requestBody);
|
||||
let folder = schema.db.folders.update(id, attrs);
|
||||
return folder;
|
||||
});
|
||||
|
||||
this.post('/users', (schema, request) => {
|
||||
let firstname = JSON.parse(request.requestBody).firstname;
|
||||
let lastname = JSON.parse(request.requestBody).lastname;
|
||||
let email = JSON.parse(request.requestBody).email;
|
||||
this.put('/folders/V0Vy5Uw_3QeDAMW9', () => {
|
||||
return {
|
||||
"id": "V0Vy5Uw_3QeDAMW9",
|
||||
"created": "2016-05-25T09:39:49Z",
|
||||
"revised": "2016-05-25T09:39:49Z",
|
||||
"name": "Test Folder",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"folderType": 2
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
"id":"V0RmtUw_3QeDAMW7",
|
||||
"created":"2016-05-24T14:35:33Z",
|
||||
"revised":"2016-05-24T14:35:33Z",
|
||||
"firstname":`${firstname}`,
|
||||
"lastname":`${lastname}`,
|
||||
"email":`${email}`,
|
||||
"initials":"TU",
|
||||
"active":true,
|
||||
"editor":true,
|
||||
"admin":false,
|
||||
"accounts":[{
|
||||
"id":"V0RmtUw_3QeDAMW8",
|
||||
"created":"2016-05-24T14:35:34Z",
|
||||
"revised":"2016-05-24T14:35:34Z",
|
||||
"admin":false,
|
||||
"editor":true,
|
||||
"userId":"V0RmtUw_3QeDAMW7",
|
||||
"orgId":"VzMuyEw_3WqiafcD",
|
||||
"company":"EmberSherpa",
|
||||
"title":"EmberSherpa",
|
||||
"message":"This Documize instance contains all our team documentation",
|
||||
"domain":""
|
||||
}
|
||||
]};
|
||||
});
|
||||
this.get('folders/:id', (schema, request) => {
|
||||
let id = request.params.id;
|
||||
return schema.db.folders.find(id);
|
||||
});
|
||||
|
||||
this.get('/users/VzMuyEw_3WqiafcE', () => {
|
||||
this.get('/organizations/VzMuyEw_3WqiafcD', () => {
|
||||
return {
|
||||
"id": "VzMuyEw_3WqiafcD",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-23T11:23:20Z",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"url": "",
|
||||
"domain": "",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"allowAnonymousAccess": false
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
"id":"VzMuyEw_3WqiafcE",
|
||||
"created":"2016-05-11T15:08:24Z",
|
||||
"revised":"2016-05-11T15:08:24Z",
|
||||
"firstname":"Lennex",
|
||||
"lastname":"Zinyando",
|
||||
"email":"brizdigital@gmail.com",
|
||||
"initials":"LZ",
|
||||
"active":true,
|
||||
"editor":true,
|
||||
"admin":true,
|
||||
"accounts":[{
|
||||
"id":"VzMuyEw_3WqiafcF",
|
||||
"created":"2016-05-11T15:08:24Z",
|
||||
"revised":"2016-05-11T15:08:24Z",
|
||||
"admin":true,
|
||||
"editor":true,
|
||||
"userId":"VzMuyEw_3WqiafcE",
|
||||
"orgId":"VzMuyEw_3WqiafcD",
|
||||
"company":"EmberSherpa",
|
||||
"title":"EmberSherpa",
|
||||
"message":"This Documize instance contains all our team documentation",
|
||||
"domain":""
|
||||
}
|
||||
]};
|
||||
});
|
||||
this.put('/organizations/VzMuyEw_3WqiafcD', (schema, request) => {
|
||||
let title = JSON.parse(request.requestBody).title;
|
||||
let message = JSON.parse(request.requestBody).title;
|
||||
let allowAnonymousAccess = JSON.parse(request.requestBody).allowAnonymousAccess;
|
||||
|
||||
this.put('/users/VzMuyEw_3WqiafcE', (schema, request) => {
|
||||
let firstname = JSON.parse(request.requestBody).firstname;
|
||||
let lastname = JSON.parse(request.requestBody).lastname;
|
||||
let email = JSON.parse(request.requestBody).email;
|
||||
return {
|
||||
"id": "VzMuyEw_3WqiafcD",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-23T11:23:20Z",
|
||||
"title": `${title}`,
|
||||
"message": `${message}`,
|
||||
"url": "",
|
||||
"domain": "",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"allowAnonymousAccess": `${allowAnonymousAccess}`
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
"id":"VzMuyEw_3WqiafcE",
|
||||
"created":"2016-05-11T15:08:24Z",
|
||||
"revised":"2016-05-11T15:08:24Z",
|
||||
"firstname":`${firstname}`,
|
||||
"lastname":`${lastname}`,
|
||||
"email":`${email}`,
|
||||
"initials":"LZ",
|
||||
"active":true,
|
||||
"editor":true,
|
||||
"admin":true,
|
||||
"accounts":[{
|
||||
"id":"VzMuyEw_3WqiafcF",
|
||||
"created":"2016-05-11T15:08:24Z",
|
||||
"revised":"2016-05-11T15:08:24Z",
|
||||
"admin":true,
|
||||
"editor":true,
|
||||
"userId":"VzMuyEw_3WqiafcE",
|
||||
"orgId":"VzMuyEw_3WqiafcD",
|
||||
"company":"EmberSherpa",
|
||||
"title":"EmberSherpa",
|
||||
"message":"This Documize instance contains all our team documentation",
|
||||
"domain":""
|
||||
}
|
||||
]};
|
||||
});
|
||||
this.get('/users', () => {
|
||||
return [{
|
||||
"id": "VzMyp0w_3WrtFztq",
|
||||
"created": "2016-05-11T13:24:55Z",
|
||||
"revised": "2016-05-11T13:33:47Z",
|
||||
"firstname": "Len",
|
||||
"lastname": "Random",
|
||||
"email": "zinyando@gmail.com",
|
||||
"initials": "LR",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": false,
|
||||
"accounts": [{
|
||||
"id": "VzMyp0w_3WrtFztr",
|
||||
"created": "2016-05-11T13:24:55Z",
|
||||
"revised": "2016-05-11T13:24:55Z",
|
||||
"admin": false,
|
||||
"editor": true,
|
||||
"userId": "VzMyp0w_3WrtFztq",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
}, {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
}];
|
||||
});
|
||||
|
||||
this.post('/folders/VzMuyEw_3WqiafcG/invitation', () => {
|
||||
return {};
|
||||
});
|
||||
this.post('/users', (schema, request) => {
|
||||
let firstname = JSON.parse(request.requestBody).firstname;
|
||||
let lastname = JSON.parse(request.requestBody).lastname;
|
||||
let email = JSON.parse(request.requestBody).email;
|
||||
|
||||
/**
|
||||
very helpful for debugging
|
||||
*/
|
||||
this.handledRequest = function(verb, path) {
|
||||
console.log(`👊${verb} ${path}`);
|
||||
};
|
||||
return {
|
||||
"id": "V0RmtUw_3QeDAMW7",
|
||||
"created": "2016-05-24T14:35:33Z",
|
||||
"revised": "2016-05-24T14:35:33Z",
|
||||
"firstname": `${firstname}`,
|
||||
"lastname": `${lastname}`,
|
||||
"email": `${email}`,
|
||||
"initials": "TU",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": false,
|
||||
"accounts": [{
|
||||
"id": "V0RmtUw_3QeDAMW8",
|
||||
"created": "2016-05-24T14:35:34Z",
|
||||
"revised": "2016-05-24T14:35:34Z",
|
||||
"admin": false,
|
||||
"editor": true,
|
||||
"userId": "V0RmtUw_3QeDAMW7",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
};
|
||||
});
|
||||
|
||||
this.unhandledRequest = function(verb, path) {
|
||||
console.log(`🔥${verb} ${path}`);
|
||||
};
|
||||
this.get('/users/VzMuyEw_3WqiafcE', () => {
|
||||
|
||||
return {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
};
|
||||
});
|
||||
|
||||
this.put('/users/VzMuyEw_3WqiafcE', (schema, request) => {
|
||||
let firstname = JSON.parse(request.requestBody).firstname;
|
||||
let lastname = JSON.parse(request.requestBody).lastname;
|
||||
let email = JSON.parse(request.requestBody).email;
|
||||
|
||||
return {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": `${firstname}`,
|
||||
"lastname": `${lastname}`,
|
||||
"email": `${email}`,
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
};
|
||||
});
|
||||
|
||||
this.post('/folders/VzMuyEw_3WqiafcG/invitation', () => {
|
||||
return {};
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
"ember-export-application-global": "^1.0.5",
|
||||
"ember-load-initializers": "^0.5.1",
|
||||
"ember-resolver": "^2.0.3",
|
||||
"ember-simple-auth": "git+https://github.com/documize/ember-simple-auth.git#21e638f9e33267d8944835002ee96884d34d568a",
|
||||
"loader.js": "^4.0.1"
|
||||
},
|
||||
"ember-addon": {
|
||||
|
@ -46,4 +47,4 @@
|
|||
"lib/intercom"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
"waitToAppear",
|
||||
"waitToAppear",
|
||||
"stubUserNotification",
|
||||
"is"
|
||||
"is",
|
||||
"authenticateUser"
|
||||
],
|
||||
"node": false,
|
||||
"browser": false,
|
||||
|
|
|
@ -3,13 +3,12 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
|
|||
|
||||
moduleForAcceptance('Acceptance | Anon access disabled');
|
||||
|
||||
|
||||
test('visiting / when not authenticated and with { allowAnonymousAccess: false } takes user to login', function(assert) {
|
||||
test('visiting / when not authenticated and with { allowAnonymousAccess: false } takes user to login', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
visit('/');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/auth/login');
|
||||
findWithAssert('#authEmail');
|
||||
findWithAssert('#authPassword');
|
||||
|
|
|
@ -3,33 +3,32 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
|
|||
|
||||
moduleForAcceptance('Acceptance | Anon access enabled');
|
||||
|
||||
test('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function(assert) {
|
||||
server.create('meta', { allowAnonymousAccess: true });
|
||||
server.createList('folder', 2);
|
||||
visit('/');
|
||||
// return pauseTest();
|
||||
test('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: true });
|
||||
server.createList('folder', 2);
|
||||
visit('/');
|
||||
|
||||
andThen(function() {
|
||||
assert.equal(find('.login').length, 1, 'Login button is 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');
|
||||
});
|
||||
andThen(function () {
|
||||
assert.equal(find('.login').length, 1, 'Login button is 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');
|
||||
});
|
||||
});
|
||||
|
||||
test('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function(assert) {
|
||||
server.create('meta', { allowAnonymousAccess: true });
|
||||
server.createList('folder', 2);
|
||||
visit('/');
|
||||
test('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: true });
|
||||
server.createList('folder', 2);
|
||||
visit('/');
|
||||
|
||||
andThen(function() {
|
||||
assert.equal(find('.login').length, 1, 'Login button is displayed');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard displayed without being signed in');
|
||||
});
|
||||
andThen(function () {
|
||||
assert.equal(find('.login').length, 1, 'Login button is displayed');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard displayed without being signed in');
|
||||
});
|
||||
|
||||
userLogin();
|
||||
userLogin();
|
||||
|
||||
andThen(function() {
|
||||
assert.equal(find('.login').length, 0, 'Login button is not displayed');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard is displayed after user is signed in');
|
||||
});
|
||||
andThen(function () {
|
||||
assert.equal(find('.login').length, 0, 'Login button is not displayed');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard is displayed after user is signed in');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,28 +3,50 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
|
|||
|
||||
moduleForAcceptance('Acceptance | Authentication');
|
||||
|
||||
test('visiting /auth/login and logging in', function(assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
visit('/auth/login');
|
||||
test('visiting /auth/login and logging in', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
visit('/auth/login');
|
||||
|
||||
fillIn('#authEmail', 'brizdigital@gmail.com');
|
||||
fillIn('#authPassword', 'zinyando123');
|
||||
click('button');
|
||||
fillIn('#authEmail', 'brizdigital@gmail.com');
|
||||
fillIn('#authPassword', 'zinyando123');
|
||||
click('button');
|
||||
|
||||
andThen(function() {
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Login successfull');
|
||||
});
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Login successful');
|
||||
});
|
||||
});
|
||||
|
||||
test('logging out a user', function(assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
userLogin();
|
||||
test('logging out a user', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
userLogin();
|
||||
|
||||
visit('/auth/logout');
|
||||
visit('/auth/logout');
|
||||
|
||||
andThen(function() {
|
||||
assert.equal(currentURL(), '/auth/login', 'Login successfull');
|
||||
});
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/auth/login', 'Logging out successful');
|
||||
});
|
||||
});
|
||||
|
||||
test('successful sso login authenticates redirects to dashboard', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
|
||||
visit('/auth/sso/OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw==');
|
||||
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'SSO login successful');
|
||||
});
|
||||
});
|
||||
|
||||
test('sso login with bad token should redirect to login', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
|
||||
visit('/auth/sso/randomToken1234567890');
|
||||
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/auth/login', 'SSO login unsuccessful');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,188 +1,195 @@
|
|||
import { test } from 'qunit';
|
||||
import { test, skip } from 'qunit';
|
||||
import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
|
||||
|
||||
moduleForAcceptance('Acceptance | Documents space');
|
||||
|
||||
test('Adding a new folder space', function(assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
userLogin();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
skip('Adding a new folder space', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
authenticateUser();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
|
||||
andThen(function() {
|
||||
let personalSpaces = find('.section div:contains(PERSONAL)').length;
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
|
||||
assert.equal(personalSpaces, 1, '1 personal space is listed');
|
||||
});
|
||||
andThen(function () {
|
||||
let personalSpaces = find('.section div:contains(PERSONAL)').length;
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
|
||||
assert.equal(personalSpaces, 1, '1 personal space is listed');
|
||||
});
|
||||
|
||||
click('#add-folder-button');
|
||||
click('#add-folder-button');
|
||||
|
||||
fillIn('#new-folder-name', 'body', 'Test Folder');
|
||||
fillIn('#new-folder-name', 'body', 'Test Folder');
|
||||
|
||||
click('.actions div:contains(Add)', 'body');
|
||||
click('.actions div:contains(Add)', 'body');
|
||||
|
||||
andThen(function() {
|
||||
assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder');
|
||||
});
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder');
|
||||
});
|
||||
});
|
||||
|
||||
// test('Adding a document to a space', function(assert) {
|
||||
// server.create('meta', { allowAnonymousAccess: false });
|
||||
// server.createList('folder', 2);
|
||||
// server.createList('permission', 4);
|
||||
// userLogin();
|
||||
// visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
//
|
||||
// andThen(function() {
|
||||
//
|
||||
// let numberOfDocuments = find('.documents-list li').length;
|
||||
// assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
|
||||
// assert.equal(numberOfDocuments, 2, '2 documents listed');
|
||||
// });
|
||||
//
|
||||
// click('#start-document-button');
|
||||
// click('.actions div:contains(Add)', 'body');
|
||||
//
|
||||
// andThen(function() {
|
||||
// let numberOfDocuments = find('.documents-list li').length;
|
||||
// assert.equal(numberOfDocuments, 3, '3 documents listed');
|
||||
// assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
|
||||
// // return pauseTest();
|
||||
// });
|
||||
// });
|
||||
skip('Adding a document to a space', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
authenticateUser();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
|
||||
test('visiting space settings page', function(assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
userLogin();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
andThen(function () {
|
||||
|
||||
click('#folder-settings-button');
|
||||
let numberOfDocuments = find('.documents-list li').length;
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
|
||||
assert.equal(numberOfDocuments, 2, '2 documents listed');
|
||||
});
|
||||
|
||||
andThen(function() {
|
||||
checkForCommonAsserts();
|
||||
assert.equal(find('#folderName').val().trim(), 'My Project', 'Space name displayed in input box');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
});
|
||||
click('#start-document-button');
|
||||
click('.actions div:contains(Add)', 'body');
|
||||
|
||||
andThen(function () {
|
||||
let numberOfDocuments = find('.documents-list li').length;
|
||||
assert.equal(numberOfDocuments, 3, '3 documents listed');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
|
||||
});
|
||||
});
|
||||
|
||||
test('changing space name', function(assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
userLogin();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
test('visiting space settings page', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
authenticateUser();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
|
||||
fillIn('#folderName', 'Test Space');
|
||||
click('.button-blue');
|
||||
click('#folder-settings-button');
|
||||
|
||||
andThen(function() {
|
||||
let spaceName = find('.breadcrumb-menu .selected').text().trim();
|
||||
checkForCommonAsserts();
|
||||
assert.equal(spaceName, 'Test Space', 'Space name has been changed');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
});
|
||||
andThen(function () {
|
||||
checkForCommonAsserts();
|
||||
assert.equal(find('#folderName').val().trim(), 'My Project', 'Space name displayed in input box');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
});
|
||||
});
|
||||
|
||||
test('sharing a space', function(assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
userLogin();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
test('changing space name', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
authenticateUser();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
|
||||
click(('.sidebar-menu .options li:contains(Share)'));
|
||||
fillIn('#inviteEmail', 'share-test@gmail.com');
|
||||
click('.button-blue');
|
||||
click('#folder-settings-button');
|
||||
|
||||
andThen(function() {
|
||||
checkForCommonAsserts();
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
});
|
||||
fillIn('#folderName', 'Test Space');
|
||||
click('.button-blue');
|
||||
|
||||
andThen(function () {
|
||||
let spaceName = find('.info .title').text().trim();
|
||||
checkForCommonAsserts();
|
||||
assert.equal(spaceName, 'Test Space', 'Space name has been changed');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
});
|
||||
});
|
||||
|
||||
test('sharing a space', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
authenticateUser();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
|
||||
click('#folder-settings-button');
|
||||
|
||||
click(('.sidebar-menu .options li:contains(Share)'));
|
||||
fillIn('#inviteEmail', 'share-test@gmail.com');
|
||||
click('.button-blue');
|
||||
|
||||
andThen(function () {
|
||||
checkForCommonAsserts();
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
});
|
||||
});
|
||||
|
||||
// Test will pass after moving to factories
|
||||
test('changing space permissions', function(assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
userLogin();
|
||||
andThen(function() {
|
||||
let numberOfPublicFolders = find('.folders-list div:first .list a').length;
|
||||
assert.equal(numberOfPublicFolders, 1, '1 folder listed as public');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
|
||||
});
|
||||
test('changing space permissions', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
authenticateUser();
|
||||
|
||||
visit('/s/VzMygEw_3WrtFzto/test/settings');
|
||||
click(('.sidebar-menu .options li:contains(Permissions)'));
|
||||
visit('/s/VzMygEw_3WrtFzto/test');
|
||||
andThen(function () {
|
||||
let numberOfPublicFolders = find('.sidebar-menu .folders-list .section .list:first a').length;
|
||||
assert.equal(numberOfPublicFolders, 1, '1 folder listed as public');
|
||||
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test');
|
||||
});
|
||||
|
||||
click('tr:contains(Everyone) #canView-');
|
||||
click('tr:contains(Everyone) #canEdit-');
|
||||
click('.button-blue');
|
||||
click('#folder-settings-button');
|
||||
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
click('.sidebar-menu .options li:contains(Permissions)');
|
||||
|
||||
andThen(function() {
|
||||
let numberOfPublicFolders = find('.folders-list div:first .list a').length;
|
||||
assert.equal(numberOfPublicFolders, 2, '2 folder listed as public');
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
|
||||
});
|
||||
click('tr:contains(Everyone) #canView-');
|
||||
click('tr:contains(Everyone) #canEdit-');
|
||||
click('.button-blue');
|
||||
|
||||
visit('/s/VzMygEw_3WrtFzto/test');
|
||||
|
||||
andThen(function () {
|
||||
let numberOfPublicFolders = find('.folders-list div:contains(EVERYONE) .list a').length;
|
||||
assert.equal(numberOfPublicFolders, 2, '2 folder listed as public');
|
||||
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test');
|
||||
});
|
||||
});
|
||||
|
||||
test('deleting a space', function(assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
userLogin();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
test('deleting a space', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
authenticateUser();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
|
||||
click('.sidebar-menu .options li:contains(Delete)');
|
||||
click('#folder-settings-button');
|
||||
|
||||
andThen(function() {
|
||||
checkForCommonAsserts();
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
});
|
||||
click('.sidebar-menu .options li:contains(Delete)');
|
||||
|
||||
andThen(function () {
|
||||
checkForCommonAsserts();
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
|
||||
});
|
||||
});
|
||||
|
||||
// test('deleting a document', function(assert) {
|
||||
// server.create('meta', { allowAnonymousAccess: false });
|
||||
// server.createList('folder', 2);
|
||||
// server.createList('permission', 4);
|
||||
// userLogin();
|
||||
// visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
//
|
||||
// andThen(function() {
|
||||
// let deleteButton = find('#delete-documents-button');
|
||||
// let numberOfDocuments = find('.documents-list li');
|
||||
// assert.equal(numberOfDocuments.length, 2, '2 documents are displayed');
|
||||
// assert.equal(deleteButton.length, 0, 'Delete button not displayed');
|
||||
// });
|
||||
//
|
||||
// click('.documents-list li:first .checkbox');
|
||||
//
|
||||
// andThen(function() {
|
||||
// let deleteButton = find('#delete-documents-button');
|
||||
// assert.equal(deleteButton.length, 1, 'Delete button displayed after selecting document');
|
||||
// });
|
||||
//
|
||||
// click('#delete-documents-button');
|
||||
//
|
||||
// waitToAppear('.drop-content');
|
||||
// click('.actions div:contains(Delete)', 'body');
|
||||
//
|
||||
// andThen(function() {
|
||||
// let numberOfDocuments = find('.documents-list li');
|
||||
// assert.equal(numberOfDocuments.length, 1, '1 documents is displayed');
|
||||
// });
|
||||
// });
|
||||
skip('deleting a document', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
server.createList('folder', 2);
|
||||
server.createList('permission', 4);
|
||||
authenticateUser();
|
||||
visit('/s/VzMuyEw_3WqiafcG/my-project');
|
||||
|
||||
andThen(function () {
|
||||
let deleteButton = find('#delete-documents-button');
|
||||
let numberOfDocuments = find('.documents-list li');
|
||||
assert.equal(numberOfDocuments.length, 2, '2 documents are displayed');
|
||||
assert.equal(deleteButton.length, 0, 'Delete button not displayed');
|
||||
});
|
||||
|
||||
click('.documents-list li:first .checkbox');
|
||||
|
||||
andThen(function () {
|
||||
let deleteButton = find('#delete-documents-button');
|
||||
assert.equal(deleteButton.length, 1, 'Delete button displayed after selecting document');
|
||||
});
|
||||
|
||||
click('#delete-documents-button');
|
||||
|
||||
waitToAppear('.drop-content');
|
||||
click('.actions div:contains(Delete)', 'body');
|
||||
|
||||
andThen(function () {
|
||||
let numberOfDocuments = find('.documents-list li');
|
||||
assert.equal(numberOfDocuments.length, 1, '1 documents is displayed');
|
||||
});
|
||||
});
|
||||
|
||||
function checkForCommonAsserts() {
|
||||
findWithAssert('.sidebar-menu');
|
||||
findWithAssert('.options li:contains(General)');
|
||||
findWithAssert('.options li:contains(Share)');
|
||||
findWithAssert('.options li:contains(Permissions)');
|
||||
findWithAssert('.options li:contains(Delete)');
|
||||
findWithAssert('.sidebar-menu');
|
||||
findWithAssert('.options li:contains(General)');
|
||||
findWithAssert('.options li:contains(Share)');
|
||||
findWithAssert('.options li:contains(Permissions)');
|
||||
findWithAssert('.options li:contains(Delete)');
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
|
|||
|
||||
moduleForAcceptance('Acceptance | user profile');
|
||||
|
||||
test('visiting /profile', function(assert) {
|
||||
test('visiting /profile', function (assert) {
|
||||
server.createList('folder', 2);
|
||||
userLogin();
|
||||
authenticateUser();
|
||||
visit('/profile');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/profile');
|
||||
assert.equal(find('#firstname').val(), 'Lennex', 'Firstaname input displays correct value');
|
||||
assert.equal(find('#lastname').val(), 'Zinyando', 'Lastname input displays correct value');
|
||||
|
@ -16,14 +16,14 @@ test('visiting /profile', function(assert) {
|
|||
});
|
||||
});
|
||||
|
||||
test('changing user details and email ', function(assert) {
|
||||
test('changing user details and email ', function (assert) {
|
||||
server.createList('folder', 2);
|
||||
userLogin();
|
||||
authenticateUser();
|
||||
visit('/profile');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/profile');
|
||||
assert.equal(find('.name').text().trim(), 'Lennex Zinyando', 'Profile name displayed');
|
||||
assert.equal(find('.content .name').text().trim(), 'Lennex Zinyando', 'Profile name displayed');
|
||||
assert.equal(find('#firstname').val(), 'Lennex', 'Firstaname input displays correct value');
|
||||
assert.equal(find('#lastname').val(), 'Zinyando', 'Lastname input displays correct value');
|
||||
assert.equal(find('#email').val(), 'brizdigital@gmail.com', 'Email input displays correct value');
|
||||
|
@ -34,7 +34,7 @@ test('changing user details and email ', function(assert) {
|
|||
fillIn('#email', 'test.user@domain.com');
|
||||
click('.button-blue');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
|
||||
assert.equal(find('.content .name').text().trim(), 'Test User', 'Profile name displayed');
|
||||
});
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import { test} from 'qunit';
|
||||
import { test } from 'qunit';
|
||||
import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
|
||||
|
||||
moduleForAcceptance('Acceptance | User Settings');
|
||||
|
||||
test('visiting /settings/general', function(assert) {
|
||||
test('visiting /settings/general', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
userLogin();
|
||||
authenticateUser();
|
||||
visit('/settings/general');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/settings/general');
|
||||
assert.equal(find('#siteTitle').val(), 'EmberSherpa', 'Website title input is filled in correctly');
|
||||
assert.equal(find('textarea').val(), 'This Documize instance contains all our team documentation', 'Message is set correctly');
|
||||
|
@ -16,12 +16,12 @@ test('visiting /settings/general', function(assert) {
|
|||
});
|
||||
});
|
||||
|
||||
test('changing the Website title and description', function(assert) {
|
||||
test('changing the Website title and description', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
userLogin();
|
||||
authenticateUser();
|
||||
visit('/settings/general');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
let websiteTitle = find('.content .title').text().trim();
|
||||
let websiteTitleInput = find('#siteTitle').val();
|
||||
assert.equal(websiteTitleInput, websiteTitle, 'Website title is set to EmberSherpa');
|
||||
|
@ -30,30 +30,30 @@ test('changing the Website title and description', function(assert) {
|
|||
fillIn('#siteTitle', 'Documize Tests');
|
||||
click('.button-blue');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
let websiteTitle = find('.content .title').text().trim();
|
||||
let websiteTitleInput = find('#siteTitle').val();
|
||||
assert.equal(websiteTitleInput, websiteTitle, 'Website title is set to Documize Tests');
|
||||
});
|
||||
});
|
||||
|
||||
test('visiting /settings/folders', function(assert) {
|
||||
test('visiting /settings/folders', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
userLogin();
|
||||
authenticateUser();
|
||||
visit('/settings/folders');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
checkForCommonAsserts();
|
||||
assert.equal(currentURL(), '/settings/folders');
|
||||
});
|
||||
});
|
||||
|
||||
test('visiting /settings/users', function(assert) {
|
||||
test('visiting /settings/users', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
userLogin();
|
||||
authenticateUser();
|
||||
visit('/settings/users');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
checkForCommonAsserts();
|
||||
findWithAssert('.user-list');
|
||||
let numberOfUsers = find('.user-list tr').length;
|
||||
|
@ -62,12 +62,12 @@ test('visiting /settings/users', function(assert) {
|
|||
});
|
||||
});
|
||||
|
||||
test('add a new user', function(assert) {
|
||||
test('add a new user', function (assert) {
|
||||
server.create('meta', { allowAnonymousAccess: false });
|
||||
userLogin();
|
||||
authenticateUser();
|
||||
visit('/settings/users');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
checkForCommonAsserts();
|
||||
findWithAssert('.user-list');
|
||||
let numberOfUsers = find('.user-list tr').length;
|
||||
|
@ -83,7 +83,7 @@ test('add a new user', function(assert) {
|
|||
// waitToAppear('.user-notification:contains(Added)');
|
||||
// waitToDisappear('.user-notification:contains(Added)');
|
||||
|
||||
andThen(function() {
|
||||
andThen(function () {
|
||||
let numberOfUsers = find('.user-list tr').length;
|
||||
assert.equal(numberOfUsers, 4, '3 Users listed');
|
||||
assert.equal(currentURL(), '/settings/users');
|
||||
|
@ -95,6 +95,5 @@ function checkForCommonAsserts() {
|
|||
findWithAssert('.sidebar-menu');
|
||||
findWithAssert('#user-button');
|
||||
findWithAssert('#accounts-button');
|
||||
findWithAssert('a:contains(Dashboard)');
|
||||
findWithAssert('a:contains(Settings)');
|
||||
findWithAssert('.info .title');
|
||||
}
|
||||
|
|
38
app/tests/helpers/authenticate-user.js
Normal file
38
app/tests/helpers/authenticate-user.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
import Ember from 'ember';
|
||||
import { authenticateSession } from 'documize/tests/helpers/ember-simple-auth';
|
||||
|
||||
const {
|
||||
merge
|
||||
} = Ember;
|
||||
|
||||
export default Ember.Test.registerAsyncHelper('authenticateUser', function(app, attrs = {}) {
|
||||
authenticateSession(app, merge({
|
||||
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
|
||||
user: {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
}
|
||||
}, attrs)
|
||||
);
|
||||
});
|
|
@ -7,7 +7,6 @@ export default function(name, options = {}) {
|
|||
beforeEach() {
|
||||
this.application = startApp();
|
||||
stubAudit(this);
|
||||
stubSession(this);
|
||||
stubUserNotification(this);
|
||||
|
||||
if (options.beforeEach) {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import Ember from 'ember';
|
||||
import Application from '../../app';
|
||||
import config from '../../config/environment';
|
||||
import './stub-session';
|
||||
import './stub-audit';
|
||||
import './user-login';
|
||||
import './wait-to-appear';
|
||||
import './wait-to-disappear';
|
||||
import './stub-user-notification';
|
||||
import './authenticate-user';
|
||||
|
||||
export default function startApp(attrs) {
|
||||
let application;
|
||||
|
|
|
@ -1,200 +0,0 @@
|
|||
import Ember from 'ember';
|
||||
import models from 'documize/utils/model';
|
||||
import encodingUtil from 'documize/utils/encoding';
|
||||
import netUtil from 'documize/utils/net';
|
||||
|
||||
const Session = Ember.Service.extend({
|
||||
|
||||
ready: false,
|
||||
appMeta: null,
|
||||
isMac: false,
|
||||
isMobile: false,
|
||||
previousTransition: null,
|
||||
user: null,
|
||||
authenticated: false,
|
||||
folderPermissions: null,
|
||||
currentFolder: null,
|
||||
ajax: Ember.inject.service(),
|
||||
|
||||
isAdmin: function() {
|
||||
if (this.authenticated && is.not.null(this.user) && this.user.id !== "") {
|
||||
return this.user.admin;
|
||||
}
|
||||
return false;
|
||||
}.property('user'),
|
||||
|
||||
isEditor: function() {
|
||||
if (this.authenticated && is.not.null(this.user) && this.user.id !== "") {
|
||||
return this.user.editor || this.user.admin;
|
||||
}
|
||||
return false;
|
||||
}.property('user'),
|
||||
|
||||
// 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();
|
||||
|
||||
if (is.empty(credentials.email) || is.empty(credentials.password)) {
|
||||
return Ember.RSVP.reject("invalid");
|
||||
}
|
||||
|
||||
var encoded = encodingUtil.Base64.encode(domain + ":" + credentials.email + ":" + credentials.password);
|
||||
var headers = {
|
||||
'Authorization': 'Basic ' + encoded
|
||||
};
|
||||
|
||||
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);
|
||||
return response;
|
||||
});
|
||||
},
|
||||
|
||||
// Goodbye
|
||||
logout: function() {
|
||||
this.clearSession();
|
||||
},
|
||||
|
||||
// Session management
|
||||
setSession: function(token, user) {
|
||||
this.set('user', user);
|
||||
this.set('authenticated', true);
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
clearSession: function() {
|
||||
this.set('user', null);
|
||||
this.set('authenticated', false);
|
||||
// localStorage.clear();
|
||||
},
|
||||
|
||||
storeSessionItem: function() {
|
||||
// localStorage[key] = data;
|
||||
// console.log(data);
|
||||
},
|
||||
|
||||
getSessionItem: function() {
|
||||
// return localStorage[key];
|
||||
// console.log(data);
|
||||
},
|
||||
|
||||
clearSessionItem: function() {
|
||||
// delete localStorage[key];
|
||||
},
|
||||
|
||||
boot() {
|
||||
let self = this;
|
||||
let dbhash = "";
|
||||
|
||||
if (is.not.null(document.head.querySelector("[property=dbhash]"))) {
|
||||
dbhash = document.head.querySelector("[property=dbhash]").content;
|
||||
}
|
||||
|
||||
if (dbhash.length > 0 && dbhash !== "{{.DBhash}}") {
|
||||
self.get('appMeta').set('orgId', "response.orgId");
|
||||
self.get('appMeta').setSafe('title', "Documize Setup");
|
||||
self.get('appMeta').set('version', "response.version");
|
||||
self.get('appMeta').setSafe('message', "response.message");
|
||||
self.get('appMeta').set('allowAnonymousAccess', false);
|
||||
self.set('ready', true);
|
||||
return new Ember.RSVP.Promise(function(resolve) {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
if (this.get('ready')) {
|
||||
return new Ember.RSVP.Promise(function(resolve) {
|
||||
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");
|
||||
//
|
||||
// if (!blockedPopupTest) {
|
||||
// this.set('popupBlocked', true);
|
||||
// } else {
|
||||
// blockedPopupTest.close();
|
||||
// this.set('popupBlocked', false);
|
||||
// }
|
||||
|
||||
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 = this.get('appMeta').getUrl(`public/validate?token=${token}`);
|
||||
|
||||
return this.get('ajax').request(tokenCheckUrl, {
|
||||
method: 'GET',
|
||||
contentType: 'json'
|
||||
}).then((user) => {
|
||||
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";
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export default Ember.Test.registerAsyncHelper('stubSession', function(app, test, attrs={}) {
|
||||
test.register('service:session', Session.extend(attrs));
|
||||
});
|
12
app/tests/unit/services/local-storage-test.js
Normal file
12
app/tests/unit/services/local-storage-test.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { moduleFor, test } from 'ember-qunit';
|
||||
|
||||
moduleFor('service:local-storage', 'Unit | Service | local storage', {
|
||||
// Specify the other units that are required for this test.
|
||||
// needs: ['service:foo']
|
||||
});
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let service = this.subject();
|
||||
assert.ok(service);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue