Skip to content

Commit

Permalink
MM-53467 Unrevert changes that update current user object (mattermost…
Browse files Browse the repository at this point in the history
…#23928)

* Revert "Revert "[MM-52547] Include current user profile in every redux action (mattermost#23219)""

This reverts commit 8f96888.

* Revert "Revert "[MM-52546] webapp/channels : Update current user and status on WebSocket reconnect (mattermost#23071)""

This reverts commit 69ee162.

* MM-53647 Fix overwriting the current user with sanitized data
  • Loading branch information
hmhealey committed Jul 11, 2023
1 parent 1167284 commit 2672af3
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

// ***************************************************************
// - [#] indicates a test step (e.g. #. Go to a page)
// - [*] indicates an assertion (e.g. * Check the title)
// - Use element ID when selecting an element. Create one if none.
// ***************************************************************

// Group: @channels

describe('MM-53377 Regression tests', () => {
let testTeam;
let testUser;
let testUser2;

before(() => {
cy.apiUpdateConfig({
PrivacySettings: {
ShowEmailAddress: false,
ShowFullName: false,
},
});

cy.apiInitSetup().then(({team, user, offTopicUrl}) => {
testTeam = team;
testUser = user;

cy.apiCreateUser().then((payload) => {
testUser2 = payload.user;
cy.apiAddUserToTeam(testTeam.id, payload.user.id);
});

cy.visit(offTopicUrl);
});
});

beforeEach(() => {
// # Login as testUser
cy.apiLogin(testUser);
});

it('should still have your email loaded after using the at-mention autocomplete', () => {
// * Ensure that this user is not an admin
cy.wrap(testUser).its('roles').should('equal', 'system_user');

// # Send a couple at mentions, quickly enough that the at mention autocomplete won't appear
cy.uiPostMessageQuickly(`@${testUser.username} @${testUser2.username}`);

// # Open the profile popover for the current user
cy.contains('.mention-link', `@${testUser.username}`).click();

// * Ensure that all fields are visible for the current user
cy.get('#user-profile-popover').within(() => {
cy.findByText(`@${testUser.username}`).should('exist');
cy.findByText(`${testUser.first_name} ${testUser.last_name}`).should('exist');
cy.findByText(testUser.email).should('exist');
});

// # Click anywhere to close profile popover
cy.get('#channelHeaderInfo').click();

// # Open the profile popover for another user
cy.contains('.mention-link', `@${testUser2.username}`).click();

// * Ensure that only the username is visible for another user
cy.get('#user-profile-popover').within(() => {
cy.findByText(`@${testUser2.username}`).should('exist');
cy.findByText(`${testUser2.first_name} ${testUser2.last_name}`).should('not.exist');
cy.findByText(testUser2.email).should('not.exist');
});

// # Start to type another at mention so that the autocomplete loads
cy.get('#post_textbox').type(`@${testUser.username}`);

// # Wait for the autocomplete to appear with the current user in it
cy.get('.suggestion-list').within(() => {
cy.findByText(`@${testUser.username}`);
});

// # Clear the post textbox to hide the autocomplete
cy.get('#post_textbox').clear();

// # Open the profile popover for the current user again
cy.contains('.mention-link', `@${testUser.username}`).click();

// * Ensure that all fields are still visible for the current user
cy.get('#user-profile-popover').within(() => {
cy.findByText(`@${testUser.username}`).should('exist');
cy.findByText(`${testUser.first_name} ${testUser.last_name}`).should('exist');
cy.findByText(testUser.email).should('exist');
});
});
});
2 changes: 1 addition & 1 deletion webapp/channels/src/actions/websocket_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export function reconnect() {
// we can request for getPosts again when socket is connected
dispatch(getPosts(currentChannelId));
}
StatusActions.loadStatusesForChannelAndSidebar();
dispatch(StatusActions.loadStatusesForChannelAndSidebar());

const crtEnabled = isCollapsedThreadsEnabled(state);
dispatch(TeamActions.getMyTeamUnreads(crtEnabled, true));
Expand Down
33 changes: 7 additions & 26 deletions webapp/channels/src/packages/mattermost-redux/src/actions/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {getServerVersion} from 'mattermost-redux/selectors/entities/general';
import {getCurrentUserId, getUsers} from 'mattermost-redux/selectors/entities/users';
import {isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences';

import {removeUserFromList} from 'mattermost-redux/utils/user_utils';
import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers';
import {General} from 'mattermost-redux/constants';

Expand Down Expand Up @@ -215,12 +214,10 @@ export function getFilteredUsersStats(options: GetFilteredUsersStatsOpts = {}, u

export function getProfiles(page = 0, perPage: number = General.PROFILE_CHUNK_SIZE, options: any = {}): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const {currentUserId} = getState().entities.users;
let profiles: UserProfile[];

try {
profiles = await Client4.getProfiles(page, perPage, options);
removeUserFromList(currentUserId, profiles);
} catch (error) {
forceLogoutIfNecessary(error, dispatch, getState);
dispatch(logError(error));
Expand Down Expand Up @@ -280,12 +277,10 @@ export function getMissingProfilesByUsernames(usernames: string[]): ActionFunc {

export function getProfilesByIds(userIds: string[], options?: any): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const {currentUserId} = getState().entities.users;
let profiles: UserProfile[];

try {
profiles = await Client4.getProfilesByIds(userIds, options);
removeUserFromList(currentUserId, profiles);
} catch (error) {
forceLogoutIfNecessary(error, dispatch, getState);
dispatch(logError(error));
Expand All @@ -303,12 +298,10 @@ export function getProfilesByIds(userIds: string[], options?: any): ActionFunc {

export function getProfilesByUsernames(usernames: string[]): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const {currentUserId} = getState().entities.users;
let profiles;

try {
profiles = await Client4.getProfilesByUsernames(usernames);
removeUserFromList(currentUserId, profiles);
} catch (error) {
forceLogoutIfNecessary(error, dispatch, getState);
dispatch(logError(error));
Expand All @@ -326,7 +319,6 @@ export function getProfilesByUsernames(usernames: string[]): ActionFunc {

export function getProfilesInTeam(teamId: string, page: number, perPage: number = General.PROFILE_CHUNK_SIZE, sort = '', options: any = {}): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const {currentUserId} = getState().entities.users;
let profiles;

try {
Expand All @@ -345,7 +337,7 @@ export function getProfilesInTeam(teamId: string, page: number, perPage: number
},
{
type: UserTypes.RECEIVED_PROFILES_LIST,
data: removeUserFromList(currentUserId, [...profiles]),
data: profiles,
},
]));

Expand Down Expand Up @@ -415,7 +407,6 @@ export enum ProfilesInChannelSortBy {

export function getProfilesInChannel(channelId: string, page: number, perPage: number = General.PROFILE_CHUNK_SIZE, sort = '', options: {active?: boolean} = {}): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const {currentUserId} = getState().entities.users;
let profiles;

try {
Expand All @@ -434,7 +425,7 @@ export function getProfilesInChannel(channelId: string, page: number, perPage: n
},
{
type: UserTypes.RECEIVED_PROFILES_LIST,
data: removeUserFromList(currentUserId, [...profiles]),
data: profiles,
},
]));

Expand All @@ -444,7 +435,6 @@ export function getProfilesInChannel(channelId: string, page: number, perPage: n

export function getProfilesInGroupChannels(channelsIds: string[]): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const {currentUserId} = getState().entities.users;
let channelProfiles;

try {
Expand All @@ -468,7 +458,7 @@ export function getProfilesInGroupChannels(channelsIds: string[]): ActionFunc {
},
{
type: UserTypes.RECEIVED_PROFILES_LIST,
data: removeUserFromList(currentUserId, [...profiles]),
data: profiles,
},
);
}
Expand All @@ -482,7 +472,6 @@ export function getProfilesInGroupChannels(channelsIds: string[]): ActionFunc {

export function getProfilesNotInChannel(teamId: string, channelId: string, groupConstrained: boolean, page: number, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const {currentUserId} = getState().entities.users;
let profiles;

try {
Expand All @@ -503,7 +492,7 @@ export function getProfilesNotInChannel(teamId: string, channelId: string, group
},
{
type: UserTypes.RECEIVED_PROFILES_LIST,
data: removeUserFromList(currentUserId, [...profiles]),
data: profiles,
},
]));

Expand Down Expand Up @@ -564,7 +553,6 @@ export function updateMyTermsOfServiceStatus(termsOfServiceId: string, accepted:

export function getProfilesInGroup(groupId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE, sort = ''): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const {currentUserId} = getState().entities.users;
let profiles;

try {
Expand All @@ -583,7 +571,7 @@ export function getProfilesInGroup(groupId: string, page = 0, perPage: number =
},
{
type: UserTypes.RECEIVED_PROFILES_LIST,
data: removeUserFromList(currentUserId, [...profiles]),
data: profiles,
},
]));

Expand All @@ -593,7 +581,6 @@ export function getProfilesInGroup(groupId: string, page = 0, perPage: number =

export function getProfilesNotInGroup(groupId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const {currentUserId} = getState().entities.users;
let profiles;

try {
Expand All @@ -612,7 +599,7 @@ export function getProfilesNotInGroup(groupId: string, page = 0, perPage: number
},
{
type: UserTypes.RECEIVED_PROFILES_LIST,
data: removeUserFromList(currentUserId, [...profiles]),
data: profiles,
},
]));

Expand Down Expand Up @@ -844,9 +831,6 @@ export function autocompleteUsers(term: string, teamId = '', channelId = '', opt
}): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
dispatch({type: UserTypes.AUTOCOMPLETE_USERS_REQUEST, data: null});

const {currentUserId} = getState().entities.users;

let data;
try {
data = await Client4.autocompleteUsers(term, teamId, channelId, options);
Expand All @@ -861,7 +845,6 @@ export function autocompleteUsers(term: string, teamId = '', channelId = '', opt
if (data.out_of_channel) {
users = [...users, ...data.out_of_channel];
}
removeUserFromList(currentUserId, users);
const actions: AnyAction[] = [{
type: UserTypes.RECEIVED_PROFILES_LIST,
data: users,
Expand Down Expand Up @@ -904,8 +887,6 @@ export function autocompleteUsers(term: string, teamId = '', channelId = '', opt

export function searchProfiles(term: string, options: any = {}): ActionFunc {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const {currentUserId} = getState().entities.users;

let profiles;
try {
profiles = await Client4.searchUsers(term, options);
Expand All @@ -915,7 +896,7 @@ export function searchProfiles(term: string, options: any = {}): ActionFunc {
return {error};
}

const actions: AnyAction[] = [{type: UserTypes.RECEIVED_PROFILES_LIST, data: removeUserFromList(currentUserId, [...profiles])}];
const actions: AnyAction[] = [{type: UserTypes.RECEIVED_PROFILES_LIST, data: profiles}];

if (options.in_channel_id) {
actions.push({
Expand Down
Loading

0 comments on commit 2672af3

Please sign in to comment.