Exemplo n.º 1
0
        public static async Task <Func <Slide, string> > BuildGetGitEditLinkFunc(string userId, Course course,
                                                                                 ICourseRolesRepo courseRolesRepo, ICoursesRepo coursesRepo)
        {
            var courseRole = await courseRolesRepo.GetRoleAsync(userId, course.Id);

            var canEditGit = courseRole <= CourseRoleType.CourseAdmin;

            if (!canEditGit)
            {
                return(s => null);
            }
            var publishedCourseVersion = await coursesRepo.GetPublishedCourseVersionAsync(course.Id);

            if (publishedCourseVersion == null)
            {
                return(s => null);
            }
            var repoUrl         = publishedCourseVersion.RepoUrl;
            var pathToCourseXml = publishedCourseVersion.PathToCourseXml;

            if (repoUrl == null || pathToCourseXml == null)
            {
                return(s => null);
            }
            var courseXmlDirectory = course.CourseXmlDirectory;

            return(slide =>
            {
                var pathRelative2CourseXml = slide.Info.SlideFile.FullName.Substring(courseXmlDirectory.FullName.Length + 1);
                return GitUtils.GetSlideEditLink(repoUrl, pathToCourseXml, pathRelative2CourseXml);
            });
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        public async Task <List <NotificationType> > GetNotificationTypes(string userId, string courseId)
        {
            var notificationTypes = GetAllNotificationTypes();

            var courseRole = await courseRolesRepo.GetRoleAsync(userId, courseId);

            notificationTypes = notificationTypes
                                .Where(t => t.GetMinCourseRole() <= courseRole)
                                .OrderByDescending(t => t.GetMinCourseRole())
                                .ThenBy(t => (int)t)
                                .ToList();

            if (!await usersRepo.IsSystemAdministrator(userId))
            {
                notificationTypes = notificationTypes.Where(t => !t.IsForSysAdminsOnly()).ToList();
            }

            return(notificationTypes);
        }