Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,22 @@ export const addIncomingIntegration = async (userId: string, integration: INewIn

const user = await Users.findOneByUsername(integration.username, { projection: { _id: 1 } });

if (!user || !(await hasPermissionAsync(user._id, 'message-impersonate'))) {
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'addIncomingIntegration',
});
}

if (!(await hasPermissionAsync(user._id, 'message-impersonate'))) {
throw new Meteor.Error(
'error-user-lacks-message-impersonate-permission',
"User selected for the incoming integration lacks the 'message-impersonate' permission.",
{
method: 'addIncomingIntegration',
},
);
}

// Default to transpiling with Babel for backwards compatibility; integrations
// can opt-out per-record by setting `skipTranspile: true` (removed in 9.0.0).
const skipTranspile = integration.skipTranspile === true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,22 @@ export const updateIncomingIntegration = async (
const username = 'username' in integration ? integration.username : currentIntegration.username;
const user = await Users.findOneByUsername(username, { projection: { _id: 1, username: 1 } });

if (!user || !(await hasPermissionAsync(user._id, 'message-impersonate'))) {
if (!user) {
throw new Meteor.Error('error-invalid-post-as-user', 'Invalid Post As User', {
method: 'updateIncomingIntegration',
});
}

if (!(await hasPermissionAsync(user._id, 'message-impersonate'))) {
throw new Meteor.Error(
'error-user-lacks-message-impersonate-permission',
"User selected for the incoming integration lacks the 'message-impersonate' permission.",
{
method: 'updateIncomingIntegration',
},
);
}

const updatedIntegration = await Integrations.findOneAndUpdate(
{ _id: integrationId },
{
Expand Down
10 changes: 8 additions & 2 deletions apps/meteor/tests/end-to-end/api/incoming-integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ describe('[Incoming Integrations]', () => {
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error', 'Invalid user [error-invalid-user]');
expect(res.body).to.have.property(
'error',
"User selected for the incoming integration lacks the 'message-impersonate' permission. [error-user-lacks-message-impersonate-permission]",
);
});
});
});
Expand Down Expand Up @@ -965,7 +968,10 @@ describe('[Incoming Integrations]', () => {
})
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error', 'Invalid Post As User [error-invalid-post-as-user]');
expect(res.body).to.have.property(
'error',
"User selected for the incoming integration lacks the 'message-impersonate' permission. [error-user-lacks-message-impersonate-permission]",
);
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -6490,6 +6490,7 @@
"error-user-is-not-activated": "User is not activated",
"error-user-is-not-agent": "User is not an Omnichannel Agent",
"error-user-is-offline": "User is offline",
"error-user-lacks-message-impersonate-permission": "User selected for the incoming integration lacks the 'message-impersonate' permission.",
"error-user-limit-exceeded": "The number of users you are trying to invite to #channel_name exceeds the limit set by the administrator",
"error-user-not-belong-to-department": "User does not belong to this department",
"error-user-not-found": "User not found",
Expand Down
Loading