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}`"))} 중 하나를 선택할 수 있어요");
public bool HasPermission(PermissionNames permission) { var claimType = PermissionHelpers.CreateClaimType(permission); foreach (var claim in this.Claims) { if (claim.ClaimType == claimType) { return(true); } } return(false); }
public PermissionAuthorizeAttribute(PermissionNames permission) : base(PortalPermissionHelpers.CreatePolicyName(permission)) { Permission = permission; }
public PermissionRequirement(PermissionNames permission) { Permission = permission; ClaimType = PermissionHelpers.CreateClaimType(permission); }
public static string CreatePolicyName(PermissionNames permission) => $"{nameof(PermissionAuthorizeAttribute)}.{permission}";
public static async Task <bool> HasPermission(this ClaimsPrincipal principal, IAuthorizationService auth, PermissionNames permission) => (await auth.AuthorizeAsync(principal, CreatePolicyName(permission))).Succeeded;
public static RoleClaim CreateIdentityRoleClaim(PermissionNames permission) => new RoleClaim { ClaimType = CreateClaimType(permission), ClaimValue = new PermissionClaimValue(true).ToJson() };
public static string CreateClaimType(PermissionNames permissionName) => $"{TraffkHelpers.TraffkUrn}/claims/{permissionName}";