Path: redb/redb.Core/Models/Entities/RedbPermission.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Models/Entities/RedbPermission.cs ---- using redb.Core.Models.Contracts; using System.Collections.Generic; using System.Text.Json.Serialization; namespace redb.Core.Models.Entities { /// /// REDB permission entity with direct data storage. /// Maps to _permissions table in PostgreSQL. /// public class RedbPermission : IRedbPermission { /// /// Unique permission identifier. /// [JsonPropertyName("id")] public long Id { get; set; } /// /// Role identifier (null if user-specific permission). /// [JsonPropertyName("id_role")] public long? IdRole { get; set; } /// /// User identifier (null if role-based permission). /// [JsonPropertyName("id_user")] public long? IdUser { get; set; } /// /// Reference object identifier (scheme, object, etc.). /// [JsonPropertyName("id_ref")] public long IdRef { get; set; } /// /// SELECT (read) permission. /// [JsonPropertyName("select")] public bool? Select { get; set; } /// /// INSERT (create) permission. /// [JsonPropertyName("insert")] public bool? Insert { get; set; } /// /// UPDATE (edit) permission. /// [JsonPropertyName("update")] public bool? Update { get; set; } /// /// DELETE (remove) permission. /// [JsonPropertyName("delete")] public bool? Delete { get; set; } /// /// Default constructor for deserialization and mapping. /// public RedbPermission() { } /// /// Check if specific permission is granted. /// public bool HasPermission(string action) { return action.ToLower() switch { "select" or "read" => Select == true, "insert" or "create" => Insert == true, "update" or "edit" => Update == true, "delete" or "remove" => Delete == true, _ => false }; } /// /// Get list of active permissions. /// public IEnumerable GetActivePermissions() { var permissions = new List(); if (Select == true) permissions.Add("Select"); if (Insert == true) permissions.Add("Insert"); if (Update == true) permissions.Add("Update"); if (Delete == true) permissions.Add("Delete"); return permissions; } public override string ToString() { var target = IdRole.HasValue ? $"Role {IdRole}" : $"User {IdUser}"; var permissions = string.Join(", ", GetActivePermissions()); return $"Permission {Id}: {target} -> Ref {IdRef} [{permissions}]"; } } }