| | 1 | = UseCase02- Manages Clients |
| | 2 | ** Initiating actor: Admin ** |
| | 3 | == Description |
| | 4 | The Admin moderates Petify by blocking a client account when the client posts disrespectful/abusive reviews, or when the client receives extremely bad reviews that indicate harmful or unacceptable behavior. The Admin reviews evidence (review comments, ratings) and then blocks the client. The system records the decision (who/when/why), marks the user as blocked, and creates a notification for the blocked user. |
| | 5 | == Scenario |
| | 6 | 1. Admin goes to the reviews page that are grouped by client. |
| | 7 | {{{ |
| | 8 | SELECT |
| | 9 | u.user_id, |
| | 10 | u.username, |
| | 11 | u.email, |
| | 12 | u.is_blocked, |
| | 13 | u.blocked_reason, |
| | 14 | u.blocked_at, |
| | 15 | u.blocked_by, |
| | 16 | |
| | 17 | COUNT(ur.review_id) AS received_review_count, |
| | 18 | COALESCE(AVG(r.rating), 0)::numeric(10,2) AS avg_received_rating, |
| | 19 | |
| | 20 | (SELECT COUNT(*) |
| | 21 | FROM reviews rw |
| | 22 | WHERE rw.reviewer_id = u.user_id) AS written_review_count |
| | 23 | |
| | 24 | FROM users u |
| | 25 | JOIN clients c ON c.user_id = u.user_id |
| | 26 | LEFT JOIN user_reviews ur ON ur.target_user_id = u.user_id |
| | 27 | LEFT JOIN reviews r ON r.review_id = ur.review_id |
| | 28 | GROUP BY |
| | 29 | u.user_id, u.username, u.email, |
| | 30 | u.is_blocked, u.blocked_reason, u.blocked_at, u.blocked_by |
| | 31 | ORDER BY |
| | 32 | (COUNT(ur.review_id) = 0) ASC, |
| | 33 | avg_received_rating ASC, |
| | 34 | received_review_count DESC, |
| | 35 | u.username; |
| | 36 | |
| | 37 | }}} |
| | 38 | 2. Admin clicks on a client so he can see all the reviews for them. |
| | 39 | {{{ |
| | 40 | SELECT |
| | 41 | r.review_id, |
| | 42 | r.reviewer_id, |
| | 43 | ru.username AS reviewer_username, |
| | 44 | r.rating, |
| | 45 | r.comment, |
| | 46 | r.created_at |
| | 47 | FROM user_reviews ur |
| | 48 | JOIN reviews r ON r.review_id = ur.review_id |
| | 49 | JOIN users ru ON ru.user_id = r.reviewer_id |
| | 50 | WHERE ur.target_user_id = $1 |
| | 51 | ORDER BY r.created_at DESC; |
| | 52 | }}} |
| | 53 | 3. Admin clicks "Block client" and enters the reason. |
| | 54 | {{{ |
| | 55 | BEGIN; |
| | 56 | |
| | 57 | SELECT u.user_id, u.email, u.is_blocked |
| | 58 | FROM users u |
| | 59 | JOIN clients c ON c.user_id = u.user_id |
| | 60 | WHERE u.user_id = $1 |
| | 61 | FOR UPDATE; |
| | 62 | |
| | 63 | UPDATE users |
| | 64 | SET |
| | 65 | is_blocked = TRUE, |
| | 66 | blocked_reason = $2, |
| | 67 | blocked_by = $4, |
| | 68 | blocked_at = NOW() |
| | 69 | WHERE user_id = $1; |
| | 70 | |
| | 71 | INSERT INTO notifications (user_id, type, message, is_read, created_at) |
| | 72 | VALUES ( |
| | 73 | $1, |
| | 74 | 'ACCOUNT_BLOCKED', |
| | 75 | CONCAT('Your account has been blocked. Reason: ', $2, '. ', COALESCE($3, '')), |
| | 76 | FALSE, |
| | 77 | NOW() |
| | 78 | ); |
| | 79 | |
| | 80 | COMMIT; |
| | 81 | }}} |
| | 82 | 4. The system sends and email to the client. |
| | 83 | {{{ |
| | 84 | SELECT |
| | 85 | email, |
| | 86 | username, |
| | 87 | blocked_reason, |
| | 88 | blocked_at |
| | 89 | FROM users |
| | 90 | WHERE user_id = $1; |
| | 91 | }}} |
| | 92 | |
| | 93 | |
| | 94 | |