Skip to content

Commit

Permalink
Integrated code lifecycle: Disable access to personal VCS access toke…
Browse files Browse the repository at this point in the history
…ns in account settings for students (#9397)
  • Loading branch information
SimonEntholzer authored Oct 12, 2024
1 parent d8c99a2 commit 2259241
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
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]);
}

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) {
<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';
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 @@ -17,7 +16,6 @@ import { DocumentationLinkComponent } from 'app/shared/components/documentation-
@NgModule({
imports: [RouterModule.forChild(userSettingsState), ArtemisSharedModule, ArtemisSharedComponentModule, ClipboardModule, FormDateTimePickerModule, DocumentationLinkComponent],
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],
providers: [
{ provide: ProfileService, useValue: profileServiceMock },
{ provide: TranslateService, useClass: MockTranslateService },
Expand Down

0 comments on commit 2259241

Please sign in to comment.