Example #1
0
        private async Task <List <AccountProblem> > GetAccountProblems(ApplicationUser user)
        {
            var problems = new List <AccountProblem>();

            if (string.IsNullOrEmpty(user.Email))
            {
                problems.Add(new AccountProblem(
                                 "Не указана эл. почта",
                                 "Укажите в профиле электронную почту, чтобы получать уведомления и восстановить доступ в случае утери пароля"
                                 ));
            }
            if (!string.IsNullOrEmpty(user.Email) && !user.EmailConfirmed)
            {
                problems.Add(new AccountProblem(
                                 "Эл. почта не подтверждена",
                                 "Подтвердите в профиле электронную почту, чтобы получать уведомления и восстановить доступ в случае утери пароля"
                                 ));
            }

            var isInstructor = await courseRolesRepo.HasUserAccessToAnyCourseAsync(user.Id, CourseRoleType.Instructor).ConfigureAwait(false);

            if (isInstructor && (string.IsNullOrEmpty(user.FirstName) || string.IsNullOrEmpty(user.LastName)))
            {
                problems.Add(new AccountProblem(
                                 "Не указаны имя или фамилия",
                                 "Укажите в профиле имя и фамилию, чтобы студентам было проще с вами работать"
                                 ));
            }

            return(problems);
        }
Example #2
0
        public async Task <IQueryable <ApplicationUser> > RestrictUsersSetAsync(IQueryable <ApplicationUser> users, ApplicationUser currentUser, string courseId,
                                                                                bool hasSystemAdministratorAccess, bool hasCourseAdminAccess, bool hasInstructorAccessToGroupMembers, bool hasInstructorAccessToCourseInstructors)
        {
            if (hasSystemAdministratorAccess && usersRepo.IsSystemAdministrator(currentUser))
            {
                return(users);
            }

            if (hasCourseAdminAccess && await courseRolesRepo.HasUserAccessToAnyCourseAsync(currentUser.Id, CourseRoleType.CourseAdmin).ConfigureAwait(false))
            {
                return(users);
            }

            var userIds = new HashSet <string>();

            if (hasInstructorAccessToGroupMembers)
            {
                var groupsMembers = await groupAccessesRepo.GetMembersOfAllGroupsAvailableForUserAsync(currentUser.Id).ConfigureAwait(false);

                userIds.UnionWith(groupsMembers.Select(m => m.UserId));
            }

            if (hasInstructorAccessToCourseInstructors)
            {
                var courseInstructors =
                    courseId != null
                                                ? await courseRolesRepo.GetUsersWithRoleAsync(courseId, CourseRoleType.Instructor)
                                                : (await groupAccessesRepo.GetInstructorsOfAllGroupsAvailableForUserAsync(currentUser.Id).ConfigureAwait(false)).Select(u => u.Id);

                userIds.UnionWith(courseInstructors);
            }

            return(users.Where(u => userIds.Contains(u.Id)));
        }
Example #3
0
        public virtual Task <bool> IsAvailableForSearchAsync(ApplicationUser currentUser)
        {
            if (usersRepo.IsSystemAdministrator(currentUser))
            {
                return(Task.FromResult(true));
            }

            return(courseRolesRepo.HasUserAccessToAnyCourseAsync(currentUser.Id, CourseRoleType.Instructor));
        }
Example #4
0
        /* Instructor can view student if he is a course admin or if student is member of one of accessible for instructor group */
        public async Task <bool> CanInstructorViewStudentAsync(string instructorId, string studentId)
        {
            if (await courseRolesRepo.HasUserAccessToAnyCourseAsync(instructorId, CourseRoleType.CourseAdmin).ConfigureAwait(false))
            {
                return(true);
            }

            var coursesIds = courseManager.GetCourses().Select(c => c.Id).ToList();
            var groups     = await GetAvailableForUserGroupsAsync(coursesIds, instructorId, false).ConfigureAwait(false);

            var members = await groupMembersRepo.GetGroupsMembersAsync(groups.Select(g => g.Id).ToList()).ConfigureAwait(false);

            return(members.Select(m => m.UserId).Contains(studentId));
        }
Example #5
0
        public async Task <ActionResult <ShortSlideInfo> > SlideInfo(Course course, Guid slideId)
        {
            var slide = course?.FindSlideById(slideId);

            if (slide == null)
            {
                var instructorNote = course?.FindInstructorNoteById(slideId);
                if (instructorNote != null && await CourseRolesRepo.HasUserAccessToAnyCourseAsync(User.GetUserId(), CourseRoleType.Instructor).ConfigureAwait(false))
                {
                    slide = instructorNote.Slide;
                }
            }

            if (slide == null)
            {
                return(NotFound(new { status = "error", message = "Course or slide not found" }));
            }

            var getSlideMaxScoreFunc = await BuildGetSlideMaxScoreFunc(SolutionsRepo, UserQuizzesRepo, VisitsRepo, GroupsRepo, course, User.GetUserId());

            return(BuildSlideInfo(course.Id, slide, getSlideMaxScoreFunc));
        }