Fix #2565 - Don't let the last owner leave the room. Warn user.

pull/2721/head
Marcelo Schmidt 10 years ago
parent 673c6a82c4
commit cb11441bd0
  1. 1
      HISTORY.md
  2. 1
      packages/rocketchat-lib/i18n/en.i18n.json
  3. 1
      packages/rocketchat-lib/i18n/pt.i18n.json
  4. 10
      packages/rocketchat-slashcommands-leave/leave.coffee
  5. 28
      packages/rocketchat-ui-sidenav/side-nav/chatRoomItem.coffee
  6. 15
      server/methods/leaveRoom.coffee

@ -1,6 +1,7 @@
## NEXT
- Fix #2634. Admins are warned if they have not verified their e-mail and e-mail verification is true.
- Fix #2565 - Don't let the last owner leave the room. Warn user.
## 0.24.0, 2016-Mar-28

@ -999,6 +999,7 @@
"you_are_in_preview_mode_of" : "You are in preview mode of channel #<strong>__room_name__</strong>",
"You_are_logged_in_as" : "You are logged in as",
"You_are_not_authorized_to_view_this_page" : "You are not authorized to view this page.",
"You_are_the_last_owner_Please_set_new_owner_before_leaving_the_room" : "You are the last owner. Please set new owner before leaving the room.",
"You_can_change_a_different_avatar_too" : "You can override the avatar used to post from this integration.",
"You_can_use_an_emoji_as_avatar" : "You can also use an emoji as an avatar.",
"You_have_been_muted" : "You have been muted and cannot speak in this room",

@ -538,6 +538,7 @@
"you_are_in_preview_mode_of" : "Esta é uma prévia do canal #<strong>__room_name__</strong>",
"You_are_logged_in_as" : "Vocês está logado como",
"You_are_not_authorized_to_view_this_page" : "Você não possui permissão para visualizar esta página.",
"You_are_the_last_owner_Please_set_new_owner_before_leaving_the_room" : "Você é o último proprietário da sala. Por favor defina um novo proprietário antes de sair.",
"You_have_successfully_unsubscribed" : "A partir de agora você não está mais cadastrado em nossa lista de e-mails.",
"You_need_confirm_email" : "Você precisa confirmar seu email para logar!",
"You_will_not_be_able_to_recover" : "Você não será capaz de desfazer!",

@ -15,7 +15,15 @@ else
class Leave
constructor: (command, params, item) ->
if(command == "leave" || command == "part")
Meteor.call 'leaveRoom', item.rid
try
Meteor.call 'leaveRoom', item.rid
catch
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {
_id: Random.id()
rid: item.rid
ts: new Date
msg: TAPi18n.__('You_are_the_last_owner_Please_set_new_owner_before_leaving_the_room', null, Meteor.user().language)
}
RocketChat.slashCommands.add 'leave', Leave
RocketChat.slashCommands.add 'part', Leave

@ -91,12 +91,24 @@ Template.chatRoomItem.events
confirmButtonColor: '#DD6B55'
confirmButtonText: t('Yes_leave_it')
cancelButtonText: t('Cancel')
closeOnConfirm: true
closeOnConfirm: false
html: false
}, ->
if FlowRouter.getRouteName() in ['channel', 'group', 'direct'] and Session.get('openedRoom') is rid
FlowRouter.go 'home'
RoomManager.close rid
Meteor.call 'leaveRoom', rid
}, (isConfirm) ->
if isConfirm
Meteor.call 'leaveRoom', rid, (err) ->
if err
swal {
title: t('Warning')
text: t("You_are_the_last_owner_Please_set_new_owner_before_leaving_the_room")
type: 'warning'
html: false
}
else
swal.close()
if FlowRouter.getRouteName() in ['channel', 'group', 'direct'] and Session.get('openedRoom') is rid
FlowRouter.go 'home'
RoomManager.close rid
else
swal.close()

@ -9,6 +9,12 @@ Meteor.methods
room = RocketChat.models.Rooms.findOneById rid
user = Meteor.user()
# If user is room owner, check if there are other owners. If there isn't anyone else, warn user to set a new owner.
if RocketChat.authz.hasRole(user._id, 'owner', room._id)
numOwners = RocketChat.authz.getUsersInRole('owner', room._id).fetch().length
if numOwners is 1
throw new Meteor.Error 'last-owner', '[methods] leaveRoom -> User is last owner in room.'
RocketChat.callbacks.run 'beforeLeaveRoom', user, room
RocketChat.models.Rooms.removeUsernameById rid, user.username
@ -20,15 +26,6 @@ Meteor.methods
if room.t is 'l'
RocketChat.models.Messages.createCommandWithRoomIdAndUser 'survey', rid, user
if room.u?._id is Meteor.userId()
newOwner = _.without(room.usernames, user.username)[0]
if newOwner?
newOwner = RocketChat.models.Users.findOneByUsername newOwner
if newOwner?
RocketChat.models.Rooms.setUserById rid, newOwner
RocketChat.models.Subscriptions.removeByRoomIdAndUserId rid, Meteor.userId()
Meteor.defer ->

Loading…
Cancel
Save