| | | 1 | | using OzonRepositories.Context.Identity; |
| | | 2 | | |
| | | 3 | | namespace OzonOrdersWeb.Areas.Studio2.ViewHelpers; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Видимость колонок списка заказов: сначала профиль (<see cref="AccessProfile"/> / AvailableOrderColumns), |
| | | 7 | | /// затем матрица ролей AppField (OrderList) — при отсутствии запрета по полю чтение разрешено. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class OrderListColumnGate |
| | | 10 | | { |
| | | 11 | | public static bool CanShowOrderColumn( |
| | | 12 | | CustomIdentityUser? user, |
| | | 13 | | IReadOnlyDictionary<string, bool>? readAccessByFieldName, |
| | | 14 | | string appFieldName, |
| | | 15 | | string availableOrderProfileKey) |
| | | 16 | | { |
| | 90 | 17 | | if (user?.AccessProfileId == null) |
| | | 18 | | { |
| | | 19 | | // Для пользователей без AccessProfile опираемся только на матрицу AppField. |
| | 90 | 20 | | if (readAccessByFieldName == null || readAccessByFieldName.Count == 0) return true; |
| | 30 | 21 | | return readAccessByFieldName.TryGetValue(appFieldName, out var onlyFieldAccess) ? onlyFieldAccess : true; |
| | | 22 | | } |
| | 30 | 23 | | var cols = user.AccessProfile?.AvailableOrderColumns; |
| | 55 | 24 | | if (cols == null || !cols.Contains(availableOrderProfileKey)) return false; |
| | 10 | 25 | | if (readAccessByFieldName == null || readAccessByFieldName.Count == 0) return true; |
| | 0 | 26 | | return readAccessByFieldName.TryGetValue(appFieldName, out var v) ? v : true; |
| | | 27 | | } |
| | | 28 | | } |