Commit eeff695d authored by George Goldberg's avatar George Goldberg

MM-13425: Fix set header option in DM/GM dropdown. (#2175)

Should not depend on permissions for these channel types.
parent 8b3fab7d
...@@ -20,15 +20,7 @@ const SetChannelHeader = ({channel, isArchived, isReadonly}) => { ...@@ -20,15 +20,7 @@ const SetChannelHeader = ({channel, isArchived, isReadonly}) => {
return null; return null;
} }
const isPrivate = channel.type === Constants.PRIVATE_CHANNEL; let menuItem = (
const permission = isPrivate ? Permissions.MANAGE_PRIVATE_CHANNEL_PROPERTIES : Permissions.MANAGE_PUBLIC_CHANNEL_PROPERTIES;
return (
<ChannelPermissionGate
channelId={channel.id}
teamId={channel.team_id}
permissions={[permission]}
>
<li role='presentation'> <li role='presentation'>
<ToggleModalButtonRedux <ToggleModalButtonRedux
id='channelEditHeader' id='channelEditHeader'
...@@ -43,8 +35,24 @@ const SetChannelHeader = ({channel, isArchived, isReadonly}) => { ...@@ -43,8 +35,24 @@ const SetChannelHeader = ({channel, isArchived, isReadonly}) => {
/> />
</ToggleModalButtonRedux> </ToggleModalButtonRedux>
</li> </li>
);
const isPrivate = channel.type === Constants.PRIVATE_CHANNEL;
const permission = isPrivate ? Permissions.MANAGE_PRIVATE_CHANNEL_PROPERTIES : Permissions.MANAGE_PUBLIC_CHANNEL_PROPERTIES;
if (channel.type !== Constants.DM_CHANNEL && channel.type !== Constants.GM_CHANNEL) {
menuItem = (
<ChannelPermissionGate
channelId={channel.id}
teamId={channel.team_id}
permissions={[permission]}
>
{menuItem}
</ChannelPermissionGate> </ChannelPermissionGate>
); );
}
return menuItem;
}; };
SetChannelHeader.propTypes = { SetChannelHeader.propTypes = {
......
...@@ -46,18 +46,100 @@ describe('components/ChannelHeaderDropdown/MenuItem.SetChannelHeader', () => { ...@@ -46,18 +46,100 @@ describe('components/ChannelHeaderDropdown/MenuItem.SetChannelHeader', () => {
expect(wrapper.isEmptyRender()).toBeTruthy(); expect(wrapper.isEmptyRender()).toBeTruthy();
}); });
it('should requires right permission level for channel type to manage header', () => { it('should not be permissions gated for a DM channel', () => {
const props = {
...baseProps,
channel: {
...baseProps.channel,
type: Constants.DM_CHANNEL,
},
};
const wrapper = shallow(<SetChannelHeader {...props}/>);
expect(wrapper).toMatchInlineSnapshot(`
<li
role="presentation"
>
<Connect(ModalToggleButtonRedux)
dialogProps={
Object {
"channel": Object {
"id": "channel_id",
"team_id": "team_id",
"type": "D",
},
}
}
dialogType={[Function]}
id="channelEditHeader"
modalId="edit_channel_header"
role="menuitem"
>
<FormattedMessage
defaultMessage="Edit Channel Header"
id="channel_header.setHeader"
values={Object {}}
/>
</Connect(ModalToggleButtonRedux)>
</li>
`);
});
it('should not be permissions gated for a GM channel', () => {
const props = {
...baseProps,
channel: {
...baseProps.channel,
type: Constants.GM_CHANNEL,
},
};
const wrapper = shallow(<SetChannelHeader {...props}/>);
expect(wrapper).toMatchInlineSnapshot(`
<li
role="presentation"
>
<Connect(ModalToggleButtonRedux)
dialogProps={
Object {
"channel": Object {
"id": "channel_id",
"team_id": "team_id",
"type": "G",
},
}
}
dialogType={[Function]}
id="channelEditHeader"
modalId="edit_channel_header"
role="menuitem"
>
<FormattedMessage
defaultMessage="Edit Channel Header"
id="channel_header.setHeader"
values={Object {}}
/>
</Connect(ModalToggleButtonRedux)>
</li>
`);
});
it('should requires right permission level for channel type to manage header in Public and Private channels', () => {
const props = { const props = {
...baseProps, ...baseProps,
channel: {...baseProps.channel}, channel: {...baseProps.channel},
}; };
const makeWrapper = () => shallow(<SetChannelHeader {...props}/>); const makeWrapper = () => shallow(<SetChannelHeader {...props}/>);
// Public, DM, GM (is this correct?) // Public Channel
props.channel.type = Constants.OPEN_CHANNEL; props.channel.type = Constants.OPEN_CHANNEL;
expect(makeWrapper().prop('permissions')[0]).toBe(Permissions.MANAGE_PUBLIC_CHANNEL_PROPERTIES); expect(makeWrapper().prop('permissions')[0]).toBe(
Permissions.MANAGE_PUBLIC_CHANNEL_PROPERTIES
);
props.channel.type = Constants.PRIVATE_CHANNEL; props.channel.type = Constants.PRIVATE_CHANNEL;
expect(makeWrapper().prop('permissions')[0]).toBe(Permissions.MANAGE_PRIVATE_CHANNEL_PROPERTIES); expect(makeWrapper().prop('permissions')[0]).toBe(
Permissions.MANAGE_PRIVATE_CHANNEL_PROPERTIES
);
}); });
}); });
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment