Skip to content

Commit

Permalink
[MM-20164] Member to Admin not updating has been fixed in Channnel Me…
Browse files Browse the repository at this point in the history
…mber Dropdown (mattermost#4274)

* [MM-20164] Fixed going from system admin to member not updating dropdown menu

* fix linting errors

* fix test

* Updated tests and approach to problem

* added comments and fixed linting

* Fix lint

* remove baseurl

* Fix baseurl

* updated cypress test

* Fix linting
  • Loading branch information
hahmadia committed Dec 2, 2019
1 parent 5ce3c06 commit f27c97e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions actions/websocket_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,11 @@ function handleUserRoleUpdated(msg) {

if (user) {
const roles = msg.data.roles;
const newRoles = roles.split(' ');
const demoted = user.roles.includes(Constants.PERMISSIONS_SYSTEM_ADMIN) && !roles.includes(Constants.PERMISSIONS_SYSTEM_ADMIN);

store.dispatch({type: UserTypes.RECEIVED_PROFILE, data: {...user, roles}});
dispatch(loadRolesIfNeeded(newRoles));

if (demoted && global.location.pathname.startsWith('/admin_console')) {
redirectUserToDefaultTeam();
Expand Down
1 change: 1 addition & 0 deletions components/popover_list_members/popover_list_members.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default class PopoverListMembers extends React.Component {
>
<button
className='btn btn-link'
data-testid='membersModal'
onClick={this.showMembersModal}
>
{membersName}
Expand Down
1 change: 1 addition & 0 deletions components/user_list_row/user_list_row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default class UserListRow extends React.Component {
{this.props.extraInfo}
</div>
<div
data-testid='userListItemActions'
className='more-modal__actions'
>
{buttons}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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.
// ***************************************************************

import users from '../../fixtures/users.json';

const demoteToMember = (user) => {
cy.externalRequest({user: users.sysadmin, method: 'put', path: `users/${user.id}/roles`, data: {roles: 'system_user'}});
};

const promoteToSysAdmin = (user) => {
cy.externalRequest({user: users.sysadmin, method: 'put', path: `users/${user.id}/roles`, data: {roles: 'system_user system_admin'}});
};

describe('View Members modal', () => {
it('MM-20164 - Going from a Member to an Admin should update the modal', () => {
cy.apiLogin('user-1');
cy.apiGetMe().then((res) => {
// # Make user a regular member
demoteToMember(res.body);

// # Visit Town square and go to view members modal
cy.visit('/');
cy.get('#sidebarItem_town-square').click({force: true});
cy.get('#member_popover').click();
cy.findByTestId('membersModal').click();

// * Check to see if no drop down menu exists
cy.findAllByTestId('userListItemActions').then((el) => {
expect(el[0].childElementCount).equal(0);
cy.wrap(el[0]).should('not.be.visible');
});

// Promote user to a system admin
promoteToSysAdmin(res.body);

// * Check to see if a drop now exists now
cy.findAllByTestId('userListItemActions').then((el) => {
expect(el[0].childElementCount).equal(1);
cy.wrap(el[0]).should((children) => {
expect(children).contain('Channel Member');
});
});
});
});
});

0 comments on commit f27c97e

Please sign in to comment.