Path: redb/redb.Core/Models/Permissions/PermissionFlags.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/Permissions/PermissionFlags.cs
----
using System;
namespace redb.Core.Models.Permissions
{
///
/// Permission flags for REDB objects
/// Correspond to _select, _insert, _update, _delete fields in _permissions table
///
[Flags]
public enum PermissionFlags
{
///
/// No permissions
///
None = 0,
///
/// Read permission (SELECT)
///
Select = 1,
///
/// Create permission (INSERT)
///
Insert = 2,
///
/// Update permission (UPDATE)
///
Update = 4,
///
/// Delete permission (DELETE)
///
Delete = 8,
///
/// All permissions (RIUD)
///
All = Select | Insert | Update | Delete,
///
/// Read and write (RI_U)
///
ReadWrite = Select | Insert | Update,
///
/// Read only (R)
///
ReadOnly = Select
}
///
/// Extensions for working with PermissionFlags
///
public static class PermissionFlagsExtensions
{
///
/// Check if has read permission
///
public static bool CanSelect(this PermissionFlags flags) => flags.HasFlag(PermissionFlags.Select);
///
/// Check if has create permission
///
public static bool CanInsert(this PermissionFlags flags) => flags.HasFlag(PermissionFlags.Insert);
///
/// Check if has update permission
///
public static bool CanUpdate(this PermissionFlags flags) => flags.HasFlag(PermissionFlags.Update);
///
/// Check if has delete permission
///
public static bool CanDelete(this PermissionFlags flags) => flags.HasFlag(PermissionFlags.Delete);
///
/// Convert to display string (e.g. "RIUD")
///
public static string ToDisplayString(this PermissionFlags flags)
{
var result = "";
if (flags.CanSelect()) result += "R";
if (flags.CanInsert()) result += "I";
if (flags.CanUpdate()) result += "U";
if (flags.CanDelete()) result += "D";
return string.IsNullOrEmpty(result) ? "----" : result;
}
///
/// Create PermissionFlags from boolean values (as in DB)
///
public static PermissionFlags FromBooleans(bool select, bool insert, bool update, bool delete)
{
var flags = PermissionFlags.None;
if (select) flags |= PermissionFlags.Select;
if (insert) flags |= PermissionFlags.Insert;
if (update) flags |= PermissionFlags.Update;
if (delete) flags |= PermissionFlags.Delete;
return flags;
}
}
}