Skip to content

Commit

Permalink
Prevent setup wizard redirects (#10811)
Browse files Browse the repository at this point in the history
* Prevent setup wizard redirects

* Fix setup wizard layout

* Prometheus: Track user agent
  • Loading branch information
rodrigok committed May 18, 2018
1 parent c297420 commit 2117624
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/rocketchat-api/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ class API extends Restivus {
const rocketchatRestApiEnd = RocketChat.metrics.rocketchatRestApi.startTimer({
method,
version,
user_agent: this.request.headers['user-agent'],
entrypoint: route
});

this.logger.debug(`${ this.request.method.toUpperCase() }: ${ this.request.url }`);
let result;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function shouldNotifyAudio({
}

export function notifyAudioUser(userId, message, room) {
RocketChat.metrics.notificationsSent.inc({ notification_type: 'audio' }, 1, new Date());
RocketChat.metrics.notificationsSent.inc({ notification_type: 'audio' });
RocketChat.Notifications.notifyUser(userId, 'audioNotification', {
payload: {
_id: message._id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function notifyDesktopUser({
return;
}

RocketChat.metrics.notificationsSent.inc({ notification_type: 'desktop' }, 1, new Date());
RocketChat.metrics.notificationsSent.inc({ notification_type: 'desktop' });
RocketChat.Notifications.notifyUser(userId, 'notification', {
title,
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function sendEmail({ message, user, subscription, room, emailAddress, toA
}

Meteor.defer(() => {
RocketChat.metrics.notificationsSent.inc({ notification_type: 'email' }, 1, new Date());
RocketChat.metrics.notificationsSent.inc({ notification_type: 'email' });
Email.send(email);
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/server/lib/PushNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PushNotification {
};
}

RocketChat.metrics.notificationsSent.inc({ notification_type: 'mobile' }, 1, new Date());
RocketChat.metrics.notificationsSent.inc({ notification_type: 'mobile' });
return Push.send(config);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-lib/server/lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RocketChat.metrics.rocketchatHooks = new client.Summary({
RocketChat.metrics.rocketchatRestApi = new client.Summary({
name: 'rocketchat_rest_api',
help: 'summary of rocketchat rest api count and time',
labelNames: ['method', 'entrypoint', 'status', 'version']
labelNames: ['method', 'entrypoint', 'user_agent', 'status', 'version']
});

RocketChat.metrics.meteorSubscriptions = new client.Summary({
Expand All @@ -41,7 +41,7 @@ RocketChat.metrics.meteorSubscriptions = new client.Summary({
});

RocketChat.metrics.messagesSent = new client.Counter({'name': 'rocketchat_message_sent', 'help': 'cumulated number of messages sent'});
RocketChat.metrics.notificationsSent = new client.Counter({'name': 'rocketchat_notification_sent', labelNames: ['type'], 'help': 'cumulated number of notifications sent'});
RocketChat.metrics.notificationsSent = new client.Counter({'name': 'rocketchat_notification_sent', labelNames: ['notification_type'], 'help': 'cumulated number of notifications sent'});

RocketChat.metrics.ddpSessions = new client.Gauge({'name': 'rocketchat_ddp_sessions_count', 'help': 'number of open ddp sessions'});
RocketChat.metrics.ddpAthenticatedSessions = new client.Gauge({'name': 'rocketchat_ddp_sessions_auth', 'help': 'number of authenticated open ddp sessions'});
Expand Down
38 changes: 30 additions & 8 deletions packages/rocketchat-setup-wizard/client/setupWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ const setSettingsAndGo = (settings, registerServer = true) => {

Template.setupWizard.onCreated(function() {
const userId = Meteor.userId();
const Show_Setup_Wizard = RocketChat.settings.get('Show_Setup_Wizard');

if (!userId || Show_Setup_Wizard === 'completed' || !RocketChat.authz.hasRole(userId, 'admin')) {
FlowRouter.go('home');
}
this.autorun((c) => {
const Show_Setup_Wizard = RocketChat.settings.get('Show_Setup_Wizard');
const user = Meteor.user();

// Wait for roles and setup wizard setting
if ((userId && (!user || !user.status)) || !Show_Setup_Wizard) {
return;
}

c.stop();

if ((!userId && Show_Setup_Wizard !== 'pending') || Show_Setup_Wizard === 'completed' || (userId && !RocketChat.authz.hasRole(userId, 'admin'))) {
FlowRouter.go('home');
}
});

if (localStorage.getItem('wizardFinal')) {
FlowRouter.go('setup-wizard-final');
Expand Down Expand Up @@ -253,11 +264,22 @@ Template.setupWizard.helpers({
Template.setupWizardFinal.onCreated(function() {
this.autorun(() => {
const userId = Meteor.userId();
const Show_Setup_Wizard = RocketChat.settings.get('Show_Setup_Wizard');

if (!userId || Show_Setup_Wizard === 'completed' || !RocketChat.authz.hasRole(userId, 'admin')) {
FlowRouter.go('home');
}
this.autorun((c) => {
const Show_Setup_Wizard = RocketChat.settings.get('Show_Setup_Wizard');
const user = Meteor.user();

// Wait for roles and setup wizard setting
if ((userId && (!user || !user.status)) || !Show_Setup_Wizard) {
return;
}

c.stop();

if ((!userId && Show_Setup_Wizard !== 'pending') || Show_Setup_Wizard === 'completed' || (userId && !RocketChat.authz.hasRole(userId, 'admin'))) {
FlowRouter.go('home');
}
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
justify-content: center;

&-info {
flex: 0 0 auto;
flex: 0 1 auto;

margin: 55px 65px 30px 80px;

Expand Down

0 comments on commit 2117624

Please sign in to comment.