Skip to content

Commit 6688ca5

Browse files
committed
remove ids and use miq product features
1 parent 0fc99e9 commit 6688ca5

File tree

6 files changed

+60
-62
lines changed

6 files changed

+60
-62
lines changed

app/controllers/ops_controller/ops_rbac.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,12 @@ def rbac_role_edit_get
131131
@_params[:id] = obj[0]
132132
end
133133
@hide_bottom_bar = true
134-
require 'byebug'
135-
byebug
136134
role = MiqUserRole.find_by(id: params[:id])
137135
render :json => {
138136
:name => role.name,
139137
:vm_restriction => role[:settings] && role[:settings][:restrictions][:vms],
140138
:service_template_restriction => role[:settings] && role[:settings][:restrictions][:service_templates],
141-
:featuresWithId => role.miq_product_features,
139+
:miqProductFeatures => role.miq_product_features,
142140
}
143141
end
144142

@@ -1370,11 +1368,8 @@ def rbac_role_get_form_vars
13701368
@edit[:new][:vm_restriction] = params[:vm_restriction].to_sym if params[:vm_restriction]
13711369
@edit[:new][:service_template_restriction] = params[:service_template_restriction].to_sym if params[:service_template_restriction]
13721370
@edit[:new][:features] = params[:features] if params[:features]
1373-
@edit[:new][:features_with_id] = params[:featuresWithId] if params[:featuresWithId]
13741371
@edit[:new][:features].uniq!
13751372
@edit[:new][:features].sort!
1376-
@edit[:new][:features_with_id].uniq!
1377-
@edit[:new][:features_with_id].sort!
13781373
end
13791374

13801375
# Walk the features tree, removing features up to the top
@@ -1412,7 +1407,6 @@ def rbac_role_set_record_vars(role)
14121407
role.settings[:restrictions][:service_templates] = @edit[:new][:service_template_restriction]
14131408
end
14141409
role.settings = nil if role.settings[:restrictions].blank?
1415-
role[:features_with_id] = @edit[:new][:features_with_id]
14161410
end
14171411

14181412
def populate_role_features(role)

app/helpers/ops_helper/role_rbac_details_helper.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ def role_rbac_details(role, rbac_menu_tree)
99
end
1010

1111
def rbac_role_info_view(role, rbac_menu_tree)
12-
require 'byebug'
13-
byebug
1412
rows = [
1513
row_data(_('ID'), role.id),
1614
row_data(_('Name'), role.name),
@@ -25,8 +23,6 @@ def rbac_role_info_view(role, rbac_menu_tree)
2523
end
2624

2725
def rbac_role_product_features(role, rbac_menu_tree)
28-
require 'byebug'
29-
byebug
3026
cells = row_data(_("Product Features (Read Only)"), {:input => 'component', :component => 'TREE_VIEW_REDUX', :props => rbac_menu_tree.locals_for_render, :name => rbac_menu_tree.name})
3127
cells[:cells][:value][:props]
3228
end

app/javascript/components/rbac-role-form/index.jsx

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,37 @@ import miqRedirectBack from '../../helpers/miq-redirect-back';
1212
let idCounter = 0;
1313

1414
let modified = false;
15-
const features = [];
15+
let features = new Set();
1616
const RbacRoleForm = (props) => {
1717
const {
18-
selectOptions, url, getURL, customProps, role,
18+
selectOptions, url, getURL, customProps, role, existingProductFeatures,
1919
} = props;
2020

2121
const generateId = () => idCounter++;
2222

23+
// necessary for older roles that do only have top level nodes as features
24+
const checkChildren = (productFeature, child) => {
25+
if (!child.children) {
26+
features.add(child.value);
27+
} else {
28+
for (let nextChild of child.children) {
29+
checkChildren(productFeature, nextChild);
30+
}
31+
}
32+
};
33+
34+
// find checked boxes for all role features
2335
const findCheck = (productFeature, node) => {
2436
const result = node.value.split('__')[1].split('#')[0];
37+
2538
if (result === productFeature) {
26-
features.push(node.value);
39+
features.add(node.value);
40+
if (node.children) {
41+
for (let child of node.children) {
42+
checkChildren(productFeature, child);
43+
}
44+
}
2745
}
28-
2946
if (node.children) {
3047
for (let child of node.children) {
3148
findCheck(productFeature, child);
@@ -41,9 +58,6 @@ const RbacRoleForm = (props) => {
4158
label: node.text,
4259
};
4360

44-
if (node.key === 'infra_topology') {
45-
console.log('infra_topology');
46-
}
4761
let icon;
4862
switch (node.icon) {
4963
case 'fa fa-search':
@@ -87,13 +101,13 @@ const RbacRoleForm = (props) => {
87101
const customValidation = (values) => {
88102
const errors = {};
89103
if (values.tree_dropdown === undefined) {
90-
values.tree_dropdown = formData.initialValues.featuresWithId || [];
104+
values.tree_dropdown = formData.initialValues.miqProductFeatures || [];
91105
}
92106
if (values) {
93107
if (values.name === formData.initialValues.name
94108
&& values.vm_restriction === formData.initialValues.vm_restriction
95109
&& values.service_template_restriction === formData.initialValues.service_template_restriction
96-
&& JSON.stringify(values.tree_dropdown) === JSON.stringify(formData.initialValues.featuresWithId)) {
110+
&& JSON.stringify(values.tree_dropdown) === JSON.stringify(formData.initialValues.miqProductFeatures)) {
97111
modified = false;
98112
} else {
99113
modified = true;
@@ -121,42 +135,35 @@ const RbacRoleForm = (props) => {
121135
if (roleValues) {
122136
const bsTree = JSON.parse(customProps.bs_tree);
123137
const nodes = bsTree.map(transformTree);
124-
const uniqueBoxes = [];
125-
const identifiers = [];
126-
roleValues.featuresWithId.forEach((feature) => {
127-
identifiers.push(feature.identifier);
128-
});
129-
console.log("roleValues: ", identifiers);
130-
roleValues.featuresWithId.forEach((productFeature) => {
131-
uniqueBoxes.push(findCheck(productFeature.identifier, nodes[0]));
138+
roleValues.miqProductFeatures.forEach((productFeature) => {
139+
findCheck(productFeature.identifier, nodes[0]);
132140
});
133-
console.log("features: ", features);
134141
setFormData({
135142
...formData, isLoading: false, initialValues: roleValues, nodes, checked: features,
136143
});
137144
}
138145
});
139146
} else {
140-
let uniqueBoxes = [];
141-
if (role.features_with_id) {
142-
uniqueBoxes = role.features_with_id.map((str) => {
143-
const parts = str.split('__');
144-
parts[0] = 'new';
145-
return parts.join('__');
146-
});
147-
}
148147
const initialValues = {
149148
name: role.name !== null ? `Copy of ${role.name}` : '',
150149
vm_restriction: role && role.settings && role.settings.restrictions && role.settings.restrictions.vms,
151150
service_template_restriction: role && role.settings && role.settings.restrictions && role.settings.restrictions.service_templates,
152-
tree_dropdown: role.name !== null ? role && role.features_with_id : [],
153151
};
154152
const bsTree = JSON.parse(customProps.bs_tree);
155153
const nodes = bsTree.map(transformTree);
156-
console.log(nodes);
154+
if (role.name) {
155+
idCounter = 0;
156+
const bsTree = JSON.parse(customProps.bs_tree);
157+
const nodes = bsTree.map(transformTree);
158+
existingProductFeatures.forEach((productFeature) => {
159+
findCheck(productFeature.identifier, nodes[0]);
160+
});
161+
}
162+
initialValues.tree_dropdown = features;
163+
console.log("initial Values: ", initialValues);
157164
if (initialValues) {
158165
setFormData({
159-
...formData, isLoading: false, initialValues, nodes, checked: uniqueBoxes,
166+
...formData, isLoading: false, initialValues, nodes, checked: features,
160167
});
161168
}
162169
}
@@ -167,10 +174,10 @@ const RbacRoleForm = (props) => {
167174
if (!values.tree_dropdown) {
168175
values.tree_dropdown = formData.checked;
169176
}
170-
171-
const treeDropdown = values.tree_dropdown;
172-
const treeValues = treeDropdown.map((string) => string.split('#')[0]);
177+
const checkedBoxes = Array.from(values.tree_dropdown);
178+
const treeValues = checkedBoxes.map((feature) => feature.split('#')[0]);
173179
const splitValues = treeValues.map((string) => string.split('__')[1]);
180+
const productFeatures = splitValues;
174181
values.tree_dropdown = splitValues;
175182

176183
if (values.vm_restriction === '-1') {
@@ -186,8 +193,7 @@ const RbacRoleForm = (props) => {
186193
name: values.name,
187194
vm_restriction: values.vm_restriction,
188195
service_template_restriction: values.service_template_restriction,
189-
features: values.tree_dropdown,
190-
featuresWithId: treeDropdown,
196+
features: productFeatures,
191197
};
192198

193199
setFormData({
@@ -207,18 +213,19 @@ const RbacRoleForm = (props) => {
207213
};
208214

209215
const onReset = () => {
216+
features = new Set();
217+
idCounter = 0;
210218
http.get(`${getURL}/${role.id}`).then((roleValues) => {
211219
if (roleValues) {
212-
let uniqueBoxes = [];
213-
if (roleValues.featuresWithId) {
214-
uniqueBoxes = roleValues.featuresWithId.map((str) => {
215-
const parts = str.split('__');
216-
parts[0] = role.id;
217-
return parts.join('__');
220+
if (roleValues.miqProductFeatures) {
221+
const bsTree = JSON.parse(customProps.bs_tree);
222+
const nodes = bsTree.map(transformTree);
223+
roleValues.miqProductFeatures.forEach((productFeature) => {
224+
findCheck(productFeature.identifier, nodes[0]);
218225
});
219226
}
220227
setFormData({
221-
...formData, isLoading: false, initialValues: roleValues, checked: uniqueBoxes,
228+
...formData, isLoading: false, initialValues: roleValues, checked: features,
222229
});
223230
}
224231
});
@@ -321,14 +328,15 @@ RbacRoleForm.propTypes = {
321328
vms: PropTypes.string.isRequired,
322329
}),
323330
}),
324-
features_with_id: PropTypes.arrayOf(PropTypes.string),
325331
}),
332+
existingProductFeatures: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
326333
};
327334

328335
RbacRoleForm.defaultProps = {
329336
url: '',
330337
getURL: '',
331338
role: undefined,
339+
existingProductFeatures: undefined,
332340
};
333341

334342
FormTemplate.propTypes = {

app/javascript/components/tree-view/checkbox_tree.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const CheckboxTreeComponent = (props) => {
5151
CheckboxTreeComponent.propTypes = {
5252
label: PropTypes.string.isRequired,
5353
nodes: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
54-
checked: PropTypes.arrayOf(PropTypes.string),
54+
checked: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
5555
};
5656

5757
CheckboxTreeComponent.defaultProps = {

app/javascript/spec/rbac-role-form/__snapshots__/rbac-role-form.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`Rbac Role Form Component render add rbac role form 1`] = `
44
<div>
55
<div
6-
className="dialog-provision-form"
6+
className="rbac-role-form"
77
>
88
<Connect(MiqFormRenderer)
99
FormTemplate={[Function]}
@@ -103,7 +103,7 @@ exports[`Rbac Role Form Component render add rbac role form 1`] = `
103103
exports[`Rbac Role Form Component render copy rbac role form 1`] = `
104104
<div>
105105
<div
106-
className="dialog-provision-form"
106+
className="rbac-role-form"
107107
>
108108
<Connect(MiqFormRenderer)
109109
FormTemplate={[Function]}
@@ -203,7 +203,7 @@ exports[`Rbac Role Form Component render copy rbac role form 1`] = `
203203
exports[`Rbac Role Form Component render edit rbac role form 1`] = `
204204
<div>
205205
<div
206-
className="dialog-provision-form"
206+
className="rbac-role-form"
207207
>
208208
<Connect(MiqFormRenderer)
209209
FormTemplate={[Function]}

app/views/ops/_rbac_role_details.html.haml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
- custom_props = rbac_role_product_features(@role, @rbac_menu_tree)
1010
= react('RbacRoleForm',
1111
:selectOptions => select_options,
12-
:url => url,
13-
:getURL => get_url,
14-
:customProps => custom_props,
15-
:role => @role,
16-
:rbacMenuTree => @rbac_menu_tree)
12+
:url => url,
13+
:getURL => get_url,
14+
:customProps => custom_props,
15+
:role => @role,
16+
:existingProductFeatures => @role.miq_product_features)
1717
- else
1818
= role_rbac_details(@role, @rbac_menu_tree)

0 commit comments

Comments
 (0)