[IMPROVE] Replace stdout publication by REST (#16004)

pull/16036/head
Marcos Spessatto Defendi 6 years ago committed by Diego Sampaio
parent a632a32979
commit 08cb4999be
  1. 18
      app/api/server/v1/misc.js
  2. 2
      app/logger/client/viewLogs.js
  3. 14
      app/logger/client/views/viewLogs.js
  4. 18
      app/logger/server/publish.js

@ -3,13 +3,14 @@ import { check } from 'meteor/check';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import s from 'underscore.string';
import { hasRole } from '../../../authorization';
import { Info } from '../../../utils';
import { Users } from '../../../models';
import { settings } from '../../../settings';
import { hasRole, hasPermission } from '../../../authorization/server';
import { Info } from '../../../utils/server';
import { Users } from '../../../models/server';
import { settings } from '../../../settings/server';
import { API } from '../api';
import { getDefaultUserFields } from '../../../utils/server/functions/getDefaultUserFields';
import { getURL } from '../../../utils/lib/getURL';
import { StdOut } from '../../../logger/server/publish';
// DEPRECATED
@ -202,3 +203,12 @@ API.v1.addRoute('directory', { authRequired: true }, {
});
},
});
API.v1.addRoute('stdout.queue', { authRequired: true }, {
get() {
if (!hasPermission(this.userId, 'view-logs')) {
return API.v1.unauthorized();
}
return API.v1.success({ queue: StdOut.queue });
},
});

@ -7,7 +7,7 @@ import { AdminBox } from '../../ui-utils';
import { hasAllPermission } from '../../authorization';
import { t } from '../../utils';
export const stdout = new Mongo.Collection('stdout');
export const stdout = new Mongo.Collection(null);
Meteor.startup(function() {
AdminBox.addOption({

@ -9,12 +9,22 @@ import { hasAllPermission } from '../../../authorization';
import { SideNav } from '../../../ui-utils/client';
import './viewLogs.html';
import './viewLogs.css';
import { APIClient } from '../../../utils/client';
Template.viewLogs.onCreated(function() {
this.subscribe('stdout');
const stdoutStreamer = new Meteor.Streamer('stdout');
Template.viewLogs.onCreated(async function() {
const { queue } = await APIClient.v1.get('stdout.queue');
(queue || []).forEach((item) => stdout.insert(item));
stdoutStreamer.on('stdout', (item) => stdout.insert(item));
this.atBottom = true;
});
Template.viewLogs.onDestroyed(() => {
stdout.remove({});
stdoutStreamer.removeListener('stdout');
});
Template.viewLogs.helpers({
hasPermission() {
return hasAllPermission('view-logs');

@ -6,7 +6,7 @@ import { EJSON } from 'meteor/ejson';
import { Log } from 'meteor/logging';
import { settings } from '../../settings';
import { hasPermission } from '../../authorization';
import { hasPermission } from '../../authorization/server';
export const processString = function(string, date) {
let obj;
@ -52,12 +52,26 @@ export const StdOut = new class extends EventEmitter {
}
}();
const stdoutStreamer = new Meteor.Streamer('stdout');
stdoutStreamer.allowWrite('none');
stdoutStreamer.allowRead(function() {
return this.userId ? hasPermission(this.userId, 'view-logs') : false;
});
Meteor.startup(() => {
const handler = (string, item) => {
stdoutStreamer.emit('stdout', {
...item,
});
};
StdOut.on('write', handler);
});
Meteor.publish('stdout', function() {
console.warn('The publication "stdout" is deprecated and will be removed after version v3.0.0');
if (!this.userId || hasPermission(this.userId, 'view-logs') !== true) {
return this.ready();
}
const handler = (string, item) => {
this.added('stdout', item.id, {
string: item.string,

Loading…
Cancel
Save