The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/methods/saveRoomName.coffee

39 lines
1.1 KiB

Meteor.methods
saveRoomName: (rid, name) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] sendMessage -> Invalid user")
room = RocketChat.models.Rooms.findOneById rid
if room.t not in ['c', 'p']
throw new Meteor.Error 403, 'Not allowed'
unless RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', rid)
#if room.u._id isnt Meteor.userId() and not hasPermission
throw new Meteor.Error 403, 'Not allowed'
try
nameValidation = new RegExp '^' + RocketChat.settings.get('UTF8_Names_Validation') + '$'
catch
nameValidation = new RegExp '^[0-9a-zA-Z-_.]+$'
if not nameValidation.test name
throw new Meteor.Error 'name-invalid'
if RocketChat.settings.get 'UTF8_Names_slugify'
name = _.slugify name
if name is room.name
return
# avoid duplicate names
if RocketChat.models.Rooms.findOneByName name
throw new Meteor.Error 'duplicate-name'
RocketChat.models.Rooms.setNameById rid, name
RocketChat.models.Subscriptions.updateNameByRoomId rid, name
RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser rid, name, Meteor.user()
return name