diff --git a/src/portal/src/app/global-message/message.component.html b/src/portal/src/app/global-message/message.component.html index ba653063e..7ce6e7d3d 100644 --- a/src/portal/src/app/global-message/message.component.html +++ b/src/portal/src/app/global-message/message.component.html @@ -8,4 +8,4 @@ -
+
diff --git a/src/portal/src/app/global-message/message.component.ts b/src/portal/src/app/global-message/message.component.ts index 419912d00..a213b505f 100644 --- a/src/portal/src/app/global-message/message.component.ts +++ b/src/portal/src/app/global-message/message.component.ts @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. import { Component, Input, OnInit, OnDestroy, ElementRef } from '@angular/core'; -import { Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { Subscription } from "rxjs"; import { TranslateService } from '@ngx-translate/core'; import { Message } from './message'; import { MessageService } from './message.service'; import { CommonRoutes, dismissInterval, httpStatusCode } from "../../lib/entities/shared.const"; - +const YES: string = 'yes'; @Component({ selector: 'global-message', templateUrl: 'message.component.html', @@ -41,6 +41,7 @@ export class MessageComponent implements OnInit, OnDestroy { private elementRef: ElementRef, private messageService: MessageService, private router: Router, + private route: ActivatedRoute, private translate: TranslateService) { } ngOnInit(): void { @@ -135,4 +136,8 @@ export class MessageComponent implements OnInit, OnDestroy { } this.globalMessageOpened = false; } + // if navigate from global search(un-logged users visit public project) + isFromGlobalSearch(): boolean { + return this.route.snapshot.queryParams['publicAndNotLogged'] === YES; + } } diff --git a/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts b/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts index 50b5d6fbc..0e1d25ce9 100644 --- a/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts +++ b/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts @@ -72,6 +72,7 @@ export interface LabelState { show: boolean; } export const AVAILABLE_TIME = '0001-01-01T00:00:00.000Z'; +const YES: string = 'yes'; @Component({ selector: 'artifact-list-tab', templateUrl: './artifact-list-tab.component.html', @@ -822,7 +823,11 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { goIntoArtifactSummaryPage(artifact: Artifact): void { const relativeRouterLink: string[] = ['artifacts', artifact.digest]; - this.router.navigate(relativeRouterLink , { relativeTo: this.activatedRoute }); + if (this.activatedRoute.snapshot.queryParams['publicAndNotLogged'] === YES) { + this.router.navigate(relativeRouterLink , { relativeTo: this.activatedRoute, queryParams: {publicAndNotLogged: YES} }); + } else { + this.router.navigate(relativeRouterLink , { relativeTo: this.activatedRoute }); + } } onSuccess($event: any): void { @@ -941,7 +946,11 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { depth = artifact.digest; } const linkUrl = ['harbor', 'projects', this.projectId, 'repositories', this.repoName, 'depth', depth]; - this.router.navigate(linkUrl); + if (this.activatedRoute.snapshot.queryParams['publicAndNotLogged'] === YES) { + this.router.navigate(linkUrl, {queryParams: {publicAndNotLogged: YES}}); + } else { + this.router.navigate(linkUrl); + } } selectFilterType() { this.lastFilteredTagName = ''; diff --git a/src/portal/src/app/shared/list-repository-ro/list-repository-ro.component.spec.ts b/src/portal/src/app/shared/list-repository-ro/list-repository-ro.component.spec.ts index 65c9125a3..6cf48655c 100644 --- a/src/portal/src/app/shared/list-repository-ro/list-repository-ro.component.spec.ts +++ b/src/portal/src/app/shared/list-repository-ro/list-repository-ro.component.spec.ts @@ -6,9 +6,9 @@ import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform import { ClarityModule } from '@clr/angular'; import { FormsModule } from '@angular/forms'; import { RouterTestingModule } from '@angular/router/testing'; -import { of } from 'rxjs'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { SearchTriggerService } from '../../base/global-search/search-trigger.service'; +import { SessionService } from "../session.service"; describe('ListRepositoryRoComponent', () => { let component: ListRepositoryROComponent; @@ -33,6 +33,7 @@ describe('ListRepositoryRoComponent', () => { declarations: [ListRepositoryROComponent], providers: [ TranslateService, + SessionService, { provide: SearchTriggerService, useValue: mockSearchTriggerService } ] diff --git a/src/portal/src/app/shared/list-repository-ro/list-repository-ro.component.ts b/src/portal/src/app/shared/list-repository-ro/list-repository-ro.component.ts index 9d9d3144a..fd2b1c07e 100644 --- a/src/portal/src/app/shared/list-repository-ro/list-repository-ro.component.ts +++ b/src/portal/src/app/shared/list-repository-ro/list-repository-ro.component.ts @@ -20,7 +20,8 @@ import { Repository } from '../../../../ng-swagger-gen/models/repository'; import { SearchTriggerService } from '../../base/global-search/search-trigger.service'; import {Subscription} from "rxjs"; - +import { SessionService } from "../session.service"; +const YES: string = 'yes'; @Component({ selector: 'list-repository-ro', templateUrl: 'list-repository-ro.component.html', @@ -38,7 +39,8 @@ export class ListRepositoryROComponent implements OnInit, OnDestroy { constructor( private router: Router, private searchTrigger: SearchTriggerService, - private ref: ChangeDetectorRef) { + private ref: ChangeDetectorRef, + private sessionService: SessionService) { this.router.routeReuseStrategy.shouldReuseRoute = function() { return false; }; @@ -71,7 +73,11 @@ export class ListRepositoryROComponent implements OnInit, OnDestroy { let projectName = repoName.split('/')[0]; let repositorieName = projectName ? repoName.substr(projectName.length + 1) : repoName; let linkUrl = ['harbor', 'projects', projectId, 'repositories', repositorieName ]; - this.router.navigate(linkUrl); + if (this.sessionService.getCurrentUser()) { + this.router.navigate(linkUrl); + } else {// if not logged in and it's a public project, add param 'publicAndNotLogged' + this.router.navigate(linkUrl, {queryParams: {publicAndNotLogged: YES}}); + } } }