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> GetVersion(Guid networkId, Guid versionId)
        {
            bool canAccess = User.Identity.IsAuthenticated
                ? await _networkService.CanAccessNetworkAsync(networkId, User.GetId())
                : await _networkService.CanAccessNetworkAnonymouslyAsync(networkId);

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

            NetworkVersionMetadata version = await _networkVersionsService.GetVersionInfoAsync(versionId);

            NetworkVersionMetadata currentVersion = await _networkVersionsService.GetCurrentVersionInfoAsync(networkId);

            Network network = await _networkService.GetNetworkAsync(networkId);

            User author = await _userService.GetUserAsync(version.AuthorId);

            bool canEdit = User.Identity.IsAuthenticated &&
                           await _networkService.CanEditNetworkAsync(networkId, User.GetId());

            var model = new NetworkVersionDetailsModel(version, network, author, canEdit, currentVersion.Id == versionId);

            return(View("GetVersion", model));
        }
示例#3
0
        public NetworkVersionModel(NetworkVersionMetadata versionMetadata, User author)
        {
            Id        = versionMetadata.Id;
            NetworkId = versionMetadata.NetworkId;
            Comment   = versionMetadata.Comment;
            Date      = versionMetadata.Date;

            Author = new UserDisplayModel(author);
        }
        public async Task <IActionResult> ResetToVersion(Guid versionId)
        {
            NetworkVersionMetadata version = await _networkVersionsService.GetVersionInfoAsync(versionId);

            bool canEdit = await _networkService.CanEditNetworkAsync(version.NetworkId, User.GetId());

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

            await _networkVersionsService.ResetToVersionAsync(versionId);

            return(RedirectToAction(nameof(NetworksController.GetNetwork), "Networks", new { id = version.NetworkId }));
        }
示例#5
0
        public NetworkVersionDetailsModel(
            NetworkVersionMetadata versionMetadata,
            Network network,
            User author,
            bool canEdit,
            bool isCurrentVersion)
        {
            Id          = versionMetadata.Id;
            Comment     = versionMetadata.Comment;
            Date        = versionMetadata.Date;
            NetworkId   = network.Id;
            NetworkName = network.Name;
            IsReadOnly  = !isCurrentVersion || !canEdit;

            Author = new UserDisplayModel(author);
        }
        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));
        }
示例#7
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));
        }
        public async Task <IActionResult> GetCurrentVersion(Guid networkId)
        {
            NetworkVersionMetadata currentVersion = await _networkVersionsService.GetCurrentVersionInfoAsync(networkId);

            return(await GetVersion(networkId, currentVersion.Id));
        }