73 lines
3.2 KiB
C#
73 lines
3.2 KiB
C#
using MCVIngenieros.Transactional.Abstractions.Interfaces;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace back.DataModels;
|
|
|
|
public record PermissionDto
|
|
{
|
|
public string Id { get; set; } = null!;
|
|
}
|
|
|
|
[Table("Permissions")]
|
|
public partial class Permission : IEntity<Permission>
|
|
{
|
|
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
public string Id { get; set; } = null!;
|
|
[Required, MaxLength(100)]
|
|
public string Name { get; set; } = null!;
|
|
[MaxLength(255)]
|
|
public string? Description { get; set; }
|
|
public virtual ICollection<Role> Roles { get; set; } = [];
|
|
|
|
public override int GetHashCode() => HashCode.Combine(Id, Name);
|
|
|
|
public override bool Equals(object? obj)
|
|
=> obj is Permission other && Equals(other);
|
|
public bool Equals(Permission? other)
|
|
{
|
|
if (other is null) return false;
|
|
if (ReferenceEquals(this, other)) return true;
|
|
return
|
|
Id == other.Id || GetHashCode() == other.GetHashCode();
|
|
}
|
|
|
|
public bool IsNull => this is null;
|
|
|
|
public object Clone() => (Permission)MemberwiseClone();
|
|
|
|
public int CompareTo(object? obj)
|
|
{
|
|
if (obj is null) return 1;
|
|
if (obj is not Permission other) throw new ArgumentException("Object is not a Person");
|
|
return CompareTo(other);
|
|
}
|
|
|
|
public int CompareTo(Permission? other)
|
|
{
|
|
if (other is null) return 1;
|
|
if (ReferenceEquals(this, other)) return 0;
|
|
return string.Compare(Id, other.Id, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
public PermissionDto ToDto()
|
|
{
|
|
return new PermissionDto
|
|
{
|
|
Id = Id
|
|
};
|
|
}
|
|
|
|
// Static permissions
|
|
public static readonly Permission ViewContentPermission = new() { Id = "1", Name = "VIEW_CONTENT", Description = "Permission to view content" };
|
|
public static readonly Permission LikeContentPermission = new() { Id = "2", Name = "LIKE_CONTENT", Description = "Permission to like content" };
|
|
public static readonly Permission EditContentPermission = new() { Id = "3", Name = "EDIT_CONTENT", Description = "Permission to edit content" };
|
|
public static readonly Permission DeleteContentPermission = new() { Id = "4", Name = "DELETE_CONTENT", Description = "Permission to delete content" };
|
|
public static readonly Permission CreateContentPermission = new() { Id = "5", Name = "CREATE_CONTENT", Description = "Permission to create new content" };
|
|
public static readonly Permission EditUserPermission = new() { Id = "6", Name = "EDIT_USER", Description = "Permission to edit user" };
|
|
public static readonly Permission DeleteUserPermission = new() { Id = "7", Name = "DELETE_USER", Description = "Permission to delete user" };
|
|
public static readonly Permission DisableUserPermission = new() { Id = "8", Name = "DISABLE_USER", Description = "Permission to disable user" };
|
|
public static readonly Permission CreateUserPermission = new() { Id = "9", Name = "CREATE_USER", Description = "Permission to create new user" };
|
|
public static readonly Permission EditWebConfigPermission = new() { Id = "10", Name = "EDIT_WEB_CONFIG", Description = "Permission to edit web configuration" };
|
|
}
|