Improve add scanner and add robot page (#14042)

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
Will Sun 2021-01-21 10:41:57 +08:00 committed by GitHub
parent 9a897af67e
commit 19a72cf350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 64 additions and 13 deletions

View File

@ -82,6 +82,16 @@ export class NewScannerModalComponent {
return this.testMap[this.newScannerFormComponent.newScannerForm.get('url').value];
}
get canTestEndpoint(): boolean {
if (this.newScannerFormComponent.newScannerForm.get('auth').value === "Basic") {
return this.newScannerFormComponent.newScannerForm.get('accessCredential').get('username').valid
&& this.newScannerFormComponent.newScannerForm.get('accessCredential').get('password').valid;
}
if (this.newScannerFormComponent.newScannerForm.get('auth').value === "Bearer") {
return this.newScannerFormComponent.newScannerForm.get('accessCredential').get('token').valid;
}
if (this.newScannerFormComponent.newScannerForm.get('auth').value === "APIKey") {
return this.newScannerFormComponent.newScannerForm.get('accessCredential').get('apiKey').valid;
}
return !this.onTesting
&& this.newScannerFormComponent
&& !this.newScannerFormComponent.checkOnGoing

View File

@ -9,7 +9,7 @@ import { MessageHandlerService } from "../../../shared/message-handler/message-h
import {
ACTION_RESOURCE_I18N_MAP,
ExpirationType,
FrontAccess, INITIAL_ACCESSES, PermissionsKinds
FrontAccess, INITIAL_ACCESSES, onlyHasPushPermission, PermissionsKinds
} from "../../../system-robot-accounts/system-robot-util";
import { Robot } from "../../../../../ng-swagger-gen/models/robot";
import { InlineAlertComponent } from "../../../shared/inline-alert/inline-alert.component";
@ -81,7 +81,8 @@ export class AddRobotComponent implements OnInit, OnDestroy {
this.isNameExisting = false;
this.checkNameOnGoing = true;
return this.robotService.ListRobot({
q: encodeURIComponent(`Level=${PermissionsKinds.PROJECT},ProjectID=${this.projectId},name=${name}`)
q: encodeURIComponent(
`Level=${PermissionsKinds.PROJECT},ProjectID=${this.projectId},name=${this.projectName}+${name}`)
}).pipe(finalize(() => this.checkNameOnGoing = false));
}))
.subscribe(res => {
@ -205,7 +206,6 @@ export class AddRobotComponent implements OnInit, OnDestroy {
return !flag;
}
save() {
this.saveBtnState = ClrLoadingState.LOADING;
const robot: Robot = clone(this.systemRobot);
robot.disable = false;
robot.level = PermissionsKinds.PROJECT;
@ -224,6 +224,12 @@ export class AddRobotComponent implements OnInit, OnDestroy {
kind: PermissionsKinds.PROJECT,
access: access
}];
// Push permission must work with pull permission
if (onlyHasPushPermission(access)) {
this.inlineAlertComponent.showInlineError('SYSTEM_ROBOT.PUSH_PERMISSION_TOOLTIP');
return;
}
this.saveBtnState = ClrLoadingState.LOADING;
if (this.isEditMode) {
robot.disable = this.systemRobot.disable;
const opeMessage = new OperateInfo();

View File

@ -16,7 +16,7 @@ import { Access } from "../../../../ng-swagger-gen/models/access";
import {
ACTION_RESOURCE_I18N_MAP, ExpirationType,
FrontAccess, INITIAL_ACCESSES,
NAMESPACE_ALL_PROJECTS,
NAMESPACE_ALL_PROJECTS, onlyHasPushPermission,
PermissionsKinds,
} from "../system-robot-util";
import { clone } from "../../../lib/utils/utils";
@ -344,7 +344,6 @@ export class NewRobotComponent implements OnInit, OnDestroy {
return !flag1;
}
save() {
this.saveBtnState = ClrLoadingState.LOADING;
const robot: Robot = clone(this.systemRobot);
robot.disable = false;
robot.level = PermissionsKinds.SYSTEM;
@ -383,6 +382,16 @@ export class NewRobotComponent implements OnInit, OnDestroy {
});
});
}
// Push permission must work with pull permission
if (robot.permissions && robot.permissions.length) {
for (let i = 0; i < robot.permissions.length; i++) {
if (onlyHasPushPermission(robot.permissions[i].access)) {
this.inlineAlertComponent.showInlineError('SYSTEM_ROBOT.PUSH_PERMISSION_TOOLTIP');
return;
}
}
}
this.saveBtnState = ClrLoadingState.LOADING;
if (this.isEditMode) {
robot.disable = this.systemRobot.disable;
const opeMessage = new OperateInfo();

View File

@ -117,3 +117,21 @@ export enum ExpirationType {
NEVER = 'never'
}
export function onlyHasPushPermission(access: Access[]): boolean {
if (access && access.length) {
let hasPushPermission: boolean = false;
let hasPullPermission: boolean = false;
access.forEach( item => {
if (item.action === Action.PUSH && item.resource === Resource.ARTIFACT) {
hasPushPermission = true;
}
if (item.action === Action.PULL && item.resource === Resource.ARTIFACT) {
hasPullPermission = true;
}
});
if (hasPushPermission && !hasPullPermission) {
return true;
}
}
return false;
}

View File

@ -1669,6 +1669,7 @@
"SEARCH_BY_NAME": "Robot-Account mittels Namen suchen (ohne Prefix)",
"FINAL_PROJECT_NAME_TIP": "Der zusammengesetzte Robot-Account-Name besteht aus dem Prefix, dem Projektnamen, einem plus und dem Inhalt des Eingabefeldes.",
"FINAL_SYSTEM_NAME_TIP": "Der zusammengesetzte systemweite Robot-Account-Name besteht aus dem Prefix und dem Inhalt des Eingabefeldes.",
"PUSH_AND_PULL": "Push&Pull"
"PUSH_AND_PULL": "Push",
"PUSH_PERMISSION_TOOLTIP": "Push permission can not work alone, it must work with pull permission"
}
}

