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

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

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

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

            return(problems);
        }
Exemple #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.HasUserAccessTo_Any_Course(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.GetListOfUsersWithCourseRole(CourseRoleType.Instructor, courseId, true)
                                                : (await groupAccessesRepo.GetInstructorsOfAllGroupsAvailableForUserAsync(currentUser.Id).ConfigureAwait(false)).Select(u => u.Id);

                userIds.UnionWith(courseInstructors);
            }

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

            return(courseRolesRepo.HasUserAccessTo_Any_Course(currentUser.Id, CourseRoleType.Instructor));
        }
Exemple #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.HasUserAccessTo_Any_Course(instructorId, CourseRoleType.CourseAdmin).ConfigureAwait(false))
            {
                return(true);
            }

            var coursesIds = (await courseManager.GetCoursesAsync()).Select(c => c.Id).ToList();
            var groups     = await GetAvailableForUserGroupsAsync(coursesIds, instructorId, false, actual : true, archived : false).ConfigureAwait(false);

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

            return(members.Select(m => m.UserId).Contains(studentId));
        }