diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java index 806baec5..1a56b819 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java @@ -533,7 +533,7 @@ public class ResourceService { final List selection = this.restService.getBuilder(GetUserAccountNames.class) .withQueryParam(Entity.FILTER_ATTR_INSTITUTION, String.valueOf(userInfo.institutionId)) .withQueryParam(Entity.FILTER_ATTR_ACTIVE, Constants.TRUE_STRING) - .withQueryParam(UserInfo.FILTER_ATTR_ROLE, UserRole.EXAM_SUPPORTER.name()) + .withQueryParam(UserInfo.FILTER_ATTR_ROLE, UserRole.EXAM_SUPPORTER.name() + "," + UserRole.TEACHER.name()) .call() .getOr(Collections.emptyList()); return selection diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/TeacherAccountService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/TeacherAccountService.java index 15f4807d..48ed5bb8 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/TeacherAccountService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/TeacherAccountService.java @@ -17,6 +17,8 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.lms.FullLmsIntegrationServi /** Service used to maintain Teacher Ad-Hoc Accounts */ public interface TeacherAccountService { + String AD_HOC_TEACHER_ID_PREFIX = "AD_HOC_TEACHER_"; + /** Creates an Ad-Hoc Teacher account for a given existing Exam. * * @param exam The Exam instance diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/impl/TeacherAccountServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/impl/TeacherAccountServiceImpl.java index 31a82776..984f2277 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/impl/TeacherAccountServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/impl/TeacherAccountServiceImpl.java @@ -85,7 +85,7 @@ public class TeacherAccountServiceImpl implements TeacherAccountService { throw new RuntimeException("examId and/or userId cannot be null"); } - return "TEACHER_" + Constants.UNDERLINE + lmsId + Constants.UNDERLINE + userId; + return AD_HOC_TEACHER_ID_PREFIX + Constants.UNDERLINE + lmsId + Constants.UNDERLINE + userId; } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java index 12acaeec..54e95458 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java @@ -11,19 +11,13 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.dao.impl; import static ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.UserRecordDynamicSqlSupport.*; import static org.mybatis.dynamic.sql.SqlBuilder.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.function.Predicate; import java.util.stream.Collectors; import javax.validation.constraints.NotNull; +import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.api.authorization.PrivilegeType; import ch.ethz.seb.sebserver.gbl.model.user.*; import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.*; @@ -179,8 +173,9 @@ public class UserDAOImpl implements UserDAO { public Result> allMatching(final FilterMap filterMap, final Predicate predicate) { return Result.tryCatch(() -> { final String userRole = filterMap.getUserRole(); + final Set userRoles = new HashSet<>(Arrays.asList(StringUtils.split(userRole, Constants.LIST_SEPARATOR))); final Predicate _predicate = (StringUtils.isNotBlank(userRole)) - ? predicate.and(ui -> ui.roles.contains(userRole)) + ? predicate.and(ui -> userRoles.stream().anyMatch(ui.roles::contains)) : predicate; final QueryExpressionDSL>>.QueryExpressionWhereBuilder sqlWhereClause =