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)); }
public async Task <IActionResult> GetVersion(Guid versionId) { NetworkVersion version = await _networkVersionsService.GetVersionAsync(versionId); bool canAccess = User.Identity.IsAuthenticated ? await _networkService.CanAccessNetworkAsync(version.Metadata.NetworkId, User.GetId()) : await _networkService.CanAccessNetworkAnonymouslyAsync(version.Metadata.NetworkId); if (!canAccess) { return(Forbid()); } var model = new NetworkDiagramModel(version.Diagram); return(Ok(model)); }
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)); }