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