NTP_V2/src/NTP.Application/Access/PermissionDefaults.cs

122 lines
9.8 KiB
C#

namespace NTP.Application.Access;
/// <summary>
/// Stable resource keys the front end and the API agree on. A key is a menu entry (module/screen) or an action
/// inside a screen. The front end uses the menu <c>key</c> of each entry (see web/src/features/*/routes.tsx).
/// </summary>
public static class PermissionKeys
{
// Screens (menu keys)
public const string OrdersList = "grains.orders.list";
/// <summary>Action: new order (طلبية جديدة) button, create page and POST /orders.</summary>
public const string OrdersCreate = "grains.orders.create";
public const string OrdersQuotas = "grains.orders.quotas";
public const string OrdersBilling = "grains.orders.billing";
public const string OrdersInvoices = "grains.orders.invoices";
/// <summary>الغرامات and الأجور (GNAC): monthly fine / wage tables read by the billing screens.</summary>
/// <summary>التأكد من الفواتير (legacy FinancialRpts.cfm): check the billings of one invoice.</summary>
public const string OrdersInvoiceCheck = "grains.orders.invoiceCheck";
public const string OrdersFines = "grains.orders.fines";
public const string OrdersWages = "grains.orders.wages";
public const string OrdersWeights = "grains.orders.weights";
/// <summary>طلبية التموين: distributed permits per destination type (orders menu).</summary>
public const string OrdersSupply = "grains.orders.supply";
public const string OrdersCompanyDest = "grains.orders.companyDest";
public const string OrdersReportOrders = "grains.orders.reportOrders";
public const string OrdersReportFinance = "grains.orders.reportFinance";
public const string PermitsList = "grains.permits.list";
public const string PermitsCreate = "grains.permits.create";
public const string PermitsDestinations = "grains.permits.destinations";
public const string PermitsDistribution = "grains.permits.distribution";
public const string PermitsWeighbridge = "grains.permits.weighbridge";
public const string RegistryTrucks = "grains.registry.trucks";
public const string RegistryTrailers = "grains.registry.trailers";
public const string RegistryDrivers = "grains.registry.drivers";
public const string RegistryBlacklist = "grains.registry.blacklist";
public const string RegistryWeighbridge = "grains.registry.weighbridge";
public const string RegistryLocationCounts = "grains.registry.locationCounts";
// Actions: register (add) a truck / trailer / driver. Granted ONLY by rows in GRAINS_SCREEN_PERMISSIONS (SU always).
public const string RegistryTrucksCreate = "grains.registry.trucks.create";
public const string RegistryTrailersCreate = "grains.registry.trailers.create";
public const string RegistryDriversCreate = "grains.registry.drivers.create";
// Actions: edit an existing truck / trailer (the record status rules still apply). Granted ONLY by rows in GRAINS_SCREEN_PERMISSIONS.
public const string RegistryTrucksEdit = "grains.registry.trucks.edit";
public const string RegistryTrailersEdit = "grains.registry.trailers.edit";
// Actions: Excel export of the trucks / trailers / drivers lists. Granted ONLY by rows in GRAINS_SCREEN_PERMISSIONS (SU always).
public const string RegistryTrucksExport = "grains.registry.trucks.export";
public const string RegistryTrailersExport = "grains.registry.trailers.export";
public const string RegistryDriversExport = "grains.registry.drivers.export";
// Actions / sub-screens of the permits module that have no menu entry of their own
public const string PermitsClose = "grains.permits.close"; // legacy arrivalTruck.cfm
public const string PermitsTruckOrder = "grains.permits.truckOrder"; // legacy processOpenPermit.cfm
public const string PermitsTruckStatus = "grains.permits.truckStatus"; // legacy distributionDetails.cfm
public const string PermitsActivation = "grains.permits.activation"; // legacy activateOrders.cfm
public const string PermitsManualEntry = "grains.permits.manualEntry"; // legacy ManualInput.cfm
public const string PermitsAbsence = "grains.permits.absence"; // legacy activeOrInactiveAbsenceFeature.cfm
public const string PermitsVoiceCall = "grains.permits.voiceCall"; // legacy GNPermits.cfm "نظام الاتصال الصوتي" (action 96)
// Report screens outside the business sheet allow-list: SU only (no seed rows)
public const string ReportsDashboard = "grains.reports.dashboard";
public const string ReportsNumOfTrips = "grains.reports.numOfTrips";
public const string ReportsQuota = "grains.reports.quota";
public const string ReportsFrequency = "grains.reports.frequency";
public const string ReportsDistribution = "grains.reports.distribution";
public const string ReportsDetails = "grains.reports.details";
public const string ReportsMotMulti = "grains.reports.motMulti";
/// <summary>Prefix of the per-table report keys (const so attributes can use it).</summary>
public const string TableKeyPrefix = "grains.reports.t.";
/// <summary>Tabular report menu key (grains.reports.t.{table key}; keys in web/src/features/grains-reports/meta.tsx).</summary>
public static string ReportTable(string tableKey) => TableKeyPrefix + tableKey;
}
/// <summary>
/// Built-in permission table, taken from the business sheet authorities.xlsx (role codes per screen). Used only when
/// the database table GRAINS_SCREEN_PERMISSIONS does not exist yet (see db/grains-screen-permissions.sql); once the
/// table exists the database is the single source of truth. SU is not listed: it is always allowed everything.
/// Screens that are not listed here are hidden from every role except SU (allow-list).
/// </summary>
public static class PermissionDefaults
{
public static readonly IReadOnlyDictionary<string, string[]> RolesByResource = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase)
{
[PermissionKeys.PermitsList] = ["GTO", "CO", "GGO", "GOO", "GPO", "DISP"], // ارسالية عطاء التموين (DISP: own company only)
[PermissionKeys.RegistryTrucks] = ["GTO", "CO", "GOO", "GPO"], // شاشة القاطرات
[PermissionKeys.RegistryTrailers] = ["GTO", "CO", "GOO", "GPO"], // شاشة المقطورات
[PermissionKeys.RegistryDrivers] = ["GTO", "CO", "GOO", "GPO"], // شاشة السائقين المسجلين
[PermissionKeys.OrdersList] = ["GTO", "CO", "GOO"], // الطلبيات
[PermissionKeys.OrdersCreate] = ["GTO", "CO"], // طلبية جديدة (GOO was removed again; add a row per role to grant it)
[PermissionKeys.PermitsWeighbridge] = ["GTO", "CO", "GGO"], // شاشة القبان
[PermissionKeys.PermitsClose] = ["GTO", "CO", "GGO", "GOO", "GPO"], // اغلاق إرسالية
[PermissionKeys.PermitsTruckOrder] = ["GTO", "CO"], // طلبية لسيارة
[PermissionKeys.RegistryBlacklist] = ["GTO", "CO", "GOO", "GPO"], // شاشة الأيقاف والإنتظار
[PermissionKeys.PermitsDistribution] = ["GTO", "CO", "GOO"], // طلبية التموين
[PermissionKeys.OrdersSupply] = ["GTO", "CO", "GOO"], // طلبية التموين (orders menu)
[PermissionKeys.PermitsTruckStatus] = ["GTO", "CO", "GOO"], // استعلام عن حالة التوزيع لسيارة
[PermissionKeys.PermitsActivation] = ["GTO", "CO"], // شاشة تفعيل الطلبية
[PermissionKeys.PermitsManualEntry] = ["GTO", "CO"], // شاشة الادخال اليدوي
[PermissionKeys.PermitsAbsence] = ["GTO", "CO"], // إيقاف\تفعيل الاستنكاف
[PermissionKeys.PermitsVoiceCall] = ["GTO", "CO"], // الاتصال الصوتي
[PermissionKeys.OrdersInvoiceCheck] = ["GNAC"], // التأكد من الفواتير
[PermissionKeys.OrdersFines] = ["GNAC"], // الغرامات
[PermissionKeys.OrdersWages] = ["GNAC"], // الأجور
[PermissionKeys.OrdersWeights] = ["GTO", "CO"], // تثبيت أوزان التحميل
[PermissionKeys.ReportTable("weighbridge-events")] = ["GTO", "CO", "GOO"], // تقارير حركات قبان التحميل والتفريغ
[PermissionKeys.ReportTable("companies-turn")] = ["GTO", "CO", "GOO"], // تقرير دور الشركات
[PermissionKeys.ReportTable("owners-turn")] = ["GTO", "CO"], // تقرير دور الأفراد
[PermissionKeys.ReportTable("loading-weights")] = ["GTO", "CO"], // تقرير أوزان التحميل
[PermissionKeys.ReportTable("closed-permits")] = ["GTO", "CO"], // الارساليات المكتملة
[PermissionKeys.ReportTable("tender-order")] = ["GTO", "CO"], // ارسالية عطاء التموين
[PermissionKeys.ReportTable("distribution-summary")] = ["GTO", "CO"], // ملخص التوزيع
[PermissionKeys.OrdersCompanyDest] = ["GOO"], // وجهات الشركات
[PermissionKeys.PermitsDestinations] = ["GOO"], // تحديد وجهة ارسالية تموين
};
}