feat: update article all

This commit is contained in:
hanif salafi 2025-09-16 23:45:21 +07:00
parent 95cc9df933
commit 8e9fe2559b
1 changed files with 24 additions and 27 deletions

View File

@ -54,53 +54,50 @@ func (_i *articlesRepository) GetAll(clientId *uuid.UUID, userLevelId *uint, req
query = query.Where("client_id = ?", clientId)
}
_i.Log.Info().Interface("userLevelId", userLevelId).Msg("")
// Add approval workflow filtering based on user level
if userLevelId != nil {
// Complete filtering logic for article visibility
// Strict filtering logic for article visibility based on approval workflow
query = query.Where(`
(
-- Articles that don't require approval
-- Articles that don't require approval (bypass or exempt)
(bypass_approval = true OR approval_exempt = true)
OR
-- Articles that are published
(is_publish = true)
-- Articles that are published AND approved through workflow
(is_publish = true AND status_id = 2)
OR
-- Articles where this user level is an approver in current step
(
workflow_id IS NOT NULL
AND current_approval_step > 0
AND EXISTS (
SELECT 1 FROM article_approval_flows aaf
JOIN approval_workflow_steps aws ON aaf.workflow_id = aws.workflow_id
WHERE aaf.article_id = articles.id
AND aaf.status_id = 1
AND aws.required_user_level_id = ?
AND aws.step_order = aaf.current_step
)
)
OR
-- Articles created by users at same or lower hierarchy
-- Articles created by users at HIGHER hierarchy only (not same or lower)
EXISTS (
SELECT 1 FROM users u
JOIN user_levels ul ON u.user_level_id = ul.id
WHERE u.id = articles.created_by_id
AND ul.level_number >= (
AND ul.level_number < (
SELECT ul2.level_number FROM user_levels ul2 WHERE ul2.id = ?
)
)
OR
-- Articles where this user level is ANY approver in the workflow
-- Articles where this user level is the CURRENT approver in the workflow
(
workflow_id IS NOT NULL
AND EXISTS (
SELECT 1 FROM article_approval_flows aaf
JOIN approval_workflow_steps aws ON aaf.workflow_id = aws.workflow_id
WHERE aaf.article_id = articles.id
AND aaf.status_id IN (1, 4)
AND EXISTS (
SELECT 1 FROM approval_workflow_steps aws
WHERE aws.workflow_id = aaf.workflow_id
AND aws.required_user_level_id = ?
)
AND aaf.status_id = 1 -- Only in progress
AND aws.required_user_level_id = ?
AND aws.step_order = aaf.current_step -- Must be current step
)
)
OR
-- Articles that have been approved by this user level
(
workflow_id IS NOT NULL
AND EXISTS (
SELECT 1 FROM article_approval_flows aaf
JOIN article_approval_step_logs aasl ON aaf.id = aasl.approval_flow_id
WHERE aaf.article_id = articles.id
AND aasl.user_level_id = ?
AND aasl.action = 'approve'
)
)
)