Skip to content

Commit f181f47

Browse files
Update
1 parent 2e17a79 commit f181f47

File tree

5 files changed

+199
-72
lines changed

5 files changed

+199
-72
lines changed

app/javascript/components/async-credentials/edit-password-field.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useFieldApi, componentTypes } from '@@ddf';
1010

1111
const EditPasswordField = ({ componentClass, ...props }) => {
1212
const {
13-
labelText, validateOnMount, isDisabled, editMode, setEditMode, buttonLabel, input, meta, ...rest
13+
labelText, validateOnMount, isDisabled, editMode, setEditMode, buttonLabel, input, meta, icon, kind, ...rest
1414
} = useFieldApi(prepareProps(props));
1515

1616
const invalid = (meta.touched || validateOnMount) && meta.error;
@@ -58,7 +58,14 @@ const EditPasswordField = ({ componentClass, ...props }) => {
5858
{ field }
5959
</div>
6060
<div className="bx--col-sm-1 bx--col-md-1 bx--col-lg-1">
61-
<Button hasIconOnly kind="secondary" size="field" onClick={setEditMode} iconDescription={buttonLabel} renderIcon={EditOff16} />
61+
<Button
62+
hasIconOnly
63+
kind={kind || 'secondary'}
64+
size="field"
65+
onClick={setEditMode}
66+
iconDescription={buttonLabel}
67+
renderIcon={icon || EditOff16}
68+
/>
6269
</div>
6370
</div>
6471
</div>

app/javascript/components/user-form/index.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import miqRedirectBack from '../../helpers/miq-redirect-back';
77
import { API } from '../../http_api';
88
import { passwordValidation } from './helper';
99

10-
const UserForm = ({ id, data, disabled }) => {
10+
const UserForm = ({
11+
id, data, disabled, dbMode,
12+
}) => {
1113
const [{
1214
initialValues, isLoading, editMode, groups, selectedGroups, // Use to populate the custom component
1315
}, setState] = useState({ isLoading: true });
@@ -154,7 +156,7 @@ const UserForm = ({ id, data, disabled }) => {
154156
return !isLoading && (
155157
<div className="col-md-12 user-form">
156158
<MiqFormRenderer
157-
schema={createSchema(id, editMode, setState, disabled, groups, selectedGroups)}
159+
schema={createSchema(id, editMode, setState, disabled, dbMode, groups, selectedGroups)}
158160
initialValues={initialValues}
159161
validate={(values) => passwordValidation(initialValues, id, editMode, values, setState, selectedGroups)}
160162
onSubmit={onSubmit}
@@ -173,6 +175,7 @@ UserForm.propTypes = {
173175
id: PropTypes.number,
174176
data: PropTypes.objectOf(PropTypes.any),
175177
disabled: PropTypes.bool,
178+
dbMode: PropTypes.string.isRequired,
176179
};
177180

178181
UserForm.defaultProps = {

app/javascript/components/user-form/user-form.schema.js

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { componentTypes, validatorTypes } from '@@ddf';
2+
import { Edit16 } from '@carbon/icons-react';
23

3-
function createSchema(id, editMode, setState, disabled, availableGroups, selectedGroups) {
4+
function createSchema(id, editMode, setState, disabled, dbMode, availableGroups, selectedGroups) {
45
const fields = [
56
{
67
component: componentTypes.TEXT_FIELD,
@@ -28,24 +29,70 @@ function createSchema(id, editMode, setState, disabled, availableGroups, selecte
2829
message: __('Required'),
2930
}],
3031
},
31-
...(id ? [
32-
...(editMode ? [
32+
...(dbMode === 'database' || (dbMode !== 'database' && disabled) ? [
33+
...(id ? [
34+
...(editMode ? [
35+
{
36+
component: 'edit-password-field',
37+
label: __('Password'),
38+
id: 'password',
39+
name: 'password',
40+
maxLength: 50,
41+
editMode,
42+
disabled: !editMode,
43+
setEditMode: () => {
44+
setState((state) => ({
45+
...state,
46+
editMode: !editMode,
47+
}));
48+
},
49+
placeholder: '●●●●●●●●',
50+
buttonLabel: editMode ? __('Cancel') : __('Change'),
51+
},
52+
{
53+
component: componentTypes.TEXT_FIELD,
54+
label: __('Confirm Password'),
55+
maxLength: 50,
56+
type: 'password',
57+
id: 'confirmPassword',
58+
name: 'confirmPassword',
59+
initialValue: '',
60+
isRequired: true,
61+
},
62+
] : [
63+
{
64+
component: 'edit-password-field',
65+
label: __('Password'),
66+
maxLength: 50,
67+
id: 'passwordPlaceholder',
68+
name: 'passwordPlaceholder',
69+
icon: Edit16,
70+
kind: 'primary',
71+
editMode,
72+
disabled: true,
73+
setEditMode: () => {
74+
setState((state) => ({
75+
...state,
76+
editMode: !editMode,
77+
}));
78+
},
79+
placeholder: '●●●●●●●●',
80+
buttonLabel: editMode ? __('Cancel') : __('Change'),
81+
},
82+
]),
83+
] : [
3384
{
34-
component: 'edit-password-field',
85+
component: componentTypes.TEXT_FIELD,
3586
label: __('Password'),
87+
maxLength: 50,
88+
type: 'password',
3689
id: 'password',
3790
name: 'password',
38-
maxLength: 50,
39-
editMode,
40-
disabled: !editMode,
41-
setEditMode: () => {
42-
setState((state) => ({
43-
...state,
44-
editMode: !editMode,
45-
}));
46-
},
47-
placeholder: '●●●●●●●●',
48-
buttonLabel: editMode ? __('Cancel') : __('Change'),
91+
isRequired: true,
92+
validate: [{
93+
type: validatorTypes.REQUIRED,
94+
message: __('Required'),
95+
}],
4996
},
5097
{
5198
component: componentTypes.TEXT_FIELD,
@@ -56,55 +103,12 @@ function createSchema(id, editMode, setState, disabled, availableGroups, selecte
56103
name: 'confirmPassword',
57104
initialValue: '',
58105
isRequired: true,
106+
validate: [{
107+
type: validatorTypes.REQUIRED,
108+
message: __('Required'),
109+
}],
59110
},
60-
] : [
61-
{
62-
component: 'edit-password-field',
63-
label: __('Password'),
64-
maxLength: 50,
65-
id: 'passwordPlaceholder',
66-
name: 'passwordPlaceholder',
67-
editMode,
68-
disabled: true,
69-
setEditMode: () => {
70-
setState((state) => ({
71-
...state,
72-
editMode: !editMode,
73-
}));
74-
},
75-
placeholder: '●●●●●●●●',
76-
buttonLabel: editMode ? __('Cancel') : __('Change'),
77-
},
78-
]),
79-
] : [
80-
{
81-
component: componentTypes.TEXT_FIELD,
82-
label: __('Password'),
83-
maxLength: 50,
84-
type: 'password',
85-
id: 'password',
86-
name: 'password',
87-
isRequired: true,
88-
validate: [{
89-
type: validatorTypes.REQUIRED,
90-
message: __('Required'),
91-
}],
92-
},
93-
{
94-
component: componentTypes.TEXT_FIELD,
95-
label: __('Confirm Password'),
96-
maxLength: 50,
97-
type: 'password',
98-
id: 'confirmPassword',
99-
name: 'confirmPassword',
100-
initialValue: '',
101-
isRequired: true,
102-
validate: [{
103-
type: validatorTypes.REQUIRED,
104-
message: __('Required'),
105-
}],
106-
},
107-
]),
111+
])] : []),
108112
{
109113
component: componentTypes.TEXT_FIELD,
110114
label: __('E-mail Address'),

app/javascript/packs/component-definitions-common.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,8 @@ ManageIQ.component.addReact('TimeProfileTable', TimeProfileTable);
333333
ManageIQ.component.addReact('ToastList', ToastList);
334334
ManageIQ.component.addReact('Toolbar', Toolbar);
335335
ManageIQ.component.addReact('TreeViewRedux', TreeViewRedux);
336-
ManageIQ.component.addReact('VmEditForm', VmEditForm);
337-
ManageIQ.component.addReact('ScheduleForm', ScheduleForm);
338-
ManageIQ.component.addReact('VmResizeForm', VmResizeForm);
339-
ManageIQ.component.addReact('UserForm', UserForm);
340336
ManageIQ.component.addReact('UsageTrendChart', UsageTrendChart);
337+
ManageIQ.component.addReact('UserForm', UserForm);
341338
ManageIQ.component.addReact('UtilizationChartGraph', UtilizationChartGraph);
342339
ManageIQ.component.addReact('VisualSettingsForm', VisualSettingsForm);
343340
ManageIQ.component.addReact('VmCommonRenameForm', VmCommonRenameForm);
Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,126 @@
11
- if @edit
22
= render :partial => "layouts/flash_msg"
33
- disabled = @edit && @edit[:new][:userid] == "admin"
4+
- db_mode = ::Settings.authentication.mode
45
#user_info
56
%h3
67
= _("User Information")
7-
= react('UserForm', {:id => (@edit[:user_id]), :data => @record.dup, :disabled => disabled})
8+
= react('UserForm', {:id => (@edit[:user_id]), :data => @record.dup, :disabled => disabled, :dbMode => db_mode})
89
- else
910
= settings_users_summary(@record)
1011
= render :partial => "rbac_tag_box"
12+
13+
-# - if @edit
14+
-# - change_stored_password ||= _("Change")
15+
-# - cancel_password_change ||= _("Cancel")
16+
-# - stored_password_placeholder = "●●●●●●●●"
17+
-# - pfx ||= ""
18+
-# - url = url_for_only_path(:action => 'rbac_user_field_changed', :id => (@edit[:user_id] || "new"))
19+
-# - observe_url_json = {:interval => '.5', :url => url}.to_json
20+
-# - disabled = @edit && @edit[:new][:userid] == "admin"
21+
-# = render :partial => "layouts/flash_msg"
22+
-# #user_info
23+
-# %h3
24+
-# = _("User Information")
25+
-# .form-horizontal
26+
-# .form-group
27+
-# %label.col-md-2.control-label
28+
-# = _("Full Name")
29+
-# .col-md-8
30+
-# = text_field_tag("name",
31+
-# @edit[:new][:name],
32+
-# :autocomplete => 'off',
33+
-# :maxlength => 50,
34+
-# :disabled => disabled,
35+
-# :class => "form-control",
36+
-# "data-miq_observe" => observe_url_json)
37+
-# - unless @edit[:new][:userid] == "admin"
38+
-# = javascript_tag(javascript_focus('name'))
39+
-# .form-group
40+
-# %label.col-md-2.control-label
41+
-# = _("Username")
42+
-# .col-md-8
43+
-# = text_field_tag("userid",
44+
-# @edit[:new][:userid],
45+
-# :autocomplete => 'off',
46+
-# :maxlength => 255,
47+
-# :disabled => disabled,
48+
-# :class => "form-control",
49+
-# "data-miq_observe" => observe_url_json)
50+
-# - db_mode = ::Settings.authentication.mode
51+
-# - if db_mode == "database" || (db_mode != "database" && disabled)
52+
-# .form-group
53+
-# %label.col-md-2.control-label
54+
-# = _("Password")
55+
-# .col-md-8
56+
-# %span.input-group{:style => "width: 100%"}
57+
-# = password_field_tag("password",
58+
-# "",
59+
-# :autocomplete => "new-password",
60+
-# :maxlength => 50,
61+
-# :disabled => @edit[:new][:userid].blank? ? false : true,
62+
-# :placeholder => @edit[:new][:userid].blank? ? "" : stored_password_placeholder,
63+
-# :class => "form-control",
64+
-# "data-miq_observe" => observe_url_json)
65+
-# - if @edit[:new][:userid] == "admin"
66+
-# = javascript_tag(javascript_focus('password'))
67+
-# - unless @edit[:new][:userid].blank?
68+
-# %span.input-group-btn
69+
-# %button.btn.btn-default{:id => "change_stored_password",
70+
-# "style" => "display:block;cursor: pointer; cursor: hand;", "onclick" => "changeStoredPassword('#{pfx}', '#{url}')"}
71+
-# = change_stored_password
72+
-# %button.btn.btn-default{:id => "cancel_password_change",
73+
-# "style" => "display:none;cursor: pointer; cursor: hand;",
74+
-# "onclick" => "cancelPasswordChange('#{pfx}', '#{url}')"}
75+
-# = cancel_password_change
76+
-# .form-group{:id => "verify_group",
77+
-# :style => @edit[:new][:userid].blank? ? "display:block" : "display:none"}
78+
-# %label.col-md-2.control-label
79+
-# = _("Confirm Password")
80+
-# .col-md-8
81+
-# = password_field_tag("verify",
82+
-# "",
83+
-# :autocomplete => "new-password",
84+
-# :maxlength => 50,
85+
-# :class => "form-control",
86+
-# "data-miq_observe" => observe_url_json)
87+
-# .form-group
88+
-# %label.col-md-2.control-label
89+
-# = _("E-mail Address")
90+
-# .col-md-8
91+
-# = text_field_tag("email",
92+
-# @edit[:new][:email],
93+
-# :autocomplete => 'off',
94+
-# :maxlength => 253,
95+
-# :class => "form-control",
96+
-# "data-miq_observe" => observe_url_json)
97+
-# .form-group
98+
-# %label.col-md-2.control-label
99+
-# = _("Available Groups")
100+
-# .col-md-2
101+
-# - groups = @record.present? && @record.miq_groups.present? ? @record.miq_groups.order(:description) : []
102+
-# - if disabled
103+
-# %p.form-control-static
104+
-# - groups.each do |group|
105+
-# = h(group.description)
106+
-# %br
107+
-# - else
108+
-# - select_groups = @edit[:new][:userid].blank? ? @edit[:new][:group] : groups.map(&:id)
109+
-# = select_tag('chosen_group',
110+
-# options_for_select(@edit[:groups], select_groups),
111+
-# :class => "selectpicker",
112+
-# :multiple => true,
113+
-# :title => "&lt;#{_('Choose one or more Groups')}&gt;",
114+
-# :style => "overflow-x: scroll;")
115+
-# :javascript
116+
-# miqInitSelectPicker();
117+
-# miqSelectPickerEvent('chosen_group', "#{url}")
118+
-# .form-group
119+
-# %label.col-md-2.control-label
120+
-# = _("Selected Groups")
121+
-# .col-md-4
122+
-# = render :partial => "ops/rbac_group_selected"
123+
-# %hr
124+
-# - else
125+
-# = settings_users_summary(@record)
126+
-# = render :partial => "rbac_tag_box"

0 commit comments

Comments
 (0)