IwbSysRole.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Abp.Domain.Entities.Auditing;
  5. using IwbZero.Authorization.Users;
  6. using Microsoft.AspNet.Identity;
  7. namespace IwbZero.Authorization.Roles
  8. {
  9. public abstract class IwbSysRole<TUser> : RoleBase, IRole<int>, IFullAudited<TUser>
  10. where TUser : IwbSysUser<TUser>
  11. {
  12. public virtual TUser CreatorUser { get; set; }
  13. public virtual TUser LastModifierUser { get; set; }
  14. public virtual TUser DeleterUser { get; set; }
  15. }
  16. [Table("Sys_Roles")]
  17. public abstract class RoleBase : FullAuditedEntity<int>
  18. {
  19. public const string AdminRoleName = "admin";
  20. public const string AdminRoleDisplayName = "admin";
  21. /// <summary>
  22. /// Maximum length of the <see cref="RoleDisplayName"/> property.
  23. /// </summary>
  24. public const int MaxDisplayNameLength = 64;
  25. public const int MaxDescriptionLength = 1000;
  26. /// <summary>
  27. /// Maximum length of the <see cref="Name"/> property.
  28. /// </summary>
  29. public const int MaxNameLength = 32;
  30. /// <summary>
  31. /// Unique name of this role.
  32. /// </summary>
  33. [Required]
  34. [StringLength(MaxNameLength)]
  35. public virtual string Name { get; set; }
  36. /// <summary>
  37. /// Display name of this role.
  38. /// </summary>
  39. [Required]
  40. [StringLength(MaxDisplayNameLength)]
  41. public virtual string RoleDisplayName { get; set; }
  42. [StringLength(MaxDescriptionLength)]
  43. public virtual string Description { get; set; }
  44. public int RoleType { get; set; }
  45. /// <summary>
  46. /// Is this a static role?
  47. /// Static roles can not be deleted, can not change their name.
  48. /// They can be used programmatically.
  49. /// </summary>
  50. public virtual bool IsStatic { get; set; }
  51. /// <summary>
  52. /// Is this role will be assigned to new users as default?
  53. /// </summary>
  54. public virtual bool IsDefault { get; set; }
  55. ///// <summary>
  56. ///// List of permissions of the role.
  57. ///// </summary>
  58. //[ForeignKey("RoleId")]
  59. //public virtual ICollection<RolePermissionSetting> Permissions { get; set; }
  60. protected RoleBase()
  61. {
  62. Name = Guid.NewGuid().ToString("N");
  63. }
  64. protected RoleBase(string roleDisplayName)
  65. : this()
  66. {
  67. RoleDisplayName = roleDisplayName;
  68. }
  69. protected RoleBase(string name, string displayName)
  70. : this(displayName)
  71. {
  72. Name = name;
  73. }
  74. public override string ToString()
  75. {
  76. return $"[Role {Id}, Name={Name}]";
  77. }
  78. }
  79. }