Make exemptions for project type apply to partner as well ()

Read  for context first

When authors select supervisor ideas during an open application period they are only allowed to select ideas corresponding to their degree type classification. This limitation can be lifted by giving the author an exemption for "Project type limitation" on the corresponding application period. However, this limitation is still enforced for any potential partner *even if* the have been given the same exemption. This change makes it so the exemption applies to any selected partner as well and not just the author selecting the supervisor idea.

## How to test
1. Log in as `oskar@example.com`
2. Go to "Ideas / My ideas" page
3. Click "Select from available ideas" on the application period "Supervisor ideas"
4. Open the one available idea
5. Try to select it with "Johan Student" as a partner
6. Log in as admin
7. Go to "Match / Application periods"
8. Click "Edit exemptions" on the "Supervisor ideas" period
9. Give "Johan Student" an exemption to "Project type limitation"
10. Repeat steps 1-5

Reviewed-on: 
Reviewed-by: Nico Athanassiadis <nico@dsv.su.se>
Co-authored-by: Andreas Svanberg <andreass@dsv.su.se>
Co-committed-by: Andreas Svanberg <andreass@dsv.su.se>
This commit is contained in:
Andreas Svanberg 2025-03-10 07:17:28 +01:00 committed by Nico Athanassiadis
parent 23e0a7f5ea
commit de18f200a7
5 changed files with 119 additions and 4 deletions
core/src
main/java/se/su/dsv/scipro/match
test/java/se/su/dsv/scipro/match
test-data/src/main/java/se/su/dsv/scipro/testdata

