foreman_webhooks 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b02cc3608aff370684d6d34c74f2fe15f794353bd2306e87ad00e15666d4ba2
4
- data.tar.gz: 12bf2e494176a7659adb7c34e22a40d20222d2d3f9e807333de78de96963fd3d
3
+ metadata.gz: 11967cfaa258f41f6eb8da34eff7cac3ffd49a0cab95c91e238f8c65945f4fbc
4
+ data.tar.gz: f843b1328b7468d718346008d107ae4fb3792a3d72cce7cdcc36ed9c9a38f310
5
5
  SHA512:
6
- metadata.gz: 8c78d4b90cc00f17c9a1c2dcee266f6dbb3282a882df71917a03393ad28c2c6dee9f911ebfcee49b09eddd530a4af1d7dd5468416373ef3745d6b292ea9801c1
7
- data.tar.gz: a7305852c794911f35efc349061a2c6ad7839269d4c3fd1e51a2ab322ef8cc825b837231d7e67c9fd439e41068bcec361519b6418975055489cc706f9477ee9e
6
+ metadata.gz: 399113aecc0426b5755fea689c673aeb6168b87243558581bbe16ffaff3653d7c7db41ed0c4bb5f8ac775c61242d49528e824633c8ce134566de8fa1a79ff0ff
7
+ data.tar.gz: 8e6143ca148607b43998723d0d1592ba90bc8592842bc1bf7c7ed02ad162e9b152a44de90736c1eb5d050b633eb460941aa7f1861396e73053b7007c4d17878b
@@ -15,6 +15,10 @@ attributes :target_url,
15
15
  :ssl_ca_certs,
16
16
  :user
17
17
 
18
+ node :password_set do |webhook|
19
+ webhook.password.present?
20
+ end
21
+
18
22
  child :webhook_template do
19
23
  extends 'api/v2/webhook_templates/base'
20
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanWebhooks
4
- VERSION = '2.0.2'
4
+ VERSION = '2.0.3'
5
5
  end
