Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        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);
        }