Ejemplo n.º 1
0
        public async Task <ResponseMessage> DeletePermissionItems(string userId, [FromBody] List <string> permissionItemIds)
        {
            ResponseMessage response = new ResponseMessage();

            if (!await _permissionExpansionManager.HavePermission(userId, "PermissionItemDelete"))
            {
                response.Code = ResponseCodeDefines.NotAllow;
                return(response);
            }
            await _permissionItemManager.DeleteListAsync(permissionItemIds, HttpContext.RequestAborted);

            await _rolePermissionManager.DeleteByPermissionItemIdsAsync(permissionItemIds, CancellationToken.None);

            await _permissionOrganizationManager.DeleteByPermissionIdsAsync(permissionItemIds, CancellationToken.None);

            await _permissionExpansionManager.RemovePermissionsAsync(permissionItemIds);

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <ResponseMessage> Delete(string userId, [FromRoute] string id)
        {
            ResponseMessage response = new ResponseMessage();

            if (!await _permissionExpansionManager.HavePermission(userId, "ApplicationDelete"))
            {
                response.Code = ResponseCodeDefines.NotAllow;
                return(response);
            }
            var applicationIds = await _roleApplicationManager.FindApplicationIdsByUserIdAsync(userId, HttpContext.RequestAborted);

            if (!applicationIds.Contains(id))
            {
                response.Code = ResponseCodeDefines.NotAllow;
                return(response);
            }
            var application = await _applicationManager.FindByIdAsync(id, HttpContext.RequestAborted);

            if (application == null)
            {
                response.Code    = ResponseCodeDefines.NotFound;
                response.Message = "对象不存在";
                return(response);
            }
            await _applicationManager.DeleteAsync(application, HttpContext.RequestAborted);

            var permissionItems = await _permissionItemManager.FindByApplicationAsync(id, CancellationToken.None);

            var permissionItemIds = permissionItems.Select(a => a.Id).ToList();
            await _permissionExpansionManager.RemovePermissionsAsync(permissionItemIds);

            await _permissionOrganizationManager.DeleteByPermissionIdsAsync(permissionItemIds, CancellationToken.None);

            await _rolePermissionManager.DeleteByPermissionItemIdsAsync(permissionItemIds, CancellationToken.None);

            await _permissionItemManager.DeleteListAsync(permissionItems, CancellationToken.None);

            return(response);
        }