diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/QuizLookupList.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/QuizLookupList.java index b17ebf58..2df044aa 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/QuizLookupList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/QuizLookupList.java @@ -246,7 +246,8 @@ public class QuizLookupList implements TemplateComposer { } private static Function quizDataLmsSetupNameFunction(final ResourceService resourceService) { - return quizData -> resourceService.getLmsSetupNameFunction() + final Function lmsSetupNameFunction = resourceService.getLmsSetupNameFunction(); + return quizData -> lmsSetupNameFunction .apply(String.valueOf(quizData.lmsSetupId)); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java index 8607f46f..058d0b38 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java @@ -9,6 +9,7 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -156,8 +157,16 @@ public class LmsAPIServiceImpl implements LmsAPIService { // case 1. if lmsSetupId is available only get quizzes from specified LmsSetup final Long lmsSetupId = filterMap.getLmsSetupId(); if (lmsSetupId != null) { - return getLmsAPITemplate(lmsSetupId) - .flatMap(template -> template.getQuizzes(filterMap)) + final Long institutionId = filterMap.getInstitutionId(); + + final LmsAPITemplate template = getLmsAPITemplate(lmsSetupId) + .getOrThrow(); + + if (institutionId != null && template.lmsSetup().institutionId != institutionId) { + return Collections.emptyList(); + } + return template + .getQuizzes(filterMap) .getOrThrow(); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleLmsAPITemplateFactory.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleLmsAPITemplateFactory.java index 636d80d5..0afdabb0 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleLmsAPITemplateFactory.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleLmsAPITemplateFactory.java @@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.moodle; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -33,7 +34,7 @@ public class MoodleLmsAPITemplateFactory { private final AsyncService asyncService; private final ClientCredentialService clientCredentialService; private final ClientHttpRequestFactoryService clientHttpRequestFactoryService; - private final MoodleCourseDataLazyLoader moodleCourseDataLazyLoader; + private final ApplicationContext applicationContext; private final String[] alternativeTokenRequestPaths; protected MoodleLmsAPITemplateFactory( @@ -41,14 +42,14 @@ public class MoodleLmsAPITemplateFactory { final AsyncService asyncService, final ClientCredentialService clientCredentialService, final ClientHttpRequestFactoryService clientHttpRequestFactoryService, - final MoodleCourseDataLazyLoader moodleCourseDataLazyLoader, + final ApplicationContext applicationContext, @Value("${sebserver.webservice.lms.moodle.api.token.request.paths:}") final String alternativeTokenRequestPaths) { this.jsonMapper = jsonMapper; this.asyncService = asyncService; this.clientCredentialService = clientCredentialService; this.clientHttpRequestFactoryService = clientHttpRequestFactoryService; - this.moodleCourseDataLazyLoader = moodleCourseDataLazyLoader; + this.applicationContext = applicationContext; this.alternativeTokenRequestPaths = (alternativeTokenRequestPaths != null) ? StringUtils.split(alternativeTokenRequestPaths, Constants.LIST_SEPARATOR) : null; @@ -61,6 +62,9 @@ public class MoodleLmsAPITemplateFactory { return Result.tryCatch(() -> { + final MoodleCourseDataLazyLoader lazyLoaderPrototype = + this.applicationContext.getBean(MoodleCourseDataLazyLoader.class); + final MoodleRestTemplateFactory moodleRestTemplateFactory = new MoodleRestTemplateFactory( this.jsonMapper, lmsSetup, @@ -74,7 +78,7 @@ public class MoodleLmsAPITemplateFactory { this.jsonMapper, lmsSetup, moodleRestTemplateFactory, - this.moodleCourseDataLazyLoader, + lazyLoaderPrototype, this.asyncService); final MoodleCourseRestriction moodleCourseRestriction = new MoodleCourseRestriction(