@ -235,10 +235,8 @@ public class IdeaServiceImpl extends AbstractServiceImpl<Idea, Long> implements
if (authorParticipatingOnActiveIdea(coAuthor, ap)) {
return new Pair<>(Boolean.FALSE, PARTNER_ALREADY_PARTICIPATING_ERROR);
}
if (
coAuthor.getDegreeType() != ProjectType.UNKNOWN &&
coAuthor.getDegreeType() != idea.getProjectType().getDegreeType()
) {
List<ProjectType> typesForCoAuthor = applicationPeriodService.getTypesForStudent(ap, coAuthor);
if (!typesForCoAuthor.contains(idea.getProjectType())) {
return new Pair<>(Boolean.FALSE, WRONG_LEVEL_FOR_YOUR_PARTNER);
}
if (!projectService.getActiveProjectsByUserAndProjectType(coAuthor, idea.getProjectType()).isEmpty()) {

@ -241,6 +241,7 @@ public class IdeaServiceImplTest {
when(generalSystemSettingsService.getGeneralSystemSettingsInstance()).thenReturn(new GeneralSystemSettings());
Idea idea = createBachelorIdea(Idea.Status.UNMATCHED);
when(applicationPeriodService.getTypesForStudent(applicationPeriod, student)).thenReturn(List.of(bachelor));
when(applicationPeriodService.getTypesForStudent(applicationPeriod, coAuthor)).thenReturn(List.of(bachelor));
Pair<Boolean, String> acceptance = ideaService.validateStudentAcceptance(
idea,
@ -401,6 +402,39 @@ public class IdeaServiceImplTest {
assertEquals(expected, ideaService.countAuthorsByApplicationPeriod(applicationPeriod, params));
}
@Test
public void wrong_type_for_author() {
when(applicationPeriodService.getTypesForStudent(applicationPeriod, student)).thenReturn(List.of(master));
when(applicationPeriodService.getTypesForStudent(applicationPeriod, coAuthor)).thenReturn(List.of(bachelor));
assertPair(
false,
"The idea is the wrong level for you, please pick another one.",
ideaService.validateStudentAcceptance(
createBachelorIdea(Idea.Status.UNMATCHED),
student,
coAuthor,
applicationPeriod
)
);
}
@Test
public void wrong_type_for_partner() {
when(applicationPeriodService.getTypesForStudent(applicationPeriod, coAuthor)).thenReturn(List.of(master));
assertPair(
false,
"The idea is the wrong level for your partner, please pick another one.",
ideaService.validateStudentAcceptance(
createBachelorIdea(Idea.Status.UNMATCHED),
student,
coAuthor,
applicationPeriod
)
);
}
private Idea mockInactiveIdea() {
Idea idea = new Idea();
Match match = new Match();

@ -1,6 +1,9 @@
package se.su.dsv.scipro.testdata;
import java.util.List;
import se.su.dsv.scipro.match.Keyword;
import se.su.dsv.scipro.system.ProjectType;
import se.su.dsv.scipro.system.ResearchArea;
/// All the base test data that can be re-used in different test cases.
///
@ -16,4 +19,11 @@ public interface BaseData {
ProjectType bachelor();
ProjectType magister();
ProjectType master();
/**
* @return generic research area with some keywords attached to it
*/
ResearchAreaAndKeywords researchArea();
record ResearchAreaAndKeywords(ResearchArea researchArea, List<Keyword> keywords) {}
}

@ -2193,6 +2193,11 @@ public class DataInitializer implements Lifecycle, BaseData, Factory {
return createEmployee(firstName);
}
@Override
public ResearchAreaAndKeywords researchArea() {
return new ResearchAreaAndKeywords(researchArea1, List.of(keyword1, keyword2));
}
private static final class SimpleTextFile implements FileUpload {
private final User uploader;

@ -0,0 +1,68 @@
package se.su.dsv.scipro.testdata.populators;
import jakarta.inject.Inject;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Set;
import org.springframework.stereotype.Service;
import se.su.dsv.scipro.match.ApplicationPeriod;
import se.su.dsv.scipro.match.ApplicationPeriodService;
import se.su.dsv.scipro.match.Idea;
import se.su.dsv.scipro.match.IdeaService;
import se.su.dsv.scipro.match.Target;
import se.su.dsv.scipro.match.TargetService;
import se.su.dsv.scipro.system.User;
import se.su.dsv.scipro.testdata.BaseData;
import se.su.dsv.scipro.testdata.Factory;
import se.su.dsv.scipro.testdata.TestDataPopulator;
@Service
public class PartnerTypeExemption implements TestDataPopulator {
private final ApplicationPeriodService applicationPeriodService;
private final IdeaService ideaService;
private final TargetService targetService;
@Inject
public PartnerTypeExemption(
ApplicationPeriodService applicationPeriodService,
IdeaService ideaService,
TargetService targetService
) {
this.applicationPeriodService = applicationPeriodService;
this.ideaService = ideaService;
this.targetService = targetService;
}
@Override
public void populate(BaseData baseData, Factory factory) {
factory.createAuthor("Oskar");
User johan = factory.createAuthor("Johan");
johan.setDegreeType(baseData.master().getDegreeType());
User supervisor = factory.createSupervisor("Elsa");
ApplicationPeriod applicationPeriod = new ApplicationPeriod("Supervisor ideas");
applicationPeriod.setStartDate(LocalDate.now());
applicationPeriod.setEndDate(LocalDate.now().plusDays(14));
applicationPeriod.setCourseStartDateTime(LocalDateTime.now().plusDays(15));
applicationPeriod.setProjectTypes(Set.of(baseData.bachelor()));
applicationPeriodService.save(applicationPeriod);
Target target = targetService.findOne(applicationPeriod, supervisor, baseData.bachelor());
target.setTarget(10);
targetService.save(target);
Idea idea = new Idea();
idea.setPublished(true);
idea.setTitle("The next gen AI 2.0 turbo edition");
idea.setPrerequisites("Hacker experience");
idea.setDescription("Better than all the rest");
idea.setProjectType(baseData.bachelor());
idea.setApplicationPeriod(applicationPeriod);
idea.setResearchArea(baseData.researchArea().researchArea());
ideaService.saveSupervisorIdea(idea, supervisor, baseData.researchArea().keywords(), true);
}
}