diff --git a/packages/rocketchat-channel-settings-mail-messages/client/lib/startup.coffee b/packages/rocketchat-channel-settings-mail-messages/client/lib/startup.coffee index c55e6956b7b..0fe36ddc31b 100644 --- a/packages/rocketchat-channel-settings-mail-messages/client/lib/startup.coffee +++ b/packages/rocketchat-channel-settings-mail-messages/client/lib/startup.coffee @@ -1,5 +1,6 @@ Meteor.startup -> RocketChat.ChannelSettings.addOption + group: ['room'] id: 'mail-messages' template: 'channelSettingsMailMessages' validation: -> diff --git a/packages/rocketchat-channel-settings/client/lib/ChannelSettings.coffee b/packages/rocketchat-channel-settings/client/lib/ChannelSettings.coffee index 57e23f6b457..4c723d54bd9 100644 --- a/packages/rocketchat-channel-settings/client/lib/ChannelSettings.coffee +++ b/packages/rocketchat-channel-settings/client/lib/ChannelSettings.coffee @@ -17,13 +17,14 @@ RocketChat.ChannelSettings = new class opts[config.id] = config options.set opts - getOptions = (currentData) -> + getOptions = (currentData, group) -> allOptions = _.toArray options.get() allowedOptions = _.compact _.map allOptions, (option) -> if not option.validation? or option.validation() option.data = Object.assign (option.data or {}), currentData return option - + allowedOptions = allowedOptions.filter (option) -> + !group or !option.group or option.group?.indexOf(group) > -1 return _.sortBy allowedOptions, 'order' addOption: addOption diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee index 40fc3162b47..8eda21ee2df 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee @@ -31,10 +31,10 @@ Template.channelSettings.helpers return Template.instance().editing.get() is field isDisabled: (field, room) -> - return Template.instance().settings[field].processing.get() or !RocketChat.authz.hasAllPermission('edit-room', room._id) + return Template.instance().settings[field].disabled?(room) or Template.instance().settings[field].processing.get() or !RocketChat.authz.hasAllPermission('edit-room', room._id) channelSettings: -> - return RocketChat.ChannelSettings.getOptions(Template.currentData()) + return RocketChat.ChannelSettings.getOptions(Template.currentData(), 'room') unscape: (value) -> return s.unescapeHTML value @@ -45,7 +45,8 @@ Template.channelSettings.helpers readOnly: -> return ChatRoom.findOne(@rid, { fields: { ro: 1 }})?.ro - + has: (v, key) -> + v?[key]? readOnlyDescription: -> readOnly = ChatRoom.findOne(@rid, { fields: { ro: 1 }})?.ro if readOnly is true @@ -160,6 +161,14 @@ Template.channelSettings.onCreated -> label: 'Private' isToggle: true processing: new ReactiveVar(false) + disabled: (room) => + room.default and not RocketChat.authz.hasRole( Meteor.userId(), 'admin') + message: (room) => + #if the user can change but the channel is default + if RocketChat.authz.hasAllPermission('edit-room', room._id) and room.default + # if you are an admin, even so you can change + unless RocketChat.authz.hasRole( Meteor.userId(), 'admin') + return 'Room_type_of_default_rooms_cant_be_changed' canView: (room) -> if room.t not in ['c', 'p'] return false @@ -168,16 +177,33 @@ Template.channelSettings.onCreated -> else if room.t is 'c' and not RocketChat.authz.hasAllPermission('create-p') return false return true - canEdit: (room) => RocketChat.authz.hasAllPermission('edit-room', room._id) + canEdit: (room) => ( RocketChat.authz.hasAllPermission('edit-room', room._id) and not room.default) or RocketChat.authz.hasRole( Meteor.userId(), 'admin') save: (value, room) -> - @processing.set(true) - value = if value then 'p' else 'c' - RocketChat.callbacks.run 'roomTypeChanged', room - Meteor.call 'saveRoomSettings', room._id, 'roomType', value, (err, result) => - return handleError err if err - @processing.set(false) - toastr.success TAPi18n.__ 'Room_type_changed_successfully' - + saveRoomSettings = => + @processing.set(true) + value = if value then 'p' else 'c' + RocketChat.callbacks.run 'roomTypeChanged', room + Meteor.call 'saveRoomSettings', room._id, 'roomType', value, (err, result) => + return handleError err if err + @processing.set(false) + toastr.success TAPi18n.__ 'Room_type_changed_successfully' + + if room.default + if RocketChat.authz.hasRole Meteor.userId(), 'admin' + swal { + title: t('Room_default_change_to_private_will_be_default_no_more') + type: 'warning' + showCancelButton: true + confirmButtonColor: '#DD6B55' + confirmButtonText: t('Yes') + cancelButtonText: t('Cancel') + closeOnConfirm: true + html: false + }, (confirmed) => + return saveRoomSettings() if confirmed + $(".channel-settings form [name='t']").prop('checked', !!room.type == 'p') + else + saveRoomSettings() ro: type: 'boolean' label: 'Read_only' diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.html b/packages/rocketchat-channel-settings/client/views/channelSettings.html index 562590be0c7..f4475a56244 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.html +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.html @@ -75,6 +75,17 @@ {{/unless}} + {{# if has $value 'message' }} + {{#let message=($value.message room)}} + {{#if message}} +