Skip to content

Commit

Permalink
fixed file permissions when cloning a view (#39)
Browse files Browse the repository at this point in the history
- update file application urls when cloning a view
- fixed returning duplicate files when getting files by view
- removed unnecessary path field from filemodel
  • Loading branch information
sei-aschlackman authored Apr 24, 2023
1 parent 74d94bf commit 9853ee5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Player.Api/Services/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,18 @@ public async Task<IEnumerable<FileModel>> GetByViewAsync(Guid viewId, Cancellati

foreach (var team in teams)
{
accessable.AddRange(_mapper.Map<IEnumerable<FileModel>>(await GetByTeamAsync(team.Id, ct)));
var teamFiles = await GetByTeamAsync(team.Id, ct);

foreach (var teamFile in teamFiles)
{
if (!accessable.Any(x => x.id == teamFile.id))
{
accessable.Add(teamFile);
}
}
}
return _mapper.Map<IEnumerable<FileModel>>(accessable);

return accessable;
}

public async Task<IEnumerable<FileModel>> GetByTeamAsync(Guid teamId, CancellationToken ct)
Expand Down
18 changes: 18 additions & 0 deletions Player.Api/Services/ViewService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,24 @@ public async Task<View> CloneAsync(Guid idToBeCloned, ViewCloneOverride viewClon
}
file.TeamIds = newTeamIds;
}

// Update any applications pointing to original files
foreach (var file in view.Files)
{
var newFile = newView.Files.Where(x => x.Path == file.Path).FirstOrDefault();

if (newFile == null)
continue;

foreach (var application in newView.Applications)
{
if (application.Url != null && application.Url.Contains(file.Id.ToString()))
{
application.Url = application.Url.Replace(file.Id.ToString(), newFile.Id.ToString());
}
}
}

await _context.SaveChangesAsync(ct);
return _mapper.Map<View>(newView);
}
Expand Down
1 change: 0 additions & 1 deletion Player.Api/ViewModels/FileModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ public class FileModel
public string Name { get; set; }
public Guid viewId { get; set; }
public List<Guid> teamIds { get; set; }
public string Path { get; set; }
}
}

0 comments on commit 9853ee5

Please sign in to comment.