public async Task <XDocument> GetDirectoryStructure(string userName) { var resultDocument = new XDocument(); var root = new XElement("root"); var user = await _context.Users.Include(x => x.ResourceAccesses).ThenInclude(x => x.OwnerUser).AsNoTracking() .SingleOrDefaultAsync(x => x.UserName == userName); var resourceGroupedByOwnerName = user.ResourceAccesses.GroupBy(x => x.OwnerUser.UserName).ToDictionary(x => x.Key, y => y.ToList()); foreach (var resourcesByOwner in resourceGroupedByOwnerName) { var userElement = new XElement("owner", new XAttribute("name", resourcesByOwner.Key)); foreach (var resource in resourcesByOwner.Value) { var fullPath = PathUtilities.ConvertUserPathToFullPath(resource.Path); var resourceDirInfo = new DirectoryInfo(fullPath); var resourceStructure = GetDirectoryXml(resourceDirInfo); if (resourceStructure.Attribute("name").Value == resource.OwnerUser.UserName) { resourceStructure.Attribute("name").Value = "\\"; } userElement.Add(resourceStructure); } root.Add(userElement); } resultDocument.Add(root); return(resultDocument); }
public IEnumerable <string> ListUserWithAccessToResource(string ownerName, string path) { var userPath = PathUtilities.GenerateUserPath(ownerName, path); if (!Directory.Exists(PathUtilities.ConvertUserPathToFullPath(userPath)) && !File.Exists(PathUtilities.ConvertUserPathToFullPath(userPath))) { throw new MiniCloudException("Path is not valid"); } var usersWithAccess = _dbContext.ResourceAccesses.Include(x => x.DoneeUser).Where(x => userPath.StartsWith(x.Path)).Select(x => x.DoneeUser.UserName); return(usersWithAccess); }