Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions admin/src/main/scala/com/neu/model/SystemConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ case class RegistryHttpsProxyCfg(
password: Option[String]
)
case class Webhook(
name: String,
url: String,
enable: Boolean,
use_proxy: Boolean,
`type`: String,
cfg_type: String,
username: Option[String] = None,
password: Option[String] = None
)

case class MaskedWebhook(
name: String,
url: String,
enable: Boolean,
use_proxy: Boolean,
`type`: String,
cfg_type: String
)

case class RemoteRepository(
nickname: String,
provider: String,
Expand Down Expand Up @@ -186,6 +198,10 @@ case class WebhookConfigWrap(
config: Webhook
)

case class MaskedWebhookConfigWrap(
config: MaskedWebhook
)

case class SystemConfig4DashboardWrap(
config: SystemConfig4Dashboard,
error: Option[Error]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object SystemConfigJsonProtocol extends DefaultJsonProtocol {
given azureDevopsConfigurationFormat: RootJsonFormat[AzureDevopsConfiguration] = jsonFormat5(
AzureDevopsConfiguration.apply
)
given webhookFormat: RootJsonFormat[Webhook] = jsonFormat6(Webhook.apply)
given webhookFormat: RootJsonFormat[Webhook] = jsonFormat8(Webhook.apply)
given remoteRepoFormat: RootJsonFormat[RemoteRepository] = jsonFormat6(RemoteRepository.apply)
given remoteRepositoryWrapFormat: RootJsonFormat[RemoteRepositoryWrap] = jsonFormat1(
RemoteRepositoryWrap.apply
Expand All @@ -52,6 +52,11 @@ object SystemConfigJsonProtocol extends DefaultJsonProtocol {
WebhookConfigWrap.apply
)

given MaskedWebhookFormat: RootJsonFormat[MaskedWebhook] = jsonFormat6(MaskedWebhook.apply)
given MaskedWebhookConfigWrapFormat: RootJsonFormat[MaskedWebhookConfigWrap] = jsonFormat1(
MaskedWebhookConfigWrap.apply
)

given systemConfigSvcCfgV2Format: RootJsonFormat[SystemConfigSvcCfgV2] = jsonFormat3(
SystemConfigSvcCfgV2.apply
)
Expand Down Expand Up @@ -104,6 +109,9 @@ object SystemConfigJsonProtocol extends DefaultJsonProtocol {
def webhookConfigWrapToJson(webhookConfigWrap: WebhookConfigWrap): String =
webhookConfigWrap.toJson.compactPrint

def maskedWebhookConfigWrapToJson(maskedWebhookConfigWrap: MaskedWebhookConfigWrap): String =
maskedWebhookConfigWrap.toJson.compactPrint

def remoteRepositoryToJson(remoteRepository: RemoteRepository): String =
remoteRepository.toJson.compactPrint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,21 @@ class DeviceService extends Directives with DefaultJsonFormats with LazyLogging
}

def updateWebhook(tokenId: String, webhook: Webhook, scope: Option[String]): Route = complete {
val printedPayload = maskedWebhookConfigWrapToJson(
MaskedWebhookConfigWrap(
MaskedWebhook(
name = webhook.name,
url = webhook.url,
enable = webhook.enable,
use_proxy = webhook.use_proxy,
`type` = webhook.`type`,
cfg_type = webhook.cfg_type
)
)
)
logger.info("Update config: {}", printedPayload)

val payload = webhookConfigWrapToJson(WebhookConfigWrap(webhook))
logger.info("Update config: {}", payload)

RestClient.httpRequestWithHeader(
scope.fold(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<mat-form-field
[hideRequiredMarker]="to.hideRequiredMarker ?? false"
class="w-100">
<mat-label>{{ field.templateOptions?.label ?? '' | translate }}</mat-label>
<mat-select
(selectionChange)="change($event)"
[attr.disabled]="field.templateOptions?.disabled ?? false"
[formControl]="formControl"
[formlyAttributes]="field"
[required]="field.templateOptions?.required ?? false">
<mat-option
*ngFor="let item of field.templateOptions?.items"
[value]="item.value">
{{ item.viewValue | translate }}
</mat-option>
</mat-select>
</mat-form-field>
<div [class]="!to.isCell ? 'd-flex align-items-center' : 'mt-3'">
<mat-form-field
[hideRequiredMarker]="to.hideRequiredMarker ?? false"
[class]="to.isCell ? 'pull-left' : 'w-' + (to.inputWidth ?? '100')"
class="w-100">
<mat-label>{{ field.templateOptions?.label ?? '' | translate }}</mat-label>
<mat-select
(selectionChange)="change($event)"
[attr.disabled]="field.templateOptions?.disabled ?? false"
[formControl]="formControl"
[formlyAttributes]="field"
[required]="field.templateOptions?.required ?? false">
<mat-option
*ngFor="let item of field.templateOptions?.items"
[value]="item.value">
{{ item.viewValue | translate }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
2 changes: 2 additions & 0 deletions admin/webapp/websrc/app/common/types/settings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export interface Webhook {
use_proxy: boolean;
type: string;
cfg_type: string;
username: string;
password: string | null;
isEditable?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,42 @@ export const WebhookTableField = {
},
},
},
{
key: 'username',
wrappers: [FormlyComponents.READONLY_WRAPPER],
type: FormlyComponents.ICON_INPUT,
templateOptions: {
viewValue: 'login.USERNAME',
placeholder: 'login.USERNAME',
isCell: true,
required: false,
hideRequiredMarker: true,
maxLength: 1000,
},
validators: {
validation: [FormlyValidators.ObjName],
},
expressionProperties: {
'templateOptions.disabled': model => {
return !model.isEditable;
},
},
},
{
key: 'password',
type: FormlyComponents.ICON_INPUT,
templateOptions: {
viewValue: 'login.PASSWORD',
isCell: true,
maxLength: 1000,
type: 'password',
},
expressionProperties: {
'templateOptions.disabled': model => {
return !model.isEditable;
},
},
},
{
key: 'use_proxy',
type: FormlyComponents.CHECKBOX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const WebhookTableField = {
templateOptions: {
viewValue: 'setting.webhook.WH_TYPE',
placeholder: 'setting.webhook.WH_TYPE',
isCell: true,
items: WebhookTypes,
required: true,
hideRequiredMarker: true,
Expand Down Expand Up @@ -112,6 +113,48 @@ export const WebhookTableField = {
},
},
},
{
key: 'username',
wrappers: [FormlyComponents.READONLY_WRAPPER],
type: FormlyComponents.ICON_INPUT,
templateOptions: {
viewValue: 'login.USERNAME',
placeholder: 'login.USERNAME',
isCell: true,
required: false,
hideRequiredMarker: true,
maxLength: 1000,
},
validators: {
validation: [FormlyValidators.ObjName],
},
expressionProperties: {
'templateOptions.disabled': (model, formState) => {
return (
!formState.permissions.isWebhookAuthorized ||
model.cfg_type === GlobalConstant.CFG_TYPE.FED
);
},
},
},
{
key: 'password',
type: FormlyComponents.ICON_INPUT,
templateOptions: {
viewValue: 'login.PASSWORD',
isCell: true,
maxLength: 1000,
type: 'password',
},
expressionProperties: {
'templateOptions.disabled': (model, formState) => {
return (
!formState.permissions.isWebhookAuthorized ||
model.cfg_type === GlobalConstant.CFG_TYPE.FED
);
},
},
},
{
key: 'use_proxy',
type: FormlyComponents.CHECKBOX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ export class ConfigFormComponent implements OnInit, OnDestroy {
this.updateWebhookValueChanges();

this.notificationService.open(this.tr.instant('setting.SUBMIT_OK'));
this._config.webhooks.forEach(webhook => {
webhook.password = '';
});
this.configOptions.resetModel?.(this._config);
setTimeout(() => this.configOptions.resetModel?.(this._config));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const RemoteRepoFormConfig: FormlyFieldConfig[] = [
fieldGroupClassName: 'row',
fieldGroup: [
{
className: 'col-12 col-md-6 mt-2',
className: 'col-12 col-md-6',
...ProviderField,
},
{
Expand Down
Loading