-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
[IMPROVE][Omnichannel] Allow set other agent status via method livechat:changeLivechatStatus
#18571
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some suggestions in order to reduce the complexity of the code.
@@ -1,14 +1,23 @@ | |||
import { Meteor } from 'meteor/meteor'; | |||
|
|||
import { Livechat } from '../lib/Livechat'; | |||
import { hasPermission, hasRole } from '../../../authorization'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { hasPermission, hasRole } from '../../../authorization'; | |
import { hasPermission } from '../../../authorization'; |
@@ -1,14 +1,23 @@ | |||
import { Meteor } from 'meteor/meteor'; | |||
|
|||
import { Livechat } from '../lib/Livechat'; | |||
import { hasPermission, hasRole } from '../../../authorization'; | |||
import { Users } from '../../../models'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { Users } from '../../../models'; | |
import { Users } from '../../../models'; | |
const getUser = (userId, agentId, options = {}) => { | |
if (!agentId) { | |
return Users.findOneById(userId, options); | |
} | |
if (!hasPermission(userId, 'manage-livechat-agents')) { | |
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:changeLivechatStatus' }); | |
} | |
return Users.findOneAgentById(agentId, options); | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do really disagree about these 'helpers functions' it creates a special complexity and does not help if we perform a global search... and getUser
means almost nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the permission manage-livechat-agents
does not look related to getUser
why I can't get a user if I'm not a manager? (I know why, but I'm questioning the function purpose)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other(better) options to implement this functionally:
- REST API endpoint
- Specific Meteor method
The complexity is increasing because the current method wasn't designed to support calls from other users other than the user who will be impacted by this action. So, that's exactly the reason a helper(local) method has been suggested, the purpose is to avoid adding more and specific code inside the main method.
The main method just needs to get a valid user, the logic/permission doesn't matter and that's the reason a helper method will avoid more complexity.
The scope of the helper function is local, which means its context and its name is local, the helper method is not being exported so, anyone may be able to know that when searching globally if it's the case.
The point is that when the user who is calling this method isn't the same(agent) who will get their service status changed, then the user who is performing the action MUST have the permission mentioned in the code.
Also, after performing the necessary validation, a User
is expected as a result and this is the reason for the name suggested, but the developer can define the helper name he wants, even the helper method is local.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not talking about if this method should or not perform both actions, it's an omnichannel design/concern...
I'm only talking about creating small functions to do whatever we want just to hide some weird complexity, but we never gonna use the function again, it really turns the development hard instead of reduce the complexity, and I'm seeing a lot this behavior being spread around the code, that's why I'm reinforcing here...
thank you for the explanation, but I'm afraid I'm quite aware about scopes, exports, modules... and again I do really disagree with this pattern
if (!Meteor.userId()) { | ||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:changeLivechatStatus' }); | ||
} | ||
|
||
const user = Meteor.user(); | ||
let user = Meteor.user(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let user = Meteor.user(); | |
const user = getUser(Meteor.userId(), agentId, { fields: { _id: 1, statusLivechat: 1 } }); | |
if (!user) { | |
throw new Meteor.Error('invalid-user', 'Invalid User', { method: 'livechat:changeLivechatStatus' }); | |
} |
return; | ||
} | ||
|
||
if (!agent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, move this check above this line. Otherwise, agent.statusLivechat
may raise an error when the agent
is not found.
Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com>
…etChat/Rocket.Chat into add-parameter-livechatStatus-Method
Squashed commit of the following: commit 3d28fb9 Author: Guilherme Gazzo <guilherme@gazzo.xyz> Date: Fri Aug 21 17:25:15 2020 -0300 Review commit b560888 Merge: 2e5417c 40c7226 Author: Guilherme Gazzo <guilherme@gazzo.xyz> Date: Fri Aug 21 17:05:37 2020 -0300 Merge branch 'ref/omni' of github.com:RocketChat/Rocket.Chat into ref/omni-curr-chats commit 40c7226 Merge: ab78f68 575df22 Author: Guilherme Gazzo <guilhermegazzo@gmail.com> Date: Fri Aug 21 17:04:51 2020 -0300 Merge branch 'develop' into ref/omni commit 2e5417c Merge: da8388b 6b04ba5 Author: Guilherme Gazzo <guilherme@gazzo.xyz> Date: Fri Aug 21 16:23:21 2020 -0300 Merge branch 'ref/omni-curr-chats' of github.com:RocketChat/Rocket.Chat into ref/omni-curr-chats commit da8388b Merge: 07f2e89 ab78f68 Author: Guilherme Gazzo <guilherme@gazzo.xyz> Date: Fri Aug 21 16:22:43 2020 -0300 Merge branch 'ref/omni' of github.com:RocketChat/Rocket.Chat into ref/omni-curr-chats commit 575df22 Author: Anton Kazarinov <askazarinov@gmail.com> Date: Fri Aug 21 23:31:45 2020 +0500 [IMPROVE] Slack bridge: add support to threads (#15992) Co-authored-by: Rodrigo Nascimento <rodrigoknascimento@gmail.com> Co-authored-by: pierre-lehnen-rc <55164754+pierre-lehnen-rc@users.noreply.github.com> commit 40520f4 Author: Douglas Gubert <d-gubert@users.noreply.github.com> Date: Fri Aug 21 15:16:10 2020 -0300 [NEW][APPS-ENGINE] Implement new IPostLivechatRoomTransferred event (#18625) * Implement new IPostLivechatRoomTransferred event * Move event trigger to correct place * Update Apps-Engine version commit ab78f68 Merge: 3aca1b0 06467a6 Author: Guilherme Gazzo <guilherme@gazzo.xyz> Date: Fri Aug 21 13:57:53 2020 -0300 Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into ref/omni commit 6b04ba5 Author: Martin <martin.schoeler@rocket.chat> Date: Fri Aug 21 03:39:05 2020 -0300 Remove old files commit 47c92ce Author: Martin <martin.schoeler@rocket.chat> Date: Fri Aug 21 03:33:21 2020 -0300 Revert develop merge commit 4a23db7 Author: Martin <martin.schoeler@rocket.chat> Date: Fri Aug 21 03:27:45 2020 -0300 add tags commit 06467a6 Author: Guilherme Gazzo <guilhermegazzo@gmail.com> Date: Fri Aug 21 03:10:31 2020 -0300 [IMPROVE] UserCard and UserInfo Show Real Names Setting (#18628) commit ebcfbd3 Author: Martin <martin.schoeler@rocket.chat> Date: Fri Aug 21 01:30:35 2020 -0300 remove test data commit 07f2e89 Author: Guilherme Gazzo <guilherme@gazzo.xyz> Date: Fri Aug 21 01:25:12 2020 -0300 Fix commit 7cb736b Merge: d7840be 7d60bee Author: Guilherme Gazzo <guilherme@gazzo.xyz> Date: Fri Aug 21 00:48:02 2020 -0300 Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into ref/omni-curr-chats commit d7840be Author: Martin <martin.schoeler@rocket.chat> Date: Fri Aug 21 00:21:26 2020 -0300 use old url commit cfb5a33 Author: Martin <martin.schoeler@rocket.chat> Date: Fri Aug 21 00:09:45 2020 -0300 lint commit 2cfbafb Author: Martin <martin.schoeler@rocket.chat> Date: Fri Aug 21 00:08:27 2020 -0300 Current Chats wip commit 7d60bee Author: Guilherme Gazzo <guilhermegazzo@gmail.com> Date: Thu Aug 20 22:45:51 2020 -0300 [FIX] MarkdownText usage (#18621) commit 3aca1b0 Author: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Thu Aug 20 22:43:22 2020 -0300 Refactor: Omnichannel Facebook Integration (#18624) Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz> commit 528fbe7 Author: Marcos Spessatto Defendi <marcos.defendi@ulbra.inf.br> Date: Thu Aug 20 22:42:05 2020 -0300 Anonymous user were being created based on manually approve users (#17427) commit 88649be Author: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Thu Aug 20 22:14:08 2020 -0300 Fix Triggers (#18626) commit abae419 Author: Rodrigo Nascimento <rodrigoknascimento@gmail.com> Date: Thu Aug 20 22:00:41 2020 -0300 Update dependencies (#18593) commit 09b825d Author: pierre-lehnen-rc <55164754+pierre-lehnen-rc@users.noreply.github.com> Date: Thu Aug 20 21:15:39 2020 -0300 [NEW] Banner for servers in the middle of the registration process (#18623) commit bce223a Author: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> Date: Fri Aug 21 04:11:42 2020 +0530 [NEW]Add new endpoint to change Omnichannel room's visitor (#18528) * add new endpoint to change room visitor * Apply suggestions from code review Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com> * fix errors in previous commit * modify livechat.config endpoint to support new param - roomId * Apply suggestions from code review Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com> * remove changes to livechat-config endpoint * move permission check into Livechat lib * refactor code * Apply suggestions from code review Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com> * query optimization and fix return value * return whole room object * limit room fields from while loading from DB * Remove unecessary promise statement. Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com> commit a0a4948 Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu Aug 20 14:10:47 2020 -0300 Bump bcrypt from 3.0.7 to 5.0.0 (#18622) Bumps [bcrypt](https://github.com/kelektiv/node.bcrypt.js) from 3.0.7 to 5.0.0. - [Release notes](https://github.com/kelektiv/node.bcrypt.js/releases) - [Changelog](https://github.com/kelektiv/node.bcrypt.js/blob/master/CHANGELOG.md) - [Commits](kelektiv/node.bcrypt.js@v3.0.7...v5.0.0) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> commit 4a2636d Author: Paulo Bernardo <paulo.bernardo@ilhasoft.com.br> Date: Thu Aug 20 11:45:56 2020 -0300 [FIX] Agents enabledDepartment attribute not set on collection (#18614) commit 28cf942 Author: jbguerraz <861556+jbguerraz@users.noreply.github.com> Date: Thu Aug 20 14:43:29 2020 +0200 [IMPROVE] Jitsi room name hash or plain (#17481) commit 452589f Author: Diego Sampaio <chinello@gmail.com> Date: Wed Aug 19 20:22:40 2020 -0300 Explain why issue is closed when not using an issue template (#18420) commit b491b26 Author: Rodrigo Nascimento <rodrigoknascimento@gmail.com> Date: Wed Aug 19 18:36:51 2020 -0300 Prevent directory API to return emails if the user has no permission (#18478) commit 0a2d8ca Author: Rodrigo Nascimento <rodrigoknascimento@gmail.com> Date: Wed Aug 19 18:20:16 2020 -0300 Set default timeout of 20s for HTTP calls (#18549) commit 0e2309e Author: Guilherme Gazzo <guilhermegazzo@gmail.com> Date: Wed Aug 19 18:07:36 2020 -0300 [FIX] UIKit Select and Multiselects not working (#18598) commit dc549a5 Author: Martin Schoeler <martin.schoeler@rocket.chat> Date: Wed Aug 19 10:27:34 2020 -0300 [IMPROVE] Add agentId parameter to changeLivechatStatus method (#18571) * Add agentId parameter to changeLivechatStatus method * Fix reviews * fix problems * return if the same as before * Update app/livechat/server/methods/changeLivechatStatus.js Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com> * Fix review Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com> Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com> Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz> commit fdda142 Author: Martin Schoeler <martin.schoeler@rocket.chat> Date: Wed Aug 19 04:11:26 2020 -0300 [FIX] Auto complete user suggestions (#18437) Co-authored-by: Tasso Evangelista <tasso.evangelista@rocket.chat>
livechat:changeLivechatStatus
Apparently this PR seems to break new RC installs on 3.6.0. New db and user w/ admin (created on initial setup) permissions:
|
Proposed changes
This allows to other users to change the status of a livechat agent, given that the user has the appropriate permission.
It should not break anything that uses this method.
Types of changes
Checklist