Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrated code lifecycle: Add editing of auxiliary repositories for instructors #9585

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -770,14 +770,17 @@ default ProgrammingExercise saveForCreation(ProgrammingExercise exercise) {
* @throws EntityNotFoundException the programming exercise could not be found.
*/
@NotNull
default ProgrammingExercise findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(long programmingExerciseId) throws EntityNotFoundException {
default ProgrammingExercise findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(long programmingExerciseId)
throws EntityNotFoundException {
// TODO: This is a dark hack. Move this into a service where we properly load only the solution participation in the second step
ProgrammingExercise programmingExerciseWithTemplate = getValueElseThrow(findWithTemplateParticipationLatestResultFeedbackTestCasesById(programmingExerciseId),
programmingExerciseId);
ProgrammingExercise programmingExerciseWithSolution = getValueElseThrow(findWithSolutionParticipationLatestResultFeedbackTestCasesById(programmingExerciseId),
programmingExerciseId);
ProgrammingExercise programmingExerciseWithAuxiliaryRepositories = findByIdWithAuxiliaryRepositoriesElseThrow(programmingExerciseId);

programmingExerciseWithTemplate.setSolutionParticipation(programmingExerciseWithSolution.getSolutionParticipation());
programmingExerciseWithTemplate.setAuxiliaryRepositories(programmingExerciseWithAuxiliaryRepositories.getAuxiliaryRepositories());
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved

return programmingExerciseWithTemplate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public ResponseEntity<ProgrammingExercise> getProgrammingExercise(@PathVariable
public ResponseEntity<ProgrammingExercise> getProgrammingExerciseWithSetupParticipations(@PathVariable long exerciseId) {
log.debug("REST request to get ProgrammingExercise with setup participations : {}", exerciseId);
User user = userRepository.getUserWithGroupsAndAuthorities();
var programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(exerciseId);
var programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, programmingExercise, user);
var assignmentParticipation = studentParticipationRepository.findByExerciseIdAndStudentIdAndTestRunWithLatestResult(programmingExercise.getId(), user.getId(), false);
Set<StudentParticipation> participations = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
/>
<!-- repository select -->
<div ngbDropdown class="d-inline-block me-2">
<button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>{{ selectedRepository }}</button>
<button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>
{{ selectedRepository === REPOSITORY.AUXILIARY ? selectedAuxiliaryRepositoryName : selectedRepository }}
</button>
<div ngbDropdownMenu aria-labelledby="dropdownBasic1">
<button
[disabled]="!exercise || !exercise.templateParticipation || !exercise.templateParticipation.id || !exercise.templateParticipation.repositoryUri"
Expand All @@ -51,7 +53,7 @@
[disabled]="!exercise || !exercise.solutionParticipation || !exercise.solutionParticipation.id || !exercise.solutionParticipation.repositoryUri"
(click)="selectSolutionParticipation()"
ngbDropdownItem
[style.background-color]="selectedRepository === REPOSITORY.SOLUTION ? '#3e8acc' : 'transparent'"
[style.background-color]="selectedRepository === REPOSITORY.SOLUTION ? 'var(--link-color)' : 'transparent'"
jhiTranslate="artemisApp.editor.repoSelect.solutionRepo"
>
<span jhiTranslate="artemisApp.editor.repoSelect.solutionRepo"></span>
Expand All @@ -67,7 +69,7 @@
"
(click)="selectAssignmentParticipation()"
ngbDropdownItem
[style.background-color]="selectedRepository === REPOSITORY.ASSIGNMENT ? '#3e8acc' : 'transparent'"
[style.background-color]="selectedRepository === REPOSITORY.ASSIGNMENT ? 'var(--link-color)' : 'transparent'"
jhiTranslate="artemisApp.editor.repoSelect.assignmentRepo"
>
Assignment Participation
Expand All @@ -76,9 +78,23 @@
[disabled]="!exercise"
(click)="selectTestRepository()"
ngbDropdownItem
[style.background-color]="selectedRepository === REPOSITORY.TEST ? '#3e8acc' : 'transparent'"
[style.background-color]="selectedRepository === REPOSITORY.TEST ? 'var(--link-color)' : 'transparent'"
jhiTranslate="artemisApp.editor.repoSelect.testRepo"
></button>
@for (auxiliaryRepository of exercise.auxiliaryRepositories; track exercise.auxiliaryRepositories; let i = $index) {
@if (auxiliaryRepository.id) {
<button
[disabled]="!exercise"
(click)="selectAuxiliaryRepository(auxiliaryRepository.id)"
ngbDropdownItem
[style.background-color]="
selectedRepository === REPOSITORY.AUXILIARY && selectedRepositoryId === auxiliaryRepository.id ? 'var(--link-color)' : 'transparent'
"
>
{{ auxiliaryRepository.name }}
</button>
}
}
</div>
</div>
<!-- action buttons -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { IrisSettings } from 'app/entities/iris/settings/iris-settings.model';
@Component({
selector: 'jhi-code-editor-instructor',
templateUrl: './code-editor-instructor-and-editor-container.component.html',
styleUrl: 'code-editor-instructor-and-editor-container.scss',
})
export class CodeEditorInstructorAndEditorContainerComponent extends CodeEditorInstructorBaseContainerComponent {
@ViewChild(UpdatingResultComponent, { static: false }) resultComp: UpdatingResultComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.btn-outline-primary:not(.list-group-item).dropdown-toggle.show {
color: var(--default-btn-font);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum REPOSITORY {
TEMPLATE = 'TEMPLATE',
SOLUTION = 'SOLUTION',
TEST = 'TEST',
AUXILIARY = 'AUXILIARY',
}

/**
Expand Down Expand Up @@ -64,6 +65,8 @@ export abstract class CodeEditorInstructorBaseContainerComponent implements OnIn
// Stores which repository is selected atm.
// Needs to be set additionally to selectedParticipation as the test repository does not have a participation
selectedRepository: REPOSITORY;
selectedRepositoryId: number;
selectedAuxiliaryRepositoryName?: string;

// Fires when the selected domain changes.
// This can either be a participation (solution, template, assignment) or the test repository.
Expand Down Expand Up @@ -95,6 +98,7 @@ export abstract class CodeEditorInstructorBaseContainerComponent implements OnIn
this.paramSub = this.route!.params.subscribe((params) => {
const exerciseId = Number(params['exerciseId']);
const participationId = Number(params['participationId']);
const repositoryId = Number(params['repositoryId']);
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
this.loadingState = LOADING_STATE.INITIALIZING;
this.loadExercise(exerciseId)
.pipe(
Expand All @@ -107,6 +111,12 @@ export abstract class CodeEditorInstructorBaseContainerComponent implements OnIn
tap(() => {
if (this.router.url.endsWith('/test')) {
this.saveChangesAndSelectDomain([DomainType.TEST_REPOSITORY, this.exercise]);
} else if (this.router.url.indexOf('auxiliary') >= 0) {
const auxiliaryRepo = this.exercise.auxiliaryRepositories?.find((repo) => repo.id === repositoryId);
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
if (auxiliaryRepo) {
this.selectedAuxiliaryRepositoryName = auxiliaryRepo.name;
this.saveChangesAndSelectDomain([DomainType.AUXILIARY_REPOSITORY, auxiliaryRepo]);
}
} else {
const nextAvailableParticipation = this.getNextAvailableParticipation(participationId);
if (nextAvailableParticipation) {
Expand Down Expand Up @@ -190,7 +200,10 @@ export abstract class CodeEditorInstructorBaseContainerComponent implements OnIn
if (this.codeEditorContainer != undefined) {
this.codeEditorContainer.initializeProperties();
}
if (domainType === DomainType.PARTICIPATION) {
if (domainType === DomainType.AUXILIARY_REPOSITORY) {
this.selectedRepository = REPOSITORY.AUXILIARY;
this.selectedRepositoryId = domainValue.id;
} else if (domainType === DomainType.PARTICIPATION) {
this.setSelectedParticipation(domainValue.id);
} else {
this.selectedParticipation = this.exercise.templateParticipation!;
Expand Down Expand Up @@ -272,28 +285,42 @@ export abstract class CodeEditorInstructorBaseContainerComponent implements OnIn
* Select the template participation repository and navigate to it
*/
selectTemplateParticipation() {
this.router.navigate(['..', this.exercise.templateParticipation!.id], { relativeTo: this.route });
this.router.navigate([this.up(), this.exercise.templateParticipation!.id], { relativeTo: this.route });
}

/**
* Select the solution participation repository and navigate to it
*/
selectSolutionParticipation() {
this.router.navigate(['..', this.exercise.solutionParticipation!.id], { relativeTo: this.route });
this.router.navigate([this.up(), this.exercise.solutionParticipation!.id], { relativeTo: this.route });
}

/**
* Select the assignment participation repository and navigate to it
*/
selectAssignmentParticipation() {
this.router.navigate(['..', this.exercise.studentParticipations![0].id], { relativeTo: this.route });
this.router.navigate([this.up(), this.exercise.studentParticipations![0].id], { relativeTo: this.route });
}

/**
* Select the test repository and navigate to it
*/
selectTestRepository() {
this.router.navigate(['..', 'test'], { relativeTo: this.route });
this.router.navigate([this.up(), 'test'], { relativeTo: this.route });
}

/**
* Select the auxiliary repository and navigate to it
*/
selectAuxiliaryRepository(repositoryId: number) {
this.router.navigate([this.up(), 'auxiliary', repositoryId], { relativeTo: this.route });
}

/**
* Go two folders up if the current view is an auxiliary repository, and one otherwise
*/
up() {
return this.selectedRepository === REPOSITORY.AUXILIARY ? '../..' : '..';
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ const routes: Routes = [
},
canActivate: [UserRouteAccessService],
},
{
path: 'auxiliary/:repositoryId',
component: CodeEditorInstructorAndEditorContainerComponent,
data: {
authorities: [Authority.EDITOR, Authority.INSTRUCTOR, Authority.ADMIN],
pageTitle: 'artemisApp.editor.home.title',
flushRepositoryCacheAfter: 900000, // 15 min
participationCache: {},
repositoryCache: {},
},
canActivate: [UserRouteAccessService],
},
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
];

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ void testRepositoryMethods() {
assertThatExceptionOfType(EntityNotFoundException.class)
.isThrownBy(() -> programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationElseThrow(Long.MAX_VALUE));

assertThatExceptionOfType(EntityNotFoundException.class)
.isThrownBy(() -> programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(Long.MAX_VALUE));
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(
() -> programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(Long.MAX_VALUE));

assertThatExceptionOfType(EntityNotFoundException.class)
.isThrownBy(() -> programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationTeamAssignmentConfigCategoriesElseThrow(Long.MAX_VALUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ void shouldReEvaluateScoreOfTheCorrectResults() throws Exception {
programmingExercise = (ProgrammingExercise) exerciseUtilService.addMaxScoreAndBonusPointsToExercise(programmingExercise);
programmingExercise = programmingExerciseUtilService.addTemplateParticipationForProgrammingExercise(programmingExercise);
programmingExercise = programmingExerciseUtilService.addSolutionParticipationForProgrammingExercise(programmingExercise);
programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());
programmingExercise = programmingExerciseRepository
.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved

var testCases = createTestCases(false);
var testParticipations = createTestParticipations();
Expand All @@ -566,7 +567,8 @@ void shouldReEvaluateScoreOfTheCorrectResults() throws Exception {
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());

// Tests
programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());
programmingExercise = programmingExerciseRepository
.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());

// template 0 %
{
Expand Down Expand Up @@ -610,7 +612,8 @@ void shouldNotIncludeTestsMarkedAsNeverVisibleInScoreCalculation(boolean isAfter
programmingExercise = (ProgrammingExercise) exerciseUtilService.addMaxScoreAndBonusPointsToExercise(programmingExercise);
programmingExercise = programmingExerciseUtilService.addTemplateParticipationForProgrammingExercise(programmingExercise);
programmingExercise = programmingExerciseUtilService.addSolutionParticipationForProgrammingExercise(programmingExercise);
programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());
programmingExercise = programmingExerciseRepository
.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());

final var testCases = createTestCases(true);
final var testParticipations = createTestParticipations();
Expand All @@ -625,7 +628,8 @@ void shouldNotIncludeTestsMarkedAsNeverVisibleInScoreCalculation(boolean isAfter
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());

// Tests
programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());
programmingExercise = programmingExerciseRepository
.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());

// the invisible test case should however be visible for the template and solution repos

Expand Down Expand Up @@ -658,7 +662,8 @@ void shouldUpdateTheLatestResultOfASingleParticipation() {
programmingExercise = (ProgrammingExercise) exerciseUtilService.addMaxScoreAndBonusPointsToExercise(programmingExercise);
programmingExercise = programmingExerciseUtilService.addTemplateParticipationForProgrammingExercise(programmingExercise);
programmingExercise = programmingExerciseUtilService.addSolutionParticipationForProgrammingExercise(programmingExercise);
programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());
programmingExercise = programmingExerciseRepository
.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());

final var testCases = createTestCases(false);
final var testParticipations = createTestParticipations();
Expand All @@ -679,7 +684,8 @@ void shouldUpdateOnlyResultsForParticipationsWithoutIndividualDueDate() {
programmingExercise = (ProgrammingExercise) exerciseUtilService.addMaxScoreAndBonusPointsToExercise(programmingExercise);
programmingExercise = programmingExerciseUtilService.addTemplateParticipationForProgrammingExercise(programmingExercise);
programmingExercise = programmingExerciseUtilService.addSolutionParticipationForProgrammingExercise(programmingExercise);
programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());
programmingExercise = programmingExerciseRepository
.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());

final var testCases = createTestCases(false);
final var testParticipations = createTestParticipations();
Expand All @@ -690,7 +696,8 @@ void shouldUpdateOnlyResultsForParticipationsWithoutIndividualDueDate() {
participationWithIndividualDueDate = studentParticipationRepository.save((StudentParticipation) participationWithIndividualDueDate);
final Long participationWithIndividualDueDateId = participationWithIndividualDueDate.getId();

programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());
programmingExercise = programmingExerciseRepository
.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());

final var updated = programmingExerciseGradingService.updateResultsOnlyRegularDueDateParticipations(programmingExercise);
// four student results + template + solution
Expand All @@ -706,7 +713,8 @@ void testWeightSumZero() {
programmingExercise = (ProgrammingExercise) exerciseUtilService.addMaxScoreAndBonusPointsToExercise(programmingExercise);
programmingExercise = programmingExerciseUtilService.addTemplateParticipationForProgrammingExercise(programmingExercise);
programmingExercise = programmingExerciseUtilService.addSolutionParticipationForProgrammingExercise(programmingExercise);
programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());
programmingExercise = programmingExerciseRepository
.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryReposAndLatestResultFeedbackTestCasesElseThrow(programmingExercise.getId());

final var testCases = createTestCases(false);
createTestParticipations();
Expand Down
Loading