Skip to content

Commit

Permalink
MM-34569 - remove step 3 to guests (mattermost#7838)
Browse files Browse the repository at this point in the history
* MM-34569 - remove step 3 to guests

* add the system_user to the roles step array

* Add the system admin role too to the condition

* revert to only system user

* duplicate the step so it shows also for admins

* make sure that the admin is in the condition

* fix the helper filter methods and the roles

* fix the right roles to first admin

* fix the firstAdmin roles in the nextStepNotFinished

* add comment and fix tests

Co-authored-by: Pablo Velez Vidal <[email protected]>
Co-authored-by: Mattermod <[email protected]>
  • Loading branch information
3 people committed Apr 14, 2021
1 parent dbf45b1 commit 4ee98ba
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
4 changes: 1 addition & 3 deletions components/next_steps_view/step_helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {isEqual} from 'lodash';

import {StepType} from './steps';

export function getAnalyticsCategory(isAdmin: boolean) {
Expand All @@ -13,7 +11,7 @@ export function getAnalyticsCategory(isAdmin: boolean) {
export function isStepForUser(step: StepType, roles: string): boolean {
const userRoles = roles.split(' ');
return (
isEqual(userRoles.sort(), step.roles.sort()) ||
userRoles.some((role) => step.roles.includes(role)) ||
step.roles.length === 0
);
}
27 changes: 25 additions & 2 deletions components/next_steps_view/steps.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ describe('components/next_steps_view/steps', () => {
name: 'team_setup',
value: 'true',
},
'recommended_next_steps--notification_setup': {
name: 'notification_setup',
value: 'true',
},
'recommended_next_steps--invite_members': {
name: 'invite_members',
value: 'true',
Expand All @@ -95,7 +99,7 @@ describe('components/next_steps_view/steps', () => {
users: {
currentUserId: 'current_user_id',
profiles: {
current_user_id: {roles: 'system_role'},
current_user_id: {roles: 'system_user'},
},
},
},
Expand All @@ -120,7 +124,26 @@ describe('components/next_steps_view/steps', () => {
},
},
};
expect(getSteps(state as any)).toHaveLength(3);
expect(getSteps(state as any)).toHaveLength(4);
});

test('should only show the complete_profile_step to guest users', () => {
const state = {
entities: {
general: {
license: {
Cloud: 'true',
},
},
users: {
currentUserId: 'current_user_id',
profiles: {
current_user_id: {roles: 'system_guest'},
},
},
},
};
expect(getSteps(state as any)).toHaveLength(1);
});

test('should only show non-admin steps for non-admin users', () => {
Expand Down
16 changes: 5 additions & 11 deletions components/next_steps_view/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type StepType = {
// An array of all roles a user must have in order to see the step e.g. admins are both system_admin and system_user
// so you would require ['system_admin','system_user'] to match.
// to show step for all roles, leave the roles array blank.
// for a step that must be shown only to the first admin, add the first_admin role to that step
roles: string[];
};

Expand All @@ -56,7 +57,7 @@ export const Steps: StepType[] = [
'next_steps_view.titles.teamSetup',
'Name your team',
),
roles: ['system_admin', 'system_user'],
roles: ['first_admin'],
component: TeamProfileStep,
visible: true,
},
Expand Down Expand Up @@ -86,7 +87,7 @@ export const Steps: StepType[] = [
'next_steps_view.titles.inviteMembers',
'Invite members to the team',
),
roles: [],
roles: ['system_admin', 'system_user'],
component: InviteMembersStep,
visible: true,
},
Expand Down Expand Up @@ -115,11 +116,7 @@ export const getSteps = createSelector(
(state: GlobalState) => getCurrentUser(state),
(state: GlobalState) => isFirstAdmin(state),
(currentUser, firstAdmin) => {
let roles = currentUser.roles;
if (!firstAdmin) {
// Only the first admin sees the admin flow. Show everyone else the end user flow
roles = 'system_user';
}
const roles = firstAdmin ? `first_admin ${currentUser.roles}` : currentUser.roles;
return Steps.filter((step) =>
isStepForUser(step, roles) && step.visible,
);
Expand Down Expand Up @@ -185,10 +182,7 @@ export const nextStepsNotFinished = createSelector(
(state: GlobalState) => getCurrentUser(state),
(state: GlobalState) => isFirstAdmin(state),
(stepPreferences, currentUser, firstAdmin) => {
let roles = currentUser.roles;
if (!firstAdmin) {
roles = 'system_user';
}
const roles = firstAdmin ? `first_admin ${currentUser.roles}` : currentUser.roles;
const checkPref = (step: StepType) => stepPreferences.some((pref) => (pref.name === step.id && pref.value === 'true') || !isStepForUser(step, roles));
return !Steps.every(checkPref);
},
Expand Down

0 comments on commit 4ee98ba

Please sign in to comment.