using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.Domain.Entities.Auditing;
using IwbZero.Authorization.Base.Roles;
using IwbZero.Authorization.Users;
using Microsoft.AspNet.Identity;
namespace IwbZero.Authorization.Roles
{
///
/// Represents a role in an application. A role is used to group permissions.
///
///
/// Application should use permissions to check if user is granted to perform an operation.
/// Checking 'if a user has a role' is not possible until the role is static ().
/// Static roles can be used in the code and can not be deleted by users.
/// Non-static (dynamic) roles can be added/removed by users and we can not know their name while coding.
/// A user can have multiple roles. Thus, user will have all permissions of all assigned roles.
///
public abstract class IwbSysRole : RoleBase, IRole, IFullAudited
where TUser : IwbSysUser
{
///
/// Maximum length of the property.
///
public const int MaxConcurrencyStampLength = 128;
///
/// Unique name of this role.
///
[Required]
[StringLength(MaxNameLength)]
public virtual string NormalizedName { get; set; }
///
/// Claims of this user.
///
[ForeignKey("RoleId")]
public virtual ICollection Claims { get; set; }
///
/// A random value that must change whenever a user is persisted to the store
///
[StringLength(MaxConcurrencyStampLength)]
public virtual string ConcurrencyStamp { get; set; } = Guid.NewGuid().ToString();
public virtual TUser DeleterUser { get; set; }
public virtual TUser CreatorUser { get; set; }
public virtual TUser LastModifierUser { get; set; }
protected IwbSysRole()
{
SetNormalizedName();
}
///
/// Creates a new object.
///
/// TenantId or null (if this is not a tenant-level role)
/// Display name of the role
protected IwbSysRole(int? tenantId, string displayName)
: base(tenantId, displayName)
{
SetNormalizedName();
}
///
/// Creates a new object.
///
/// TenantId or null (if this is not a tenant-level role)
/// Unique role name
/// Display name of the role
protected IwbSysRole(int? tenantId, string name, string displayName)
: base(tenantId, name, displayName)
{
SetNormalizedName();
}
public virtual void SetNormalizedName()
{
NormalizedName = Name.ToUpperInvariant();
}
}
}