Skip to content

Commit

Permalink
Wizard improvements (#10776)
Browse files Browse the repository at this point in the history
* Change wizard state from boolean to `pending`, `in_progress` or `completed`
* Add migration to change the wizard setting to new values and fix the old migration
* Make the wizard responsive for small screens
* Do not publish wizard settings to the client
* Do not show wizard for unlogged users after admin was created
  • Loading branch information
rodrigok committed May 15, 2018
1 parent db2492c commit 7e25b1c
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 98 deletions.
27 changes: 15 additions & 12 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,21 @@ RocketChat.settings.addGroup('OAuth', function() {
});

RocketChat.settings.addGroup('General', function() {
this.add('Show_Setup_Wizard', true, {
type: 'boolean',
public: true
this.add('Show_Setup_Wizard', 'pending', {
type: 'select',
public: true,
values: [
{
key: 'pending',
i18nLabel: 'Pending'
}, {
key: 'in_progress',
i18nLabel: 'In_progress'
}, {
key: 'completed',
i18nLabel: 'Completed'
}
]
});
this.add('Site_Url', typeof __meteor_runtime_config__ !== 'undefined' && __meteor_runtime_config__ !== null ? __meteor_runtime_config__.ROOT_URL : null, {
type: 'string',
Expand All @@ -639,15 +651,13 @@ RocketChat.settings.addGroup('General', function() {
});
this.add('Site_Name', 'Rocket.Chat', {
type: 'string',
'public': true,
wizard: {
step: 3,
order: 0
}
});
this.add('Language', '', {
type: 'language',
'public': true,
wizard: {
step: 3,
order: 1
Expand Down Expand Up @@ -1666,15 +1676,13 @@ RocketChat.settings.addGroup('Setup_Wizard', function() {
i18nLabel: 'Community'
}
],
public: true,
wizard: {
step: 2,
order: 0
}
});
this.add('Organization_Name', '', {
type: 'string',
public: true,
wizard: {
step: 2,
order: 1
Expand Down Expand Up @@ -1784,7 +1792,6 @@ RocketChat.settings.addGroup('Setup_Wizard', function() {
i18nLabel: 'Other'
}
],
public: true,
wizard: {
step: 2,
order: 2
Expand Down Expand Up @@ -1826,7 +1833,6 @@ RocketChat.settings.addGroup('Setup_Wizard', function() {
i18nLabel: '4000 or more people'
}
],
public: true,
wizard: {
step: 2,
order: 3
Expand Down Expand Up @@ -2796,15 +2802,13 @@ RocketChat.settings.addGroup('Setup_Wizard', function() {
i18nLabel: 'Country_Zimbabwe'
}
],
public: true,
wizard: {
step: 2,
order: 4
}
});
this.add('Website', '', {
type: 'string',
public: true,
wizard: {
step: 2,
order: 5
Expand All @@ -2822,7 +2826,6 @@ RocketChat.settings.addGroup('Setup_Wizard', function() {
i18nLabel: 'Public_Community'
}
],
public: true,
wizard: {
step: 3,
order: 2
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-setup-wizard/client/setupWizard.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ <h1 class="setup-wizard-info__content-title setup-wizard-final__box-title">{{_ "
</template>

<template name="setupWizard">
<div class="rc-old connection-status">
{{> status}}
</div>
<div class="setup-wizard">
<section class="setup-wizard-info">
<header class="setup-wizard-info__header">
Expand Down Expand Up @@ -105,6 +108,7 @@ <h1 class="setup-wizard-forms__header-title">{{headerTitle}}</h1>
<div class="rc-input__title">{{_ i18nLabel}}</div>
<div class="rc-select">
<select class="rc-select__element js-setting-data" name="{{_id}}">
<option value="" disabled selected="{{selectedValue _id undefined}}">{{_ "Select_an_option"}}</option>
{{#each values}}
<option class="rc-select__option" value="{{key}}" selected="{{selectedValue ../_id key}}">{{_ i18nLabel}}</option>
{{/each}}
Expand Down
16 changes: 13 additions & 3 deletions packages/rocketchat-setup-wizard/client/setupWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ 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');
}

if (localStorage.getItem('wizardFinal')) {
FlowRouter.go('setup-wizard-final');
}
Expand Down Expand Up @@ -60,7 +67,7 @@ Template.setupWizard.onCreated(function() {
this.state.set('currentStep', 1);
}

if (RocketChat.settings.get('Show_Setup_Wizard') === false) {
if (RocketChat.settings.get('Show_Setup_Wizard') === 'completed') {
FlowRouter.go('home');
}

Expand Down Expand Up @@ -245,7 +252,10 @@ Template.setupWizard.helpers({

Template.setupWizardFinal.onCreated(function() {
Tracker.autorun(() => {
if (RocketChat.settings.get('Show_Setup_Wizard') === false) {
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');
}
});
Expand All @@ -257,7 +267,7 @@ Template.setupWizardFinal.onRendered(function() {

Template.setupWizardFinal.events({
'click .js-finish'() {
RocketChat.settings.set('Show_Setup_Wizard', false, function() {
RocketChat.settings.set('Show_Setup_Wizard', 'completed', function() {
localStorage.removeItem('wizard');
localStorage.removeItem('wizardFinal');
FlowRouter.go('home');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
justify-content: center;

&-info {
flex: 0 0 350px;
flex: 0 0 auto;

margin: 55px 65px 0 80px;
margin: 55px 65px 30px 80px;

&__header{
display: flex;
Expand Down Expand Up @@ -463,3 +463,15 @@
}
}
}

@media (width <= 760px) {
.setup-wizard {
flex-direction: column;
justify-content: initial;

& .setup-wizard-forms__wrapper {
margin: 0;
width: 100%;
}
}
}
11 changes: 6 additions & 5 deletions packages/rocketchat-ui-master/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ Template.main.helpers({
}
},
showSetupWizard() {
if (RocketChat.settings.get('Show_Setup_Wizard') === false) {
return false;
}
const userId = Meteor.userId();
const Show_Setup_Wizard = RocketChat.settings.get('Show_Setup_Wizard');

return true;
return (!userId && Show_Setup_Wizard === 'pending') || (userId && RocketChat.authz.hasRole(userId, 'admin') && Show_Setup_Wizard === 'in_progress');
}
});

Expand All @@ -197,9 +196,11 @@ Template.main.onRendered(function() {
}, 100);
});
return Tracker.autorun(function() {
const userId = Meteor.userId();
const user = Meteor.user();
const Show_Setup_Wizard = RocketChat.settings.get('Show_Setup_Wizard');

if (RocketChat.settings.get('Show_Setup_Wizard')) {
if ((!userId && Show_Setup_Wizard === 'pending') || (userId && RocketChat.authz.hasRole(userId, 'admin') && Show_Setup_Wizard === 'in_progress')) {
FlowRouter.go('setup-wizard');
}

Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-ui/client/lib/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ this.menu.on('clickOut', function() {
});

this.menu.on('close', function() {
if (!this.sidebar) {
return;
}

this.sidebar.css('transition', '');
this.sidebarWrap.css('transition', '');
if (passClosePopover) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui/client/lib/tapi18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ this.tr = function(key, options, ...replaces) {
};

this.isRtl = (lang) => {
const language = lang ? lang : localStorage.getItem('userLanguage');
const language = lang ? lang : localStorage.getItem('userLanguage') ? localStorage.getItem('userLanguage') : 'en-US';
return ['ar', 'dv', 'fa', 'he', 'ku', 'ps', 'sd', 'ug', 'ur', 'yi'].includes(language.split('-').shift().toLowerCase());
};
3 changes: 3 additions & 0 deletions server/lib/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ Accounts.insertUserDoc = _.wrap(Accounts.insertUserDoc, function(insertUserDoc,
roles.push('user');
} else {
roles.push('admin');
if (RocketChat.settings.get('Show_Setup_Wizard') === 'pending') {
RocketChat.models.Settings.updateValueById('Show_Setup_Wizard', 'in_progress');
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions server/startup/initialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ Meteor.startup(function() {

if (oldestUser) {
RocketChat.authz.addUserRoles(oldestUser._id, 'admin');
if (RocketChat.settings.get('Show_Setup_Wizard') === 'pending') {
RocketChat.models.Settings.updateValueById('Show_Setup_Wizard', 'in_progress');
}
console.log(`No admins are found. Set ${ oldestUser.username } as admin for being the oldest user`);
}
}
Expand Down Expand Up @@ -188,6 +191,10 @@ Meteor.startup(function() {

RocketChat.authz.addUserRoles(adminUser._id, 'admin');

if (RocketChat.settings.get('Show_Setup_Wizard') === 'pending') {
RocketChat.models.Settings.updateValueById('Show_Setup_Wizard', 'in_progress');
}

return RocketChat.addUserToDefaultChannels(adminUser, true);
}
});
Expand Down
14 changes: 8 additions & 6 deletions server/startup/migrations/v117.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
RocketChat.Migrations.add({
version: 117,
up() {
if (RocketChat &&
RocketChat.authz &&
RocketChat.authz.getUsersInRole('admin').count() &&
if (RocketChat.authz &&
RocketChat.models &&
RocketChat.models.Settings) {
RocketChat.models.Settings &&
RocketChat.authz.getUsersInRole('admin').count()) {
RocketChat.models.Settings.upsert(
{ _id: 'Show_Setup_Wizard' },
{ $set: { value: false }}
{
_id: 'Show_Setup_Wizard'
}, {
$set: { value: 'completed' }
}
);
}
}
Expand Down
20 changes: 20 additions & 0 deletions server/startup/migrations/v119.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
RocketChat.Migrations.add({
version: 119,
up() {
if (RocketChat.models && RocketChat.models.Settings) {
RocketChat.models.Settings.update({
_id: 'Show_Setup_Wizard',
value: true
}, {
$set: { value: 'pending' }
});

RocketChat.models.Settings.update({
_id: 'Show_Setup_Wizard',
value: false
}, {
$set: { value: 'completed' }
});
}
}
});
Loading

0 comments on commit 7e25b1c

Please sign in to comment.