View File

@ -1669,6 +1669,7 @@
"SEARCH_BY_NAME": "Search by name(without prefix)",
"FINAL_PROJECT_NAME_TIP": "The final project robot name consists of the prefix,the project name,a plus mark and the current input value",
"FINAL_SYSTEM_NAME_TIP": "The final system robot name consists of the prefix and the current input value",
"PUSH_AND_PULL": "Push&Pull"
"PUSH_AND_PULL": "Push",
"PUSH_PERMISSION_TOOLTIP": "Push permission can not work alone, it must work with pull permission"
}
}

View File

@ -1667,6 +1667,7 @@
"SEARCH_BY_NAME": "Search by name(without prefix)",
"FINAL_PROJECT_NAME_TIP": "The final project robot name consists of the prefix,the project name,a plus mark and the current input value",
"FINAL_SYSTEM_NAME_TIP": "The final system robot name consists of the prefix and the current input value",
"PUSH_AND_PULL": "Push&Pull"
"PUSH_AND_PULL": "Push",
"PUSH_PERMISSION_TOOLTIP": "Push permission can not work alone, it must work with pull permission"
}
}

View File

@ -1637,6 +1637,7 @@
"SEARCH_BY_NAME": "Search by name(without prefix)",
"FINAL_PROJECT_NAME_TIP": "The final project robot name consists of the prefix,the project name,a plus mark and the current input value",
"FINAL_SYSTEM_NAME_TIP": "The final system robot name consists of the prefix and the current input value",
"PUSH_AND_PULL": "Push&Pull"
"PUSH_AND_PULL": "Push",
"PUSH_PERMISSION_TOOLTIP": "Push permission can not work alone, it must work with pull permission"
}
}

View File

@ -1665,7 +1665,8 @@
"SEARCH_BY_NAME": "Search by name(without prefix)",
"FINAL_PROJECT_NAME_TIP": "The final project robot name consists of the prefix,the project name,a plus mark and the current input value",
"FINAL_SYSTEM_NAME_TIP": "The final system robot name consists of the prefix and the current input value",
"PUSH_AND_PULL": "Push&Pull"
"PUSH_AND_PULL": "Push",
"PUSH_PERMISSION_TOOLTIP": "Push permission can not work alone, it must work with pull permission"
}
}

View File

@ -1669,6 +1669,7 @@
"SEARCH_BY_NAME": "Search by name(without prefix)",
"FINAL_PROJECT_NAME_TIP": "The final project robot name consists of the prefix,the project name,a plus mark and the current input value",
"FINAL_SYSTEM_NAME_TIP": "The final system robot name consists of the prefix and the current input value",
"PUSH_AND_PULL": "Push&Pull"
"PUSH_AND_PULL": "Push",
"PUSH_PERMISSION_TOOLTIP": "Push permission can not work alone, it must work with pull permission"
}
}

View File

@ -1666,6 +1666,7 @@
"SEARCH_BY_NAME": "按名称(不含前缀)搜索",
"FINAL_PROJECT_NAME_TIP": "项目级机器人的最终名称由前缀,项目名称,一个加号以及当前输入值组成",
"FINAL_SYSTEM_NAME_TIP": "系统级机器人的最终名称由前缀和当前输入值组成",
"PUSH_AND_PULL": "推送&拉取"
"PUSH_AND_PULL": "推送",
"PUSH_PERMISSION_TOOLTIP": "推送权限无法单独工作,请在选择推送权限的时,确保已经勾选了拉取权限"
}
}

View File

@ -1653,6 +1653,7 @@
"SEARCH_BY_NAME": "Search by name(without prefix)",
"FINAL_PROJECT_NAME_TIP": "The final project robot name consists of the prefix,the project name,a plus mark and the current input value",
"FINAL_SYSTEM_NAME_TIP": "The final system robot name consists of the prefix and the current input value",
"PUSH_AND_PULL": "Push&Pull"
"PUSH_AND_PULL": "Push",
"PUSH_PERMISSION_TOOLTIP": "Push permission can not work alone, it must work with pull permission"
}
}