예제 #1
0
        public async Task <IActionResult> SaveVersion([FromBody] NetworkVersionInputModel networkVersion)
        {
            bool canEdit = await _networkService.CanEditNetworkAsync(networkVersion.NetworkId, User.GetId());

            if (!canEdit)
            {
                return(BadRequest("Version creation is not allowed"));
            }

            NetworkVersionMetadata currentVersion =
                await _networkVersionsService.GetCurrentVersionInfoAsync(networkVersion.NetworkId);

            if (currentVersion?.Id != networkVersion.BaseVersionId)
            {
                return(BadRequest("Version is outdated"));
            }

            var versionDto = new NewNetworkVersion(
                networkVersion.NetworkId,
                networkVersion.Comment,
                networkVersion.Network.ToDto(),
                User.GetId());

            Guid newVersionId = await _networkVersionsService.SaveVersionAsync(versionDto);

            return(Ok(newVersionId));
        }
        public async Task <IActionResult> CreateVersion(Guid networkId)
        {
            bool canEdit = await _networkService.CanEditNetworkAsync(networkId, User.GetId());

            if (!canEdit)
            {
                return(Forbid());
            }

            NetworkVersionMetadata currentVersion = await _networkVersionsService.GetCurrentVersionInfoAsync(networkId);

            Network network = await _networkService.GetNetworkAsync(networkId);

            var model = new NewNetworkVersionModel(network, currentVersion?.Id);

            return(View(model));
        }
예제 #3
0
        public async Task <IActionResult> GetNetwork(Guid id)
        {
            bool canAccess = User.Identity.IsAuthenticated
                ? await _networkService.CanAccessNetworkAsync(id, User.GetId())
                : await _networkService.CanAccessNetworkAnonymouslyAsync(id);

            if (!canAccess)
            {
                return(Forbid());
            }

            Network network = await _networkService.GetNetworkAsync(id);

            List <Guid> networkUserIds = network.ReadAccess.PermittedUsers
                                         .Union(network.WriteAccess.PermittedUsers)
                                         .Union(Enumerable.Repeat(network.OwnerId, 1))
                                         .ToList();

            Dictionary <Guid, User> users = (await _userService.GetUsersAsync(networkUserIds)).ToDictionary(u => u.Id);

            bool isOwner = false;
            bool canEdit = false;

            if (User.Identity.IsAuthenticated)
            {
                Guid userId = User.GetId();

                isOwner = userId == network.OwnerId;
                canEdit = User.Identity.IsAuthenticated &&
                          await _networkService.CanEditNetworkAsync(id, userId);
            }

            NetworkVersionMetadata currentVersion = await _networkVersionsService.GetCurrentVersionInfoAsync(id);

            var model = new NetworkDetailsModel(network, users, isOwner, canEdit, currentVersion != null);

            return(View(model));
        }