Пример #1
0
        public async Task SetPermissionRole([Name("권한")] string permission, [Name("")] string permission2, [Remainder, Name("역할")] SocketRole role)
        {
            permission += $" {permission2}";

            if (!PermissionNames.Contains(permission))
            {
                await Context.MsgReplyEmbedAsync($"알 수 없는 권한이에요\n{string.Join(", ", PermissionNames[..(PermissionNames.Length - 2)].Select(c => $"`{c}`"))} 중 하나를 선택할 수 있어요");
Пример #2
0
        public bool HasPermission(PermissionNames permission)
        {
            var claimType = PermissionHelpers.CreateClaimType(permission);

            foreach (var claim in this.Claims)
            {
                if (claim.ClaimType == claimType)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
 public PermissionAuthorizeAttribute(PermissionNames permission)
     : base(PortalPermissionHelpers.CreatePolicyName(permission))
 {
     Permission = permission;
 }
Пример #4
0
 public PermissionRequirement(PermissionNames permission)
 {
     Permission = permission;
     ClaimType  = PermissionHelpers.CreateClaimType(permission);
 }
Пример #5
0
 public static string CreatePolicyName(PermissionNames permission)
 => $"{nameof(PermissionAuthorizeAttribute)}.{permission}";
Пример #6
0
 public static async Task <bool> HasPermission(this ClaimsPrincipal principal, IAuthorizationService auth, PermissionNames permission)
 => (await auth.AuthorizeAsync(principal, CreatePolicyName(permission))).Succeeded;
Пример #7
0
 public static RoleClaim CreateIdentityRoleClaim(PermissionNames permission)
 => new RoleClaim
 {
     ClaimType  = CreateClaimType(permission),
     ClaimValue = new PermissionClaimValue(true).ToJson()
 };
Пример #8
0
 public static string CreateClaimType(PermissionNames permissionName)
 => $"{TraffkHelpers.TraffkUrn}/claims/{permissionName}";