Skip to content
Snippets Groups Projects
Commit f87d44fc authored by Diego Sampaio's avatar Diego Sampaio
Browse files

fixed errors saving room info in admin

parent a459e640
No related branches found
No related tags found
No related merge requests found
......@@ -63,7 +63,7 @@ Template.adminRoomInfo.events
'keydown input[type=text]': (e, t) ->
if e.keyCode is 13
e.preventDefault()
t.saveSetting()
t.saveSetting(@rid)
'click [data-edit]': (e, t) ->
e.preventDefault()
......@@ -76,22 +76,21 @@ Template.adminRoomInfo.events
'click .save': (e, t) ->
e.preventDefault()
t.saveSetting()
t.saveSetting(@rid)
Template.adminRoomInfo.onCreated ->
@editing = new ReactiveVar
@validateRoomType = =>
@validateRoomType = (rid) =>
type = @$('input[name=roomType]:checked').val()
if type not in ['c', 'p']
toastr.error t('Invalid_room_type', type)
return true
@validateRoomName = =>
rid = Template.currentData()?.rid
@validateRoomName = (rid) =>
room = ChatRoom.findOne rid
if not RocketChat.authz.hasAllPermission('edit-room', @rid) or room.t not in ['c', 'p']
if not RocketChat.authz.hasAllPermission('edit-room', rid) or room.t not in ['c', 'p']
toastr.error t('Not_allowed')
return false
......@@ -102,28 +101,28 @@ Template.adminRoomInfo.onCreated ->
return true
@validateRoomTopic = =>
@validateRoomTopic = (rid) =>
return true
@saveSetting = =>
@saveSetting = (rid) =>
switch @editing.get()
when 'roomName'
if @validateRoomName()
Meteor.call 'saveRoomSettings', @data?.rid, 'roomName', @$('input[name=roomName]').val(), (err, result) ->
if @validateRoomName(rid)
Meteor.call 'saveRoomSettings', rid, 'roomName', @$('input[name=roomName]').val(), (err, result) ->
if err
if err.error in [ 'duplicate-name', 'name-invalid' ]
return toastr.error TAPi18n.__(err.reason, err.details.channelName)
return toastr.error TAPi18n.__(err.reason)
toastr.success TAPi18n.__ 'Room_name_changed_successfully'
when 'roomTopic'
if @validateRoomTopic()
Meteor.call 'saveRoomSettings', @data?.rid, 'roomTopic', @$('input[name=roomTopic]').val(), (err, result) ->
if @validateRoomTopic(rid)
Meteor.call 'saveRoomSettings', rid, 'roomTopic', @$('input[name=roomTopic]').val(), (err, result) ->
if err
return toastr.error TAPi18n.__(err.reason)
toastr.success TAPi18n.__ 'Room_topic_changed_successfully'
when 'roomType'
if @validateRoomType()
Meteor.call 'saveRoomSettings', @data?.rid, 'roomType', @$('input[name=roomType]:checked').val(), (err, result) ->
if @validateRoomType(rid)
Meteor.call 'saveRoomSettings', rid, 'roomType', @$('input[name=roomType]:checked').val(), (err, result) ->
if err
if err.error is 'invalid-room-type'
return toastr.error TAPi18n.__(err.reason, err.details.roomType)
......@@ -131,13 +130,13 @@ Template.adminRoomInfo.onCreated ->
toastr.success TAPi18n.__ 'Room_type_changed_successfully'
when 'archivationState'
if @$('input[name=archivationState]:checked').val() is 'true'
if ChatRoom.findOne(@data.rid)?.archived isnt true
Meteor.call 'archiveRoom', @data?.rid, (err, results) ->
if ChatRoom.findOne(rid)?.archived isnt true
Meteor.call 'archiveRoom', rid, (err, results) ->
return toastr.error err.reason if err
toastr.success TAPi18n.__ 'Room_archived'
else
if ChatRoom.findOne(@data.rid)?.archived is true
Meteor.call 'unarchiveRoom', @data?.rid, (err, results) ->
if ChatRoom.findOne(rid)?.archived is true
Meteor.call 'unarchiveRoom', rid, (err, results) ->
return toastr.error err.reason if err
toastr.success TAPi18n.__ 'Room_unarchived'
@editing.set()
......@@ -19,7 +19,8 @@ Meteor.publish('adminRooms', function(filter, types, limit) {
muted: 1,
default: 1,
topic: 1,
msgs: 1
msgs: 1,
archived: 1
},
limit: limit,
sort: {
......
......@@ -6,10 +6,6 @@ Meteor.methods
room = RocketChat.models.Rooms.findOneById rid
if room.u? and room.u._id is Meteor.userId() or RocketChat.authz.hasRole(Meteor.userId(), 'admin')
update =
$set:
archived: true
RocketChat.models.Rooms.archiveById rid
for username in room.usernames
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment