Beispiel #1
0
        public async Task <IActionResult> AllMy()
        {
            var user = await AuthenticationHelper.GetAuthorizedUser(HttpContext.User, _userManager);

            if (await AuthorizationHelper.CheckIfAdmin(user, _userManager))
            {
                return(Ok(await _modelService.GetAllAsync()));
            }
            return(Ok(await _fieldOfStudyService.GetAllMy(user)));
        }
Beispiel #2
0
        public async Task AdminValidationTest(SyllabusManagerUser user, SyllabusManagerUser inputUser, List <string> roles, bool expectedResult)
        {
            // Arrange
            var store           = new Mock <IUserStore <SyllabusManagerUser> >();
            var userManagerMock = new Mock <UserManager <SyllabusManagerUser> >(store.Object, null, null, null, null, null, null, null, null);

            userManagerMock
            .Setup(r => r.GetRolesAsync(inputUser ?? user))
            .ReturnsAsync(roles);

            // Act
            var actualResult = await AuthorizationHelper.CheckIfAdmin(user, userManagerMock.Object);

            // Assert
            Assert.Equal(expectedResult, actualResult);
        }
 public async Task <bool> CheckIfFosSupervisor(SyllabusManagerUser user, string fosCode)
 {
     return(await AuthorizationHelper.CheckIfAdmin(user, _userManager) ||
            _dbContext.FieldsOfStudies.Include(f => f.Supervisor)
            .FirstOrDefault(f => f.Code == fosCode)?.Supervisor.Id == user.Id);
 }