Allow un-logged users to visit public repos

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
AllForNothing 2020-10-12 17:23:22 +08:00
parent c491c4f513
commit 59fe9830b5
5 changed files with 30 additions and 9 deletions

View File

@ -8,4 +8,4 @@
</div>
</clr-alert>
</div>
<div *ngIf="globalMessageOpened && needAuth" class="mask-layer"></div>
<div *ngIf="globalMessageOpened && needAuth && !isFromGlobalSearch()" class="mask-layer"></div>

View File

@ -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;
}
}

View File

@ -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 = '';

View File

@ -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 }
]

View File

@ -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}});
}
}
}