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