@@ -662,7 +662,13 @@ const createControllerMethods = function (UserProfile, Project, cache) {
662662
663663 const hasChangeStatusPermission = await hasPermission ( requestor , 'changeUserStatus' ) ;
664664 const hasFinalDayPermission = await hasPermission ( requestor , 'setFinalDay' ) ;
665- if ( ! ( hasChangeStatusPermission && hasFinalDayPermission && canEditProtectedAccount ) ) {
665+ const hasPausePermission = await hasPermission ( requestor , 'interactWithPauseUserButton' ) ;
666+ if (
667+ ! (
668+ ( ( hasChangeStatusPermission && hasFinalDayPermission ) || hasPausePermission ) &&
669+ canEditProtectedAccount
670+ )
671+ ) {
666672 if ( PROTECTED_EMAIL_ACCOUNT . includes ( requestor . email ) ) {
667673 logger . logInfo (
668674 `Unauthorized attempt to change protected user status. Requestor: ${ requestor . requestorId } Target: ${ userId } ` ,
@@ -929,7 +935,12 @@ const createControllerMethods = function (UserProfile, Project, cache) {
929935 } ;
930936
931937 const getUserProfiles = async function ( req , res ) {
932- if ( ! ( await checkPermission ( req , 'getUserProfiles' ) ) ) {
938+ if (
939+ ! (
940+ ( await checkPermission ( req , 'getUserProfiles' ) ) ||
941+ ( await checkPermission ( req , 'interactWithPauseUserButton' ) )
942+ )
943+ ) {
933944 return forbidden ( res , 'You are not authorized to view all users' ) ;
934945 }
935946
@@ -1233,9 +1244,7 @@ const createControllerMethods = function (UserProfile, Project, cache) {
12331244 ) ;
12341245
12351246 if ( verificationUser . bioPosted !== bioPosted ) {
1236- console . error (
1237- `WARNING: Database update failed! Expected: ${ bioPosted } , Actual: ${ verificationUser . bioPosted } ` ,
1238- ) ;
1247+ logger . logInfo ( 'Database update failed while verifying bio status change.' ) ;
12391248 return res . status ( 500 ) . json ( { error : 'Failed to update bio status in database.' } ) ;
12401249 }
12411250
@@ -1651,7 +1660,7 @@ const createControllerMethods = function (UserProfile, Project, cache) {
16511660
16521661 await user . save ( ) ;
16531662
1654- console . log ( `✅ Saved ${ key } in DB:` , user [ key ] ) ;
1663+ logger . logInfo ( ` Saved ${ key } in database.` ) ;
16551664
16561665 // ================================
16571666 // CACHE INVALIDATION (MERGED)
@@ -1903,7 +1912,6 @@ const createControllerMethods = function (UserProfile, Project, cache) {
19031912 }
19041913 return null ;
19051914 } ;
1906-
19071915 const changeUserStatus = async function ( req , res ) {
19081916 const { userId } = req . params ;
19091917 const { action, endDate, reactivationDate } = req . body ;
@@ -2031,6 +2039,74 @@ const createControllerMethods = function (UserProfile, Project, cache) {
20312039 }
20322040 } ;
20332041
2042+ const pauseResumeUser = async function ( req , res ) {
2043+ const { userId } = req . params ;
2044+ const activationDate = req . body . reactivationDate ;
2045+ const status = req . body . status === 'Active' ;
2046+
2047+ if ( ! mongoose . Types . ObjectId . isValid ( userId ) ) {
2048+ return res . status ( 400 ) . send ( { error : 'Bad Request' } ) ;
2049+ }
2050+
2051+ const canEditProtectedAccount = await canRequestorUpdateUser (
2052+ req . body . requestor . requestorId ,
2053+ userId ,
2054+ ) ;
2055+
2056+ if (
2057+ ! (
2058+ ( await hasPermission ( req . body . requestor , 'interactWithPauseUserButton' ) ) &&
2059+ canEditProtectedAccount
2060+ )
2061+ ) {
2062+ if ( PROTECTED_EMAIL_ACCOUNT . includes ( req . body . requestor . email ) ) {
2063+ logger . logInfo (
2064+ `Unauthorized attempt to change protected user status. Requestor: ${ req . body . requestor . requestorId } Target: ${ userId } ` ,
2065+ ) ;
2066+ }
2067+ return res . status ( 403 ) . send ( 'You are not authorized to change user status' ) ;
2068+ }
2069+
2070+ cache . removeCache ( `user-${ userId } ` ) ;
2071+
2072+ try {
2073+ const user = await UserProfile . findById ( userId , 'isActive email firstName lastName' ) ;
2074+ if ( ! user ) {
2075+ return res . status ( 404 ) . send ( { error : 'User not found' } ) ;
2076+ }
2077+
2078+ user . set ( {
2079+ isActive : status ,
2080+ reactivationDate : activationDate ,
2081+ } ) ;
2082+
2083+ await user . save ( ) ;
2084+
2085+ const isUserInCache = cache . hasCache ( 'allusers' ) ;
2086+ if ( isUserInCache ) {
2087+ const allUserData = JSON . parse ( cache . getCache ( 'allusers' ) ) ;
2088+ const userIdx = allUserData . findIndex ( ( u ) => u . _id === userId ) ;
2089+ if ( userIdx !== - 1 ) {
2090+ const userData = allUserData [ userIdx ] ;
2091+ userData . isActive = user . isActive ;
2092+ allUserData . splice ( userIdx , 1 , userData ) ;
2093+ cache . setCache ( 'allusers' , JSON . stringify ( allUserData ) ) ;
2094+ }
2095+ }
2096+
2097+ auditIfProtectedAccountUpdated ( {
2098+ requestorId : req . body . requestor . requestorId ,
2099+ updatedRecordEmail : user . email ,
2100+ actionPerformed : 'UserStatusUpdate' ,
2101+ } ) ;
2102+
2103+ return res . status ( 200 ) . send ( { message : 'status updated' } ) ;
2104+ } catch ( error ) {
2105+ logger . logException ( error ) ;
2106+ return res . status ( 500 ) . send ( { error : 'Internal Error' } ) ;
2107+ }
2108+ } ;
2109+
20342110 const changeUserRehireableStatus = async function ( req , res ) {
20352111 const { userId } = req . params ;
20362112 const { isRehireable } = req . body ;
@@ -2955,8 +3031,8 @@ const createControllerMethods = function (UserProfile, Project, cache) {
29553031 }
29563032 return res . status ( 200 ) . json ( result . data ) ;
29573033 } catch ( error ) {
2958- console . error ( 'Error fetching skill data:' , error ) ;
2959- return res . status ( 500 ) . send ( { error : error . message } ) ;
3034+ logger . logException ( error ) ;
3035+ return res . status ( 500 ) . send ( { error : 'Internal Error' } ) ;
29603036 }
29613037 } ;
29623038
@@ -2976,6 +3052,7 @@ const createControllerMethods = function (UserProfile, Project, cache) {
29763052 getTeamMembersofUser,
29773053 getProjectMembers,
29783054 changeUserStatus,
3055+ pauseResumeUser,
29793056 resetPassword,
29803057 getUserByName,
29813058 getAllUsersWithFacebookLink,
0 commit comments