1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 07:39:43 +02:00

use saved secrets in trello and paper trail

Alter trello to used stored secret token.
Alter papertrail to auto-login where a secret exists.
This commit is contained in:
Elliott Stoneham 2016-07-08 12:29:53 +01:00
parent 5f584f7895
commit 61e66e5203
5 changed files with 224 additions and 219 deletions

View file

@ -42,9 +42,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
this.set('config', config);
if (this.get('config.APIToken').length > 0) {
this.send('auth');
}
this.send('auth');
},
willDestroyElement() {
@ -65,15 +63,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
},
auth() {
// missing data?
this.set('config.APIToken', this.get('config.APIToken').trim());
if (is.empty(this.get('config.APIToken'))) {
$("#papertrail-apitoken").addClass("error").focus();
console.log("auth token empty");
return;
}
let page = this.get('page');
let config = this.get('config');
let self = this;
@ -93,7 +82,12 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
self.set('waiting', false);
let options = self.get('options');
let group = _.findWhere(options.groups, { id: config.group.id });
let group = {};
if (is.not.null(config.group)) {
group = _.findWhere(options.groups, { id: config.group.id });
} else {
group = options.groups[0];
}
if (is.not.undefined(group)) {
Ember.set(config, 'group', group);
}

View file

@ -16,50 +16,50 @@ import TooltipMixin from '../../../mixins/tooltip';
import SectionMixin from '../../../mixins/section';
export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, {
sectionService: Ember.inject.service('section'),
isDirty: false,
busy: false,
authenticated: false,
config: {},
boards: null,
noBoards: false,
sectionService: Ember.inject.service('section'),
isDirty: false,
busy: false,
authenticated: false,
config: {},
boards: null,
noBoards: false,
appKey: "",
boardStyle: Ember.computed('config.board', function() {
let board = this.get('config.board');
boardStyle: Ember.computed('config.board', function () {
let board = this.get('config.board');
if (is.null(board) || is.undefined(board)) {
return "#4c4c4c";
}
if (is.null(board) || is.undefined(board)) {
return "#4c4c4c";
}
let color = board.prefs.backgroundColor;
return Ember.String.htmlSafe("background-color: " + color);
}),
let color = board.prefs.backgroundColor;
return Ember.String.htmlSafe("background-color: " + color);
}),
didReceiveAttrs() {
let page = this.get('page');
didReceiveAttrs() {
let page = this.get('page');
let config = {};
let self = this;
try {
config = JSON.parse(this.get('meta.config'));
}
catch (e) {}
config = JSON.parse(this.get('meta.config'));
} catch (e) {}
if (is.empty(config)) {
config = {
token: "",
user: null,
board: null,
lists: []
};
}
if (is.empty(config)) {
config = {
token: "",
user: null,
board: null,
lists: []
};
}
this.set('config', config);
this.set('config', config);
this.get('sectionService').fetch(page, "config", {})
.then(function(s) {
.then(function (s) {
self.set('appKey', s.appKey);
self.set('config.token', s.token); // the user's own token, drawn from the DB
// On auth callback capture user token
let hashToken = window.location.hash;
@ -70,175 +70,173 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
}
}
if (self.get('appKey') !== "" && self.get('config.token') !== "") {
self.send('auth');
}
else {
Ember.$.getScript("https://api.trello.com/1/client.js?key=" + self.get('appKey'), function() {
Trello.deauthorize();
});
}
}, function(error) { //jshint ignore: line
console.log(error);
});
},
if (self.get('appKey') !== "" && self.get('config.token') !== "") {
self.send('auth');
} else {
Ember.$.getScript("https://api.trello.com/1/client.js?key=" + self.get('appKey'), function () {
Trello.deauthorize();
});
}
}, function (error) { //jshint ignore: line
console.log(error);
});
},
willDestroyElement() {
this.destroyTooltips();
},
willDestroyElement() {
this.destroyTooltips();
},
getBoardLists() {
this.set('busy', true);
getBoardLists() {
this.set('busy', true);
let self = this;
let boards = this.get('boards');
let board = this.get('config.board');
let page = this.get('page');
let self = this;
let boards = this.get('boards');
let board = this.get('config.board');
let page = this.get('page');
if (is.null(boards) || is.undefined(boards) || boards.length === 0) {
this.set('noBoards', true);
return;
}
if (is.null(boards) || is.undefined(boards) || boards.length === 0) {
this.set('noBoards', true);
return;
}
this.set('noBoards', false);
this.set('noBoards', false);
if (is.null(board) || is.undefined(board)) {
if (boards.length) {
board = boards[0];
this.set('config.board', board);
}
}
else {
this.set('config.board', boards.findBy('id', board.id));
}
if (is.null(board) || is.undefined(board)) {
if (boards.length) {
board = boards[0];
this.set('config.board', board);
}
} else {
this.set('config.board', boards.findBy('id', board.id));
}
this.get('sectionService').fetch(page, "lists", self.get('config'))
.then(function(lists) {
let savedLists = self.get('config.lists');
if (savedLists === null) {
savedLists = [];
}
this.get('sectionService').fetch(page, "lists", self.get('config'))
.then(function (lists) {
let savedLists = self.get('config.lists');
if (savedLists === null) {
savedLists = [];
}
lists.forEach(function(list) {
let saved = savedLists.findBy("id", list.id);
let included = true;
if (is.not.undefined(saved)) {
included = saved.included;
}
list.included = included;
});
lists.forEach(function (list) {
let saved = savedLists.findBy("id", list.id);
let included = true;
if (is.not.undefined(saved)) {
included = saved.included;
}
list.included = included;
});
self.set('config.lists', lists);
self.set('busy', false);
}, function(error) { //jshint ignore: line
self.set('busy', false);
self.set('authenticated', false);
self.showNotification("Unable to fetch board lists");
console.log(error);
});
},
self.set('config.lists', lists);
self.set('busy', false);
}, function (error) { //jshint ignore: line
self.set('busy', false);
self.set('authenticated', false);
self.showNotification("Unable to fetch board lists");
console.log(error);
});
},
actions: {
isDirty() {
return this.get('isDirty');
},
actions: {
isDirty() {
return this.get('isDirty');
},
onListCheckbox(id) {
let lists = this.get('config.lists');
let list = lists.findBy('id', id);
onListCheckbox(id) {
let lists = this.get('config.lists');
let list = lists.findBy('id', id);
if (list !== null) {
Ember.set(list, 'included', !list.included);
}
},
if (list !== null) {
Ember.set(list, 'included', !list.included);
}
},
auth() {
if (this.get('appKey') === "") {
$("#trello-appkey").addClass('error').focus();
this.set('authenticated', false);
return;
}
auth() {
if (this.get('appKey') === "") {
$("#trello-appkey").addClass('error').focus();
this.set('authenticated', false);
return;
}
let self = this;
let page = this.get('page');
let self = this;
let page = this.get('page');
self.set('busy', true);
self.set('busy', true);
Ember.$.getScript("https://api.trello.com/1/client.js?key=" + this.get('appKey'), function() {
Trello.authorize({
type: "redirect",
interactive: true,
name: "Documize",
scope: {
read: true,
write: false
},
expiration: "never",
persist: true,
success: function() {
self.set('authenticated', true);
self.set('config.token', Trello.token());
self.set('busy', true);
Ember.$.getScript("https://api.trello.com/1/client.js?key=" + this.get('appKey'), function () {
Trello.authorize({
type: "redirect",
interactive: true,
name: "Documize",
scope: {
read: true,
write: false
},
expiration: "never",
persist: true,
success: function () {
self.set('authenticated', true);
self.set('config.token', Trello.token());
self.set('busy', true);
Trello.members.get("me", function(user) {
self.set('config.user', user);
}, function(error) {
console.log(error);
});
Trello.members.get("me", function (user) {
self.set('config.user', user);
}, function (error) {
console.log(error);
});
self.get('sectionService').fetch(page, "boards", self.get('config'))
.then(function(boards) {
self.set('busy', false);
self.set('boards', boards);
self.getBoardLists();
}, function(error) { //jshint ignore: line
self.set('busy', false);
self.set('authenticated', false);
self.showNotification("Unable to fetch boards");
console.log(error);
});
},
error: function(error) {
self.set('busy', false);
self.set('authenticated', false);
self.showNotification("Unable to authenticate");
console.log(error);
}
});
});
},
self.get('sectionService').fetch(page, "boards", self.get('config'))
.then(function (boards) {
self.set('busy', false);
self.set('boards', boards);
self.getBoardLists();
}, function (error) { //jshint ignore: line
self.set('busy', false);
self.set('authenticated', false);
self.showNotification("Unable to fetch boards");
console.log(error);
});
},
error: function (error) {
self.set('busy', false);
self.set('authenticated', false);
self.showNotification("Unable to authenticate");
console.log(error);
}
});
});
},
onBoardChange(board) {
this.set('isDirty', true);
this.set('config.board', board);
this.set('config.lists', []);
this.getBoardLists();
},
onBoardChange(board) {
this.set('isDirty', true);
this.set('config.board', board);
this.set('config.lists', []);
this.getBoardLists();
},
onCancel() {
this.attrs.onCancel();
},
onCancel() {
this.attrs.onCancel();
},
onAction(title) {
this.set('busy', true);
onAction(title) {
this.set('busy', true);
let self = this;
let page = this.get('page');
let meta = this.get('meta');
page.set('title', title);
meta.set('rawBody', '');
meta.set('config', JSON.stringify(this.get('config')));
meta.set('externalSource', true);
let self = this;
let page = this.get('page');
let meta = this.get('meta');
page.set('title', title);
meta.set('rawBody', '');
meta.set('config', JSON.stringify(this.get('config')));
meta.set('externalSource', true);
this.get('sectionService').fetch(page, "cards", this.get('config'))
.then(function(response) {
meta.set('rawBody', JSON.stringify(response));
self.set('busy', false);
self.attrs.onAction(page, meta);
}, function(reason) { //jshint ignore: line
self.set('busy', false);
self.attrs.onAction(page, meta);
});
}
}
});
this.get('sectionService').fetch(page, "cards", this.get('config'))
.then(function (response) {
meta.set('rawBody', JSON.stringify(response));
self.set('busy', false);
self.attrs.onAction(page, meta);
}, function (reason) { //jshint ignore: line
self.set('busy', false);
self.attrs.onAction(page, meta);
});
}
}
});