Beispiel #1
0
        public async Task <bool> CheckIsGrantedAsync(params string[] permissions)
        {
            var permissionDefinitions = permissionDefinitionContext.PermissionDefinitions();

            /*先判断权限是否有定义*/
            if (!permissionDefinitions.Any(v => v.Child.Any(r => permissions.Contains(r.Name))))
            {
                return(false);
            }

            var currUser = appSessionProvider.CurrUser;

            if (currUser.IsAdmin)
            {
                return(true);
            }

            var existsQuery = from a in roleMemberRepository
                              join b in rolePermissionRepository on a.Role_Id equals b.Role_Id
                              join c in roleRepository on a.Role_Id equals c.Id
                              where (a.User_Id == currUser.Id || c.IsDefault) &&
                              permissions.Contains(b.PermissionKey)
                              select 1;

            return(await existsQuery.AnyAsync());
        }