Skip to content

Commit

Permalink
[IMPROVE] Replace personalAccessTokens publication by REST (#15644)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosSpessatto authored and sampaiodiego committed Nov 5, 2019
1 parent 29d3e8c commit 45b9e65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
25 changes: 14 additions & 11 deletions imports/personal-access-tokens/client/personalAccessTokens.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';
import { Template } from 'meteor/templating';
Expand All @@ -9,17 +8,20 @@ import moment from 'moment';
import { t } from '../../../app/utils';
import { modal, SideNav } from '../../../app/ui-utils';
import { hasAllPermission } from '../../../app/authorization';

import './personalAccessTokens.html';
import { APIClient } from '../../../app/utils/client';

const PersonalAccessTokens = new Mongo.Collection('personal_access_tokens');
const loadTokens = async (instance) => {
const { tokens } = await APIClient.v1.get('users.getPersonalAccessTokens');
instance.personalAccessTokens.set(tokens);
};

Template.accountTokens.helpers({
isAllowed() {
return hasAllPermission(['create-personal-access-tokens']);
},
tokens() {
return (PersonalAccessTokens.find({}).fetch()[0] && PersonalAccessTokens.find({}).fetch()[0].tokens) || [];
return Template.instance().personalAccessTokens.get();
},
dateFormated(date) {
return moment(date).format('L LT');
Expand Down Expand Up @@ -50,10 +52,11 @@ Template.accountTokens.events({
return toastr.error(t(error.error));
}
showSuccessModal(token);
loadTokens(instance);
instance.find('#tokenName').value = '';
});
},
'click .remove-personal-access-token'() {
'click .remove-personal-access-token'(e, instance) {
modal.open({
title: t('Are_you_sure'),
text: t('API_Personal_Access_Tokens_Remove_Modal'),
Expand All @@ -71,11 +74,12 @@ Template.accountTokens.events({
if (error) {
return toastr.error(t(error.error));
}
loadTokens(instance);
toastr.success(t('Removed'));
});
});
},
'click .regenerate-personal-access-token'() {
'click .regenerate-personal-access-token'(e, instance) {
modal.open({
title: t('Are_you_sure'),
text: t('API_Personal_Access_Tokens_Regenerate_Modal'),
Expand All @@ -93,18 +97,17 @@ Template.accountTokens.events({
if (error) {
return toastr.error(t(error.error));
}
loadTokens(instance);
showSuccessModal(token);
});
});
},
});

Template.accountTokens.onCreated(function() {
this.ready = new ReactiveVar(true);
const subscription = this.subscribe('personalAccessTokens');
this.autorun(() => {
this.ready.set(subscription.ready());
});
this.personalAccessTokens = new ReactiveVar([]);

loadTokens(this);
});

Template.accountTokens.onRendered(function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Meteor } from 'meteor/meteor';
import { hasPermission } from '../../../../app/authorization';
import { Users } from '../../../../app/models';

console.warn('The publication "personalAccessTokens" is deprecated and will be removed after version v3.0.0');
Meteor.publish('personalAccessTokens', function() {
if (!this.userId) {
return this.ready();
Expand Down

0 comments on commit 45b9e65

Please sign in to comment.