public async Task <bool> CanUserSeeAllCourseGroupsAsync(string userId, string courseId) { var canViewAllGroupMembersGlobal = await systemAccessesRepo.HasSystemAccessAsync(userId, SystemAccessType.ViewAllGroupMembers).ConfigureAwait(false); var canViewAllGroupMembersInCourse = await coursesRepo.HasCourseAccessAsync(userId, courseId, CourseAccessType.ViewAllGroupMembers).ConfigureAwait(false); var isCourseAdmin = await courseRolesRepo.HasUserAccessToCourseAsync(userId, courseId, CourseRoleType.CourseAdmin).ConfigureAwait(false); return(isCourseAdmin || canViewAllGroupMembersGlobal || canViewAllGroupMembersInCourse); }
protected async Task <bool> CanUserSeeNotApprovedCommentsAsync(string userId, string courseId) { if (string.IsNullOrEmpty(userId)) { return(false); } var hasCourseAccessForCommentEditing = await coursesRepo.HasCourseAccessAsync(userId, courseId, CourseAccessType.EditPinAndRemoveComments).ConfigureAwait(false); var isCourseAdmin = await courseRolesRepo.HasUserAccessToCourseAsync(userId, courseId, CourseRoleType.CourseAdmin).ConfigureAwait(false); return(isCourseAdmin || hasCourseAccessForCommentEditing); }
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, CourseAccessRequirement requirement) { /* Get MVC context. See https://docs.microsoft.com/en-US/aspnet/core/security/authorization/policies#accessing-mvc-request-context-in-handlers */ if (!(context.Resource is AuthorizationFilterContext mvcContext)) { logger.Error("Can't get MVC context in CourseRoleAuthenticationHandler"); context.Fail(); return; } var routeData = mvcContext.RouteData; if (!(routeData.Values["courseId"] is string courseId)) { logger.Error("Can't find `courseId` parameter in route data for checking course access requirement."); context.Fail(); return; } if (!context.User.Identity.IsAuthenticated) { context.Fail(); return; } var userId = context.User.GetUserId(); var user = await usersRepo.FindUserByIdAsync(userId).ConfigureAwait(false); if (user == null) { context.Fail(); return; } if (usersRepo.IsSystemAdministrator(user)) { context.Succeed(requirement); return; } var isCourseAdmin = await courseRolesRepo.HasUserAccessToCourseAsync(userId, courseId, CourseRoleType.CourseAdmin).ConfigureAwait(false); if (isCourseAdmin || await coursesRepo.HasCourseAccessAsync(userId, courseId, requirement.CourseAccessType).ConfigureAwait(false)) { context.Succeed(requirement); } else { context.Fail(); } }
public async Task <bool> CanUserSeeAllCourseGroupsAsync(string userId, string courseId, bool?isSystemAdministrator = null) { if (isSystemAdministrator == true || isSystemAdministrator == null && await usersRepo.IsSystemAdministrator(userId)) { return(true); } var canViewAllGroupMembersGlobal = await systemAccessesRepo.HasSystemAccessAsync(userId, SystemAccessType.ViewAllGroupMembers).ConfigureAwait(false); var canViewAllGroupMembersInCourse = await coursesRepo.HasCourseAccessAsync(userId, courseId, CourseAccessType.ViewAllGroupMembers).ConfigureAwait(false); var isCourseAdmin = await courseRolesRepo.HasUserAccessToCourseAsync(userId, courseId, CourseRoleType.CourseAdmin).ConfigureAwait(false); return(isCourseAdmin || canViewAllGroupMembersGlobal || canViewAllGroupMembersInCourse); }