0

我收到错误消息:

未授予所需的权限。必须至少授予以下权限之一:[Plug entity]

还请就如何授予权限提出建议。

这是我的代码:

namespace Sprint.Plug
{
    [AbpAuthorize(PermissionNames.Pages_PlugEntity)]
    public class PlugAppService: AsyncCrudAppService<PlugEntity, PlugDto, Guid>, IPlugAppService
    {        
        public PlugAppService(IRepository<PlugEntity,Guid> repository):base(repository)
        {

        }        
    }
}

namespace Sprint.Authorization
{
    public static class PermissionNames
    {
        public const string Pages_Tenants = "Pages.Tenants";

        public const string Pages_Users = "Pages.Users";

        public const string Pages_Roles = "Pages.Roles";

        public const string Pages_PlugEntity = "Pages.PlugEntity";
    }
}

namespace Sprint.Authorization
{
    public class SprintAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            context.CreatePermission(PermissionNames.Pages_Users, L("Users"));
            context.CreatePermission(PermissionNames.Pages_Roles, L("Roles"));
            context.CreatePermission(PermissionNames.Pages_Tenants, L("Tenants"), multiTenancySides: MultiTenancySides.Host);
            context.CreatePermission(PermissionNames.Pages_PlugEntity, L("PlugEntity"), multiTenancySides: MultiTenancySides.Tenant);
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, SprintConsts.LocalizationSourceName);
        }
    }
}
4

1 回答 1

0

添加新权限后,您还需要在 AbpPermissions 表中创建关系。此外,如果您希望在错误消息中包含本地化,则需要在对应的 .xml 文件中添加记录。

于 2020-03-19T21:25:31.717 回答