From db0edc4338f249a0c571896934ca01cb188c410b Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 13 Jun 2018 19:12:01 -0300 Subject: [PATCH 1/9] [FIX] open conversation from room info (#11050) --- .../rocketchat-ui-flextab/client/tabs/userActions.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-ui-flextab/client/tabs/userActions.js b/packages/rocketchat-ui-flextab/client/tabs/userActions.js index 3b9a2096949e7..0430a6f582ef2 100644 --- a/packages/rocketchat-ui-flextab/client/tabs/userActions.js +++ b/packages/rocketchat-ui-flextab/client/tabs/userActions.js @@ -54,8 +54,11 @@ export const getActions = function({ user, directActions, hideAdminControls }) { return RocketChat.authz.hasAllPermission('set-owner', Session.get('openedRoom')); }; const canDirectMessage = (username) => { - const user = Meteor.user(); - return RocketChat.authz.hasAllPermission('create-d') && user && user.username !== username; + const rid = Session.get('openedRoom'); + const subscription = RocketChat.models.Subscriptions.findOne({ rid }); + const canOpenDm = RocketChat.authz.hasAllPermission('create-d') || RocketChat.models.Subscriptions.findOne({ name: username }); + const dmIsNotAlreadyOpen = subscription && subscription.name !== username; + return canOpenDm && dmIsNotAlreadyOpen; }; const canMuteUser = () => { return RocketChat.authz.hasAllPermission('mute-user', Session.get('openedRoom')); @@ -99,7 +102,7 @@ export const getActions = function({ user, directActions, hideAdminControls }) { Meteor.call('createDirectMessage', username, success(result => result.rid && FlowRouter.go('direct', { username }, FlowRouter.current().queryParams))) ), condition() { - return (directActions && canDirectMessage(this.username)); + return canDirectMessage(this.username); } }, From bcbb97bf02564d635fb0ab47168e3927276629da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=B3=E3=83=A1=E3=83=A9?= <39674991+vynmera@users.noreply.github.com> Date: Thu, 14 Jun 2018 00:44:46 +0200 Subject: [PATCH 2/9] [FIX] Some typos in the error message names (#11136) Some places were returning `error-action-now-allowed` instead of `error-action-not-allowed`, which is all a bit confusing but definitely should not be the case. --- packages/rocketchat-assets/server/assets.js | 6 +++--- .../server/methods/getSupportedLanguages.js | 2 +- .../rocketchat-autotranslate/server/methods/saveSettings.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/rocketchat-assets/server/assets.js b/packages/rocketchat-assets/server/assets.js index 297efb79ea473..9d2892b1586b8 100644 --- a/packages/rocketchat-assets/server/assets.js +++ b/packages/rocketchat-assets/server/assets.js @@ -396,7 +396,7 @@ Meteor.methods({ const hasPermission = RocketChat.authz.hasPermission(Meteor.userId(), 'manage-assets'); if (!hasPermission) { - throw new Meteor.Error('error-action-now-allowed', 'Managing assets not allowed', { + throw new Meteor.Error('error-action-not-allowed', 'Managing assets not allowed', { method: 'refreshClients', action: 'Managing_assets' }); @@ -414,7 +414,7 @@ Meteor.methods({ const hasPermission = RocketChat.authz.hasPermission(Meteor.userId(), 'manage-assets'); if (!hasPermission) { - throw new Meteor.Error('error-action-now-allowed', 'Managing assets not allowed', { + throw new Meteor.Error('error-action-not-allowed', 'Managing assets not allowed', { method: 'unsetAsset', action: 'Managing_assets' }); @@ -432,7 +432,7 @@ Meteor.methods({ const hasPermission = RocketChat.authz.hasPermission(Meteor.userId(), 'manage-assets'); if (!hasPermission) { - throw new Meteor.Error('error-action-now-allowed', 'Managing assets not allowed', { + throw new Meteor.Error('error-action-not-allowed', 'Managing assets not allowed', { method: 'setAsset', action: 'Managing_assets' }); diff --git a/packages/rocketchat-autotranslate/server/methods/getSupportedLanguages.js b/packages/rocketchat-autotranslate/server/methods/getSupportedLanguages.js index 841a30268f854..e312e6ed51cae 100644 --- a/packages/rocketchat-autotranslate/server/methods/getSupportedLanguages.js +++ b/packages/rocketchat-autotranslate/server/methods/getSupportedLanguages.js @@ -1,7 +1,7 @@ Meteor.methods({ 'autoTranslate.getSupportedLanguages'(targetLanguage) { if (!RocketChat.authz.hasPermission(Meteor.userId(), 'auto-translate')) { - throw new Meteor.Error('error-action-now-allowed', 'Auto-Translate is not allowed', { method: 'autoTranslate.saveSettings'}); + throw new Meteor.Error('error-action-not-allowed', 'Auto-Translate is not allowed', { method: 'autoTranslate.saveSettings'}); } return RocketChat.AutoTranslate.getSupportedLanguages(targetLanguage); diff --git a/packages/rocketchat-autotranslate/server/methods/saveSettings.js b/packages/rocketchat-autotranslate/server/methods/saveSettings.js index 1030436bcddad..e9ed6dd6fb574 100644 --- a/packages/rocketchat-autotranslate/server/methods/saveSettings.js +++ b/packages/rocketchat-autotranslate/server/methods/saveSettings.js @@ -5,7 +5,7 @@ Meteor.methods({ } if (!RocketChat.authz.hasPermission(Meteor.userId(), 'auto-translate')) { - throw new Meteor.Error('error-action-now-allowed', 'Auto-Translate is not allowed', { method: 'autoTranslate.saveSettings'}); + throw new Meteor.Error('error-action-not-allowed', 'Auto-Translate is not allowed', { method: 'autoTranslate.saveSettings'}); } check(rid, String); From 7689f2e9ba694ffe84bb36bd5ec30a1828a83610 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Thu, 14 Jun 2018 12:35:15 -0300 Subject: [PATCH 3/9] [NEW] Button to remove closed LiveChat rooms (#10301) * New button added to current chat list, allowing to remove closed livechat rooms. --- packages/rocketchat-i18n/i18n/en.i18n.json | 2 ++ packages/rocketchat-i18n/i18n/pt-BR.i18n.json | 2 ++ packages/rocketchat-i18n/i18n/pt.i18n.json | 2 ++ .../views/app/livechatCurrentChats.html | 12 ++++++- .../client/views/app/livechatCurrentChats.js | 31 +++++++++++++++++++ packages/rocketchat-livechat/package.js | 1 + .../server/methods/removeRoom.js | 31 +++++++++++++++++++ server/startup/migrations/v127.js | 20 ++++++++++++ 8 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 packages/rocketchat-livechat/server/methods/removeRoom.js create mode 100644 server/startup/migrations/v127.js diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 46d3aebac22a0..ca20919b0cec8 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -1063,7 +1063,9 @@ "error-remove-last-owner": "This is the last owner. Please set a new owner before removing this one.", "error-role-in-use": "Cannot delete role because it's in use", "error-role-name-required": "Role name is required", + "error-room-is-not-closed": "Room is not closed", "error-the-field-is-required": "The field __field__ is required.", + "error-this-is-not-a-livechat-room": "This is not a Livechat room", "error-too-many-requests": "Error, too many requests. Please slow down. You must wait __seconds__ seconds before trying again.", "error-user-has-no-roles": "User has no roles", "error-user-is-not-activated": "User is not activated", diff --git a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json index 30e1105566fd9..3c33b5ba9d8c9 100644 --- a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json @@ -1059,7 +1059,9 @@ "error-remove-last-owner": "Este é o último proprietário. Por favor, defina um novo proprietário antes de remover este.", "error-role-in-use": "Não é possível remover o papel pois ele está em uso", "error-role-name-required": "Nome do papel é obrigatório", + "error-room-is-not-closed": "Sala não está fechada", "error-the-field-is-required": "O campo __field__ é obrigatório.", + "error-this-is-not-a-livechat-room": "Esta não é uma sala de Livechat", "error-too-many-requests": "Erro, muitas solicitações. Por favor, diminua a velocidade. Você deve esperar __seconds__ segundos antes de tentar novamente.", "error-user-has-no-roles": "O usuário não possui permissões", "error-user-is-not-activated": "O usuário não está ativo", diff --git a/packages/rocketchat-i18n/i18n/pt.i18n.json b/packages/rocketchat-i18n/i18n/pt.i18n.json index bf32a1263dd1e..598fdcd3af063 100644 --- a/packages/rocketchat-i18n/i18n/pt.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt.i18n.json @@ -1059,7 +1059,9 @@ "error-remove-last-owner": "Este é o último proprietário. Por favor, defina um novo proprietário antes de remover este.", "error-role-in-use": "Não é possível remover o papel pois ele está em uso", "error-role-name-required": "Nome do papel é obrigatório", + "error-room-is-not-closed": "Sala não está fechada", "error-the-field-is-required": "O campo __field__ é obrigatório.", + "error-this-is-not-a-livechat-room": "Esta não é uma sala de Livechat", "error-too-many-requests": "Erro, muitas solicitações. Por favor, diminua a velocidade. Você deve esperar __seconds__ segundos antes de tentar novamente.", "error-user-has-no-roles": "O usuário não possui papéis", "error-user-is-not-activated": "O usuário não está ativo", diff --git a/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html b/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html index 6e3dda88d2e17..4606ad8e4f095 100644 --- a/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html +++ b/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html @@ -41,7 +41,8 @@ {{_ "Served_By"}} {{_ "Started_At"}} {{_ "Last_Message_At"}} - {{_ "Status"}} + {{_ "Status"}} +   @@ -52,6 +53,15 @@ {{startedAt}} {{lastMessage}} {{status}} + {{#requiresPermission 'remove-closed-livechat-rooms'}} + {{#if isClosed}} + + {{else}} +   + {{/if}} + {{else}} +   + {{/requiresPermission}} {{/each}} diff --git a/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js b/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js index 659784c4f33ad..f726f14381d26 100644 --- a/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js +++ b/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js @@ -21,6 +21,9 @@ Template.livechatCurrentChats.helpers({ }, agents() { return AgentUsers.find({}, { sort: { name: 1 } }); + }, + isClosed() { + return !this.open; } }); @@ -55,6 +58,34 @@ Template.livechatCurrentChats.events({ instance.filter.set(filter); instance.limit.set(20); + }, + 'click .remove-livechat-room'(event) { + event.preventDefault(); + event.stopPropagation(); + + modal.open({ + title: t('Are_you_sure'), + type: 'warning', + showCancelButton: true, + confirmButtonColor: '#DD6B55', + confirmButtonText: t('Yes'), + cancelButtonText: t('Cancel'), + closeOnConfirm: false, + html: false + }, () => { + Meteor.call('livechat:removeRoom', this._id, function(error/*, result*/) { + if (error) { + return handleError(error); + } + modal.open({ + title: t('Deleted'), + text: t('Room_has_been_deleted'), + type: 'success', + timer: 1000, + showConfirmButton: false + }); + }); + }); } }); diff --git a/packages/rocketchat-livechat/package.js b/packages/rocketchat-livechat/package.js index 537db759cac55..85745d4c6e9eb 100644 --- a/packages/rocketchat-livechat/package.js +++ b/packages/rocketchat-livechat/package.js @@ -160,6 +160,7 @@ Package.onUse(function(api) { api.addFiles('server/methods/removeDepartment.js', 'server'); api.addFiles('server/methods/removeManager.js', 'server'); api.addFiles('server/methods/removeTrigger.js', 'server'); + api.addFiles('server/methods/removeRoom.js', 'server'); api.addFiles('server/methods/saveAppearance.js', 'server'); api.addFiles('server/methods/saveCustomField.js', 'server'); api.addFiles('server/methods/saveDepartment.js', 'server'); diff --git a/packages/rocketchat-livechat/server/methods/removeRoom.js b/packages/rocketchat-livechat/server/methods/removeRoom.js new file mode 100644 index 0000000000000..a91f4309de7c3 --- /dev/null +++ b/packages/rocketchat-livechat/server/methods/removeRoom.js @@ -0,0 +1,31 @@ +Meteor.methods({ + 'livechat:removeRoom'(rid) { + if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'remove-closed-livechat-rooms')) { + throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeRoom' }); + } + + const room = RocketChat.models.Rooms.findOneById(rid); + + if (!room) { + throw new Meteor.Error('error-invalid-room', 'Invalid room', { + method: 'livechat:removeRoom' + }); + } + + if (room.t !== 'l') { + throw new Meteor.Error('error-this-is-not-a-livechat-room', 'This is not a Livechat room', { + method: 'livechat:removeRoom' + }); + } + + if (room.open) { + throw new Meteor.Error('error-room-is-not-closed', 'Room is not closed', { + method: 'livechat:removeRoom' + }); + } + + RocketChat.models.Messages.removeByRoomId(rid); + RocketChat.models.Subscriptions.removeByRoomId(rid); + return RocketChat.models.Rooms.removeById(rid); + } +}); diff --git a/server/startup/migrations/v127.js b/server/startup/migrations/v127.js new file mode 100644 index 0000000000000..546a7d526ce58 --- /dev/null +++ b/server/startup/migrations/v127.js @@ -0,0 +1,20 @@ +RocketChat.Migrations.add({ + version: 127, + up() { + if (RocketChat.models && RocketChat.models.Permissions) { + + const newPermission = RocketChat.models.Permissions.findOne('view-livechat-manager'); + if (newPermission && newPermission.roles.length) { + RocketChat.models.Permissions.upsert({ _id: 'remove-closed-livechat-rooms' }, { $set: { roles: newPermission.roles } }); + } + } + }, + + down() { + if (RocketChat.models && RocketChat.models.Permissions) { + + // Revert permission + RocketChat.models.Permissions.remove({ _id: 'remove-closed-livechat-rooms' }); + } + } +}); From e3f75431151e1cd9a52fc0db9d20dc0d7a75c078 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Thu, 14 Jun 2018 15:22:40 -0300 Subject: [PATCH 4/9] [FIX] migration 126 --- server/startup/migrations/v126.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/startup/migrations/v126.js b/server/startup/migrations/v126.js index 839985586de29..16714e45f8130 100644 --- a/server/startup/migrations/v126.js +++ b/server/startup/migrations/v126.js @@ -11,8 +11,8 @@ RocketChat.Migrations.add({ const setting = RocketChat.models.Settings.findOne(query); if (setting) { - setting._id = 'Accounts_Default_User_Preferences_idleTimeLimit'; - RocketChat.models.Settings.insert(setting); + delete setting._id; + RocketChat.models.Settings.upsert({_id: 'Accounts_Default_User_Preferences_idleTimeLimit'}, setting); RocketChat.models.Settings.remove(query); } } From 6e2d906b19cf630f3f5c6a50706150f9f99d3912 Mon Sep 17 00:00:00 2001 From: Marcos Spessatto Defendi Date: Thu, 14 Jun 2018 15:57:52 -0300 Subject: [PATCH 5/9] [FIX] title and value attachments are optionals on sendMessage method (#11021) Closes #10739 and #10942 Change required fields to optional, due to regressions in most integrations --- packages/rocketchat-lib/server/functions/sendMessage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-lib/server/functions/sendMessage.js b/packages/rocketchat-lib/server/functions/sendMessage.js index 89c58881ac175..321d085641f02 100644 --- a/packages/rocketchat-lib/server/functions/sendMessage.js +++ b/packages/rocketchat-lib/server/functions/sendMessage.js @@ -20,7 +20,7 @@ const validateAttachmentsFields = attachmentFields => { short: Boolean })); - check(attachmentFields, Match.ObjectIncluding({ + check(attachmentFields, objectMaybeIncluding({ title: String, value: String })); @@ -30,7 +30,7 @@ const validateAttachment = attachment => { check(attachment, objectMaybeIncluding({ color: String, text: String, - ts: String, + ts: Match.OneOf(String, Match.Integer), thumb_url: String, message_link: String, collapsed: Boolean, From 3d81ff0f401bec7ad03425e7e1f77a35cb2f0a77 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Thu, 14 Jun 2018 18:43:43 -0300 Subject: [PATCH 6/9] [FIX] set-toolbar-items postMessage (#11109) We had some refactors and this code was deleted... ![image](https://user-images.githubusercontent.com/5263975/41310728-bae165e8-6e58-11e8-8c55-fdfdfecc46e3.png) ![image](https://user-images.githubusercontent.com/5263975/41310793-eb98a91c-6e58-11e8-90b5-905b8aee0148.png) --- .../client/imports/components/header.css | 8 +++++++ .../client/flexTabBar.html | 15 +++++++++++-- .../client/flexTabBar.js | 4 ++++ .../client/components/header/header.js | 21 ++++++++++++------- .../client/lib/iframeCommands.js | 4 ++-- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/packages/rocketchat-theme/client/imports/components/header.css b/packages/rocketchat-theme/client/imports/components/header.css index b05a45e848cdc..00be50a788b08 100644 --- a/packages/rocketchat-theme/client/imports/components/header.css +++ b/packages/rocketchat-theme/client/imports/components/header.css @@ -259,6 +259,14 @@ font-size: 12px; font-weight: 600; } + & + & { + border-left: 1px var(--color-gray) solid; + + .rtl & { + border-left: 0; + border-right: 1px var(--color-gray) solid; + } + } } .tab-button-icon--star { diff --git a/packages/rocketchat-ui-flextab/client/flexTabBar.html b/packages/rocketchat-ui-flextab/client/flexTabBar.html index 40797a795322f..4db9b5f805af4 100644 --- a/packages/rocketchat-ui-flextab/client/flexTabBar.html +++ b/packages/rocketchat-ui-flextab/client/flexTabBar.html @@ -31,6 +31,17 @@

{{_ label}}