| | | 1 | | using OzonOrdersWeb.Areas.Admin.OrderList; |
| | | 2 | | using Services.Authorization.Dtos; |
| | | 3 | | using Services.Authorization.Services; |
| | | 4 | | |
| | | 5 | | namespace OzonOrdersWeb.WebServices.Orders; |
| | | 6 | | |
| | | 7 | | public static class OrderListFieldReadAccessBuilder |
| | | 8 | | { |
| | | 9 | | public static IReadOnlyDictionary<string, bool> FromBundle(UserPermissionsBundle bundle) |
| | | 10 | | { |
| | 0 | 11 | | if (bundle.IsSuperAdmin) |
| | | 12 | | { |
| | 0 | 13 | | return OrderListColumnCatalog.All.ToDictionary( |
| | 0 | 14 | | c => c.FieldName, |
| | 0 | 15 | | _ => true, |
| | 0 | 16 | | StringComparer.OrdinalIgnoreCase); |
| | | 17 | | } |
| | | 18 | | |
| | 0 | 19 | | var fromBundle = bundle.Fields |
| | 0 | 20 | | .Where(f => string.Equals(f.EntityName, OrderListColumnCatalog.EntityName, StringComparison.OrdinalIgnoreCas |
| | 0 | 21 | | .ToDictionary(f => f.FieldName, f => f.CanRead, StringComparer.OrdinalIgnoreCase); |
| | | 22 | | |
| | 0 | 23 | | var dict = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase); |
| | 0 | 24 | | foreach (var col in OrderListColumnCatalog.All) |
| | | 25 | | { |
| | 0 | 26 | | dict[col.FieldName] = fromBundle.TryGetValue(col.FieldName, out var r) ? r : true; |
| | | 27 | | } |
| | | 28 | | |
| | 0 | 29 | | return dict; |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | public static async Task<IReadOnlyDictionary<string, bool>> FromUserIdAsync( |
| | | 33 | | IPermissionService permissionService, |
| | | 34 | | string userId, |
| | | 35 | | CancellationToken cancellationToken = default) |
| | | 36 | | { |
| | 0 | 37 | | var bundle = await permissionService.GetUserPermissionsAsync(userId, cancellationToken); |
| | 0 | 38 | | return FromBundle(bundle); |
| | 0 | 39 | | } |
| | | 40 | | } |