mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-14 03:31:27 +01:00
Fix permission issue for edit button of repo info (#17775)
Signed-off-by: AllForNothing <sshijun@vmware.com> Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
parent
cc69b1e951
commit
40ba15ca5a
@ -3,7 +3,7 @@
|
|||||||
<div id="info-edit-button">
|
<div id="info-edit-button">
|
||||||
<button
|
<button
|
||||||
class="btn"
|
class="btn"
|
||||||
[disabled]="editing || !hasProjectAdminRole || onSaving"
|
[disabled]="editing || !hasEditPermission || onSaving"
|
||||||
(click)="editInfo()">
|
(click)="editInfo()">
|
||||||
<clr-icon shape="pencil" size="16"></clr-icon> {{
|
<clr-icon shape="pencil" size="16"></clr-icon> {{
|
||||||
'BUTTON.EDIT' | translate
|
'BUTTON.EDIT' | translate
|
||||||
|
@ -3,6 +3,7 @@ import { of } from 'rxjs';
|
|||||||
import { ArtifactInfoComponent } from './artifact-info.component';
|
import { ArtifactInfoComponent } from './artifact-info.component';
|
||||||
import { SharedTestingModule } from 'src/app/shared/shared.module';
|
import { SharedTestingModule } from 'src/app/shared/shared.module';
|
||||||
import { RepositoryService } from 'ng-swagger-gen/services/repository.service';
|
import { RepositoryService } from 'ng-swagger-gen/services/repository.service';
|
||||||
|
import { UserPermissionService } from '../../../../../../../shared/services';
|
||||||
|
|
||||||
describe('ArtifactInfoComponent', () => {
|
describe('ArtifactInfoComponent', () => {
|
||||||
let compRepo: ArtifactInfoComponent;
|
let compRepo: ArtifactInfoComponent;
|
||||||
@ -11,6 +12,11 @@ describe('ArtifactInfoComponent', () => {
|
|||||||
updateRepository: () => of(null),
|
updateRepository: () => of(null),
|
||||||
getRepository: () => of({ description: '' }),
|
getRepository: () => of({ description: '' }),
|
||||||
};
|
};
|
||||||
|
const fakedUserPermissionService = {
|
||||||
|
getPermission() {
|
||||||
|
return of(true);
|
||||||
|
},
|
||||||
|
};
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [SharedTestingModule],
|
imports: [SharedTestingModule],
|
||||||
@ -20,6 +26,10 @@ describe('ArtifactInfoComponent', () => {
|
|||||||
provide: RepositoryService,
|
provide: RepositoryService,
|
||||||
useValue: FakedRepositoryService,
|
useValue: FakedRepositoryService,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: UserPermissionService,
|
||||||
|
useValue: fakedUserPermissionService,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
});
|
});
|
||||||
@ -32,4 +42,9 @@ describe('ArtifactInfoComponent', () => {
|
|||||||
it('should create', () => {
|
it('should create', () => {
|
||||||
expect(compRepo).toBeTruthy();
|
expect(compRepo).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should check permission', async () => {
|
||||||
|
await fixture.whenStable();
|
||||||
|
expect(compRepo.hasEditPermission).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -26,6 +26,10 @@ import {
|
|||||||
import { ErrorHandler } from 'src/app/shared/units/error-handler/error-handler';
|
import { ErrorHandler } from 'src/app/shared/units/error-handler/error-handler';
|
||||||
import { dbEncodeURIComponent } from 'src/app/shared/units/utils';
|
import { dbEncodeURIComponent } from 'src/app/shared/units/utils';
|
||||||
import { finalize } from 'rxjs/operators';
|
import { finalize } from 'rxjs/operators';
|
||||||
|
import {
|
||||||
|
UserPermissionService,
|
||||||
|
USERSTATICPERMISSION,
|
||||||
|
} from '../../../../../../../shared/services';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'artifact-info',
|
selector: 'artifact-info',
|
||||||
@ -34,8 +38,9 @@ import { finalize } from 'rxjs/operators';
|
|||||||
})
|
})
|
||||||
export class ArtifactInfoComponent implements OnInit {
|
export class ArtifactInfoComponent implements OnInit {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
|
projectId: number;
|
||||||
repoName: string;
|
repoName: string;
|
||||||
hasProjectAdminRole: boolean = false;
|
hasEditPermission: boolean = false;
|
||||||
onSaving: boolean = false;
|
onSaving: boolean = false;
|
||||||
loading: boolean = false;
|
loading: boolean = false;
|
||||||
editing: boolean = false;
|
editing: boolean = false;
|
||||||
@ -48,7 +53,8 @@ export class ArtifactInfoComponent implements OnInit {
|
|||||||
private errorHandler: ErrorHandler,
|
private errorHandler: ErrorHandler,
|
||||||
private repositoryService: RepositoryService,
|
private repositoryService: RepositoryService,
|
||||||
private translate: TranslateService,
|
private translate: TranslateService,
|
||||||
private activatedRoute: ActivatedRoute
|
private activatedRoute: ActivatedRoute,
|
||||||
|
private permissionService: UserPermissionService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@ -56,13 +62,26 @@ export class ArtifactInfoComponent implements OnInit {
|
|||||||
let resolverData = this.activatedRoute.snapshot?.parent?.parent?.data;
|
let resolverData = this.activatedRoute.snapshot?.parent?.parent?.data;
|
||||||
if (resolverData) {
|
if (resolverData) {
|
||||||
this.projectName = (<Project>resolverData['projectResolver']).name;
|
this.projectName = (<Project>resolverData['projectResolver']).name;
|
||||||
this.hasProjectAdminRole = (<Project>(
|
this.projectId = (<Project>(
|
||||||
resolverData['projectResolver']
|
resolverData['projectResolver']
|
||||||
)).has_project_admin_role;
|
)).project_id;
|
||||||
}
|
}
|
||||||
|
this.checkPermission();
|
||||||
this.retrieve();
|
this.retrieve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkPermission() {
|
||||||
|
this.permissionService
|
||||||
|
.getPermission(
|
||||||
|
this.projectId,
|
||||||
|
USERSTATICPERMISSION.REPOSITORY.KEY,
|
||||||
|
USERSTATICPERMISSION.REPOSITORY.VALUE.UPDATE
|
||||||
|
)
|
||||||
|
.subscribe(res => {
|
||||||
|
this.hasEditPermission = res;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
retrieve() {
|
retrieve() {
|
||||||
let params: RepositoryService.GetRepositoryParams = {
|
let params: RepositoryService.GetRepositoryParams = {
|
||||||
projectName: this.projectName,
|
projectName: this.projectName,
|
||||||
|
Loading…
Reference in New Issue
Block a user