protected async Task HandleCreateOrUpdate( Domain.Models.Vm vmEntity, string method, string[] modifiedProperties, CancellationToken cancellationToken) { if (!vmEntity.TeamsLoaded) { if (_db.Entry(vmEntity).State == EntityState.Detached) { _db.Attach(vmEntity); } await _db.Entry(vmEntity) .Collection(x => x.VmTeams) .LoadAsync(cancellationToken); } var groupIds = await this.GetGroups(vmEntity, cancellationToken); var vm = _mapper.Map <Vm>(vmEntity); var tasks = new List <Task>(); foreach (var groupId in groupIds) { tasks.Add(_vmHub.Clients.Group(groupId.ToString()).SendAsync(method, vm, modifiedProperties, cancellationToken)); } await Task.WhenAll(tasks); }
protected async Task <Guid[]> GetGroups(Domain.Models.Vm vm, CancellationToken cancellationToken) { var groupIds = new List <Guid>(); foreach (var teamId in vm.VmTeams.Select(x => x.TeamId)) { var viewId = await _viewService.GetViewIdForTeam(teamId, cancellationToken); if (viewId.HasValue && !groupIds.Any(v => v == viewId.Value)) { groupIds.Add(viewId.Value); } groupIds.Add(teamId); } return(groupIds.ToArray()); }
public async Task <bool> CanAccessVm(Domain.Models.Vm vm, CancellationToken ct) { if (vm == null) { throw new EntityNotFoundException <Vm>(); } var teamIds = vm.VmTeams.Select(x => x.TeamId); if (!await _playerService.CanAccessTeamsAsync(teamIds, ct)) { throw new ForbiddenException(); } if (vm.UserId.HasValue && vm.UserId != _user.GetId() && !await _playerService.CanManageTeamsAsync(teamIds, false, ct)) { throw new ForbiddenException("This machine belongs to another user"); } return(true); }