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: Disable access to personal VCS access tokens in account settings for students #9397

Merged
merged 6 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
4 changes: 4 additions & 0 deletions src/main/webapp/app/core/auth/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ export class AccountService implements IAccountService {
return this.hasAnyAuthorityDirect([Authority.ADMIN]);
}

isAtLeastTutor(): boolean {
return this.hasAnyAuthorityDirect([Authority.ADMIN, Authority.EDITOR, Authority.INSTRUCTOR, Authority.TA]);
}
b-fein marked this conversation as resolved.
Show resolved Hide resolved

isAuthenticated(): boolean {
return this.authenticated;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
<a class="list-group-item btn btn-outline-primary" routerLink="science" routerLinkActive="active" jhiTranslate="artemisApp.userSettings.scienceSettings"></a>
@if (localVCEnabled) {
<a class="list-group-item btn btn-outline-primary" routerLink="ssh" routerLinkActive="active" jhiTranslate="artemisApp.userSettings.sshSettings"></a>
<a
class="list-group-item btn btn-outline-primary"
routerLink="vcs-token"
routerLinkActive="active"
jhiTranslate="artemisApp.userSettings.vcsAccessTokenSettings"
>
</a>
@if (isAtLeastTutor) {
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
<a
class="list-group-item btn btn-outline-primary"
routerLink="vcs-token"
routerLinkActive="active"
jhiTranslate="artemisApp.userSettings.vcsAccessTokenSettings"
>
</a>
}
}
<a class="list-group-item btn btn-outline-primary" routerLink="ide-preferences" routerLinkActive="active">
<!--Default IDE Settings-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, inject } from '@angular/core';
import { faUser } from '@fortawesome/free-solid-svg-icons';
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
import { ProfileService } from 'app/shared/layouts/profiles/profile.service';
import { PROFILE_LOCALVC } from 'app/app.constants';
import { User } from 'app/core/user/user.model';
import { AccountService } from 'app/core/auth/account.service';
import { tap } from 'rxjs';
import { TranslateDirective } from 'app/shared/language/translate.directive';
import { RouterModule } from '@angular/router';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';

/**
* UserSettingsContainerComponent serves as the common ground for different settings
*/
@Component({
selector: 'jhi-user-settings',
templateUrl: 'user-settings-container.component.html',
standalone: true,
styleUrls: ['user-settings-container.component.scss'],
imports: [TranslateDirective, RouterModule, FontAwesomeModule],
})
export class UserSettingsContainerComponent implements OnInit {
private readonly profileService = inject(ProfileService);
private readonly accountService = inject(AccountService);

// Icons
faUser = faUser;

currentUser?: User;
localVCEnabled = false;

constructor(
private profileService: ProfileService,
private accountService: AccountService,
) {}
isAtLeastTutor = false;

ngOnInit() {
this.profileService.getProfileInfo().subscribe((profileInfo) => {
Expand All @@ -33,7 +37,12 @@ export class UserSettingsContainerComponent implements OnInit {

this.accountService
.getAuthenticationState()
.pipe(tap((user: User) => (this.currentUser = user)))
.pipe(
tap((user: User) => {
this.currentUser = user;
this.isAtLeastTutor = this.accountService.isAtLeastTutor();
}),
)
.subscribe();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NgModule } from '@angular/core';
import { UserSettingsContainerComponent } from 'app/shared/user-settings/user-settings-container/user-settings-container.component';
import { AccountInformationComponent } from 'app/shared/user-settings/account-information/account-information.component';
import { NotificationSettingsComponent } from 'app/shared/user-settings/notification-settings/notification-settings.component';
import { ArtemisSharedModule } from 'app/shared/shared.module';
Expand All @@ -16,7 +15,6 @@ import { IdeSettingsComponent } from 'app/shared/user-settings/ide-preferences/i
@NgModule({
imports: [RouterModule.forChild(userSettingsState), ArtemisSharedModule, ArtemisSharedComponentModule, ClipboardModule, FormDateTimePickerModule],
declarations: [
UserSettingsContainerComponent,
AccountInformationComponent,
NotificationSettingsComponent,
ScienceSettingsComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { of } from 'rxjs';
import { Router, RouterModule } from '@angular/router';
import { ArtemisTestModule } from '../../test.module';
import { MockNgbModalService } from '../../helpers/mocks/service/mock-ngb-modal.service';
import { MockTranslateService, TranslatePipeMock } from '../../helpers/mocks/service/mock-translate.service';
import { MockTranslateService } from '../../helpers/mocks/service/mock-translate.service';
import { TranslateService } from '@ngx-translate/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { PROFILE_LOCALVC } from 'app/app.constants';
Expand All @@ -27,8 +27,7 @@ describe('UserSettingsContainerComponent', () => {
};

await TestBed.configureTestingModule({
imports: [ArtemisTestModule, RouterModule],
declarations: [UserSettingsContainerComponent, TranslatePipeMock],
imports: [UserSettingsContainerComponent, ArtemisTestModule, RouterModule],
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
providers: [
{ provide: ProfileService, useValue: profileServiceMock },
{ provide: TranslateService, useClass: MockTranslateService },
Expand Down
Loading