| | | 1 | | using Microsoft.AspNetCore.Authorization; |
| | | 2 | | using OzonDomains.Models.Authorization.Enums; |
| | | 3 | | |
| | | 4 | | namespace OzonOrdersWeb.Authorization; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Атрибут, помечающий действие/контроллер требуемым кодом страницы и типом доступа. |
| | | 8 | | /// Работает как AuthorizeAttribute с policy "AppPageAccess", дополнительно пробрасывая данные |
| | | 9 | | /// в HttpContext.Items для PageAccessHandler. |
| | | 10 | | /// </summary> |
| | | 11 | | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)] |
| | | 12 | | public sealed class PageAuthorizeAttribute : AuthorizeAttribute |
| | | 13 | | { |
| | | 14 | | public const string PageCodeItemKey = "__PageAuthorize_Code"; |
| | | 15 | | public const string AccessTypeItemKey = "__PageAuthorize_AccessType"; |
| | | 16 | | |
| | 15 | 17 | | public string PageCode { get; } |
| | 14 | 18 | | public AccessType Access { get; } |
| | | 19 | | |
| | 1352 | 20 | | public PageAuthorizeAttribute(string pageCode, AccessType access = AccessType.View) |
| | | 21 | | { |
| | 1352 | 22 | | PageCode = pageCode; |
| | 1352 | 23 | | Access = access; |
| | 1352 | 24 | | Policy = Services.Authorization.AuthorizationConstants.PolicyName; |
| | 1352 | 25 | | } |
| | | 26 | | } |