using System; using Oqtane.Shared; namespace Oqtane.Models { /// /// Permission information for anything in Oqtane. /// Things in Oqtane are identified as Entities, so anything that can be identified can be described here. /// public class Permission : ModelBase { /// /// Internal ID storing this information. /// public int PermissionId { get; set; } /// /// Reference to the which contains both the target Entity and permissions. /// public int SiteId { get; set; } /// /// Name of the Entity these permissions apply to. /// public string EntityName { get; set; } /// /// ID of the Entity these permissions apply to. /// public int EntityId { get; set; } /// /// What this permission is called. /// TODO: todoc - must clarify what exactly this means, I assume any module can give it's own names for Permissions /// public string PermissionName { get; set; } /// /// this permission applies to. So if all users in the Role _Customers_ have this permission, then it would reference that Role. /// If null, then the permission doesn't target a role but probably a (see ). /// public int? RoleId { get; set; } /// /// this permission applies to. /// If null, then the permission doesn't target a User but probably a (see ). /// public int? UserId { get; set; } /// /// Determines if Authorization is sufficient to receive this permission. /// public bool IsAuthorized { get; set; } /// /// Reference to the based on the - can be nullable. /// /// /// It's not certain if this will always be populated. TODO: todoc/verify /// public Role Role { get; set; } public Permission() { } public Permission(string permissionName, string roleName, bool isAuthorized) { Initialize("", -1, permissionName, roleName, null, isAuthorized); } public Permission(string permissionName, int userId, bool isAuthorized) { Initialize("", -1, permissionName, "", userId, isAuthorized); } public Permission(string entityName, string permissionName, string roleName, int? userId, bool isAuthorized) { Initialize(entityName, -1, permissionName, roleName, userId, isAuthorized); } public Permission(string entityName, int entityId, string permissionName, string roleName, int? userId, bool isAuthorized) { Initialize(entityName, entityId, permissionName, roleName, userId, isAuthorized); } private void Initialize(string entityName, int entityId, string permissionName, string roleName, int? userId, bool isAuthorized) { EntityName = entityName; EntityId = entityId; PermissionName = permissionName; if (!string.IsNullOrEmpty(roleName)) { Role = new Role { Name = roleName }; RoleId = null; UserId = null; } else { Role = null; RoleId = null; UserId = userId; } IsAuthorized = isAuthorized; } } }