Skip to content

Commit

Permalink
Refactor the navigation process
Browse files Browse the repository at this point in the history
1.Fixes goharbor#19630
2.Allow unauthenticated users to view public projects's detail page and
its public tabs

Signed-off-by: Shijun Sun <[email protected]>
  • Loading branch information
AllForNothing committed Jul 24, 2024
1 parent 64df11b commit 9c48bc5
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 183 deletions.
3 changes: 0 additions & 3 deletions src/portal/src/app/account/sign-in/sign-in.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,3 @@ export class SignInService {
);
}
}

export const UN_LOGGED_PARAM: string = 'publicAndNotLogged';
export const YES: string = 'yes';
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
<span class="back-icon"><</span>
<a *ngIf="hasSignedIn" (click)="backToProject()" class="backStyle">{{
<a (click)="backToProject()" class="backStyle">{{
'PROJECT_DETAIL.PROJECTS' | translate
}}</a>
<ng-container *ngIf="hasSignedIn && isWebhookTaskListPage()">
<ng-container *ngIf="isWebhookTaskListPage()">
<span class="back-icon"><</span>
<a (click)="backToWebhook()" class="backStyle">{{
'PROJECT_DETAIL.WEBHOOKS' | translate
}}</a>
</ng-container>
<ng-container *ngIf="hasSignedIn && isP2pPreheatTaskListPage()">
<ng-container *ngIf="isP2pPreheatTaskListPage()">
<span class="back-icon"><</span>
<a (click)="backToP2pPreheat()" class="backStyle">{{
'P2P_PROVIDER.P2P_PROVIDER' | translate
}}</a>
</ng-container>

<a *ngIf="!hasSignedIn" [routerLink]="['/harbor', 'sign-in']" class="backStyle">
{{ 'SEARCH.BACK' | translate }}</a
>
<div class="clr-row">
<div class="clr-col-5">
<h1 class="custom-h2 center" sub-header-title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
import { ActivatedRoute, Router } from '@angular/router';
import { Project } from '../project';
import { SessionService } from '../../../shared/services/session.service';
import { AppConfigService } from '../../../services/app-config.service';
import { forkJoin, Observable, Subject, Subscription } from 'rxjs';
import {
UserPermissionService,
Expand Down Expand Up @@ -146,8 +145,7 @@ export class ProjectDetailComponent
linkName: 'configs',
tabLinkInOverflow: false,
showTabName: 'PROJECT_DETAIL.CONFIG',
permissions: () =>
this.isSessionValid && this.hasConfigurationListPermission,
permissions: () => this.hasConfigurationListPermission,
},
];
previousWindowWidth: number;
Expand All @@ -163,7 +161,6 @@ export class ProjectDetailComponent
private route: ActivatedRoute,
private router: Router,
private sessionService: SessionService,
private appConfigService: AppConfigService,
private userPermissionService: UserPermissionService,
private errorHandler: ErrorHandler,
private cdf: ChangeDetectorRef,
Expand Down Expand Up @@ -342,7 +339,13 @@ export class ProjectDetailComponent
this.getQuotaInfo();
}
},
error => this.errorHandler.error(error)
error => {
this.hasProjectReadPermission = true;
this.hasRepositoryListPermission = true;
this.hasLabelListPermission = true;
this.hasLabelCreatePermission = true;
this.hasConfigurationListPermission = true;
}
);
}
getQuotaInfo() {
Expand Down
11 changes: 0 additions & 11 deletions src/portal/src/app/base/project/project.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const routes: Routes = [
children: [
{
path: 'summary',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.PROJECT.KEY,
Expand All @@ -39,7 +38,6 @@ const routes: Routes = [
},
{
path: 'repositories',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.REPOSITORY.KEY,
Expand All @@ -53,7 +51,6 @@ const routes: Routes = [
},
{
path: 'members',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.MEMBER.KEY,
Expand All @@ -65,7 +62,6 @@ const routes: Routes = [
},
{
path: 'logs',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.LOG.KEY,
Expand All @@ -79,7 +75,6 @@ const routes: Routes = [
},
{
path: 'labels',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.LABEL.KEY,
Expand All @@ -93,7 +88,6 @@ const routes: Routes = [
},
{
path: 'configs',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.CONFIGURATION.KEY,
Expand All @@ -107,7 +101,6 @@ const routes: Routes = [
},
{
path: 'robot-account',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.ROBOT.KEY,
Expand All @@ -121,7 +114,6 @@ const routes: Routes = [
},
{
path: 'tag-strategy',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.TAG_RETENTION.KEY,
Expand All @@ -135,7 +127,6 @@ const routes: Routes = [
},
{
path: 'webhook',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.WEBHOOK.KEY,
Expand All @@ -149,7 +140,6 @@ const routes: Routes = [
},
{
path: 'scanner',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.SCANNER.KEY,
Expand All @@ -163,7 +153,6 @@ const routes: Routes = [
},
{
path: 'p2p-provider',
canActivate: [MemberPermissionGuard],
data: {
permissionParam: {
resource: USERSTATICPERMISSION.P2P_PROVIDER.KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ import { errorHandler } from '../../../../../../../shared/units/shared.utils';
import { ConfirmationDialogComponent } from '../../../../../../../shared/components/confirmation-dialog';
import { ConfirmationMessage } from '../../../../../../global-confirmation-dialog/confirmation-message';
import { ConfirmationAcknowledgement } from '../../../../../../global-confirmation-dialog/confirmation-state-message';
import {
UN_LOGGED_PARAM,
YES,
} from '../../../../../../../account/sign-in/sign-in.service';
import { Label } from '../../../../../../../../../ng-swagger-gen/models/label';
import {
EventService,
Expand All @@ -84,7 +80,7 @@ import { Accessory } from 'ng-swagger-gen/models/accessory';
import { Tag } from '../../../../../../../../../ng-swagger-gen/models/tag';
import { CopyArtifactComponent } from './copy-artifact/copy-artifact.component';
import { CopyDigestComponent } from './copy-digest/copy-digest.component';
import { Scanner } from '../../../../../../left-side-nav/interrogation-services/scanner/scanner';


export const AVAILABLE_TIME = '0001-01-01T00:00:00.000Z';

Expand Down Expand Up @@ -767,20 +763,10 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {

goIntoArtifactSummaryPage(artifact: Artifact): void {
const relativeRouterLink: string[] = ['artifacts', artifact.digest];
if (this.activatedRoute.snapshot.queryParams[UN_LOGGED_PARAM] === YES) {
this.router.navigate(relativeRouterLink, {
relativeTo: this.activatedRoute,
queryParams: {
[UN_LOGGED_PARAM]: YES,
sbomDigest: artifact.sbomDigest ?? '',
},
});
} else {
this.router.navigate(relativeRouterLink, {
relativeTo: this.activatedRoute,
queryParams: { sbomDigest: artifact.sbomDigest ?? '' },
});
}
this.router.navigate(relativeRouterLink, {
relativeTo: this.activatedRoute,
queryParams: { sbomDigest: artifact.sbomDigest ?? '' },
});
}

// Get sbom status
Expand Down Expand Up @@ -977,13 +963,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
'depth',
depth,
];
if (this.activatedRoute.snapshot.queryParams[UN_LOGGED_PARAM] === YES) {
this.router.navigate(linkUrl, {
queryParams: { [UN_LOGGED_PARAM]: YES },
});
} else {
this.router.navigate(linkUrl);
}
this.router.navigate(linkUrl);
}

filterEvent(e: ArtifactFilterEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import {
dbEncodeURIComponent,
formatSize,
} from '../../../../../../../../shared/units/utils';
import {
UN_LOGGED_PARAM,
YES,
} from '../../../../../../../../account/sign-in/sign-in.service';
import { ActivatedRoute, Router } from '@angular/router';
import { Accessory } from 'ng-swagger-gen/models/accessory';
import { ArtifactService as NewArtifactService } from 'ng-swagger-gen/services/artifact.service';
Expand Down Expand Up @@ -110,22 +106,12 @@ export class SubAccessoriesComponent

goIntoArtifactSummaryPage(accessory: Accessory): void {
const relativeRouterLink: string[] = ['artifacts', accessory.digest];
if (this.activatedRoute.snapshot.queryParams[UN_LOGGED_PARAM] === YES) {
this.router.navigate(relativeRouterLink, {
relativeTo: this.activatedRoute,
queryParams: {
[UN_LOGGED_PARAM]: YES,
[AccessoryQueryParams.ACCESSORY_TYPE]: accessory.type,
},
});
} else {
this.router.navigate(relativeRouterLink, {
relativeTo: this.activatedRoute,
queryParams: {
[AccessoryQueryParams.ACCESSORY_TYPE]: accessory.type,
},
});
}
this.router.navigate(relativeRouterLink, {
relativeTo: this.activatedRoute,
queryParams: {
[AccessoryQueryParams.ACCESSORY_TYPE]: accessory.type,
},
});
}

delete(a: Accessory) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Component, Input } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ActivatedRoute, Router } from '@angular/router';
import { SbomSummary } from '../../../../../../shared/services';
import { SBOM_SCAN_STATUS } from '../../../../../../shared/units/utils';
import {
UN_LOGGED_PARAM,
YES,
} from '../../../../../../account/sign-in/sign-in.service';
import { HAS_STYLE_MODE, StyleMode } from '../../../../../../services/theme';
import { ScanTypes } from '../../../../../../shared/entities/shared.const';
import { Scanner } from '../../../../../left-side-nav/interrogation-services/scanner/scanner';
Expand All @@ -16,7 +11,6 @@ import { AccessoryType } from '../../artifact';
const MIN = 60;
const MIN_STR = 'min ';
const SEC_STR = 'sec';
const SUCCESS_PCT: number = 100;

@Component({
selector: 'hbr-sbom-tip-histogram',
Expand All @@ -32,7 +26,6 @@ export class SbomTipHistogramComponent {
@Input() sbomDigest: string = '';
@Input() accessories: Accessory[] = [];
constructor(
private translate: TranslateService,
private activatedRoute: ActivatedRoute,
private router: Router
) {}
Expand Down Expand Up @@ -109,23 +102,12 @@ export class SbomTipHistogramComponent {

goIntoArtifactSbomSummaryPage(): void {
const relativeRouterLink: string[] = ['artifacts', this.artifactDigest];
if (this.activatedRoute.snapshot.queryParams[UN_LOGGED_PARAM] === YES) {
this.router.navigate(relativeRouterLink, {
relativeTo: this.activatedRoute,
queryParams: {
[UN_LOGGED_PARAM]: YES,
sbomDigest: this.sbomDigest ?? '',
tab: ScanTypes.SBOM,
},
});
} else {
this.router.navigate(relativeRouterLink, {
relativeTo: this.activatedRoute,
queryParams: {
sbomDigest: this.sbomDigest ?? '',
tab: ScanTypes.SBOM,
},
});
}
this.router.navigate(relativeRouterLink, {
relativeTo: this.activatedRoute,
queryParams: {
sbomDigest: this.sbomDigest ?? '',
tab: ScanTypes.SBOM,
},
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { DEFAULT_PAGE_SIZE, delUrlParam } from '../../units/utils';
import { forkJoin, Observable, Subscription } from 'rxjs';
import { Project } from '../../../../../ng-swagger-gen/models/project';
import { ScannerService } from '../../../../../ng-swagger-gen/services/scanner.service';
import { UN_LOGGED_PARAM } from '../../../account/sign-in/sign-in.service';
import { CommonRoutes, httpStatusCode } from '../../entities/shared.const';
import { ActivatedRoute, Router } from '@angular/router';
import { MessageService } from '../global-message/message.service';
Expand Down Expand Up @@ -68,19 +67,13 @@ export class AppLevelAlertsComponent implements OnInit, OnDestroy {
// User session timed out, then redirect to sign-in page
if (
this.session.getCurrentUser() &&
!this.isSignInUrl() &&
this.route.snapshot.queryParams[UN_LOGGED_PARAM] !==
YES
!this.isSignInUrl()
) {
const url = delUrlParam(
this.router.url,
UN_LOGGED_PARAM
);
this.session.clear(); // because of SignInGuard, must clear user session before navigating to sign-in page
this.router.navigate(
[CommonRoutes.EMBEDDED_SIGN_IN],
{
queryParams: { redirect_url: url },
queryParams: { redirect_url: this.router.url },
}
);
}
Expand Down Expand Up @@ -166,10 +159,8 @@ export class AppLevelAlertsComponent implements OnInit, OnDestroy {
}

signIn(): void {
// remove queryParam UN_LOGGED_PARAM of redirect url
const url = delUrlParam(this.router.url, UN_LOGGED_PARAM);
this.router.navigate([CommonRoutes.EMBEDDED_SIGN_IN], {
queryParams: { redirect_url: url },
queryParams: { redirect_url: this.router.url },
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
[routerLink]="
getLink(r.project_id, r.name || r.repository_name)
"
[queryParams]="getQueryParams()"
>{{ r.name || r.repository_name }}</a
></clr-dg-cell
>
Expand Down
Loading

0 comments on commit 9c48bc5

Please sign in to comment.