| | | 1 | | using ArturRios.Util.Http; |
| | | 2 | | |
| | | 3 | | namespace ArturRios.Heimdall.Shared.Messages; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Maps each <see cref="PersonMessages" /> value to its HTTP status code, following the UC-06, |
| | | 7 | | /// UC-07, UC-08, UC-09 and UC-10 flows. Passed to the response resolver. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class PersonMessageMap |
| | | 10 | | { |
| | 4 | 11 | | public static readonly IReadOnlyDictionary<string, int> StatusCodes = |
| | 4 | 12 | | DataAccessMessageMap.CombinedWith(new Dictionary<string, int> |
| | 4 | 13 | | { |
| | 4 | 14 | | // UC-06 main flow — person created. |
| | 4 | 15 | | [PersonMessages.PersonCreatedSuccessfully] = HttpStatusCodes.Created, |
| | 4 | 16 | | // AF-06a — email already exists. |
| | 4 | 17 | | [PersonMessages.EmailAlreadyExists] = HttpStatusCodes.Conflict, |
| | 4 | 18 | | // AF-08k — the email sign-in method is enabled; a state the caller must change first, as |
| | 4 | 19 | | // AF-36a's "already active" is. |
| | 4 | 20 | | [PersonMessages.EmailSignInMethodEnabled] = HttpStatusCodes.Conflict, |
| | 4 | 21 | | // AF-06b — scope not found. |
| | 4 | 22 | | [PersonMessages.ScopeNotFound] = HttpStatusCodes.NotFound, |
| | 4 | 23 | | // AF-06e — actor is not an owner of the target scope. |
| | 4 | 24 | | [PersonMessages.NotScopeOwner] = HttpStatusCodes.Forbidden, |
| | 4 | 25 | | // AF-06d — invalid input. |
| | 4 | 26 | | [PersonMessages.NameRequired] = HttpStatusCodes.BadRequest, |
| | 4 | 27 | | [PersonMessages.NameTooLong] = HttpStatusCodes.BadRequest, |
| | 4 | 28 | | [PersonMessages.EmailRequired] = HttpStatusCodes.BadRequest, |
| | 4 | 29 | | [PersonMessages.EmailInvalid] = HttpStatusCodes.BadRequest, |
| | 4 | 30 | | [PersonMessages.EmailTooLong] = HttpStatusCodes.BadRequest, |
| | 4 | 31 | | [PersonMessages.PasswordRequired] = HttpStatusCodes.BadRequest, |
| | 4 | 32 | | [PersonMessages.PasswordTooShort] = HttpStatusCodes.BadRequest, |
| | 4 | 33 | | [PersonMessages.InvalidRole] = HttpStatusCodes.BadRequest, |
| | 4 | 34 | | // UC-07 main flow — person(s) retrieved, by any of reads a to e. |
| | 4 | 35 | | [PersonMessages.PersonRetrievedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 36 | | [PersonMessages.PersonsRetrievedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 37 | | // AF-07a — person not found. |
| | 4 | 38 | | [PersonMessages.PersonNotFound] = HttpStatusCodes.NotFound, |
| | 4 | 39 | | // AF-07b — caller may not view the person. |
| | 4 | 40 | | [PersonMessages.NotAuthorizedToViewPerson] = HttpStatusCodes.Forbidden, |
| | 4 | 41 | | // UC-08 main flow — person updated. |
| | 4 | 42 | | [PersonMessages.PersonUpdatedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 43 | | // UC-08 — caller may not update the person; AF-08c for the role-change case. |
| | 4 | 44 | | [PersonMessages.NotAuthorizedToUpdatePerson] = HttpStatusCodes.Forbidden, |
| | 4 | 45 | | [PersonMessages.RoleChangeRequiresSystemAdmin] = HttpStatusCodes.Forbidden, |
| | 4 | 46 | | // AF-08h / AF-08i (FR-PE-14, FR-AU-13) — an own email change without the current password, |
| | 4 | 47 | | // or without the second factor when it is active, or while the re-authentication budget is |
| | 4 | 48 | | // paused. UC-39's one refusal, and UC-39's status for it. |
| | 4 | 49 | | [AuthMessages.PasswordOrCodeIncorrect] = HttpStatusCodes.Unauthorized, |
| | 4 | 50 | | // UC-08 — the transition needs a scope the request does not carry, or the role is unknown. |
| | 4 | 51 | | [PersonMessages.UnsupportedRoleTransition] = HttpStatusCodes.BadRequest, |
| | 4 | 52 | | [PersonMessages.UnknownRole] = HttpStatusCodes.BadRequest, |
| | 4 | 53 | | // NFR-12 — the change would strip a scope of its last owner (UC-08 role change, UC-09 AF-09e). |
| | 4 | 54 | | [PersonMessages.ScopeWouldLoseLastOwner] = HttpStatusCodes.Conflict, |
| | 4 | 55 | | // UC-09 main flow and AF-09b — person deleted, or already was. |
| | 4 | 56 | | [PersonMessages.PersonDeletedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 57 | | // AF-09c — caller may not delete the person; AF-09d / AF-10c — caller targeted themselves. |
| | 4 | 58 | | [PersonMessages.NotAuthorizedToDeletePerson] = HttpStatusCodes.Forbidden, |
| | 4 | 59 | | [PersonMessages.CannotDeleteSelf] = HttpStatusCodes.Forbidden, |
| | 4 | 60 | | // UC-10 main flow — person hard deleted. AF-10a reuses PersonNotFound (404), AF-10b reuses |
| | 4 | 61 | | // ScopeWouldLoseLastOwner (409), and AF-10c reuses CannotDeleteSelf (403). |
| | 4 | 62 | | [PersonMessages.PersonHardDeletedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 63 | | // UC-21 main flow — ownership added. AF-21d answers 200 instead, so the two paths carry |
| | 4 | 64 | | // different messages; AF-21a reuses ScopeNotFound (404) and AF-21c NotScopeOwner (403). |
| | 4 | 65 | | [PersonMessages.ScopeOwnerAddedSuccessfully] = HttpStatusCodes.Created, |
| | 4 | 66 | | [PersonMessages.AlreadyScopeOwner] = HttpStatusCodes.Ok, |
| | 4 | 67 | | // AF-21b — the named person is not a usable ScopeAdmin. |
| | 4 | 68 | | [PersonMessages.PersonNotValidScopeAdmin] = HttpStatusCodes.BadRequest, |
| | 4 | 69 | | // UC-22 main flow — ownership removed. AF-22a reuses ScopeNotFound (404) for its scope half, |
| | 4 | 70 | | // AF-22b reuses ScopeWouldLoseLastOwner (409) and AF-22c NotScopeOwner (403). |
| | 4 | 71 | | [PersonMessages.ScopeOwnerRemovedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 72 | | // AF-22a — the named person holds no ownership row for this scope. |
| | 4 | 73 | | [PersonMessages.PersonNotScopeOwner] = HttpStatusCodes.NotFound, |
| | 4 | 74 | | // UC-23 main flow — the User was promoted to owner. AF-23a reuses ScopeNotFound (404), |
| | 4 | 75 | | // AF-23c NotScopeOwner (403), and the FR-PE-09 namespace guard EmailAlreadyExists (409). |
| | 4 | 76 | | [PersonMessages.ScopeUserPromotedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 77 | | // AF-23b — the named person is not a usable User of the target scope. |
| | 4 | 78 | | [PersonMessages.PersonNotScopeUser] = HttpStatusCodes.BadRequest, |
| | 4 | 79 | | // AF-23d — the person is already a ScopeAdmin. |
| | 4 | 80 | | [PersonMessages.AlreadyScopeAdmin] = HttpStatusCodes.Conflict, |
| | 4 | 81 | | // UC-51 main flow — the verification email was handed to the sender. AF-51a reuses |
| | 4 | 82 | | // PersonNotFound (404). |
| | 4 | 83 | | [PersonMessages.VerificationEmailSentToPerson] = HttpStatusCodes.Ok, |
| | 4 | 84 | | // AF-51b / AF-52b — the caller may not email this person. |
| | 4 | 85 | | [PersonMessages.NotAuthorizedToEmailPerson] = HttpStatusCodes.Forbidden, |
| | 4 | 86 | | // AF-51c / AF-52c — deleted, or restricted (NFR-24). |
| | 4 | 87 | | [PersonMessages.PersonIsDeleted] = HttpStatusCodes.Conflict, |
| | 4 | 88 | | [PersonMessages.PersonProcessingRestricted] = HttpStatusCodes.Conflict, |
| | 4 | 89 | | // AF-51d — already verified; the refusal UC-15 gives, so the same status here. |
| | 4 | 90 | | [AuthMessages.EmailAlreadyVerified] = HttpStatusCodes.BadRequest, |
| | 4 | 91 | | // AF-51e / AF-52e — the per-person cooldown is running (FR-EV-07, FR-PR-06). |
| | 4 | 92 | | [PersonMessages.AccountEmailSentRecently] = HttpStatusCodes.TooManyRequests, |
| | 4 | 93 | | // AF-08j — an own email change the person's account-email budget refused (FR-PE-16). |
| | 4 | 94 | | [AuthMessages.EmailSentRecently] = HttpStatusCodes.TooManyRequests, |
| | 4 | 95 | | [AuthMessages.AccountEmailLimitReached] = HttpStatusCodes.TooManyRequests, |
| | 4 | 96 | | // UC-52 main flow — the reset email was handed to the sender. AF-52a reuses PersonNotFound |
| | 4 | 97 | | // (404); AF-52b, AF-52c and AF-52e share UC-51's entries above. |
| | 4 | 98 | | [PersonMessages.PasswordResetSentToPerson] = HttpStatusCodes.Ok, |
| | 4 | 99 | | // AF-52d — the account cannot sign in (FR-AU-06/07). |
| | 4 | 100 | | [PersonMessages.PersonCannotSignIn] = HttpStatusCodes.Conflict, |
| | 4 | 101 | | // UC-07 reads b to e (NFR-10) — invalid pagination or an over-length name/email filter. |
| | 4 | 102 | | [PaginationMessages.InvalidPageNumber] = HttpStatusCodes.BadRequest, |
| | 4 | 103 | | [PaginationMessages.InvalidPageSize] = HttpStatusCodes.BadRequest, |
| | 4 | 104 | | [PaginationMessages.FilterTooLong] = HttpStatusCodes.BadRequest |
| | 4 | 105 | | }); |
| | | 106 | | } |