Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert oauth2-server-config package to js #7017

Merged
merged 10 commits into from
May 31, 2017

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this.ChatOAuthApps = new Mongo.Collection('rocketchat_oauth_apps');
17 changes: 0 additions & 17 deletions packages/rocketchat-oauth2-server-config/admin/client/route.coffee

This file was deleted.

22 changes: 22 additions & 0 deletions packages/rocketchat-oauth2-server-config/admin/client/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FlowRouter.route('/admin/oauth-apps', {
name: 'admin-oauth-apps',
action() {
return BlazeLayout.render('main', {
center: 'pageSettingsContainer',
pageTitle: t('OAuth_Applications'),
pageTemplate: 'oauthApps'
});
}
});

FlowRouter.route('/admin/oauth-app/:id?', {
name: 'admin-oauth-app',
action(params) {
return BlazeLayout.render('main', {
center: 'pageSettingsContainer',
pageTitle: t('OAuth_Application'),
pageTemplate: 'oauthApp',
params
});
}
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
RocketChat.AdminBox.addOption({
href: 'admin-oauth-apps',
i18nLabel: 'OAuth Apps',
permissionGranted() {
return RocketChat.authz.hasAllPermission('manage-oauth-apps');
}
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* globals ChatOAuthApps */
import toastr from 'toastr';

Template.oauthApp.onCreated(function() {
this.subscribe('oauthApps');
this.record = new ReactiveVar({
active: true
});
});

Template.oauthApp.helpers({
hasPermission() {
return RocketChat.authz.hasAllPermission('manage-oauth-apps');
},
data() {
const instance = Template.instance();
if (typeof instance.data.params === 'function') {
const params = instance.data.params();
if (params && params.id) {
const data = ChatOAuthApps.findOne({ _id: params.id });
if (data) {
data.authorization_url = Meteor.absoluteUrl('oauth/authorize');
data.access_token_url = Meteor.absoluteUrl('oauth/token');
Template.instance().record.set(data);
return data;
}
}
}
return Template.instance().record.curValue;
}
});

Template.oauthApp.events({
'click .submit > .delete'() {
const params = Template.instance().data.params();
swal({
title: t('Are_you_sure'),
text: t('You_will_not_be_able_to_recover'),
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes_delete_it'),
cancelButtonText: t('Cancel'),
closeOnConfirm: false,
html: false
}, function() {
Meteor.call('deleteOAuthApp', params.id, function() {
swal({
title: t('Deleted'),
text: t('Your_entry_has_been_deleted'),
type: 'success',
timer: 1000,
showConfirmButton: false
});
FlowRouter.go('admin-oauth-apps');
});
});
},
'click .submit > .save'() {
const instance = Template.instance();
const name = $('[name=name]').val().trim();
const active = $('[name=active]:checked').val().trim() === '1';
const redirectUri = $('[name=redirectUri]').val().trim();
if (name === '') {
return toastr.error(TAPi18n.__('The_application_name_is_required'));
}
if (redirectUri === '') {
return toastr.error(TAPi18n.__('The_redirectUri_is_required'));
}
const app = {
name,
active,
redirectUri
};
if (typeof instance.data.params === 'function') {
const params = instance.data.params();
if (params && params.id) {
return Meteor.call('updateOAuthApp', params.id, app, function(err) {
if (err != null) {
return handleError(err);
}
toastr.success(TAPi18n.__('Application_updated'));
});
}
}
Meteor.call('addOAuthApp', app, function(err, data) {
if (err != null) {
return handleError(err);
}
toastr.success(TAPi18n.__('Application_added'));
FlowRouter.go('admin-oauth-app', { id: data._id });
});
}
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* globals ChatOAuthApps */
import moment from 'moment';

Template.oauthApps.onCreated(() => this.subscribe('oauthApps'));

Template.oauthApps.helpers({
hasPermission() {
return RocketChat.authz.hasAllPermission('manage-oauth-apps');
},
applications() {
return ChatOAuthApps.find();
},
dateFormated(date) {
return moment(date).format('L LT');
}
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Meteor.methods({
addOAuthApp(application) {
if (!RocketChat.authz.hasPermission(this.userId, 'manage-oauth-apps')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'addOAuthApp' });
}
if (!_.isString(application.name) || application.name.trim() === '') {
throw new Meteor.Error('error-invalid-name', 'Invalid name', { method: 'addOAuthApp' });
}
if (!_.isString(application.redirectUri) || application.redirectUri.trim() === '') {
throw new Meteor.Error('error-invalid-redirectUri', 'Invalid redirectUri', { method: 'addOAuthApp' });
}
if (!_.isBoolean(application.active)) {
throw new Meteor.Error('error-invalid-arguments', 'Invalid arguments', { method: 'addOAuthApp' });
}
application.clientId = Random.id();
application.clientSecret = Random.secret();
application._createdAt = new Date;
application._createdBy = RocketChat.models.Users.findOne(this.userId, { fields: { username: 1 } });
application._id = RocketChat.models.OAuthApps.insert(application);
return application;
}
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Meteor.methods({
deleteOAuthApp(applicationId) {
if (!RocketChat.authz.hasPermission(this.userId, 'manage-oauth-apps')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'deleteOAuthApp' });
}
const application = RocketChat.models.OAuthApps.findOne(applicationId);
if (application == null) {
throw new Meteor.Error('error-application-not-found', 'Application not found', { method: 'deleteOAuthApp' });
}
RocketChat.models.OAuthApps.remove({ _id: applicationId });
return true;
}
});

This file was deleted.

Loading