Skip to content

Commit

Permalink
Merge branch 'rm/362026' into 'master'
Browse files Browse the repository at this point in the history
last admin and user of a private channel can only archive it

See merge request kchat/webapp!933
  • Loading branch information
antonbuks committed Sep 26, 2024
2 parents 414ae39 + 597cece commit 157020d
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,14 @@ Object {
>
Cancel
</button>
<div
class="btn-leave"
<button
class="btn btn-danger"
data-testid="confirmModalButton"
id="confirmModalButton"
type="button"
>
<button
class="btn btn-danger"
data-testid="confirmModalButton"
id="confirmModalButton"
type="button"
>
Leave
</button>
</div>
Leave
</button>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('components/LeaveChannelModal', () => {

return Promise.resolve({error});
}),
deleteChannel: jest.fn(),
getChannelMemberAction: jest.fn(),
getChannelStats: jest.fn(),
getChannelMember: jest.fn(),
Expand Down Expand Up @@ -96,6 +97,7 @@ describe('components/LeaveChannelModal', () => {

return Promise.resolve({error});
}),
deleteChannel: jest.fn(),
getChannelMemberAction: jest.fn(),
getChannelStats: jest.fn(),
getChannelMember: jest.fn(),
Expand Down Expand Up @@ -150,6 +152,7 @@ describe('components/LeaveChannelModal', () => {
last_root_post_at: 0,
},
actions: {
deleteChannel: jest.fn(),
getChannelMemberAction: jest.fn(),
loadProfilesAndReloadChannelMembers: jest.fn(),
leaveChannel: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Props = {
onAddCallback?: (userProfiles?: UserProfileValue[]) => void;
onExited: () => void;
actions: {
deleteChannel: (channelId: string) => void;
leaveChannel: (channelId: string) => Promise<ActionResult>;
getChannelStats: (channelId: string) => void;
getChannelMemberAction: (channelId: string, userId: string) => Promise<ActionResult<ChannelMembership, any>>;
Expand Down Expand Up @@ -142,6 +143,14 @@ const IkLeaveChannelModal: FC<Props> = ({actions, channel, currentMemberIsChanne
}
};

const handleArchiveSubmit = () => {
if (channel) {
const channelId = channel.id;
actions.deleteChannel(channelId);
handleHide();
}
};

const handleMakeChannelAdmin = (userIds: string, channelId: string) => {
updateChannelMemberSchemeRole(true, userIds, channelId);
};
Expand Down Expand Up @@ -360,6 +369,16 @@ const IkLeaveChannelModal: FC<Props> = ({actions, channel, currentMemberIsChanne
}}
/>
);
} else if (hasChannelMembersAdmin && profilesInCurrentChannel!.length === 1) {
message = (
<FormattedMessage
id='leave_private_channel_modal.last_user'
defaultMessage='Do you want to archive the channel {channel}?'
values={{
channel: <b>{channel.display_name}</b>,
}}
/>
);
} else {
message = (
<FormattedMessage
Expand Down Expand Up @@ -497,6 +516,14 @@ const IkLeaveChannelModal: FC<Props> = ({actions, channel, currentMemberIsChanne
/>
);

const buttonArchiveClass = 'btn btn-danger';
const archiveButton = (
<FormattedMessage
id='delete_channel.del'
defaultMessage='Archive'
/>
);

return (
<Modal
id='addUsersToChannelModal'
Expand Down Expand Up @@ -536,7 +563,18 @@ const IkLeaveChannelModal: FC<Props> = ({actions, channel, currentMemberIsChanne
>
{localizeMessage('multiselect.cancel', 'Cancel')}
</button>
<div className='btn-leave'>
{hasChannelMembersAdmin ? (<div className='btn-leave'>
<button
className={buttonArchiveClass}
autoFocus={true}
type='button'
data-testid='confirmModalButton'
onClick={handleArchiveSubmit}
id='confirmModalButton'
>
{archiveButton}
</button>
</div>) : (
<button
className={buttonClass}
autoFocus={true}
Expand All @@ -546,8 +584,7 @@ const IkLeaveChannelModal: FC<Props> = ({actions, channel, currentMemberIsChanne
id='confirmModalButton'
>
{button}
</button>
</div>
</button>)}
</Modal.Footer>}
</Modal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {getProfilesInCurrentChannel, makeGetProfilesInChannel} from 'mattermost-
import {addUsersToChannel} from 'actions/channel_actions';
import {loadStatusesForProfilesList} from 'actions/status_actions';
import {loadProfilesAndReloadChannelMembers} from 'actions/user_actions';
import {leaveChannel} from 'actions/views/channel';
import {leaveChannel, deleteChannel} from 'actions/views/channel';
import {searchAssociatedGroupsForReference} from 'actions/views/group';
import {closeModal} from 'actions/views/modals';

Expand Down Expand Up @@ -80,6 +80,7 @@ function makeMapStateToProps(state: GlobalState, initialProps: OwnProps) {
function mapDispatchToProps(dispatch: Dispatch) {
return {
actions: bindActionCreators({
deleteChannel,
closeModal,
loadProfilesAndReloadChannelMembers,
getChannelMemberAction,
Expand Down
5 changes: 3 additions & 2 deletions webapp/channels/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -3386,7 +3386,7 @@
"delete_channel.cancel": "Abbrechen",
"delete_channel.confirm": "Archiviere den {visibility} <strong>{channel}</strong> Kanal",
"delete_channel.del": "Archivieren",
"delete_channel.question": "Dies wird den Kanal aus dem Team archivieren und die Inhalte für alle Benutzer unzugänglich machen.",
"delete_channel.question": "Benutzer dieses Kanals können weiterhin die Nachrichten in diesem Kanal anzeigen. Sie oder ein Administrator können ihn jederzeit wiederherstellen.",
"delete_channel.viewArchived.question": "Dies wird den Kanal archivieren. Kanalinhalte werden weiterhin für Kanalmitglieder verfügbar sein.",
"delete_post.cancel": "Abbrechen",
"delete_post.comment": "Kommentar",
Expand Down Expand Up @@ -4226,9 +4226,10 @@
"leave_private_channel_modal.leave": "Ja, Kanal verlassen",
"leave_private_channel_modal.message": "Bist du sicher, dass du den privaten Kanal {channel} verlassen möchtest? Du musst erneut eingeladen werden, um diesen Kanal erneut zu betreten.",
"leave_private_channel_modal.information": "Nur ein Administrator des Channels kann Sie dazu auffordern, diesem Channel erneut beizutreten.",
"leave_private_channel_modal.last_user": "Möchten Sie den Kanal {channel} archivieren?",
"leave_private_channel_modal.title": "Privaten Kanal {channel} verlassen",
"leave_private_channel_modal.last_admin": "Als letzter Administrator dieses Kanals weisen Sie einem anderen Mitglied administrative Rechte zu, bevor Sie diesen Kanal verlassen.",
"leave_private_channel_modal.one_admin": "Sie sind der letzte Benutzer dieses privaten Kanals. Der Kanal wird archiviert und kann nur von einem Administrator wiederhergestellt werden.",
"leave_private_channel_modal.one_admin": "Als letzter Benutzer können Sie diesen privaten Kanal nicht verlassen, sondern nur archivieren. Sie oder ein Administrator können ihn jederzeit wiederherstellen.",
"leave_private_channel_modal.which_user": "Welchem Benutzer möchten Sie administrative Rechte auf diesem Kanal gewähren?",
"leave_public_channel_modal.message": "Bist du sicher, dass du den Kanal {channel} verlassen möchtest? Du kannst diesem Kanal in Zukunft wieder beitreten, wenn du deine Meinung änderst.",
"leave_public_channel_modal.title": "Kanal {channel} verlassen",
Expand Down
5 changes: 3 additions & 2 deletions webapp/channels/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3467,7 +3467,7 @@
"delete_channel.cancel": "Cancel",
"delete_channel.confirm": "Archive the {visibility} <strong>{channel}</strong> channel",
"delete_channel.del": "Archive",
"delete_channel.question": "This will archive the channel from the team and remove it from the user interface. Archived channels can be unarchived if needed again. \n \nAre you sure you wish to archive the {display_name} channel?",
"delete_channel.question": "Users of this channel will still be able to view the messages in this channel. You, or an administrator, can always unarchive it.",
"delete_channel.viewArchived.question": "This will archive the channel from the team. Channel contents will still be accessible by channel members.\n \nAre you sure you wish to archive the **{display_name}** channel?",
"delete_post.cancel": "Cancel",
"delete_post.comment": "Comment",
Expand Down Expand Up @@ -4205,8 +4205,9 @@
"leave_private_channel_modal.message": "Do you really want to leave the {channel} channel?",
"leave_private_channel_modal.information": "Only a channel administrator can invite you to join this channel again.",
"leave_private_channel_modal.title": "Leave Private Channel {channel}",
"leave_private_channel_modal.last_user": "Do you want to archive the channel {channel}?",
"leave_private_channel_modal.last_admin": "As the last administrator of this channel, assign administrative rights to another member before leaving this channel.",
"leave_private_channel_modal.one_admin": "You are the last user of this private channel. The channel will be archived and can only be unarchived by an administrator.",
"leave_private_channel_modal.one_admin": "As the last user, you cannot leave this private channel but only archive it. You, or an administrator, can always unarchive it.",
"leave_private_channel_modal.which_user": "To which user would you like to grant administrative rights on this channel?",
"leave_public_channel_modal.message": "Are you sure you wish to leave the channel {channel}? You can re-join this channel in the future if you change your mind.",
"leave_public_channel_modal.title": "Leave Channel {channel}",
Expand Down
5 changes: 3 additions & 2 deletions webapp/channels/src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -3105,7 +3105,7 @@
"delete_channel.cancel": "Cancelar",
"delete_channel.confirm": "Archivar el canal {visibility} <strong>{channel}</strong>",
"delete_channel.del": "Archivar",
"delete_channel.question": "Esto archivará el canal del equipo y lo eliminará de la interfaz de usuario. Los canales archivados pueden ser restaurados de ser necesario.\n \n¿Estás seguro de que quieres archivar el canal **{display_name}**?",
"delete_channel.question": "Los usuarios de este canal aún podrán ver los mensajes en este canal. Tú, o un administrador, siempre pueden desarchivarlo.",
"delete_channel.viewArchived.question": "Esta operación archivará el canal para su equipo. El contenido del canal seguirá estando disponibles para los miembros del canal.\n\n¿Estás seguro que quieres archivar el canal **{display_name}**?",
"delete_post.cancel": "Cancelar",
"delete_post.comment": "Comentario",
Expand Down Expand Up @@ -3677,8 +3677,9 @@
"leave_private_channel_modal.message": "¿De verdad quieres dejar el canal {channel}?",
"leave_private_channel_modal.information": "Sólo un administrador del canal puede invitarte a unirte de nuevo a este canal.",
"leave_private_channel_modal.title": "Abandonar Canal Privado {channel}",
"leave_private_channel_modal.last_user": "¿Desea archivar el canal {channel}?",
"leave_private_channel_modal.last_admin": "Como último administrador de este canal, asigna derechos administrativos a otro miembro antes de abandonar este canal.",
"leave_private_channel_modal.one_admin": "Eres el último usuario de este canal privado. El canal se archivará y solo podrá ser desarchivado por un administrador.",
"leave_private_channel_modal.one_admin": "Como último usuario, no puedes abandonar este canal privado, solo archivarlo. Tú, o un administrador, siempre pueden desarchivarlo.",
"leave_private_channel_modal.which_user": "¿A qué usuario le gustaría otorgar derechos administrativos en este canal?",
"leave_public_channel_modal.message": "¿Estás seguro de que deseas abandonar el canal {channel}? Puedes volver a unirte a este canal en el futuro si cambias de opinión.",
"leave_public_channel_modal.title": "Abandonar canal {channel}",
Expand Down
7 changes: 4 additions & 3 deletions webapp/channels/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3062,11 +3062,11 @@
"delete_category_modal.deleteCategory": "Supprimer cette catégorie ?",
"delete_category_modal.helpText": "Les canaux dans **{category_name}** seront replacés dans les catégories des canaux et des messages directs. Vous ne serez retiré d'aucun canal.",
"delete_channel.cancel": "Annuler",
"delete_channel.confirm": "Archiver le canal {visibility} <strong>{channel}</strong>",
"delete_channel.confirm": "Souhaitez-vous vraiment archiver le canal {visibility} <strong>{channel}</strong> ?",
"delete_channel.del": "Archiver",
"delete_channel.public": "public",
"delete_channel.private": "privé",
"delete_channel.question": "Ceci va archiver le canal et l'enlever de l'interface utilisateur. Les canaux archivés peuvent être désarchivés si vous souhaitez y accéder à nouveau.",
"delete_channel.question": "Les utlisateurs de ce canal pourront toujours consulter les messages de ce canal. Vous, ou un administrateur, pourrez toujours le désarchiver.",
"delete_channel.viewArchived.question": "Ceci va archiver le canal de cette équipe. Le contenu du canal sera toujours accessible des membres du canal.",
"delete_post.cancel": "Annuler",
"delete_post.comment": "Commentaire",
Expand Down Expand Up @@ -3624,8 +3624,9 @@
"leave_private_channel_modal.message": "Souhaitez-vous vraiment quitter le canal {channel} ?",
"leave_private_channel_modal.information": "Seul un administrateur du canal peut vous inviter à rejoindre ce canal de nouveau.",
"leave_private_channel_modal.title": "Quitter le canal privé {channel}",
"leave_private_channel_modal.last_user": "Souhaitez-vous archiver le canal {channel} ?",
"leave_private_channel_modal.last_admin": "En tant que dernier administrateur de ce canal, attribuez des droits d’administration à un autre membre avant de quitter ce canal.",
"leave_private_channel_modal.one_admin": "Vous êtes le dernier utilisateur de ce canal privé. Le canal sera archivé et ne pourra être désarchivié que par un administrateur.",
"leave_private_channel_modal.one_admin": "En tant que dernier utilisateur, vous ne pouvez pas quitter ce canal privé mais uniquement l'archiver. Vous, ou un administrateur, pourrez toujours le désarchiver.",
"leave_private_channel_modal.which_user": "A quel utilisateur souhaitez-vous accorder un droit d’administrateur sur ce canal ?",
"leave_public_channel_modal.message": "Êtes-vous sûr de vouloir quitter le canal {channel} ? Vous pouvez rejoindre ce canal à l'avenir si vous changez d'avis.",
"leave_public_channel_modal.title": "Quitter le canal {channel}",
Expand Down
5 changes: 3 additions & 2 deletions webapp/channels/src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,7 @@
"delete_channel.cancel": "Annulla",
"delete_channel.confirm": "Archiviare il canale {visibility} <strong>{channel}</strong>",
"delete_channel.del": "Archivia",
"delete_channel.question": "Questo archivierà il canale dal gruppo e renderà il suo contenuto inaccessibile a tutti gli utenti.",
"delete_channel.question": "Gli utenti di questo canale potranno comunque visualizzare i messaggi in questo canale. Tu, o un amministratore, potete sempre ripristinarlo.",
"delete_channel.viewArchived.question": "Questa operazione archivierà il canale dalla squadra. I contenuti del canale rimarranno visibili ai membri del canale.",
"delete_post.cancel": "Annulla",
"delete_post.comment": "Commento",
Expand Down Expand Up @@ -2805,9 +2805,10 @@
"leave_private_channel_modal.leave": "Lascia",
"leave_private_channel_modal.message": "Vuoi davvero lasciare il canale {channel}?",
"leave_private_channel_modal.information": "Solo l'amministratore del canale può invitare l'utente a unirsi nuovamente a questo canale.",
"leave_private_channel_modal.last_user": "Vuoi archiviare il canale {channel}?",
"leave_private_channel_modal.title": "Abbandona il canale privato {channel}",
"leave_private_channel_modal.last_admin": "Essendo l'ultimo amministratore di questo canale, assegna i diritti amministrativi a un altro membro prima di lasciare questo canale.",
"leave_private_channel_modal.one_admin": "Sei l'ultimo utente di questo canale privato. Il canale verrà archiviato e potrà essere ripristinato solo da un amministratore.",
"leave_private_channel_modal.one_admin": "Come ultimo utente, non puoi lasciare questo canale privato ma solo archiviarlo. Tu, o un amministratore, potete sempre ripristinarlo.",
"leave_private_channel_modal.which_user": "A quale utente desideri concedere i diritti amministrativi su questo canale?",
"leave_public_channel_modal.message": "Sei sicuro di voler lasciare il canale {channel}? Puoi iscriverti nuovamente a questo canale in futuro se cambi idea.",
"leave_public_channel_modal.title": "Lasciare il canale {channel}",
Expand Down

0 comments on commit 157020d

Please sign in to comment.