Skip to content

Commit

Permalink
Merge branch '#8381-search_provider_concept' of https://github.com/re…
Browse files Browse the repository at this point in the history
…dlink-gmbh/Rocket.Chat into redlink-local/#8381-search_provider_concept
  • Loading branch information
tkurz committed Apr 19, 2018
2 parents 08449c9 + fe5cf57 commit eb1561c
Show file tree
Hide file tree
Showing 39 changed files with 439 additions and 270 deletions.
7 changes: 0 additions & 7 deletions .meteor/.id

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
],
"scripts": {
"start": "meteor npm i && meteor",
"debug": "meteor run --inspect",
"lint": "eslint .",
"lint-fix": "eslint . --fix",
"stylelint": "stylelint packages/**/*.css",
Expand Down
23 changes: 0 additions & 23 deletions packages/rocketchat-api/server/v1/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@ RocketChat.API.v1.addRoute('info', { authRequired: false }, {
}
});

RocketChat.API.v1.addRoute('settings.oauth', { authRequired: false }, {
get() {
const mountOAuthServices = () => {
const oAuthServicesEnabled = ServiceConfiguration.configurations.find({}).fetch();

return oAuthServicesEnabled.map((service) => {
return {
id: service._id,
name: service.service,
appId: service.appId || service.clientId,
buttonLabelText: service.buttonLabelText || '',
buttonColor: service.buttonColor || '',
buttonLabelColor: service.buttonLabelColor || ''
};
});
};

return RocketChat.API.v1.success({
services: mountOAuthServices()
});
}
});

