RoleBase.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Abp.Domain.Entities;
  5. using Abp.Domain.Entities.Auditing;
  6. namespace IwbZero.Authorization.Base.Roles
  7. {
  8. /// <summary>
  9. /// Base class for role.
  10. /// </summary>
  11. [Table("Sys_Roles")]
  12. public abstract class RoleBase : FullAuditedEntity<int>, IMayHaveTenant
  13. {
  14. /// <summary>
  15. /// Maximum length of the <see cref="DisplayName"/> property.
  16. /// </summary>
  17. public const int MaxDisplayNameLength = 64;
  18. /// <summary>
  19. /// Maximum length of the <see cref="Name"/> property.
  20. /// </summary>
  21. public const int MaxNameLength = 32;
  22. /// <summary>
  23. /// Tenant's Id, if this role is a tenant-level role. Null, if not.
  24. /// </summary>
  25. [Index]
  26. public int? TenantId { get; set; }
  27. /// <summary>
  28. /// Unique name of this role.
  29. /// </summary>
  30. [Required]
  31. [StringLength(MaxNameLength)]
  32. [Index]
  33. public string Name { get; set; }
  34. [Index]
  35. public int RoleType { get; set; }
  36. [Index]
  37. public int? AccountType { get; set; }
  38. /// <summary>
  39. /// Display name of this role.
  40. /// </summary>
  41. [Required]
  42. [StringLength(MaxDisplayNameLength)]
  43. public string DisplayName { get; set; }
  44. /// <summary>
  45. /// Is this a static role?
  46. /// Static roles can not be deleted, can not change their name.
  47. /// They can be used programmatically.
  48. /// </summary>
  49. public bool IsStatic { get; set; }
  50. /// <summary>
  51. /// Is this role will be assigned to new users as default?
  52. /// </summary>
  53. public bool IsDefault { get; set; }
  54. protected RoleBase()
  55. {
  56. Name = Guid.NewGuid().ToString("N");
  57. }
  58. protected RoleBase(int? tenantId, string displayName)
  59. : this()
  60. {
  61. TenantId = tenantId;
  62. DisplayName = displayName;
  63. }
  64. protected RoleBase(int? tenantId, string name, string displayName)
  65. : this(tenantId, displayName)
  66. {
  67. Name = name;
  68. }
  69. public override string ToString()
  70. {
  71. return $"[Role {Id}, Name={Name}]";
  72. }
  73. }
  74. }