feat: update article all
This commit is contained in:
parent
95cc9df933
commit
8e9fe2559b
|
|
@ -54,54 +54,51 @@ func (_i *articlesRepository) GetAll(clientId *uuid.UUID, userLevelId *uint, req
|
||||||
query = query.Where("client_id = ?", clientId)
|
query = query.Where("client_id = ?", clientId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_i.Log.Info().Interface("userLevelId", userLevelId).Msg("")
|
||||||
// Add approval workflow filtering based on user level
|
// Add approval workflow filtering based on user level
|
||||||
if userLevelId != nil {
|
if userLevelId != nil {
|
||||||
// Complete filtering logic for article visibility
|
// Strict filtering logic for article visibility based on approval workflow
|
||||||
query = query.Where(`
|
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)
|
(bypass_approval = true OR approval_exempt = true)
|
||||||
OR
|
OR
|
||||||
-- Articles that are published
|
-- Articles that are published AND approved through workflow
|
||||||
(is_publish = true)
|
(is_publish = true AND status_id = 2)
|
||||||
OR
|
OR
|
||||||
-- Articles where this user level is an approver in current step
|
-- Articles created by users at HIGHER hierarchy only (not same or lower)
|
||||||
(
|
|
||||||
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
|
|
||||||
EXISTS (
|
EXISTS (
|
||||||
SELECT 1 FROM users u
|
SELECT 1 FROM users u
|
||||||
JOIN user_levels ul ON u.user_level_id = ul.id
|
JOIN user_levels ul ON u.user_level_id = ul.id
|
||||||
WHERE u.id = articles.created_by_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 = ?
|
SELECT ul2.level_number FROM user_levels ul2 WHERE ul2.id = ?
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
OR
|
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
|
workflow_id IS NOT NULL
|
||||||
AND EXISTS (
|
AND EXISTS (
|
||||||
SELECT 1 FROM article_approval_flows aaf
|
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
|
WHERE aaf.article_id = articles.id
|
||||||
AND aaf.status_id IN (1, 4)
|
AND aaf.status_id = 1 -- Only in progress
|
||||||
AND EXISTS (
|
|
||||||
SELECT 1 FROM approval_workflow_steps aws
|
|
||||||
WHERE aws.workflow_id = aaf.workflow_id
|
|
||||||
AND aws.required_user_level_id = ?
|
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'
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
`, *userLevelId, *userLevelId, *userLevelId)
|
`, *userLevelId, *userLevelId, *userLevelId)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue