From 423a4be51b4c12f7db9caff5eb504c2e0add387d Mon Sep 17 00:00:00 2001 From: Josepablo C Date: Fri, 28 Feb 2025 21:59:59 -0600 Subject: [PATCH] fix: Allow modification of role warehouse in users endpoint --- v1/src/apps/private/users/services.js | 28 ++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/v1/src/apps/private/users/services.js b/v1/src/apps/private/users/services.js index fdac532..766e1ae 100644 --- a/v1/src/apps/private/users/services.js +++ b/v1/src/apps/private/users/services.js @@ -54,24 +54,38 @@ const patchProfileData = async(req, res) => { } }; +/** + * Verify if the author has enough rights to change the affected user role + * @param {*} change_author_job_role + * @param {*} affected_job_role + * @returns + */ function job_role_change_allowance( change_author_job_role , affected_job_role ){ try{ + /** Only owner and managers can change the role */ if( (change_author_job_role !== "owner") && (change_author_job_role !== "manager") ){ return false; } + /** No one can affect the role of the owner */ if( affected_job_role === "owner" ){ return false; } - switch( affected_job_role ){ - case 'manager': - case 'driver': - case 'staff': - return true; - default: - return false; + /** You can only modify the role of a user if it is in the following list */ + const modifiable_roles = [ + 'manager', + 'driver', + 'staff', + 'warehouse' + ]; + + if( modifiable_roles.includes( affected_job_role ) ){ + return true; + }else{ + return false; } + }catch( error ){ console.error( error ); return res.status( 500 ).send( { error } );