-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathFilesPrivacyFilter.cs
More file actions
71 lines (62 loc) · 2.26 KB
/
Copy pathFilesPrivacyFilter.cs
File metadata and controls
71 lines (62 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using HwProj.CoursesService.Client;
using HwProj.Models.ContentService.DTO;
using HwProj.Models.CourseUnitType;
using HwProj.SolutionsService.Client;
namespace HwProj.APIGateway.API.Filters;
public class FilesPrivacyFilter(
ICoursesServiceClient coursesServiceClient,
ISolutionsServiceClient solutionsServiceClient)
{
private async Task<HashSet<string>> GetSolutionStudentIds(long solutionId)
{
var studentIds = new HashSet<string>();
var solution = await solutionsServiceClient.GetSolutionById(solutionId);
studentIds.Add(solution.StudentId);
if (solution.GroupId is { } groupId)
{
var groups = await coursesServiceClient.GetGroupsById(groupId);
if (groups is [var group]) studentIds.UnionWith(group.StudentsIds.ToHashSet());
}
return studentIds;
}
public async Task<bool> CheckDownloadRights(string? userId, ScopeDTO fileScope)
{
if (userId == null) return false;
switch (fileScope.CourseUnitType)
{
case CourseUnitType.Homework:
return true;
case CourseUnitType.Solution:
{
var studentIds = await GetSolutionStudentIds(fileScope.CourseUnitId);
if (studentIds.Contains(userId)) return true;
var mentorIds = await coursesServiceClient.GetCourseLecturersIds(fileScope.CourseId);
return mentorIds.Contains(userId);
}
default:
return false;
}
}
public async Task<bool> CheckUploadRights(string? userId, ScopeDTO fileScope)
{
if (userId == null) return false;
switch (fileScope.CourseUnitType)
{
case CourseUnitType.Homework:
{
var mentorIds = await coursesServiceClient.GetCourseLecturersIds(fileScope.CourseId);
return mentorIds.Contains(userId);
}
case CourseUnitType.Solution:
{
var studentIds = await GetSolutionStudentIds(fileScope.CourseUnitId);
return studentIds.Contains(userId);
}
default:
return false;
}
}
}