-
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
Changes from 1 commit
9b46e5e
4042004
277a22e
a3e0ddd
ae7a8a8
d57aaae
1002ab1
91cbea1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and the permission There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are other(better) options to implement this functionally:
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 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Meteor.methods({ | ||||||||||||||||||||||||||||||
'livechat:changeLivechatStatus'() { | ||||||||||||||||||||||||||||||
'livechat:changeLivechatStatus'(agentId) { | ||||||||||||||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (agentId && hasPermission(Meteor.userId(), 'manage-livechat-agents')) { | ||||||||||||||||||||||||||||||
user = Users.findOneById(agentId); | ||||||||||||||||||||||||||||||
if (!user || !hasRole(agentId, 'livechat-agent')) { | ||||||||||||||||||||||||||||||
throw new Meteor.Error('error-user-is-not-agent', 'User is not a livechat agent', { method: 'livechat:saveAgentInfo' }); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const newStatus = user.statusLivechat === 'available' ? 'not-available' : 'available'; | ||||||||||||||||||||||||||||||
if (!Livechat.allowAgentChangeServiceStatus(newStatus, user._id)) { | ||||||||||||||||||||||||||||||
|
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.