Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just admins can change a Default Channel to Private (the channel will be a non default channel) #6426

Merged
merged 2 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Meteor.startup ->
RocketChat.ChannelSettings.addOption
group: ['room']
id: 'mail-messages'
template: 'channelSettingsMailMessages'
validation: ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ <h2>{{_ "Room_Info"}}</h2>
{{/unless}}
</div>
</li>
{{# if has $value 'message' }}
{{#let message=($value.message room)}}
{{#if message}}
<li>
<div class="alert alert-warning pending-background pending-border">
{{_ message}}
</div>
</li>
{{/if}}
{{/let}}
{{/if}}
{{/let}}
{{/if}}
{{/each}}
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,8 @@
"Room_has_been_deleted": "Room has been deleted",
"Room_has_been_archived": "Room has been archived",
"Room_has_been_unarchived": "Room has been unarchived",
"Room_type_of_default_rooms_cant_be_changed": "This is a default room and the type can not be changed, please consult with your administrator.",
"Room_default_change_to_private_will_be_default_no_more": "This is a default channel and changing it to a private group will cause it to no longer be a default channel. Do you want to proceed?",
"Room_Info": "Room Info",
"room_is_blocked": "This room is blocked",
"room_is_read_only": "This room is read only",
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/server/models/Rooms.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,11 @@ class ModelRooms extends RocketChat.models._Base
setTypeById: (_id, type) ->
query =
_id: _id

update =
$set:
t: type
if type == 'p'
update.$unset = {default: ''}

return @update query, update

Expand Down
25 changes: 20 additions & 5 deletions packages/rocketchat-ui-admin/client/rooms/adminRoomInfo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Template.adminRoomInfo.helpers
roomType: ->
return AdminChatRoom.findOne(@rid, { fields: { t: 1 }})?.t
channelSettings: ->
return RocketChat.ChannelSettings.getOptions()
return RocketChat.ChannelSettings.getOptions(null, 'admin-room')
roomTypeDescription: ->
roomType = AdminChatRoom.findOne(@rid, { fields: { t: 1 }})?.t
if roomType is 'c'
Expand Down Expand Up @@ -138,12 +138,27 @@ Template.adminRoomInfo.onCreated ->
toastr.success TAPi18n.__ 'Room_topic_changed_successfully'
RocketChat.callbacks.run 'roomTopicChanged', AdminChatRoom.findOne(rid)
when 'roomType'
val = @$('input[name=roomType]:checked').val()
if @validateRoomType(rid)
RocketChat.callbacks.run 'roomTypeChanged', AdminChatRoom.findOne(rid)
Meteor.call 'saveRoomSettings', rid, 'roomType', @$('input[name=roomType]:checked').val(), (err, result) ->
if err
return handleError(err)
toastr.success TAPi18n.__ 'Room_type_changed_successfully'
saveRoomSettings = =>
Meteor.call 'saveRoomSettings', rid, 'roomType', val, (err, result) ->
if err
return handleError(err)
toastr.success TAPi18n.__ 'Room_type_changed_successfully'
unless AdminChatRoom.findOne(rid, { fields: { default: 1 }}).default
return saveRoomSettings()
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 !confirmed || saveRoomSettings()
when 'archivationState'
if @$('input[name=archivationState]:checked').val() is 'true'
if AdminChatRoom.findOne(rid)?.archived isnt true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Template.adminRooms.onCreated ->
});

RocketChat.ChannelSettings.addOption
group: ['admin-room']
id: 'make-default'
template: 'channelSettingsDefault'
data: ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import toastr from 'toastr';
/* globals ChatRoom */
/* globals AdminChatRoom */

Template.channelSettingsDefault.helpers({
canMakeDefault() {
var room = ChatRoom.findOne(this.rid, { fields: { t: 1 }});
var room = AdminChatRoom.findOne(this.rid, { fields: { t: 1 }});
return room && room.t === 'c';
},
editing(field) {
return Template.instance().editing.get() === field;
},
roomDefault() {
var room = ChatRoom.findOne(this.rid, { fields: { default: 1 }});
var room = AdminChatRoom.findOne(this.rid, { fields: { default: 1 }});

if (room) {
return room.default;
}
},
defaultDescription() {
var room = ChatRoom.findOne(this.rid, { fields: { default: 1 }});
var room = AdminChatRoom.findOne(this.rid, { fields: { default: 1 }});
if (room && room.default) {
return t('True');
} else {
Expand Down