Do not sync user which are enabled with UserGroup related to UserJob.

Updated SQL queries to include checks for user.enabled status, ensuring proper handling of both enabled and null states. This improves the synchronization logic by aligning it with user activity and account status conditions.
This commit is contained in:
2025-05-23 15:52:11 +02:00
parent ebdfa04843
commit e8bca6a502

View File

@@ -87,8 +87,8 @@ final readonly class UserGroupRelatedToUserJobSync implements UserGroupRelatedTo
AND chill_main_user_group_user.user_id = u.id AND chill_main_user_group_user.user_id = u.id
AND jh.user_id = u.id AND tsrange(jh.startdate, jh.enddate) @> localtimestamp AND jh.user_id = u.id AND tsrange(jh.startdate, jh.enddate) @> localtimestamp
-- only when the user's jobid is different than the user_group id -- only when the user's jobid is different than the user_group id
AND ug.userjob_id IS NOT NULL -- or where the user.enabled is null
AND jh.job_id <> ug.userjob_id AND ((ug.userjob_id IS NOT NULL AND jh.job_id <> ug.userjob_id) OR u.enabled IS NULL)
SQL; SQL;
$result = $connection->executeQuery($sql); $result = $connection->executeQuery($sql);
@@ -103,7 +103,8 @@ final readonly class UserGroupRelatedToUserJobSync implements UserGroupRelatedTo
SELECT cmug.id, jh.user_id SELECT cmug.id, jh.user_id
FROM chill_main_user_group cmug FROM chill_main_user_group cmug
JOIN chill_main_user_job_history jh ON jh.job_id = cmug.userjob_id AND tsrange(jh.startdate, jh.enddate) @> localtimestamp JOIN chill_main_user_job_history jh ON jh.job_id = cmug.userjob_id AND tsrange(jh.startdate, jh.enddate) @> localtimestamp
WHERE cmug.userjob_id IS NOT NULL JOIN users u ON u.id = jh.user_id
WHERE cmug.userjob_id IS NOT NULL AND u.enabled IS TRUE
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
SQL; SQL;