| | | 1 | | using ArturRios.Util.Http; |
| | | 2 | | |
| | | 3 | | namespace ArturRios.Heimdall.Shared.Messages; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Maps each <see cref="ScopeMessages" /> value to the HTTP status code that should accompany it, |
| | | 7 | | /// following the UC-01 / UC-02 flows. Passed to the response resolver so it can pick the status |
| | | 8 | | /// code from the output's first message (on success) or first error (on failure). |
| | | 9 | | /// </summary> |
| | | 10 | | public static class ScopeMessageMap |
| | | 11 | | { |
| | 4 | 12 | | public static readonly IReadOnlyDictionary<string, int> StatusCodes = |
| | 4 | 13 | | DataAccessMessageMap.CombinedWith(new Dictionary<string, int> |
| | 4 | 14 | | { |
| | 4 | 15 | | // UC-01 main flow — scope created. |
| | 4 | 16 | | [ScopeMessages.ScopeCreatedSuccessfully] = HttpStatusCodes.Created, |
| | 4 | 17 | | // UC-03 main flow — scope updated. |
| | 4 | 18 | | [ScopeMessages.ScopeUpdatedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 19 | | // UC-04 main flow (and AF-04b idempotent) — scope deleted. |
| | 4 | 20 | | [ScopeMessages.ScopeDeletedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 21 | | // UC-05 main flow — scope hard deleted. |
| | 4 | 22 | | [ScopeMessages.ScopeHardDeletedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 23 | | // UC-02 main flow — scope(s) retrieved. |
| | 4 | 24 | | [ScopeMessages.ScopeRetrievedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 25 | | [ScopeMessages.ScopesRetrievedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 26 | | // AF-02a — scope not found. |
| | 4 | 27 | | [ScopeMessages.ScopeNotFound] = HttpStatusCodes.NotFound, |
| | 4 | 28 | | // AF-02b — caller may not view this scope. |
| | 4 | 29 | | [ScopeMessages.NotAuthorizedToViewScope] = HttpStatusCodes.Forbidden, |
| | 4 | 30 | | [ScopeMessages.NotAuthorizedToListScopes] = HttpStatusCodes.Forbidden, |
| | 4 | 31 | | // AF-01b — invalid input data, or no owner specified. |
| | 4 | 32 | | [ScopeMessages.NameRequired] = HttpStatusCodes.BadRequest, |
| | 4 | 33 | | [ScopeMessages.AtLeastOneOwnerRequired] = HttpStatusCodes.BadRequest, |
| | 4 | 34 | | // AF-01a — scope name already exists. |
| | 4 | 35 | | [ScopeMessages.NameAlreadyExists] = HttpStatusCodes.Conflict, |
| | 4 | 36 | | // AF-01d — an owner is not an existing, non-deleted ScopeAdmin. |
| | 4 | 37 | | [ScopeMessages.OwnerNotValidScopeAdmin] = HttpStatusCodes.BadRequest, |
| | 4 | 38 | | // UC-24 main flow — Google Sign-In enabled or disabled. AF-24a reuses ScopeNotFound (404). |
| | 4 | 39 | | [ScopeMessages.GoogleSignInUpdatedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 40 | | // UC-47 toggle main flow — self-registration opened or closed. Shares ScopeNotFound (404), |
| | 4 | 41 | | // NotScopeOwner and EnabledRequired (400) with UC-24. |
| | 4 | 42 | | [ScopeMessages.SelfRegistrationUpdatedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 43 | | // Per-scope email links set. Shares ScopeNotFound (404) and NotScopeOwner (403) with UC-24. |
| | 4 | 44 | | [ScopeMessages.EmailLinksUpdatedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 45 | | // A scope email link is not an absolute http(s) URL within the column length. |
| | 4 | 46 | | [ScopeMessages.EmailLinkInvalid] = HttpStatusCodes.BadRequest, |
| | 4 | 47 | | // AF-24b — actor is not an owner of the target scope. |
| | 4 | 48 | | [ScopeMessages.NotScopeOwner] = HttpStatusCodes.Forbidden, |
| | 4 | 49 | | // UC-24 (NFR-10) — the request omitted the value to set. |
| | 4 | 50 | | [ScopeMessages.EnabledRequired] = HttpStatusCodes.BadRequest, |
| | 4 | 51 | | // UC-49 main flow and AF-49c — pending registrations listed, an empty page included. |
| | 4 | 52 | | // AF-49a reuses ScopeNotFound (404), AF-49b NotScopeOwner (403), and the page bounds the |
| | 4 | 53 | | // NFR-10 entries below (400). |
| | 4 | 54 | | [ScopeMessages.PendingRegistrationsRetrieved] = HttpStatusCodes.Ok, |
| | 4 | 55 | | // UC-50 main flow — the registration was discarded. AF-50a reuses ScopeNotFound (404) and |
| | 4 | 56 | | // AF-50b NotScopeOwner (403). |
| | 4 | 57 | | [ScopeMessages.PendingRegistrationDiscarded] = HttpStatusCodes.Ok, |
| | 4 | 58 | | // AF-50c — not in this scope, never existed, or already confirmed or purged. |
| | 4 | 59 | | [ScopeMessages.PendingRegistrationNotFound] = HttpStatusCodes.NotFound, |
| | 4 | 60 | | // UC-02 read b (NFR-10) — invalid pagination or an over-length name filter. |
| | 4 | 61 | | [PaginationMessages.InvalidPageNumber] = HttpStatusCodes.BadRequest, |
| | 4 | 62 | | [PaginationMessages.InvalidPageSize] = HttpStatusCodes.BadRequest, |
| | 4 | 63 | | [PaginationMessages.FilterTooLong] = HttpStatusCodes.BadRequest, |
| | 4 | 64 | | // AF-03e/f/g (NFR-23) — the tenant's declared basis or notice URI is not usable. |
| | 4 | 65 | | [ScopeMessages.ConsentBasisNotSupported] = HttpStatusCodes.BadRequest, |
| | 4 | 66 | | [ScopeMessages.PrivacyNoticeUriInvalid] = HttpStatusCodes.BadRequest, |
| | 4 | 67 | | [ScopeMessages.LegalBasisUnknown] = HttpStatusCodes.BadRequest |
| | 4 | 68 | | }); |
| | | 69 | | } |