From 5b1e6894408a186a0ca03917067a1be0c1e0310b Mon Sep 17 00:00:00 2001 From: Marcos Defendi Date: Thu, 29 Nov 2018 15:05:01 -0200 Subject: [PATCH] Convert rocketchat-oauth2-server-config to main module structure --- .../admin/client/collection.js | 3 - .../client/admin/collection.js | 3 + .../{admin/client => client/admin}/route.js | 1 + .../{admin/client => client/admin}/startup.js | 2 + .../admin}/views/oauthApp.html | 0 .../client => client/admin}/views/oauthApp.js | 5 +- .../admin}/views/oauthApps.html | 0 .../admin}/views/oauthApps.js | 3 +- .../client/index.js | 9 +++ .../oauth}/oauth2-client.html | 0 .../client => client/oauth}/oauth2-client.js | 3 +- .../oauth}/stylesheets/oauth2.css | 0 .../package.js | 57 +++++-------------- .../admin}/methods/addOAuthApp.js | 1 + .../admin}/methods/deleteOAuthApp.js | 1 + .../admin}/methods/updateOAuthApp.js | 1 + .../admin}/publications/oauthApps.js | 1 + .../server/index.js | 7 +++ .../server/models/OAuthApps.js | 2 + .../oauth}/default-services.js | 2 + .../server => server/oauth}/oauth2-server.js | 3 +- 21 files changed, 52 insertions(+), 52 deletions(-) delete mode 100644 packages/rocketchat-oauth2-server-config/admin/client/collection.js create mode 100644 packages/rocketchat-oauth2-server-config/client/admin/collection.js rename packages/rocketchat-oauth2-server-config/{admin/client => client/admin}/route.js (93%) rename packages/rocketchat-oauth2-server-config/{admin/client => client/admin}/startup.js (79%) rename packages/rocketchat-oauth2-server-config/{admin/client => client/admin}/views/oauthApp.html (100%) rename packages/rocketchat-oauth2-server-config/{admin/client => client/admin}/views/oauthApp.js (94%) rename packages/rocketchat-oauth2-server-config/{admin/client => client/admin}/views/oauthApps.html (100%) rename packages/rocketchat-oauth2-server-config/{admin/client => client/admin}/views/oauthApps.js (79%) create mode 100644 packages/rocketchat-oauth2-server-config/client/index.js rename packages/rocketchat-oauth2-server-config/{oauth/client => client/oauth}/oauth2-client.html (100%) rename packages/rocketchat-oauth2-server-config/{oauth/client => client/oauth}/oauth2-client.js (93%) rename packages/rocketchat-oauth2-server-config/{oauth/client => client/oauth}/stylesheets/oauth2.css (100%) rename packages/rocketchat-oauth2-server-config/{admin/server => server/admin}/methods/addOAuthApp.js (95%) rename packages/rocketchat-oauth2-server-config/{admin/server => server/admin}/methods/deleteOAuthApp.js (91%) rename packages/rocketchat-oauth2-server-config/{admin/server => server/admin}/methods/updateOAuthApp.js (96%) rename packages/rocketchat-oauth2-server-config/{admin/server => server/admin}/publications/oauthApps.js (86%) create mode 100644 packages/rocketchat-oauth2-server-config/server/index.js rename packages/rocketchat-oauth2-server-config/{oauth/server => server/oauth}/default-services.js (88%) rename packages/rocketchat-oauth2-server-config/{oauth/server => server/oauth}/oauth2-server.js (95%) diff --git a/packages/rocketchat-oauth2-server-config/admin/client/collection.js b/packages/rocketchat-oauth2-server-config/admin/client/collection.js deleted file mode 100644 index 5fbd5c5042c3..000000000000 --- a/packages/rocketchat-oauth2-server-config/admin/client/collection.js +++ /dev/null @@ -1,3 +0,0 @@ -import { Mongo } from 'meteor/mongo'; - -this.ChatOAuthApps = new Mongo.Collection('rocketchat_oauth_apps'); diff --git a/packages/rocketchat-oauth2-server-config/client/admin/collection.js b/packages/rocketchat-oauth2-server-config/client/admin/collection.js new file mode 100644 index 000000000000..b0b7c48c45a4 --- /dev/null +++ b/packages/rocketchat-oauth2-server-config/client/admin/collection.js @@ -0,0 +1,3 @@ +import { Mongo } from 'meteor/mongo'; + +export const ChatOAuthApps = new Mongo.Collection('rocketchat_oauth_apps'); diff --git a/packages/rocketchat-oauth2-server-config/admin/client/route.js b/packages/rocketchat-oauth2-server-config/client/admin/route.js similarity index 93% rename from packages/rocketchat-oauth2-server-config/admin/client/route.js rename to packages/rocketchat-oauth2-server-config/client/admin/route.js index dc1433a0479c..991dde709f2c 100644 --- a/packages/rocketchat-oauth2-server-config/admin/client/route.js +++ b/packages/rocketchat-oauth2-server-config/client/admin/route.js @@ -1,5 +1,6 @@ import { FlowRouter } from 'meteor/kadira:flow-router' ; import { BlazeLayout } from 'meteor/kadira:blaze-layout'; +import { t } from 'meteor/rocketchat:ui'; FlowRouter.route('/admin/oauth-apps', { name: 'admin-oauth-apps', diff --git a/packages/rocketchat-oauth2-server-config/admin/client/startup.js b/packages/rocketchat-oauth2-server-config/client/admin/startup.js similarity index 79% rename from packages/rocketchat-oauth2-server-config/admin/client/startup.js rename to packages/rocketchat-oauth2-server-config/client/admin/startup.js index 39b9b24bf4d6..1d3eb2cbdff5 100644 --- a/packages/rocketchat-oauth2-server-config/admin/client/startup.js +++ b/packages/rocketchat-oauth2-server-config/client/admin/startup.js @@ -1,3 +1,5 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + RocketChat.AdminBox.addOption({ href: 'admin-oauth-apps', i18nLabel: 'OAuth Apps', diff --git a/packages/rocketchat-oauth2-server-config/admin/client/views/oauthApp.html b/packages/rocketchat-oauth2-server-config/client/admin/views/oauthApp.html similarity index 100% rename from packages/rocketchat-oauth2-server-config/admin/client/views/oauthApp.html rename to packages/rocketchat-oauth2-server-config/client/admin/views/oauthApp.html diff --git a/packages/rocketchat-oauth2-server-config/admin/client/views/oauthApp.js b/packages/rocketchat-oauth2-server-config/client/admin/views/oauthApp.js similarity index 94% rename from packages/rocketchat-oauth2-server-config/admin/client/views/oauthApp.js rename to packages/rocketchat-oauth2-server-config/client/admin/views/oauthApp.js index 3991ad831235..ea3932455313 100644 --- a/packages/rocketchat-oauth2-server-config/admin/client/views/oauthApp.js +++ b/packages/rocketchat-oauth2-server-config/client/admin/views/oauthApp.js @@ -1,10 +1,11 @@ -/* globals ChatOAuthApps */ - import { Meteor } from 'meteor/meteor'; import { ReactiveVar } from 'meteor/reactive-var'; import { FlowRouter } from 'meteor/kadira:flow-router'; import { Template } from 'meteor/templating'; import { TAPi18n } from 'meteor/tap:i18n'; +import { RocketChat, handleError } from 'meteor/rocketchat:lib'; +import { t, modal } from 'meteor/rocketchat:ui'; +import { ChatOAuthApps } from '../collection'; import toastr from 'toastr'; Template.oauthApp.onCreated(function() { diff --git a/packages/rocketchat-oauth2-server-config/admin/client/views/oauthApps.html b/packages/rocketchat-oauth2-server-config/client/admin/views/oauthApps.html similarity index 100% rename from packages/rocketchat-oauth2-server-config/admin/client/views/oauthApps.html rename to packages/rocketchat-oauth2-server-config/client/admin/views/oauthApps.html diff --git a/packages/rocketchat-oauth2-server-config/admin/client/views/oauthApps.js b/packages/rocketchat-oauth2-server-config/client/admin/views/oauthApps.js similarity index 79% rename from packages/rocketchat-oauth2-server-config/admin/client/views/oauthApps.js rename to packages/rocketchat-oauth2-server-config/client/admin/views/oauthApps.js index fd7eead8b6e1..c779e6b08d7a 100644 --- a/packages/rocketchat-oauth2-server-config/admin/client/views/oauthApps.js +++ b/packages/rocketchat-oauth2-server-config/client/admin/views/oauthApps.js @@ -1,5 +1,6 @@ -/* globals ChatOAuthApps */ import { Template } from 'meteor/templating'; +import { RocketChat } from 'meteor/rocketchat:lib'; +import { ChatOAuthApps } from '../collection'; import moment from 'moment'; Template.oauthApps.onCreated(function() { diff --git a/packages/rocketchat-oauth2-server-config/client/index.js b/packages/rocketchat-oauth2-server-config/client/index.js new file mode 100644 index 000000000000..2d7b53348a21 --- /dev/null +++ b/packages/rocketchat-oauth2-server-config/client/index.js @@ -0,0 +1,9 @@ +import './oauth/stylesheets/oauth2.css'; +import './oauth/oauth2-client.html'; +import './oauth/oauth2-client'; +import './admin/startup'; +import './admin/route'; +import './admin/views/oauthApp.html'; +import './admin/views/oauthApp'; +import './admin/views/oauthApps.html'; +import './admin/views/oauthApps'; diff --git a/packages/rocketchat-oauth2-server-config/oauth/client/oauth2-client.html b/packages/rocketchat-oauth2-server-config/client/oauth/oauth2-client.html similarity index 100% rename from packages/rocketchat-oauth2-server-config/oauth/client/oauth2-client.html rename to packages/rocketchat-oauth2-server-config/client/oauth/oauth2-client.html diff --git a/packages/rocketchat-oauth2-server-config/oauth/client/oauth2-client.js b/packages/rocketchat-oauth2-server-config/client/oauth/oauth2-client.js similarity index 93% rename from packages/rocketchat-oauth2-server-config/oauth/client/oauth2-client.js rename to packages/rocketchat-oauth2-server-config/client/oauth/oauth2-client.js index 3c4df1b89f4b..e6b02c2adffb 100644 --- a/packages/rocketchat-oauth2-server-config/oauth/client/oauth2-client.js +++ b/packages/rocketchat-oauth2-server-config/client/oauth/oauth2-client.js @@ -1,9 +1,8 @@ -// @ChatOAuthApps = new Mongo.Collection 'rocketchat_oauth_apps' -/* globals ChatOAuthApps */ import { Meteor } from 'meteor/meteor'; import { FlowRouter } from 'meteor/kadira:flow-router' ; import { BlazeLayout } from 'meteor/kadira:blaze-layout'; import { Template } from 'meteor/templating'; +import { ChatOAuthApps } from '../admin/collection'; FlowRouter.route('/oauth/authorize', { action(params, queryParams) { diff --git a/packages/rocketchat-oauth2-server-config/oauth/client/stylesheets/oauth2.css b/packages/rocketchat-oauth2-server-config/client/oauth/stylesheets/oauth2.css similarity index 100% rename from packages/rocketchat-oauth2-server-config/oauth/client/stylesheets/oauth2.css rename to packages/rocketchat-oauth2-server-config/client/oauth/stylesheets/oauth2.css diff --git a/packages/rocketchat-oauth2-server-config/package.js b/packages/rocketchat-oauth2-server-config/package.js index cad6a769f8bd..385315692e58 100644 --- a/packages/rocketchat-oauth2-server-config/package.js +++ b/packages/rocketchat-oauth2-server-config/package.js @@ -5,47 +5,18 @@ Package.describe({ }); Package.onUse(function(api) { - api.use('webapp'); - api.use('mongo'); - api.use('ecmascript'); - api.use('rocketchat:lib'); - api.use('rocketchat:api'); - api.use('rocketchat:theme'); - api.use('rocketchat:oauth2-server'); - - api.use('templating', 'client'); - api.use('kadira:flow-router', 'client'); - api.use('kadira:blaze-layout', 'client'); - - // // General // - // Server - api.addFiles('server/models/OAuthApps.js', 'server'); - - // // OAuth // - // Server - api.addFiles('oauth/server/oauth2-server.js', 'server'); - api.addFiles('oauth/server/default-services.js', 'server'); - - api.addFiles('oauth/client/stylesheets/oauth2.css', 'client'); - - // Client - api.addFiles('oauth/client/oauth2-client.html', 'client'); - api.addFiles('oauth/client/oauth2-client.js', 'client'); - - - // // Admin // - // Client - api.addFiles('admin/client/startup.js', 'client'); - api.addFiles('admin/client/collection.js', 'client'); - api.addFiles('admin/client/route.js', 'client'); - api.addFiles('admin/client/views/oauthApp.html', 'client'); - api.addFiles('admin/client/views/oauthApp.js', 'client'); - api.addFiles('admin/client/views/oauthApps.html', 'client'); - api.addFiles('admin/client/views/oauthApps.js', 'client'); - - // Server - api.addFiles('admin/server/publications/oauthApps.js', 'server'); - api.addFiles('admin/server/methods/addOAuthApp.js', 'server'); - api.addFiles('admin/server/methods/updateOAuthApp.js', 'server'); - api.addFiles('admin/server/methods/deleteOAuthApp.js', 'server'); + api.use([ + 'ecmascript', + 'webapp', + 'mongo', + 'rocketchat:lib', + 'rocketchat:api', + 'rocketchat:theme', + 'rocketchat:oauth2-server', + 'templating', + 'kadira:flow-router', + 'kadira:blaze-layout', + ]); + api.mainModule('client/index.js', 'client'); + api.mainModule('server/index.js', 'server'); }); diff --git a/packages/rocketchat-oauth2-server-config/admin/server/methods/addOAuthApp.js b/packages/rocketchat-oauth2-server-config/server/admin/methods/addOAuthApp.js similarity index 95% rename from packages/rocketchat-oauth2-server-config/admin/server/methods/addOAuthApp.js rename to packages/rocketchat-oauth2-server-config/server/admin/methods/addOAuthApp.js index 5d915849217b..75c08982cacf 100644 --- a/packages/rocketchat-oauth2-server-config/admin/server/methods/addOAuthApp.js +++ b/packages/rocketchat-oauth2-server-config/server/admin/methods/addOAuthApp.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { Random } from 'meteor/random'; +import { RocketChat } from 'meteor/rocketchat:lib'; import _ from 'underscore'; Meteor.methods({ diff --git a/packages/rocketchat-oauth2-server-config/admin/server/methods/deleteOAuthApp.js b/packages/rocketchat-oauth2-server-config/server/admin/methods/deleteOAuthApp.js similarity index 91% rename from packages/rocketchat-oauth2-server-config/admin/server/methods/deleteOAuthApp.js rename to packages/rocketchat-oauth2-server-config/server/admin/methods/deleteOAuthApp.js index b9baddc7ee55..d1fabde3b8c3 100644 --- a/packages/rocketchat-oauth2-server-config/admin/server/methods/deleteOAuthApp.js +++ b/packages/rocketchat-oauth2-server-config/server/admin/methods/deleteOAuthApp.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { RocketChat } from 'meteor/rocketchat:lib'; Meteor.methods({ deleteOAuthApp(applicationId) { diff --git a/packages/rocketchat-oauth2-server-config/admin/server/methods/updateOAuthApp.js b/packages/rocketchat-oauth2-server-config/server/admin/methods/updateOAuthApp.js similarity index 96% rename from packages/rocketchat-oauth2-server-config/admin/server/methods/updateOAuthApp.js rename to packages/rocketchat-oauth2-server-config/server/admin/methods/updateOAuthApp.js index 4e2813f52dc3..788fbebd2ccd 100644 --- a/packages/rocketchat-oauth2-server-config/admin/server/methods/updateOAuthApp.js +++ b/packages/rocketchat-oauth2-server-config/server/admin/methods/updateOAuthApp.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { RocketChat } from 'meteor/rocketchat:lib'; import _ from 'underscore'; Meteor.methods({ diff --git a/packages/rocketchat-oauth2-server-config/admin/server/publications/oauthApps.js b/packages/rocketchat-oauth2-server-config/server/admin/publications/oauthApps.js similarity index 86% rename from packages/rocketchat-oauth2-server-config/admin/server/publications/oauthApps.js rename to packages/rocketchat-oauth2-server-config/server/admin/publications/oauthApps.js index f982776b1d43..c6f872421f33 100644 --- a/packages/rocketchat-oauth2-server-config/admin/server/publications/oauthApps.js +++ b/packages/rocketchat-oauth2-server-config/server/admin/publications/oauthApps.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { RocketChat } from 'meteor/rocketchat:lib'; Meteor.publish('oauthApps', function() { if (!this.userId) { diff --git a/packages/rocketchat-oauth2-server-config/server/index.js b/packages/rocketchat-oauth2-server-config/server/index.js new file mode 100644 index 000000000000..0ca7e49a6905 --- /dev/null +++ b/packages/rocketchat-oauth2-server-config/server/index.js @@ -0,0 +1,7 @@ +import './models/OAuthApps'; +import './oauth/oauth2-server'; +import './oauth/default-services'; +import './admin/publications/oauthApps'; +import './admin/methods/addOAuthApp'; +import './admin/methods/updateOAuthApp'; +import './admin/methods/deleteOAuthApp'; diff --git a/packages/rocketchat-oauth2-server-config/server/models/OAuthApps.js b/packages/rocketchat-oauth2-server-config/server/models/OAuthApps.js index 5d6ecbc8701e..4d889bbd974a 100644 --- a/packages/rocketchat-oauth2-server-config/server/models/OAuthApps.js +++ b/packages/rocketchat-oauth2-server-config/server/models/OAuthApps.js @@ -1,3 +1,5 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + RocketChat.models.OAuthApps = new class extends RocketChat.models._Base { constructor() { super('oauth_apps'); diff --git a/packages/rocketchat-oauth2-server-config/oauth/server/default-services.js b/packages/rocketchat-oauth2-server-config/server/oauth/default-services.js similarity index 88% rename from packages/rocketchat-oauth2-server-config/oauth/server/default-services.js rename to packages/rocketchat-oauth2-server-config/server/oauth/default-services.js index 6ff8ced688b2..156d79920211 100644 --- a/packages/rocketchat-oauth2-server-config/oauth/server/default-services.js +++ b/packages/rocketchat-oauth2-server-config/server/oauth/default-services.js @@ -1,3 +1,5 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + if (!RocketChat.models.OAuthApps.findOne('zapier')) { RocketChat.models.OAuthApps.insert({ _id: 'zapier', diff --git a/packages/rocketchat-oauth2-server-config/oauth/server/oauth2-server.js b/packages/rocketchat-oauth2-server-config/server/oauth/oauth2-server.js similarity index 95% rename from packages/rocketchat-oauth2-server-config/oauth/server/oauth2-server.js rename to packages/rocketchat-oauth2-server-config/server/oauth/oauth2-server.js index 77cca296e015..ec1da72899c6 100644 --- a/packages/rocketchat-oauth2-server-config/oauth/server/oauth2-server.js +++ b/packages/rocketchat-oauth2-server-config/server/oauth/oauth2-server.js @@ -1,6 +1,7 @@ -/* global OAuth2Server */ import { Meteor } from 'meteor/meteor'; import { WebApp } from 'meteor/webapp'; +import { RocketChat } from 'meteor/rocketchat:lib'; +import { OAuth2Server } from 'meteor/rocketchat:oauth2-server'; const oauth2server = new OAuth2Server({ accessTokensCollectionName: 'rocketchat_oauth_access_tokens',