From 4ee98badf4ceeac55d64d82f603d56ffb7b0f0a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20V=C3=A9lez=20Vidal?= Date: Wed, 14 Apr 2021 21:58:50 +0200 Subject: [PATCH] MM-34569 - remove step 3 to guests (#7838) * 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 Co-authored-by: Mattermod --- components/next_steps_view/step_helpers.ts | 4 +--- components/next_steps_view/steps.test.tsx | 27 ++++++++++++++++++++-- components/next_steps_view/steps.ts | 16 ++++--------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/components/next_steps_view/step_helpers.ts b/components/next_steps_view/step_helpers.ts index cee9607e8687..a49e616c345a 100644 --- a/components/next_steps_view/step_helpers.ts +++ b/components/next_steps_view/step_helpers.ts @@ -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) { @@ -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 ); } diff --git a/components/next_steps_view/steps.test.tsx b/components/next_steps_view/steps.test.tsx index 1969d977143f..d79a036c3c68 100644 --- a/components/next_steps_view/steps.test.tsx +++ b/components/next_steps_view/steps.test.tsx @@ -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', @@ -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'}, }, }, }, @@ -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', () => { diff --git a/components/next_steps_view/steps.ts b/components/next_steps_view/steps.ts index cf081ef5c8de..348f81ac3633 100644 --- a/components/next_steps_view/steps.ts +++ b/components/next_steps_view/steps.ts @@ -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[]; }; @@ -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, }, @@ -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, }, @@ -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, ); @@ -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); },