@@ -21,6 +21,8 @@ const ForemanFormikField = ({
21
21
  placeholder,
22
22
  options,
23
23
  isLoading,
24
+ disabled,
25
+ setDisabled,
24
26
  }) => (
25
27
  <FormikField name={name}>
26
28
  {({
@@ -32,6 +34,15 @@ const ForemanFormikField = ({
32
34
 
33
35
  return filter(initialOptions, o => o.value === fieldValue);
34
36
  };
37
+ const passwordInput = (
38
+ <input
39
+ {...field}
40
+ placeholder={disabled ? '********' : ''}
41
+ type={type}
42
+ disabled={disabled}
43
+ className="form-control"
44
+ />
45
+ );
35
46
  let content = null;
36
47
  switch (type) {
37
48
  case 'textarea':
@@ -56,10 +67,30 @@ const ForemanFormikField = ({
56
67
  onChange={selected =>
57
68
  setFieldValue(field.name, selected[0]?.value)
58
69
  }
59
- // onBlur={e => setFieldTouched(field.name, true)}
60
70
  />
61
71
  );
62
72
  break;
73
+ case 'password':
74
+ content = setDisabled ? (
75
+ <div className="input-group">
76
+ {passwordInput}
77
+ <span className="input-group-btn">
78
+ <button
79
+ className="btn btn-default"
80
+ onClick={e => {
81
+ e.preventDefault();
82
+ setDisabled(!disabled);
83
+ }}
84
+ title={__('Change the password')}
85
+ >
86
+ <span className="pficon pficon-edit" />
87
+ </button>
88
+ </span>
89
+ </div>
90
+ ) : (
91
+ passwordInput
92
+ );
93
+ break;
63
94
  default:
64
95
  content = (
65
96
  <input
@@ -101,6 +132,8 @@ ForemanFormikField.propTypes = {
101
132
  placeholder: PropTypes.string,
102
133
  options: PropTypes.array,
103
134
  isLoading: PropTypes.bool,
135
+ disabled: PropTypes.bool,
136
+ setDisabled: PropTypes.func,
104
137
  };
105
138
 
106
139
  ForemanFormikField.defaultProps = {
@@ -112,6 +145,8 @@ ForemanFormikField.defaultProps = {
112
145
  placeholder: '',
113
146
  options: null,
114
147
  isLoading: false,
148
+ disabled: false,
149
+ setDisabled: undefined,
115
150
  };
116
151
 
117
152
  export default ForemanFormikField;
@@ -18,6 +18,8 @@ const WebhookFormTabs = ({
18
18
  availableEvents,
19
19
  isTemplatesLoading,
20
20
  isEventsLoading,
21
+ isPasswordDisabled,
22
+ setIsPasswordDisabled,
21
23
  }) => (
22
24
  <Tabs activeKey={activeTab} onSelect={handleTabClick} isFilled>
23
25
  <Tab
@@ -90,6 +92,8 @@ const WebhookFormTabs = ({
90
92
  type="password"
91
93
  label={__('Password')}
92
94
  labelHelp={__('Authentication credentials')}
95
+ disabled={isPasswordDisabled}
96
+ setDisabled={setIsPasswordDisabled}
93
97
  />
94
98
  <ForemanFormikField
95
99
  name="verify_ssl"
@@ -153,11 +157,15 @@ WebhookFormTabs.propTypes = {
153
157
  availableEvents: PropTypes.array.isRequired,
154
158
  isTemplatesLoading: PropTypes.bool.isRequired,
155
159
  isEventsLoading: PropTypes.bool.isRequired,
160
+ isPasswordDisabled: PropTypes.bool,
161
+ setIsPasswordDisabled: PropTypes.func,
156
162
  };
157
163
 
158
164
  WebhookFormTabs.defaultProps = {
159
165
  disabled: false,
160
166
  formProps: {},
167
+ isPasswordDisabled: false,
168
+ setIsPasswordDisabled: undefined,
161
169
  };
162
170
 
163
171
  export default WebhookFormTabs;
@@ -25,6 +25,8 @@ const WebhookForm = ({
25
25
  availableEvents,
26
26
  isTemplatesLoading,
27
27
  isEventsLoading,
28
+ isPasswordDisabled,
29
+ setIsPasswordDisabled,
28
30
  }) => {
29
31
  const webhookTemplates = templates.map(t => ({ value: t.id, label: t.name }));
30
32
 
@@ -51,6 +53,8 @@ const WebhookForm = ({
51
53
  availableEvents={availableEvents}
52
54
  isEventsLoading={isEventsLoading}
53
55
  isTemplatesLoading={isTemplatesLoading}
56
+ isPasswordDisabled={isPasswordDisabled}
57
+ setIsPasswordDisabled={setIsPasswordDisabled}
54
58
  />
55
59
  </ForemanForm>
56
60
  );
@@ -64,6 +68,13 @@ WebhookForm.propTypes = {
64
68
  availableEvents: PropTypes.array.isRequired,
65
69
  isEventsLoading: PropTypes.bool.isRequired,
66
70
  isTemplatesLoading: PropTypes.bool.isRequired,
71
+ isPasswordDisabled: PropTypes.bool,
72
+ setIsPasswordDisabled: PropTypes.func,
73
+ };
74
+
75
+ WebhookForm.defaultProps = {
76
+ isPasswordDisabled: false,
77
+ setIsPasswordDisabled: undefined,
67
78
  };
68
79
 
69
80
  export default WebhookForm;
@@ -241,6 +241,7 @@ exports[`WebhookForm rendering should render for edit page 1`] = `
241
241
  ]
242
242
  }
243
243
  isEventsLoading={false}
244
+ isPasswordDisabled={false}
244
245
  isTemplatesLoading={false}
245
246
  webhookTemplates={
246
247
  Array [
@@ -492,6 +493,7 @@ exports[`WebhookForm rendering should render for new page 1`] = `
492
493
  ]
493
494
  }
494
495
  isEventsLoading={false}
496
+ isPasswordDisabled={false}
495
497
  isTemplatesLoading={false}
496
498
  webhookTemplates={
497
499
  Array [
@@ -24,7 +24,13 @@ import {
24
24
 
25
25
  const params = { page: 1, search: 'snippet = false', per_page: 'all' };
26
26
 
27
- const ConnectedWebhookForm = ({ onCancel, handleSubmit, initialValues }) => {
27
+ const ConnectedWebhookForm = ({
28
+ onCancel,
29
+ handleSubmit,
30
+ initialValues,
31
+ isPasswordDisabled,
32
+ setIsPasswordDisabled,
33
+ }) => {
28
34
  const dispatch = useDispatch();
29
35
 
30
36
  const templates = useSelector(selectWebhookTemplates);
@@ -60,6 +66,8 @@ const ConnectedWebhookForm = ({ onCancel, handleSubmit, initialValues }) => {
60
66
  initialValues={initialValues}
61
67
  isTemplatesLoading={isTemplatesLoading}
62
68
  isEventsLoading={isEventsLoading}
69
+ isPasswordDisabled={isPasswordDisabled}
70
+ setIsPasswordDisabled={setIsPasswordDisabled}
63
71
  />
64
72
  );
65
73
  };
@@ -68,6 +76,13 @@ ConnectedWebhookForm.propTypes = {
68
76
  onCancel: PropTypes.func.isRequired,
69
77
  handleSubmit: PropTypes.func.isRequired,
70
78
  initialValues: PropTypes.object.isRequired,
79
+ isPasswordDisabled: PropTypes.bool,
80
+ setIsPasswordDisabled: PropTypes.func,
81
+ };
82
+
83
+ ConnectedWebhookForm.defaultProps = {
84
+ isPasswordDisabled: false,
85
+ setIsPasswordDisabled: undefined,
71
86
  };
72
87
 
73
88
  export default ConnectedWebhookForm;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import { Modal } from 'patternfly-react';
3
4
  import { useDispatch } from 'react-redux';
4
5
 
5
6
  import { translate as __ } from 'foremanReact/common/I18n';
@@ -47,11 +48,12 @@ const WebhookCreateModal = ({ onSuccess, onCancel }) => {
47
48
  return (
48
49
  <ForemanModal
49
50
  id={WEBHOOK_CREATE_MODAL_ID}
50
- title={__('Create Webhook')}
51
51
  backdrop="static"
52
52
  className="webhooks-modal"
53
53
  >
54
- <ForemanModal.Header />
54
+ <Modal.Header>
55
+ <Modal.Title>{__('Create Webhook')}</Modal.Title>
56
+ </Modal.Header>
55
57
  <ConnectedWebhookForm
56
58
  handleSubmit={handleSubmit}
57
59
  initialValues={initialWebhookValues}
@@ -1,4 +1,5 @@
1
- import React, { useEffect } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Modal } from 'patternfly-react';
2
3
  import { useSelector, useDispatch } from 'react-redux';
3
4
  import PropTypes from 'prop-types';
4
5
 
@@ -29,22 +30,11 @@ import './WebhookModal.scss';
29
30
  const WebhookEditModal = ({ toEdit, onSuccess, onCancel }) => {
30
31
  const dispatch = useDispatch();
31
32
 
33
+ const [isPasswordDisabled, setIsPasswordDisabled] = useState(false);
32
34
  const id = toEdit;
33
35
 
34
- const handleSubmit = (values, actions) =>
35
- dispatch(
36
- submitForm({
37
- url: foremanUrl(`/api${WEBHOOKS_PATH}/${id}`),
38
- values: { ...values, controller: 'webhooks' },
39
- item: 'Webhook',
40
- message: __('Webhook was successfully updated.'),
41
- method: 'put',
42
- successCallback: onSuccess,
43
- actions,
44
- })
45
- );
46
-
47
36
  const isLoading = useSelector(selectIsLoading);
37
+ const isPasswordSet = useSelector(selectWebhookValues).passwordSet;
48
38
  const initialWebhookValues = {
49
39
  id: useSelector(selectWebhookValues).id,
50
40
  name: useSelector(selectWebhookValues).name,
@@ -62,6 +52,27 @@ const WebhookEditModal = ({ toEdit, onSuccess, onCancel }) => {
62
52
  proxy_authorization: useSelector(selectWebhookValues).proxyAuthorization,
63
53
  };
64
54
 
55
+ useEffect(() => {
56
+ setIsPasswordDisabled(isPasswordSet);
57
+ }, [isPasswordSet]);
58
+
59
+ const handleSubmit = (values, actions) => {
60
+ if (isPasswordDisabled) {
61
+ delete values.password;
62
+ }
63
+ dispatch(
64
+ submitForm({
65
+ url: foremanUrl(`/api${WEBHOOKS_PATH}/${id}`),
66
+ values: { ...values, controller: 'webhooks' },
67
+ item: 'Webhook',
68
+ message: __('Webhook was successfully updated.'),
69
+ method: 'put',
70
+ successCallback: onSuccess,
71
+ actions,
72
+ })
73
+ );
74
+ };
75
+
65
76
  useEffect(() => {
66
77
  if (id) {
67
78
  dispatch(
@@ -73,21 +84,31 @@ const WebhookEditModal = ({ toEdit, onSuccess, onCancel }) => {
73
84
  }
74
85
  }, [id, dispatch]);
75
86
 
87
+ const onEditCancel = () => {
88
+ if (isPasswordSet) setIsPasswordDisabled(true);
89
+ onCancel();
90
+ };
91
+
76
92
  return (
77
93
  <ForemanModal
78
94
  id={WEBHOOK_EDIT_MODAL_ID}
79
- title={`${__('Edit')} ${initialWebhookValues.name}`}
80
95
  backdrop="static"
81
96
  className="webhooks-modal"
82
97
  >
83
- <ForemanModal.Header />
98
+ <Modal.Header>
99
+ <Modal.Title>
100
+ {`${__('Edit')} ${initialWebhookValues.name}`}
101
+ </Modal.Title>
102
+ </Modal.Header>
84
103
  {isLoading ? (
85
104
  <Loading />
86
105
  ) : (
87
106
  <ConnectedWebhookForm
88
107
  handleSubmit={handleSubmit}
89
108
  initialValues={initialWebhookValues}
90
- onCancel={onCancel}
109
+ onCancel={onEditCancel}
110
+ isPasswordDisabled={isPasswordDisabled}
111
+ setIsPasswordDisabled={setIsPasswordDisabled}
91
112
  />
92
113
  )}
93
114
  </ForemanModal>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_webhooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Goebel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-03 00:00:00.000000000 Z
11
+ date: 2022-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc