mirror of
https://github.com/documize/community.git
synced 2025-07-22 22:59: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:
parent
5f584f7895
commit
61e66e5203
5 changed files with 224 additions and 219 deletions
|
@ -42,9 +42,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
|
|
||||||
this.set('config', config);
|
this.set('config', config);
|
||||||
|
|
||||||
if (this.get('config.APIToken').length > 0) {
|
this.send('auth');
|
||||||
this.send('auth');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
|
@ -65,15 +63,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
},
|
},
|
||||||
|
|
||||||
auth() {
|
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 page = this.get('page');
|
||||||
let config = this.get('config');
|
let config = this.get('config');
|
||||||
let self = this;
|
let self = this;
|
||||||
|
@ -93,7 +82,12 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
self.set('waiting', false);
|
self.set('waiting', false);
|
||||||
|
|
||||||
let options = self.get('options');
|
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)) {
|
if (is.not.undefined(group)) {
|
||||||
Ember.set(config, 'group', group);
|
Ember.set(config, 'group', group);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,50 +16,50 @@ import TooltipMixin from '../../../mixins/tooltip';
|
||||||
import SectionMixin from '../../../mixins/section';
|
import SectionMixin from '../../../mixins/section';
|
||||||
|
|
||||||
export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, {
|
export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, {
|
||||||
sectionService: Ember.inject.service('section'),
|
sectionService: Ember.inject.service('section'),
|
||||||
isDirty: false,
|
isDirty: false,
|
||||||
busy: false,
|
busy: false,
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
config: {},
|
config: {},
|
||||||
boards: null,
|
boards: null,
|
||||||
noBoards: false,
|
noBoards: false,
|
||||||
appKey: "",
|
appKey: "",
|
||||||
|
|
||||||
boardStyle: Ember.computed('config.board', function() {
|
boardStyle: Ember.computed('config.board', function () {
|
||||||
let board = this.get('config.board');
|
let board = this.get('config.board');
|
||||||
|
|
||||||
if (is.null(board) || is.undefined(board)) {
|
if (is.null(board) || is.undefined(board)) {
|
||||||
return "#4c4c4c";
|
return "#4c4c4c";
|
||||||
}
|
}
|
||||||
|
|
||||||
let color = board.prefs.backgroundColor;
|
let color = board.prefs.backgroundColor;
|
||||||
return Ember.String.htmlSafe("background-color: " + color);
|
return Ember.String.htmlSafe("background-color: " + color);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
didReceiveAttrs() {
|
didReceiveAttrs() {
|
||||||
let page = this.get('page');
|
let page = this.get('page');
|
||||||
let config = {};
|
let config = {};
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = JSON.parse(this.get('meta.config'));
|
config = JSON.parse(this.get('meta.config'));
|
||||||
}
|
} catch (e) {}
|
||||||
catch (e) {}
|
|
||||||
|
|
||||||
if (is.empty(config)) {
|
if (is.empty(config)) {
|
||||||
config = {
|
config = {
|
||||||
token: "",
|
token: "",
|
||||||
user: null,
|
user: null,
|
||||||
board: null,
|
board: null,
|
||||||
lists: []
|
lists: []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set('config', config);
|
this.set('config', config);
|
||||||
|
|
||||||
this.get('sectionService').fetch(page, "config", {})
|
this.get('sectionService').fetch(page, "config", {})
|
||||||
.then(function(s) {
|
.then(function (s) {
|
||||||
self.set('appKey', s.appKey);
|
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
|
// On auth callback capture user token
|
||||||
let hashToken = window.location.hash;
|
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') !== "") {
|
if (self.get('appKey') !== "" && self.get('config.token') !== "") {
|
||||||
self.send('auth');
|
self.send('auth');
|
||||||
}
|
} else {
|
||||||
else {
|
Ember.$.getScript("https://api.trello.com/1/client.js?key=" + self.get('appKey'), function () {
|
||||||
Ember.$.getScript("https://api.trello.com/1/client.js?key=" + self.get('appKey'), function() {
|
Trello.deauthorize();
|
||||||
Trello.deauthorize();
|
});
|
||||||
});
|
}
|
||||||
}
|
}, function (error) { //jshint ignore: line
|
||||||
}, function(error) { //jshint ignore: line
|
console.log(error);
|
||||||
console.log(error);
|
});
|
||||||
});
|
},
|
||||||
},
|
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
this.destroyTooltips();
|
this.destroyTooltips();
|
||||||
},
|
},
|
||||||
|
|
||||||
getBoardLists() {
|
getBoardLists() {
|
||||||
this.set('busy', true);
|
this.set('busy', true);
|
||||||
|
|
||||||
let self = this;
|
let self = this;
|
||||||
let boards = this.get('boards');
|
let boards = this.get('boards');
|
||||||
let board = this.get('config.board');
|
let board = this.get('config.board');
|
||||||
let page = this.get('page');
|
let page = this.get('page');
|
||||||
|
|
||||||
if (is.null(boards) || is.undefined(boards) || boards.length === 0) {
|
if (is.null(boards) || is.undefined(boards) || boards.length === 0) {
|
||||||
this.set('noBoards', true);
|
this.set('noBoards', true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set('noBoards', false);
|
this.set('noBoards', false);
|
||||||
|
|
||||||
if (is.null(board) || is.undefined(board)) {
|
if (is.null(board) || is.undefined(board)) {
|
||||||
if (boards.length) {
|
if (boards.length) {
|
||||||
board = boards[0];
|
board = boards[0];
|
||||||
this.set('config.board', board);
|
this.set('config.board', board);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
this.set('config.board', boards.findBy('id', board.id));
|
||||||
this.set('config.board', boards.findBy('id', board.id));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.get('sectionService').fetch(page, "lists", self.get('config'))
|
this.get('sectionService').fetch(page, "lists", self.get('config'))
|
||||||
.then(function(lists) {
|
.then(function (lists) {
|
||||||
let savedLists = self.get('config.lists');
|
let savedLists = self.get('config.lists');
|
||||||
if (savedLists === null) {
|
if (savedLists === null) {
|
||||||
savedLists = [];
|
savedLists = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
lists.forEach(function(list) {
|
lists.forEach(function (list) {
|
||||||
let saved = savedLists.findBy("id", list.id);
|
let saved = savedLists.findBy("id", list.id);
|
||||||
let included = true;
|
let included = true;
|
||||||
if (is.not.undefined(saved)) {
|
if (is.not.undefined(saved)) {
|
||||||
included = saved.included;
|
included = saved.included;
|
||||||
}
|
}
|
||||||
list.included = included;
|
list.included = included;
|
||||||
});
|
});
|
||||||
|
|
||||||
self.set('config.lists', lists);
|
self.set('config.lists', lists);
|
||||||
self.set('busy', false);
|
self.set('busy', false);
|
||||||
}, function(error) { //jshint ignore: line
|
}, function (error) { //jshint ignore: line
|
||||||
self.set('busy', false);
|
self.set('busy', false);
|
||||||
self.set('authenticated', false);
|
self.set('authenticated', false);
|
||||||
self.showNotification("Unable to fetch board lists");
|
self.showNotification("Unable to fetch board lists");
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
isDirty() {
|
isDirty() {
|
||||||
return this.get('isDirty');
|
return this.get('isDirty');
|
||||||
},
|
},
|
||||||
|
|
||||||
onListCheckbox(id) {
|
onListCheckbox(id) {
|
||||||
let lists = this.get('config.lists');
|
let lists = this.get('config.lists');
|
||||||
let list = lists.findBy('id', id);
|
let list = lists.findBy('id', id);
|
||||||
|
|
||||||
if (list !== null) {
|
if (list !== null) {
|
||||||
Ember.set(list, 'included', !list.included);
|
Ember.set(list, 'included', !list.included);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
auth() {
|
auth() {
|
||||||
if (this.get('appKey') === "") {
|
if (this.get('appKey') === "") {
|
||||||
$("#trello-appkey").addClass('error').focus();
|
$("#trello-appkey").addClass('error').focus();
|
||||||
this.set('authenticated', false);
|
this.set('authenticated', false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let self = this;
|
let self = this;
|
||||||
let page = this.get('page');
|
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() {
|
Ember.$.getScript("https://api.trello.com/1/client.js?key=" + this.get('appKey'), function () {
|
||||||
Trello.authorize({
|
Trello.authorize({
|
||||||
type: "redirect",
|
type: "redirect",
|
||||||
interactive: true,
|
interactive: true,
|
||||||
name: "Documize",
|
name: "Documize",
|
||||||
scope: {
|
scope: {
|
||||||
read: true,
|
read: true,
|
||||||
write: false
|
write: false
|
||||||
},
|
},
|
||||||
expiration: "never",
|
expiration: "never",
|
||||||
persist: true,
|
persist: true,
|
||||||
success: function() {
|
success: function () {
|
||||||
self.set('authenticated', true);
|
self.set('authenticated', true);
|
||||||
self.set('config.token', Trello.token());
|
self.set('config.token', Trello.token());
|
||||||
self.set('busy', true);
|
self.set('busy', true);
|
||||||
|
|
||||||
Trello.members.get("me", function(user) {
|
Trello.members.get("me", function (user) {
|
||||||
self.set('config.user', user);
|
self.set('config.user', user);
|
||||||
}, function(error) {
|
}, function (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.get('sectionService').fetch(page, "boards", self.get('config'))
|
self.get('sectionService').fetch(page, "boards", self.get('config'))
|
||||||
.then(function(boards) {
|
.then(function (boards) {
|
||||||
self.set('busy', false);
|
self.set('busy', false);
|
||||||
self.set('boards', boards);
|
self.set('boards', boards);
|
||||||
self.getBoardLists();
|
self.getBoardLists();
|
||||||
}, function(error) { //jshint ignore: line
|
}, function (error) { //jshint ignore: line
|
||||||
self.set('busy', false);
|
self.set('busy', false);
|
||||||
self.set('authenticated', false);
|
self.set('authenticated', false);
|
||||||
self.showNotification("Unable to fetch boards");
|
self.showNotification("Unable to fetch boards");
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: function(error) {
|
error: function (error) {
|
||||||
self.set('busy', false);
|
self.set('busy', false);
|
||||||
self.set('authenticated', false);
|
self.set('authenticated', false);
|
||||||
self.showNotification("Unable to authenticate");
|
self.showNotification("Unable to authenticate");
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onBoardChange(board) {
|
onBoardChange(board) {
|
||||||
this.set('isDirty', true);
|
this.set('isDirty', true);
|
||||||
this.set('config.board', board);
|
this.set('config.board', board);
|
||||||
this.set('config.lists', []);
|
this.set('config.lists', []);
|
||||||
this.getBoardLists();
|
this.getBoardLists();
|
||||||
},
|
},
|
||||||
|
|
||||||
onCancel() {
|
onCancel() {
|
||||||
this.attrs.onCancel();
|
this.attrs.onCancel();
|
||||||
},
|
},
|
||||||
|
|
||||||
onAction(title) {
|
onAction(title) {
|
||||||
this.set('busy', true);
|
this.set('busy', true);
|
||||||
|
|
||||||
let self = this;
|
let self = this;
|
||||||
let page = this.get('page');
|
let page = this.get('page');
|
||||||
let meta = this.get('meta');
|
let meta = this.get('meta');
|
||||||
page.set('title', title);
|
page.set('title', title);
|
||||||
meta.set('rawBody', '');
|
meta.set('rawBody', '');
|
||||||
meta.set('config', JSON.stringify(this.get('config')));
|
meta.set('config', JSON.stringify(this.get('config')));
|
||||||
meta.set('externalSource', true);
|
meta.set('externalSource', true);
|
||||||
|
|
||||||
this.get('sectionService').fetch(page, "cards", this.get('config'))
|
this.get('sectionService').fetch(page, "cards", this.get('config'))
|
||||||
.then(function(response) {
|
.then(function (response) {
|
||||||
meta.set('rawBody', JSON.stringify(response));
|
meta.set('rawBody', JSON.stringify(response));
|
||||||
self.set('busy', false);
|
self.set('busy', false);
|
||||||
self.attrs.onAction(page, meta);
|
self.attrs.onAction(page, meta);
|
||||||
}, function(reason) { //jshint ignore: line
|
}, function (reason) { //jshint ignore: line
|
||||||
self.set('busy', false);
|
self.set('busy', false);
|
||||||
self.attrs.onAction(page, meta);
|
self.attrs.onAction(page, meta);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -104,7 +104,7 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
||||||
|
|
||||||
config.Clean()
|
config.Clean()
|
||||||
|
|
||||||
if config.APIToken == provider.SecretReplacement {
|
if config.APIToken == provider.SecretReplacement || config.APIToken == "" {
|
||||||
config.APIToken = ctx.GetSecrets("APIToken")
|
config.APIToken = ctx.GetSecrets("APIToken")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,10 @@ const renderTemplate = `
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
|
||||||
|
type secrets struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
}
|
||||||
|
|
||||||
type trelloConfig struct {
|
type trelloConfig struct {
|
||||||
AppKey string `json:"appKey"`
|
AppKey string `json:"appKey"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
|
|
@ -25,7 +25,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var meta provider.TypeMeta
|
var meta provider.TypeMeta
|
||||||
var appKey string
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
meta = provider.TypeMeta{}
|
meta = provider.TypeMeta{}
|
||||||
|
@ -49,11 +48,6 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
method := query.Get("method")
|
method := query.Get("method")
|
||||||
|
|
||||||
if len(method) == 0 {
|
|
||||||
provider.WriteMessage(w, "trello", "missing method name")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
|
||||||
|
@ -70,19 +64,20 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if appKey == "" {
|
config.Clean()
|
||||||
appKey = request.ConfigString(meta.ConfigHandle(), "appKey")
|
config.AppKey = request.ConfigString(meta.ConfigHandle(), "appKey")
|
||||||
|
|
||||||
|
if len(config.AppKey) == 0 {
|
||||||
|
log.ErrorString("missing trello App Key")
|
||||||
|
provider.WriteMessage(w, "trello", "Missing appKey")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Clean()
|
if len(config.Token) == 0 {
|
||||||
config.AppKey = appKey
|
config.Token = ctx.GetSecrets("token") // get a token, if we have one
|
||||||
|
}
|
||||||
|
|
||||||
if method != "config" {
|
if method != "config" {
|
||||||
if len(config.AppKey) == 0 {
|
|
||||||
provider.WriteMessage(w, "trello", "Missing appKey")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(config.Token) == 0 {
|
if len(config.Token) == 0 {
|
||||||
provider.WriteMessage(w, "trello", "Missing token")
|
provider.WriteMessage(w, "trello", "Missing token")
|
||||||
return
|
return
|
||||||
|
@ -94,8 +89,9 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
render, err := getCards(config)
|
render, err := getCards(config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.IfErr(err)
|
||||||
provider.WriteError(w, "trello", err)
|
provider.WriteError(w, "trello", err)
|
||||||
|
log.IfErr(ctx.SaveSecrets("")) // failure means our secrets are invalid
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,8 +101,9 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
render, err := getBoards(config)
|
render, err := getBoards(config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.IfErr(err)
|
||||||
provider.WriteError(w, "trello", err)
|
provider.WriteError(w, "trello", err)
|
||||||
|
log.IfErr(ctx.SaveSecrets("")) // failure means our secrets are invalid
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,24 +113,36 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
render, err := getLists(config)
|
render, err := getLists(config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.IfErr(err)
|
||||||
provider.WriteError(w, "trello", err)
|
provider.WriteError(w, "trello", err)
|
||||||
|
log.IfErr(ctx.SaveSecrets("")) // failure means our secrets are invalid
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
provider.WriteJSON(w, render)
|
provider.WriteJSON(w, render)
|
||||||
|
|
||||||
case "config":
|
case "config":
|
||||||
if method == "config" {
|
var ret struct {
|
||||||
var config struct {
|
AppKey string `json:"appKey"`
|
||||||
AppKey string `json:"appKey"`
|
Token string `json:"token"`
|
||||||
}
|
|
||||||
|
|
||||||
config.AppKey = appKey
|
|
||||||
provider.WriteJSON(w, config)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
ret.AppKey = config.AppKey
|
||||||
|
ret.Token = config.Token
|
||||||
|
provider.WriteJSON(w, ret)
|
||||||
|
return
|
||||||
|
|
||||||
|
default:
|
||||||
|
log.ErrorString("trello unknown method name: " + method)
|
||||||
|
provider.WriteMessage(w, "trello", "missing method name")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the token has just worked, so save it as our secret
|
||||||
|
var s secrets
|
||||||
|
s.Token = config.Token
|
||||||
|
b, e := json.Marshal(s)
|
||||||
|
log.IfErr(e)
|
||||||
|
log.IfErr(ctx.SaveSecrets(string(b)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue