PLT-7206: Remove the "Delete Channel" option for private channels if you're the last channel member and policy setting restricts channel deletion (#7050)

* PLT-7206: UI changes. Removed last user in channel loophole, refactored code to clean it up, added differentiated support for public and private channels, added unit tests. Still need to implement server-side checks

* PLT-7206: All helper methods in channel_utils.jsx now accept the same three boolean variables in the same order and use the same boolean logic to check their values.

* PLT-7206: Added unit tests for showManagementOptions(...)

* PLT-7206: Fixed test case descriptions

* Added unit tests for showCreateOption(...)

* PLT-7206: Added unit tests for canManageMembers(...)

* PLT-7206: Removed last person in channel loophole from server-side code

* PLT-7206: Reverted config.json

* PLT-7206: Fixed double negatives in unit test names

* PLT-7206: PR feedback - Removed confusing comment and unused variable
Этот коммит содержится в:
Jonathan
2017-08-09 09:34:09 -04:00
коммит произвёл GitHub
родитель 6b741c4cea
Коммит fd6856b674
15 изменённых файлов: 875 добавлений и 118 удалений

Просмотреть файл

@@ -160,12 +160,12 @@ export function createOffTopicIntroMessage(channel, centeredIntro) {
/>
);
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
let setHeaderButton = createSetHeaderButton(channel);
if (!showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
if (!showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
setHeaderButton = null;
}
@@ -199,20 +199,20 @@ export function createDefaultIntroMessage(channel, centeredIntro) {
</a>
);
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
if (global.window.mm_license.IsLicensed === 'true') {
if (global.window.mm_config.RestrictTeamInvite === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
inviteModalLink = null;
} else if (global.window.mm_config.RestrictTeamInvite === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
} else if (global.window.mm_config.RestrictTeamInvite === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
inviteModalLink = null;
}
}
let setHeaderButton = createSetHeaderButton(channel);
if (!showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
if (!showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
setHeaderButton = null;
}
@@ -321,12 +321,12 @@ export function createStandardIntroMessage(channel, centeredIntro) {
);
}
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
let setHeaderButton = createSetHeaderButton(channel);
if (!showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
if (!showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
setHeaderButton = null;
}

Просмотреть файл

@@ -138,7 +138,7 @@ export function getChannelDisplayName(channel) {
return channel.display_name;
}
export function showCreateOption(channelType, isAdmin, isSystemAdmin) {
export function showCreateOption(channelType, isTeamAdmin, isSystemAdmin) {
if (global.window.mm_license.IsLicensed !== 'true') {
return true;
}
@@ -146,13 +146,13 @@ export function showCreateOption(channelType, isAdmin, isSystemAdmin) {
if (channelType === Constants.OPEN_CHANNEL) {
if (global.window.mm_config.RestrictPublicChannelCreation === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
return false;
} else if (global.window.mm_config.RestrictPublicChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
} else if (global.window.mm_config.RestrictPublicChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
return false;
}
} else if (channelType === Constants.PRIVATE_CHANNEL) {
if (global.window.mm_config.RestrictPrivateChannelCreation === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
return false;
} else if (global.window.mm_config.RestrictPrivateChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
} else if (global.window.mm_config.RestrictPrivateChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
return false;
}
}
@@ -160,88 +160,88 @@ export function showCreateOption(channelType, isAdmin, isSystemAdmin) {
return true;
}
export function showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin) {
export function showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) {
if (global.window.mm_license.IsLicensed !== 'true') {
// policies are only enforced in enterprise editions
return true;
}
if (channel.type === Constants.OPEN_CHANNEL) {
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) {
return false;
}
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
return false;
}
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
return false;
}
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
return false;
}
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) {
return false;
}
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) {
return false;
}
}
return true;
}
export function showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, userCount) {
export function showDeleteOptionForCurrentUser(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) {
if (global.window.mm_license.IsLicensed !== 'true') {
// policies are only enforced in enterprise editions
return true;
}
if (ChannelStore.isDefault(channel)) {
// can't delete default channels, no matter who you are
return false;
}
if (channel.type === Constants.OPEN_CHANNEL) {
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) {
return false;
}
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
return false;
}
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
return false;
}
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
return false;
}
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) {
return false;
}
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
if (userCount === 1) {
return true;
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) {
return false;
}
}
return true;
}
export function canManageMembers(channel, isSystemAdmin, isTeamAdmin, isChannelAdmin) {
export function canManageMembers(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) {
if (global.window.mm_license.IsLicensed !== 'true') {
return true;
}
if (channel.type === Constants.PRIVATE_CHANNEL) {
if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_TEAM_ADMIN && !isTeamAdmin && !isSystemAdmin) {
return false;
}
if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isTeamAdmin && !isSystemAdmin) {
return false;
}
}
return true;