private async Task <List <string> > GetUserIdsWithProgressNotVisibleForUser(string courseId, List <string> userIds) { var isSystemAdministrator = await IsSystemAdministratorAsync().ConfigureAwait(false); if (isSystemAdministrator) { return(null); } if (await groupAccessesRepo.CanUserSeeAllCourseGroupsAsync(UserId, courseId)) { return(null); } var userRole = await courseRolesRepo.GetRoleAsync(UserId, courseId).ConfigureAwait(false); var groups = userRole == CourseRoleType.Instructor ? await groupAccessesRepo.GetAvailableForUserGroupsAsync(courseId, UserId, false, true, false) : new List <Group>(); groups = groups .Concat((await groupMembersRepo.GetUserGroupsAsync(courseId, UserId, false)).Where(g => g.CanUsersSeeGroupProgress)) .Distinct().ToList(); var members = new [] { UserId }.Concat(await groupMembersRepo.GetGroupsMembersIdsAsync(groups.Select(g => g.Id).ToList())).ToHashSet(); var allIdsInMembers = members.IsSupersetOf(userIds); if (allIdsInMembers) { return(null); } var notVisibleUserIds = userIds.ToHashSet(); notVisibleUserIds.ExceptWith(members); return(notVisibleUserIds.ToList()); }
public async Task <IActionResult> ResetLimitsForStudents(int groupId, ResetLimitsParameters parameters) { var hasEditAccess = await groupAccessesRepo.HasUserEditAccessToGroupAsync(groupId, UserId); if (!hasEditAccess) { return(StatusCode((int)HttpStatusCode.Forbidden, new ErrorResponse("You have no edit access to this group"))); } var group = await groupsRepo.FindGroupByIdAsync(groupId); var members = await groupMembersRepo.GetGroupsMembersIdsAsync(new [] { groupId }); var studentsToProcessSet = parameters.StudentIds.ToHashSet(); studentsToProcessSet.IntersectWith(members); foreach (var studentId in studentsToProcessSet) { await slideCheckingsRepo.ResetAutomaticCheckingLimitsForUser(group.CourseId, studentId); } return(Ok(new SuccessResponseWithMessage($"Limits for {studentsToProcessSet.Count} students have been reset"))); }