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

Programming exercises: Provide theia clone information on redirect #9379

Open
wants to merge 39 commits into
base: feature/re-key
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a0497f3
Move Theia Button to Code Button
iyannsch Sep 23, 2024
2ab444e
Add functionality to pull build config on demand from server
iyannsch Sep 24, 2024
389f5fd
Merge branch 'develop' into feature/programming-exercises/provide-the…
iyannsch Sep 28, 2024
7ce3a49
Add Uri, Token, and landing-page URL to Theia Button
iyannsch Sep 28, 2024
4160302
Add Form test and re-key endpoint
iyannsch Oct 3, 2024
eae2c89
Clean up initTheia method
iyannsch Oct 3, 2024
0f18104
Fix formatting
iyannsch Oct 3, 2024
486b2c5
Fix implicit type expressions
iyannsch Oct 4, 2024
d9bf634
Fix rekey endpoint to be reachable
iyannsch Oct 4, 2024
a643b42
Merge upstream key endpoint
iyannsch Oct 4, 2024
34a84d7
Merge branch 'feature/re-key' into feature/programming-exercises/prov…
iyannsch Oct 4, 2024
4f1a99b
Fix endpoint theia-token connection
iyannsch Oct 4, 2024
4aa5171
Merge branch 'develop' into feature/programming-exercises/provide-the…
iyannsch Oct 8, 2024
7abb02c
Merge branch 'feature/re-key' into feature/programming-exercises/prov…
iyannsch Oct 8, 2024
b7ebea0
Merge upstream bearer branch
iyannsch Oct 8, 2024
685a483
Get Token unconditionally
iyannsch Oct 8, 2024
e8be59c
Merge branch 'develop' into feature/programming-exercises/provide-the…
iyannsch Oct 29, 2024
575379b
Fix failing correct data submission test
iyannsch Oct 29, 2024
2d2a5b7
Remove minus from appDef to align to TS configuration
iyannsch Oct 29, 2024
6207ce8
Fix configuration values to align with new system
iyannsch Nov 7, 2024
a6cc06e
Merge branch 'develop' into feature/programming-exercises/provide-the…
iyannsch Nov 7, 2024
f82d6fb
Merge branch 'feature/re-key' into feature/programming-exercises/prov…
iyannsch Nov 7, 2024
beb3d48
Merge branch 'feature/re-key' of github.com:ls1intum/Artemis into fea…
iyannsch Nov 7, 2024
625216e
Rename endpoint to theia-token
iyannsch Nov 7, 2024
2946389
Merge branch 'feature/re-key' of github.com:ls1intum/Artemis into fea…
iyannsch Nov 12, 2024
c7c5322
Rename endpoint to tool-token
iyannsch Nov 12, 2024
9b0bcc3
Add ArtemisURL to theia query params
iyannsch Nov 12, 2024
d3817c8
Add gitUser and gitMail to Theia LP
iyannsch Nov 13, 2024
ac87b07
Remove debug for artemisUrl
iyannsch Nov 13, 2024
10648b0
Merge branch 'develop' of github.com:ls1intum/Artemis into feature/pr…
iyannsch Nov 13, 2024
2941799
Merge branch 'develop' of github.com:ls1intum/Artemis into feature/pr…
iyannsch Nov 18, 2024
5b1dc16
Merge branch 'feature/re-key' of github.com:ls1intum/Artemis into fea…
iyannsch Nov 21, 2024
f770151
Remove public from API URL
iyannsch Nov 26, 2024
6e6eea3
Refactor initTheia into changes
iyannsch Nov 26, 2024
dd2e128
Merge branch 'feature/re-key' into feature/programming-exercises/prov…
iyannsch Nov 26, 2024
432148e
Refactor initTheia back into the init
iyannsch Nov 26, 2024
9fc561e
Adjust access modifier
iyannsch Nov 26, 2024
6bbbb67
Merge branch 'develop' into feature/programming-exercises/provide-the…
iyannsch Dec 13, 2024
261fc2c
Merge branch 'feature/re-key' into feature/programming-exercises/prov…
iyannsch Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import de.tum.cit.aet.artemis.core.dto.vm.LoginVM;
import de.tum.cit.aet.artemis.core.exception.AccessForbiddenException;
import de.tum.cit.aet.artemis.core.security.SecurityUtils;
import de.tum.cit.aet.artemis.core.security.UserNotActivatedException;
import de.tum.cit.aet.artemis.core.security.annotations.EnforceAtLeastStudent;
import de.tum.cit.aet.artemis.core.security.annotations.EnforceNothing;
import de.tum.cit.aet.artemis.core.security.jwt.JWTCookieService;
import de.tum.cit.aet.artemis.core.service.connectors.SAML2Service;
Expand Down Expand Up @@ -94,6 +96,24 @@ public ResponseEntity<Void> authorize(@Valid @RequestBody LoginVM loginVM, @Requ
}
}