RocketChat.API.v1.addRoute('me', { authRequired: true }, {
get() {
const me = _.pick(this.user, [
Expand Down
29 changes: 28 additions & 1 deletion packages/rocketchat-api/server/v1/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ RocketChat.API.v1.addRoute('settings.public', { authRequired: false }, {
}
});

RocketChat.API.v1.addRoute('settings.oauth', { authRequired: false }, {
get() {
const mountOAuthServices = () => {
const oAuthServicesEnabled = ServiceConfiguration.configurations.find({}).fetch();

return oAuthServicesEnabled.map((service) => {
if (service.custom) {
return { ...service };
}
return {
id: service._id,
name: service.service,
clientId: service.appId || service.clientId,
buttonLabelText: service.buttonLabelText || '',
buttonColor: service.buttonColor || '',
buttonLabelColor: service.buttonLabelColor || '',
custom: false
};
});
};

return RocketChat.API.v1.success({
services: mountOAuthServices()
});
}
});

RocketChat.API.v1.addRoute('settings', { authRequired: true }, {
get() {
const { offset, count } = this.getPaginationItems();
Expand Down Expand Up @@ -90,7 +117,7 @@ RocketChat.API.v1.addRoute('service.configurations', { authRequired: false }, {
const ServiceConfiguration = Package['service-configuration'].ServiceConfiguration;

return RocketChat.API.v1.success({
configurations: ServiceConfiguration.configurations.find({}, {fields: {secret: 0}}).fetch()
configurations: ServiceConfiguration.configurations.find({}, { fields: { secret: 0 } }).fetch()
});
}
});
2 changes: 1 addition & 1 deletion packages/rocketchat-apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ An orchestrator is the file/class which is responsible for orchestrating (starti
A bridge is a file/class which is responsible for bridging the Rocket.Chat system's data and the App system's data. They are implementations of the interfaces inside of the Rocket.Chat Apps-engine project `src/server/bridges`. They allow the two systems to talk to each other (hince the name bridge, as they "bridge the gap").

## What is a "Converter"?
A converter does what the name implies, it handles converting from one system's data type into the other's.
A converter does what the name implies, it handles converting from one system's data type into the other's. **Note**: This causes a schema to be forced on the rooms and messages.
24 changes: 22 additions & 2 deletions packages/rocketchat-apps/client/admin/appInstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ Template.appInstall.onCreated(function() {
instance.file = new ReactiveVar('');
instance.isInstalling = new ReactiveVar(false);
instance.appUrl = new ReactiveVar('');
instance.isUpdatingId = new ReactiveVar('');

// Allow passing in a url as a query param to show installation of
if (FlowRouter.getQueryParam('url')) {
instance.appUrl.set(FlowRouter.getQueryParam('url'));
FlowRouter.setQueryParams({ url: null });
}

if (FlowRouter.getQueryParam('isUpdatingId')) {
instance.isUpdatingId.set(FlowRouter.getQueryParam('isUpdatingId'));
}
});

Template.appInstall.events({
Expand All @@ -55,13 +60,21 @@ Template.appInstall.events({
if (url) {
try {
t.isInstalling.set(true);
const result = await RocketChat.API.post('apps', { url });
let result;

if (t.isUpdatingId.get()) {
result = await RocketChat.API.post(`apps/${ t.isUpdatingId.get() }`, { url });
} else {
result = await RocketChat.API.post('apps', { url });
}

FlowRouter.go(`/admin/apps/${ result.app.id }`);
} catch (err) {
console.warn('err', err);
} finally {
t.isInstalling.set(false);
}

return;
}

Expand All @@ -85,7 +98,14 @@ Template.appInstall.events({

t.isInstalling.set(true);
try {
const result = await RocketChat.API.upload('apps', data);
let result;

if (t.isUpdatingId.get()) {
result = await RocketChat.API.upload(`apps/${ t.isUpdatingId.get() }`, data);
} else {
result = await RocketChat.API.upload('apps', data);
}

FlowRouter.go(`/admin/apps/${ result.app.id }`);
} catch (err) {
console.warn('err', err);
Expand Down
10 changes: 7 additions & 3 deletions packages/rocketchat-apps/client/admin/appLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ Template.appLogs.helpers({
return moment(date).format('L LTS');
},
jsonStringify(data) {
let value = '';

if (!data) {
return '';
return value;
} else if (typeof data === 'object') {
return hljs.highlight('json', JSON.stringify(data, null, 2)).value;
value = hljs.highlight('json', JSON.stringify(data, null, 2)).value;
} else {
return hljs.highlight('json', data).value;
value = hljs.highlight('json', data).value;
}

return value.replace(/\\\\n/g, '<br>');
}
});

Expand Down
8 changes: 5 additions & 3 deletions packages/rocketchat-apps/client/admin/appManage.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="rc-apps-details__content">
<div class="rc-apps-details__row">
<div class="rc-apps-details__name">{{name}}</div>
<div class="rc-apps-details__version">v {{version}}</div>
<div class="rc-apps-details__version">v{{version}}</div>
</div>
<div class="rc-apps-details__row">{{description}}</div>
<div class="rc-apps-details__row">
Expand All @@ -37,13 +37,13 @@
{{#if author.homepage}}
<a href="{{author.homepage}}" class="rc-apps-details__item">
{{> icon icon='permalink'}}
author homepage
{{_ "App_author_homepage"}}
</a>
{{/if}}
{{#if author.support}}
<a href="{{author.support}}" class="rc-apps-details__item">
{{> icon icon='at'}}
support url
{{_ "App_support_url"}}
</a>
{{/if}}
</div>
Expand Down Expand Up @@ -384,6 +384,8 @@
<button class="rc-button rc-button--secondary js-cancel">{{ _ "Cancel" }}</button>
<button class="rc-button rc-button--primary js-save {{#if saving}} loading{{/if}}" disabled='{{disabled}}'>{{ _ "Save" }}</button>
<button class="rc-button rc-button--cancel js-uninstall">{{ _ "Uninstall" }}</button>
<button class="rc-button rc-button--secondary js-update">{{_ "Update" }}</button>
<button class="rc-button rc-button--secondary js-view-logs">{{_ "View_Logs" }}</button>
</div>
</div>
{{else if hasError}}
Expand Down
8 changes: 6 additions & 2 deletions packages/rocketchat-apps/client/admin/appManage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Template.appManage.onCreated(function() {
function _morphSettings(settings) {
Object.keys(settings).forEach((k) => {
settings[k].i18nPlaceholder = settings[k].i18nPlaceholder || ' ';
settings[k].value = settings[k].value !== undefined ? settings[k].value : settings[k].packageValue;
settings[k].value = settings[k].value !== undefined && settings[k].value !== null ? settings[k].value : settings[k].packageValue;
settings[k].oldValue = settings[k].value;
settings[k].hasChanged = false;
});
Expand Down Expand Up @@ -208,7 +208,11 @@ Template.appManage.events({
}
},

'click .logs': (e, t) => {
'click .js-update': (e, t) => {
FlowRouter.go(`/admin/app/install?isUpdatingId=${ t.id.get() }`);
},

'click .js-view-logs': (e, t) => {
FlowRouter.go(`/admin/apps/${ t.id.get() }/logs`);
},

Expand Down
10 changes: 5 additions & 5 deletions packages/rocketchat-apps/client/admin/apps.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<table class="rc-table">
<thead class="rc-table-head">
<tr class="rc-table-tr">
<td class="rc-table-td">Name</td>
<td class="rc-table-td">Version</td>
<td class="rc-table-td">Status</td>
<td class="rc-table-td">{{_ "Name"}}</td>
<td class="rc-table-td">{{_ "Version"}}</td>
<td class="rc-table-td">{{_ "Status"}}</td>
<td class="rc-table-td"></td>
</tr>
</thead>
Expand All @@ -33,7 +33,7 @@
</td>
<td class="rc-table-td rc-table-td--users">{{version}}</td>
<td class="rc-table-td">
{{status}}
{{parseStatus status}}
</td>
<td class="rc-table-td">
<button class="rc-button rc-button--nude rc-tooltip manage" aria-label="{{_ "Manage_the_App"}}">
Expand All @@ -44,7 +44,7 @@
{{else}}
<tr class="rc-table-tr" data-name="{{name}}">
<td class="rc-table-td rc-table-td--name">
you dont have any app installed :/
{{_ "There_are_no_applications_installed"}}
</td>
</tr>
{{/each}}
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-apps/client/admin/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Template.apps.helpers({
},
apps() {
return Template.instance().apps.get();
},
parseStatus(status) {
return t(`App_status_${ status }`);
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-apps/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ Package.onUse(function(api) {

Npm.depends({
'busboy': '0.2.13',
'@rocket.chat/apps-engine': '0.4.8',
'@rocket.chat/apps-ts-definition': '0.7.15'
'@rocket.chat/apps-engine': '0.5.11',
'@rocket.chat/apps-ts-definition': '0.9.6'
});
16 changes: 8 additions & 8 deletions packages/rocketchat-apps/server/bridges/activation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ export class AppActivationBridge {
this.orch = orch;
}

appAdded(app) {
this.orch.getNotifier().appAdded(app.getID());
async appAdded(app) {
await this.orch.getNotifier().appAdded(app.getID());
}

appUpdated(app) {
this.orch.getNotifier().appUpdated(app.getID());
async appUpdated(app) {
await this.orch.getNotifier().appUpdated(app.getID());
}

appRemoved(app) {
this.orch.getNotifier().appRemoved(app.getID());
async appRemoved(app) {
await this.orch.getNotifier().appRemoved(app.getID());
}

appStatusChanged(app, status) {
this.orch.getNotifier().appStatusUpdated(app.getID(), status);
async appStatusChanged(app, status) {
await this.orch.getNotifier().appStatusUpdated(app.getID(), status);
}
}
6 changes: 3 additions & 3 deletions packages/rocketchat-apps/server/bridges/environmental.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class AppEnvironmentalVariableBridge {
this.allowed = ['NODE_ENV', 'ROOT_URL', 'INSTANCE_IP'];
}

getValueByName(envVarName, appId) {
async getValueByName(envVarName, appId) {
console.log(`The App ${ appId } is getting the environmental variable value ${ envVarName }.`);

if (this.isReadable(envVarName, appId)) {
Expand All @@ -14,13 +14,13 @@ export class AppEnvironmentalVariableBridge {
throw new Error(`The environmental variable "${ envVarName }" is not readable.`);
}

isReadable(envVarName, appId) {
async isReadable(envVarName, appId) {
console.log(`The App ${ appId } is checking if the environmental variable is readable ${ envVarName }.`);

return this.allowed.includes(envVarName.toUpperCase());
}

isSet(envVarName, appId) {
async isSet(envVarName, appId) {
console.log(`The App ${ appId } is checking if the environmental variable is set ${ envVarName }.`);

if (this.isReadable(envVarName, appId)) {
Expand Down
10 changes: 5 additions & 5 deletions packages/rocketchat-apps/server/bridges/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export class AppHttpBridge {

console.log(`The App ${ info.appId } is requesting from the outter webs:`, info);

try {
return HTTP.call(info.method, info.url, info.request);
} catch (e) {
return e.response;
}
return new Promise((resolve, reject) => {
HTTP.call(info.method, info.url, info.request, (e, result) => {
return e ? reject(e.response) : resolve(result);
});
});
}
}
32 changes: 28 additions & 4 deletions packages/rocketchat-apps/server/bridges/listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,37 @@ export class AppListenerBridge {
this.orch = orch;
}

messageEvent(inte, message) {
async messageEvent(inte, message) {
const msg = this.orch.getConverters().get('messages').convertMessage(message);
return this.orch.getManager().getListenerManager().executeListener(inte, msg);
const result = await this.orch.getManager().getListenerManager().executeListener(inte, msg);

if (typeof result === 'boolean') {
return result;
} else {
return this.orch.getConverters().get('messages').convertAppMessage(result);
}
// try {

// } catch (e) {
// console.log(`${ e.name }: ${ e.message }`);
// console.log(e.stack);
// }
}

roomEvent(inte, room) {
async roomEvent(inte, room) {
const rm = this.orch.getConverters().get('rooms').convertRoom(room);
return this.orch.getManager().getListenerManager().executeListener(inte, rm);
const result = await this.orch.getManager().getListenerManager().executeListener(inte, rm);

if (typeof result === 'boolean') {
return result;
} else {
return this.orch.getConverters().get('rooms').convertAppRoom(result);
}
// try {

// } catch (e) {
// console.log(`${ e.name }: ${ e.message }`);
// console.log(e.stack);
// }
}
}
Loading

0 comments on commit eb1561c

Please sign in to comment.