UserAccessExpressionEvaluator implements ExpressionEvaluator { @Override public boolean hasAccessToProjects(Authentication authentication, User user) { return userAccessService.userHasActiveAccessInterval(user) || userService.userIsManager(user); } @Autowired  UserAccessExpressionEvaluator(UserService userService,
                                         UserAccessService userAccessService,
                                         ProjectService projectService,
                                         ApplicationService applicationService,
                                         BookmarkService bookmarkService,
                                         ProjectBoardConfigurationProperties properties); @Override boolean hasAccessToProjects(Authentication authentication, User user); @Override boolean hasAccessToProject(Authentication authentication, User user, String projectId); @Override boolean hasPermissionToApplyToProject(Authentication authentication, User user, String projectId); @Override boolean hasPermissionToAccessUser(Authentication authentication, User user, String userId); @Override boolean hasElevatedAccessToUser(Authentication authentication, User user, String userId);  }
@Test public void hasAccessToProjectsReturnsTrueWhenUserIsManager() { given(userServiceMock.userIsManager(userMock)).willReturn(true); boolean actualHasAccess = evaluator.hasAccessToProjects(authenticationMock, userMock); assertThat(actualHasAccess).isTrue(); }
@Test public void hasAccessToProjectsReturnsTrueWhenUserIsNoManagerButAccessIsActive() { given(userAccessServiceMock.userHasActiveAccessInterval(userMock)).willReturn(true); boolean actualHasAccess = evaluator.hasAccessToProjects(authenticationMock, userMock); assertThat(actualHasAccess).isTrue(); }
@Test public void hasAccessToProjectsReturnsFalseWhenUserIsNoManagerAndNoAccess() { boolean actualHasAccess = evaluator.hasAccessToProjects(authenticationMock, userMock); assertThat(actualHasAccess).isFalse(); }