/**
* Sends the token back as either a cookie or a bearer token
*
* @param response HTTP response
* @return the ResponseEntity with status 200 (ok), 401 (unauthorized)
*/
@PostMapping("re-key")
@EnforceAtLeastStudent
public ResponseEntity<String> reKey(@RequestParam(value = "as-bearer", defaultValue = "false") boolean asBearer, HttpServletResponse response) {
ResponseCookie responseCookie = jwtCookieService.buildLoginCookie(true);
if (asBearer) {
return ResponseEntity.ok(responseCookie.getValue());
}
response.addHeader(HttpHeaders.SET_COOKIE, responseCookie.toString());

return ResponseEntity.ok().build();
}
iyannsch marked this conversation as resolved.
Show resolved Hide resolved

/**
* Authorizes a User logged in with SAML2
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@Entity
@Table(name = "programming_exercise_build_config")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(value = { "programmingExercise" })
iyannsch marked this conversation as resolved.
Show resolved Hide resolved
public class ProgrammingExerciseBuildConfig extends DomainObject {

private static final Logger log = LoggerFactory.getLogger(ProgrammingExerciseBuildConfig.class);
Expand Down Expand Up @@ -58,7 +59,6 @@ public class ProgrammingExerciseBuildConfig extends DomainObject {
private String dockerFlags;

@OneToOne(mappedBy = "buildConfig")
@JsonIgnoreProperties("buildConfig")
private ProgrammingExercise programmingExercise;

@Column(name = "testwise_coverage_enabled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,14 @@ default void generateBuildPlanAccessSecretIfNotExists(ProgrammingExerciseBuildCo
default void loadAndSetBuildConfig(ProgrammingExercise programmingExercise) {
programmingExercise.setBuildConfig(getProgrammingExerciseBuildConfigElseThrow(programmingExercise));
}

/**
* Find a build config by its programming exercise's id and throw an Exception if it cannot be found
*
* @param programmingExerciseId of the programming exercise.
* @return The programming exercise related to the given id
*/
default ProgrammingExerciseBuildConfig findByExerciseIdElseThrow(long programmingExerciseId) {
return getValueElseThrow(findByProgrammingExerciseId(programmingExerciseId));
}
iyannsch marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import de.tum.cit.aet.artemis.core.security.annotations.EnforceAtLeastEditor;
import de.tum.cit.aet.artemis.core.security.annotations.EnforceAtLeastInstructor;
import de.tum.cit.aet.artemis.core.security.annotations.EnforceAtLeastTutor;
import de.tum.cit.aet.artemis.core.security.annotations.enforceRoleInExercise.EnforceAtLeastStudentInExercise;
import de.tum.cit.aet.artemis.core.security.annotations.enforceRoleInExercise.EnforceAtLeastTutorInExercise;
import de.tum.cit.aet.artemis.core.service.AuthorizationCheckService;
import de.tum.cit.aet.artemis.core.service.CourseService;
Expand All @@ -71,13 +72,15 @@
import de.tum.cit.aet.artemis.plagiarism.service.PlagiarismDetectionConfigHelper;
import de.tum.cit.aet.artemis.programming.domain.AuxiliaryRepository;
import de.tum.cit.aet.artemis.programming.domain.ProgrammingExercise;
import de.tum.cit.aet.artemis.programming.domain.ProgrammingExerciseBuildConfig;
import de.tum.cit.aet.artemis.programming.domain.ProgrammingExerciseTestCase;
import de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage;
import de.tum.cit.aet.artemis.programming.dto.BuildLogStatisticsDTO;
import de.tum.cit.aet.artemis.programming.dto.CheckoutDirectoriesDTO;
import de.tum.cit.aet.artemis.programming.dto.ProgrammingExerciseResetOptionsDTO;
import de.tum.cit.aet.artemis.programming.dto.ProgrammingExerciseTestCaseStateDTO;
import de.tum.cit.aet.artemis.programming.repository.BuildLogStatisticsEntryRepository;
import de.tum.cit.aet.artemis.programming.repository.ProgrammingExerciseBuildConfigRepository;
import de.tum.cit.aet.artemis.programming.repository.ProgrammingExerciseRepository;
import de.tum.cit.aet.artemis.programming.repository.ProgrammingExerciseTestCaseRepository;
import de.tum.cit.aet.artemis.programming.repository.SolutionProgrammingExerciseParticipationRepository;
Expand Down Expand Up @@ -114,6 +117,8 @@ public class ProgrammingExerciseResource {

private final ProgrammingExerciseTestCaseRepository programmingExerciseTestCaseRepository;

private final ProgrammingExerciseBuildConfigRepository programmingExerciseBuildConfigRepository;

private final UserRepository userRepository;

private final CourseService courseService;
Expand Down Expand Up @@ -157,9 +162,9 @@ public class ProgrammingExerciseResource {
private final Environment environment;

public ProgrammingExerciseResource(ProgrammingExerciseRepository programmingExerciseRepository, ProgrammingExerciseTestCaseRepository programmingExerciseTestCaseRepository,
UserRepository userRepository, AuthorizationCheckService authCheckService, CourseService courseService,
Optional<ContinuousIntegrationService> continuousIntegrationService, Optional<VersionControlService> versionControlService, ExerciseService exerciseService,
ExerciseDeletionService exerciseDeletionService, ProgrammingExerciseService programmingExerciseService,
ProgrammingExerciseBuildConfigRepository programmingExerciseBuildConfigRepository, UserRepository userRepository, AuthorizationCheckService authCheckService,
CourseService courseService, Optional<ContinuousIntegrationService> continuousIntegrationService, Optional<VersionControlService> versionControlService,
ExerciseService exerciseService, ExerciseDeletionService exerciseDeletionService, ProgrammingExerciseService programmingExerciseService,
ProgrammingExerciseRepositoryService programmingExerciseRepositoryService, ProgrammingExerciseTaskService programmingExerciseTaskService,
StudentParticipationRepository studentParticipationRepository, StaticCodeAnalysisService staticCodeAnalysisService,
GradingCriterionRepository gradingCriterionRepository, CourseRepository courseRepository, GitService gitService, AuxiliaryRepositoryService auxiliaryRepositoryService,
Expand All @@ -170,6 +175,7 @@ public ProgrammingExerciseResource(ProgrammingExerciseRepository programmingExer
this.programmingExerciseTaskService = programmingExerciseTaskService;
this.programmingExerciseRepository = programmingExerciseRepository;
this.programmingExerciseTestCaseRepository = programmingExerciseTestCaseRepository;
this.programmingExerciseBuildConfigRepository = programmingExerciseBuildConfigRepository;
this.userRepository = userRepository;
this.courseService = courseService;
this.authCheckService = authCheckService;
Expand Down Expand Up @@ -492,6 +498,21 @@ public ResponseEntity<ProgrammingExercise> getProgrammingExercise(@PathVariable
return ResponseEntity.ok().body(programmingExercise);
}

/**
* GET /programming-exercises/:exerciseId/build-config : get the build config of "exerciseId" programmingExercise.
*
* @param exerciseId the id of the programmingExercise to retrieve the config for
* @return the ResponseEntity with status 200 (OK) and with body the programmingExerciseBuildConfig, or with status 404 (Not Found)
*/
@GetMapping("programming-exercises/{exerciseId}/build-config")
@EnforceAtLeastStudentInExercise
public ResponseEntity<ProgrammingExerciseBuildConfig> getBuildConfig(@PathVariable long exerciseId) {
iyannsch marked this conversation as resolved.
Show resolved Hide resolved
log.debug("REST request to get build config of ProgrammingExercise : {}", exerciseId);
var buildConfig = programmingExerciseBuildConfigRepository.findByExerciseIdElseThrow(exerciseId);

return ResponseEntity.ok().body(buildConfig);
}

/**
* GET /programming-exercises/:exerciseId/with-participations/ : get the "exerciseId" programmingExercise.
*
Expand Down
8 changes: 8 additions & 0 deletions src/main/webapp/app/core/auth/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,12 @@ export class AccountService implements IAccountService {
const params = new HttpParams().set('participationId', participationId);
return this.http.put<string>('api/account/participation-vcs-access-token', null, { observe: 'response', params, responseType: 'text' as 'json' });
}

/**
* Trades the current cookie for a new bearer token which is also able to authenticate the user.
* The Cookie stays valid, a new bearer token is generated on every call.
*/
rekeyCookieToBearerToken() {
return this.http.post<string>('api/public/rekey?as-bearer=true', null);
}
iyannsch marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Participation } from 'app/entities/participation/participation.model';
import { PlagiarismResultDTO } from 'app/exercises/shared/plagiarism/types/PlagiarismResultDTO';
import { ImportOptions } from 'app/types/programming-exercises';
import { CheckoutDirectoriesDto } from 'app/entities/programming/checkout-directories-dto';
import { ProgrammingExerciseBuildConfig } from 'app/entities/programming/programming-exercise-build.config';

export type EntityResponseType = HttpResponse<ProgrammingExercise>;
export type EntityArrayResponseType = HttpResponse<ProgrammingExercise[]>;
Expand Down Expand Up @@ -660,6 +661,10 @@ export class ProgrammingExerciseService {
return this.http.get<BuildLogStatisticsDTO>(`${this.resourceUrl}/${exerciseId}/build-log-statistics`);
}

getBuildConfig(exerciseId: number): Observable<ProgrammingExerciseBuildConfig> {
return this.http.get<ProgrammingExerciseBuildConfig>(`${this.resourceUrl}/${exerciseId}/build-config`);
}

/** Imports a programming exercise from a given zip file **/
importFromFile(exercise: ProgrammingExercise, courseId: number): Observable<EntityResponseType> {
let copy = this.convertDataFromClient(exercise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@
[useParticipationVcsAccessToken]="true"
/>
}
@if (theiaEnabled) {
<a class="btn btn-primary" [class.btn-sm]="smallButtons" (click)="startOnlineIDE()" target="_blank" rel="noopener noreferrer">
<fa-icon [icon]="faDesktop" [fixedWidth]="true" />
<span class="d-none d-md-inline" jhiTranslate="artemisApp.exerciseActions.openOnlineIDE"></span>
</a>
}
@if (exercise.allowFeedbackRequests) {
@if (athenaEnabled) {
<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { ProgrammingExercise } from 'app/entities/programming/programming-exerci
import { StudentParticipation } from 'app/entities/participation/student-participation.model';
import { ArtemisQuizService } from 'app/shared/quiz/quiz.service';
import { finalize } from 'rxjs/operators';
import { faCodeBranch, faDesktop, faEye, faFolderOpen, faPenSquare, faPlayCircle, faRedo, faUsers } from '@fortawesome/free-solid-svg-icons';
import { faCodeBranch, faEye, faFolderOpen, faPenSquare, faPlayCircle, faRedo, faUsers } from '@fortawesome/free-solid-svg-icons';
iyannsch marked this conversation as resolved.
Show resolved Hide resolved
import { CourseExerciseService } from 'app/exercises/shared/course-exercises/course-exercise.service';
import { TranslateService } from '@ngx-translate/core';
import { ParticipationService } from 'app/exercises/shared/participation/participation.service';
import dayjs from 'dayjs/esm';
import { QuizExercise } from 'app/entities/quiz/quiz-exercise.model';
import { ProfileService } from 'app/shared/layouts/profiles/profile.service';
import { PROFILE_ATHENA, PROFILE_LOCALVC, PROFILE_THEIA } from 'app/app.constants';
import { PROFILE_ATHENA, PROFILE_LOCALVC } from 'app/app.constants';
import { AssessmentType } from 'app/entities/assessment-type.model';

@Component({
Expand Down Expand Up @@ -60,17 +60,13 @@ export class ExerciseDetailsStudentActionsComponent implements OnInit, OnChanges
routerLink: string;
repositoryLink: string;

theiaEnabled: boolean = false;
theiaPortalURL: string;

// Icons
readonly faFolderOpen = faFolderOpen;
readonly faUsers = faUsers;
readonly faEye = faEye;
readonly faPlayCircle = faPlayCircle;
readonly faRedo = faRedo;
readonly faCodeBranch = faCodeBranch;
readonly faDesktop = faDesktop;
readonly faPenSquare = faPenSquare;

private feedbackSent = false;
Expand Down Expand Up @@ -110,28 +106,6 @@ export class ExerciseDetailsStudentActionsComponent implements OnInit, OnChanges
this.profileService.getProfileInfo().subscribe((profileInfo) => {
this.localVCEnabled = profileInfo.activeProfiles?.includes(PROFILE_LOCALVC);
this.athenaEnabled = profileInfo.activeProfiles?.includes(PROFILE_ATHENA);
// The online IDE is only available with correct SpringProfile and if it's enabled for this exercise
if (profileInfo.activeProfiles?.includes(PROFILE_THEIA) && this.programmingExercise) {
this.theiaEnabled = true;

// Set variables now, sanitize later on
this.theiaPortalURL = profileInfo.theiaPortalURL ?? '';

// Verify that Theia's portal URL is set
if (this.theiaPortalURL === '') {
this.theiaEnabled = false;
}

// Verify that the exercise allows the online IDE
if (!this.programmingExercise.allowOnlineIde) {
this.theiaEnabled = false;
}

// Verify that the exercise has a theia blueprint configured
if (!this.programmingExercise.buildConfig?.theiaImage) {
this.theiaEnabled = false;
}
}
});
} else if (this.exercise.type === ExerciseType.MODELING) {
this.editorLabel = 'openModelingEditor';
Expand All @@ -158,10 +132,6 @@ export class ExerciseDetailsStudentActionsComponent implements OnInit, OnChanges
this.isTeamAvailable = !!(this.exercise.teamMode && this.exercise.studentAssignedTeamIdComputed && this.exercise.studentAssignedTeamId);
}

startOnlineIDE() {
window.open(this.theiaPortalURL, '_blank');
}

receiveNewParticipation(newParticipation: StudentParticipation) {
const studentParticipations = this.exercise.studentParticipations ?? [];
if (studentParticipations.map((participation) => participation.id).includes(newParticipation.id)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ <h5>{{ cloneHeadline | artemisTranslate }}</h5>
style="min-width: 100px"
jhiTranslate="{{ wasCopied ? 'artemisApp.exerciseActions.copiedUrl' : 'artemisApp.exerciseActions.copyUrl' }}"
></button>
@if (theiaEnabled) {
<a class="btn btn-primary btn-sm me-2" (click)="startOnlineIDE()" target="_blank" rel="noopener noreferrer">
<span class="d-none d-md-inline" jhiTranslate="artemisApp.exerciseActions.openOnlineIDE"></span>
</a>
}
iyannsch marked this conversation as resolved.
Show resolved Hide resolved
<a
class="btn btn-primary btn-sm"
target="hidden-iframe"
Expand Down
Loading
Loading