diff --git a/.changeset/sour-kids-heal.md b/.changeset/sour-kids-heal.md new file mode 100644 index 0000000000000..9dbeff968bbfd --- /dev/null +++ b/.changeset/sour-kids-heal.md @@ -0,0 +1,6 @@ +--- +"@rocket.chat/meteor": patch +"@rocket.chat/ddp-client": patch +--- + +Fixed a problem where chained callbacks' return value was being overrided by some callbacks returning something different, causing callbacks with lower priority to operate on invalid values diff --git a/apps/meteor/ee/app/authorization/server/callback.ts b/apps/meteor/ee/app/authorization/server/callback.ts index 4da07733ab515..707d45d96e0e6 100644 --- a/apps/meteor/ee/app/authorization/server/callback.ts +++ b/apps/meteor/ee/app/authorization/server/callback.ts @@ -12,10 +12,36 @@ License.onInstall(() => { callbacks.priority.HIGH, 'validateUserRoles', ); - callbacks.add('afterSaveUser', () => License.shouldPreventAction('activeUsers'), callbacks.priority.HIGH, 'validateUserRoles'); - callbacks.add('afterDeleteUser', () => License.shouldPreventAction('activeUsers'), callbacks.priority.HIGH, 'validateUserRoles'); + callbacks.add( + 'afterSaveUser', + async (user) => { + await License.shouldPreventAction('activeUsers'); - callbacks.add('afterDeactivateUser', () => License.shouldPreventAction('activeUsers'), callbacks.priority.HIGH, 'validateUserStatus'); + return user; + }, + callbacks.priority.HIGH, + 'validateUserRoles', + ); + callbacks.add( + 'afterDeleteUser', + async (user) => { + await License.shouldPreventAction('activeUsers'); + + return user; + }, + callbacks.priority.HIGH, + 'validateUserRoles', + ); + + callbacks.add( + 'afterDeactivateUser', + async (user) => { + await License.shouldPreventAction('activeUsers'); + return user; + }, + callbacks.priority.HIGH, + 'validateUserStatus', + ); callbacks.add( 'beforeActivateUser', diff --git a/apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts b/apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts index 0585c20bf1275..936c6525f9f13 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts @@ -806,6 +806,7 @@ describe('LIVECHAT - business hours', function () { }); it('should verify if agent becomes unavailable to take chats when user is deactivated', async () => { + await makeAgentAvailable(await login(agent.username, password)); await setUserActiveStatus(agent._id, false); const latestAgent = await getUserByUsername(agent.username);