Skip to content

Commit

Permalink
Added CRUD support for Automate Domains.
Browse files Browse the repository at this point in the history
- Added support to Add/Edit/Delete Automate Domains. Moved some of the methods to private area and changed existing code that was being used to add/edit namespaces to be used for add/edit of domains.
- Added support to change priority of Automate Domains.
- Added support to allow users to local/unlock domains. This feature is protected by RBAC, so only users that have access to these features will be able to see these buttons.
- Added product features for the new buttons.
- Changed role_allows? method in user model to check for allows_any? feature when a hidden feature comes in.
- Added spec tests to verify, lock/unlock and priority order change features.
- Fixed any broken spec tests in application_helper specs, deleted any AE related spec tests that aren't valid any more.
- Fixed an issue where correct tabs were not shown as inactive tabs on edit screen.

Issue ManageIQ#2045
  • Loading branch information
h-kataria committed Jun 18, 2014
1 parent 4b6a900 commit f7e08ad
Show file tree
Hide file tree
Showing 17 changed files with 660 additions and 277 deletions.
4 changes: 2 additions & 2 deletions vmdb/app/assets/javascripts/cfme_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,11 +1150,11 @@ function miq_jquery_disable_inactive_tabs(tabs_div){
//getting length of tabs on screen
tab_len = $j('#' + tabs_div).tabs('length');
//getting index of currently active tabs
curTab = $j('.ui-tabs-panel:not(.ui-tabs-hide)')
curTab = $j('#' + tabs_div).tabs().tabs('option', 'selected').valueOf();
//building array of tab indexes to be disabled, excluding active tab index
var arr=new Array
for(var i=1,j=0;i<=tab_len;i++){
if(i != curTab.index()){
if(i != curTab+1){
arr[j++] = i-1;
}
}
Expand Down
610 changes: 393 additions & 217 deletions vmdb/app/controllers/miq_ae_class_controller.rb

Large diffs are not rendered by default.

38 changes: 23 additions & 15 deletions vmdb/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,15 @@ def build_toolbar_hide_button(id)
when "action_delete"
return true if !role_allows(:feature=>"action_delete")
end
when "MiqAeClass", "MiqAeField", "MiqAeInstance", "MiqAeMethod", "MiqAeNamespace"
case id
when "miq_ae_domain_lock"
return true unless @record.editable?
when "miq_ae_domain_unlock"
return true if @record.editable? || @record.priority.to_i == 0
else
return true unless @record.editable?
end
when "MiqAlert"
case id
when "alert_copy"
Expand Down Expand Up @@ -1165,6 +1174,17 @@ def build_toolbar_disable_button(id)
return "Default actions can not be deleted." if @record.action_type == "default"
return "Actions assigned to Policies can not be deleted" if @record.miq_policies.length > 0
end
when "MiqAeNamespace"
case id
when "miq_ae_domain_delete"
return "Read Only Domain cannot be deleted." unless @record.editable?
when "miq_ae_domain_edit"
return "Read Only Domain cannot be edited" unless @record.editable?
when "miq_ae_domain_lock"
return "Domain is Locked." unless @record.editable?
when "miq_ae_domain_unlock"
return "Domain is Unlocked." if @record.editable?
end
when "MiqAlert"
case id
when "alert_delete"
Expand Down Expand Up @@ -1895,9 +1915,8 @@ def center_toolbar_filename_explorer

def center_toolbar_filename_automate
nodes = x_node.split('-')
return "blank_view_tb" unless ae_object_editable?(nodes)
return case nodes.first
when "root" then "blank_view_tb"
when "root" then "miq_ae_domains_center_tb"
when "aen" then domain_or_namespace_toolbar(nodes.last)
when "aec" then case @sb[:active_tab]
when "methods" then "miq_ae_methods_center_tb"
Expand All @@ -1910,21 +1929,10 @@ def center_toolbar_filename_automate
end
end

def ae_object_editable?(nodes)
kls = case nodes.first
when "aen" then MiqAeNamespace
when "aec" then MiqAeClass
when "aei" then MiqAeInstance
when "aem" then MiqAeMethod
else nil
end
kls.find_by_id(from_cid(nodes.last)).editable? unless kls.nil?
end

def domain_or_namespace_toolbar(node_id)
ns = MiqAeNamespace.find(from_cid(node_id))
if ns.domain? && ns.editable?
"miq_ae_namespaces_center_tb"
if ns.domain?
"miq_ae_domain_center_tb"
elsif !ns.domain?
"miq_ae_namespace_center_tb"
else
Expand Down
6 changes: 6 additions & 0 deletions vmdb/app/models/miq_ae_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ class MiqAeDomain < MiqAeNamespace
def self.enabled
where(:enabled => true)
end

protected

def self.highest_priority
MiqAeDomain.order('priority DESC').first.priority
end
end
5 changes: 4 additions & 1 deletion vmdb/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ def ldap_group

def role_allows?(options={})
return false if self.miq_user_role.nil?
self.miq_user_role.allows?(options)
feature = MiqProductFeature.find_by_identifier(options[:identifier])
feature.try(:hidden) ?
self.miq_user_role.allows_any?(:identifiers => [options[:identifier]]) :
self.miq_user_role.allows?(options)
end

def role_allows_any?(options={})
Expand Down
2 changes: 1 addition & 1 deletion vmdb/app/views/layouts/_page_header_navbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
%a{:href=>'/dashboard/maintab/?tab=aut'}= h(MAIN_TABS[:aut])
%ul(class="#{primary_nav_class(:aut)}")

-if role_allows(:feature => 'miq_ae_class_explorer')
-if role_allows(:feature => 'miq_ae_domain_view')
%li(class="#{secondary_nav_class('miq_ae_class')}")
%a{:href=>'/miq_ae_class/explorer'}Explorer

Expand Down
48 changes: 48 additions & 0 deletions vmdb/app/views/miq_ae_class/_domains_priority_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<%= render :partial => "layouts/flash_msg", :locals=>{:div_num=>"_domains_priority"} %>
<div id="domains_list">
<table class="admintable">
<tbody>
<tr>
<td >
<table width="50%" class="form" id="formtest">
<tr>
<td align="left" class="widthed">Domains:</td>
<td></td>
</tr>
<tr>
<td align="left" valign="top">
<%= select_tag('seq_fields[]', options_for_select(@edit[:new][:domain_order], @selected), { :multiple=> true, :style=>"width: 450px", :size=>20, :id=>"seq_fields" } ) %>
</td>
<td width="30" align="left" valign="middle">
<% if @edit[:new][:domain_order].length < 2 %>
<%= image_tag("/images/toolbars/up.png", :class=>"dimmed small") %>
<% else %>
<%= link_to(image_tag("/images/toolbars/up.png",
:class=>"rollover small", :alt=>"Move selected fields up"),
{:action=>'priority_form_field_changed', :button=>'up', :id=>"priority__edit"},
"data-submit" =>"domains_list",
:remote=>true,
:title=>'Move selected fields up')
%>
<% end %>

<% if @edit[:new][:domain_order].length < 2 %>
<%= image_tag("/images/toolbars/down.png", :class=>"dimmed small") %>
<% else %>
<%= link_to(image_tag("/images/toolbars/down.png",
:class=>"rollover small", :alt=>"Move selected fields down"),
{:action=>'priority_form_field_changed', :button=>'down', :id=>"priority__edit"},
"data-submit" =>"domains_list",
:remote=>true,
:title=>'Move selected fields down')
%>
<% end %>
</td>
</tr>
<div class="note">* Select one or more consecutive groups to move up or down.</div>
</table>
</td>
</tr>
</tbody>
</table>
</div>
4 changes: 4 additions & 0 deletions vmdb/app/views/miq_ae_class/_fields_seq_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@
</tbody>
</table>
</div>
<script>
<%# disable any other tabs on screen when in edit %>
miq_jquery_disable_inactive_tabs('ae_tabs');
</script>
24 changes: 20 additions & 4 deletions vmdb/app/views/miq_ae_class/_ns_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
<fieldset>
<p class="legend">Info</p>
<table class="style1">
<tr>
<td class="key"><%= Dictionary::gettext('fqname', :type=>:column, :notfound=>:titleize)%></td>
<td class="wide"><%= h(@sb[:namespace_path]) %></td>
</tr>
<% unless @edit[:new][:domain] %>
<tr>
<td class="key"><%= Dictionary::gettext('fqname', :type=>:column, :notfound=>:titleize)%></td>
<td class="wide"><%= h(@sb[:namespace_path]) %></td>
</tr>
<% end %>
<tr>
<td class="key">Name</td>
<td class="wide">
Expand All @@ -53,8 +55,22 @@
"data-miq_observe"=>{:interval=>'.5', :url=>url}.to_json) %>
</td>
</tr>
<% if @edit[:new][:domain] %>
<tr>
<td class="key">Enabled</td>
<td>
<%= check_box_tag("ns_enabled",
value = "1",
checked = @edit[:new][:enabled],
"data-miq_observe_checkbox"=>{:url=>url}.to_json) %>
</td>
</tr>
<% end %>
</table>
</fieldset>
</div>
<%# Need this to bind checkbox observers when under DHTMLX tabs %>
<%# TODO: Remove when DHTMLX tabs are converted to jQuery tabs %>
<script>miqObserveCheckboxes();</script>
<% end %>
</div>
4 changes: 4 additions & 0 deletions vmdb/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,12 @@ en:
no_records_selected_for_task: 'No %{model} were selected for %{task}'
no_records_selected_to_be_disabled: 'No %{model} were selected to be disabled'
no_records_selected_to_be_enabled: 'No %{model} were selected to be enabled'
no_records_selected_to_be_marked: 'No %{model} were selected to be marked as %{action}'
no_utilization_data_available: "No Utilization data available"
no_vc_defined: "No Virtual Center instances have been defined, press a button to Add or Discover one"
press_back_button: "Press your browser's Back button or click a tab to continue"
priority_order_cancelled: "Edit of Priority Order was cancelled by the user"
priority_order_saved: "Priority Order was saved"
record_no_longer_exists: "%{record_name} no longer exists in the database"
record_not_authorized for user: "You are not authorized to view %{record_name}"
search_not_found: "The selected Filter record was not found"
Expand Down Expand Up @@ -427,6 +430,7 @@ en:
selected_records_deleted_with_count: "Successfully deleted %{count_model} from the CFME Database"
selected_records_were_disabled: 'The selected %{model} were disabled'
selected_records_were_enabled: 'The selected %{model} were enabled'
selected_records_were_marked: 'The selected %{model} were marked as %{action}'
task_cancelled: "%{task} was cancelled by the user"
unknown_error: "Unknown error has occurred"
user_not_authorized: "The user is not authorized for this task or item."
Expand Down
2 changes: 2 additions & 0 deletions vmdb/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@
create_instance
create_method
create_ns
domains_priority_edit
explorer
expand_toggle
field_accept
Expand All @@ -542,6 +543,7 @@
form_instance_field_changed
form_method_field_changed
form_ns_field_changed
priority_form_field_changed
reload
tree_select
tree_autoload_dynatree
Expand Down
38 changes: 38 additions & 0 deletions vmdb/db/fixtures/miq_product_features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,44 @@
:feature_type: node
:identifier: miq_ae_class_explorer
:children:
- :name: Automate Domains
:description: Automate Domains
:feature_type: node
:identifier: miq_ae_domain
:children:
- :name: View
:description: View
:feature_type: view
:identifier: miq_ae_domain_view
- :name: Modify
:description: Modify Domain
:feature_type: admin
:identifier: miq_ae_domain_admin
:children:
- :name: Add
:description: Add Automate Domain
:feature_type: admin
:identifier: miq_ae_domain_new
- :name: Edit
:description: Edit Automate Domain
:feature_type: admin
:identifier: miq_ae_domain_edit
- :name: Delete
:description: Delete Automate Domain
:feature_type: admin
:identifier: miq_ae_domain_delete
- :name: Priority Order
:description: Edit Priority Order of Domains
:feature_type: admin
:identifier: miq_ae_domain_priority_edit
- :name: Unlock
:description: Unlock Domain
:feature_type: admin
:identifier: miq_ae_domain_unlock
- :name: Lock
:description: Lock Domain
:feature_type: admin
:identifier: miq_ae_domain_lock
- :name: Automate Namespace
:description: Automate Namespace
:feature_type: node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@
# Toolbar config file
#
---
:model: MiqAeNamespace
:model: MiqAeDomain
:button_groups:
- :name: miq_ae_namespace_vmdb
- :name: miq_ae_domain_vmdb
:items:
- :buttonSelect: miq_ae_namespace_vmdb_choice
- :buttonSelect: miq_ae_domain_vmdb_choice
:image: vmdb
:title: Configuration
:text: Configuration
:items:
- :button: miq_ae_domain_edit
:image: edit
:text: 'Edit this Domain'
:title: 'Edit this Domain'
- :button: miq_ae_domain_delete
:image: delete
:text: 'Remove this Domain'
:title: 'Remove this Domain'
:confirm: 'Are you sure you want to remove this Domain?'
- :button: miq_ae_domain_unlock
:image: enable
:text: Unlock this Domain
:title: Unlock this Domain
- :button: miq_ae_domain_lock
:image: disable
:text: Lock this Domain
:title: Lock this Domain
- :separator:
- :button: miq_ae_namespace_new
:image: new_namespace
:text: 'Add a New Namespace'
Expand All @@ -29,4 +47,5 @@
:url_parms: 'main_div'
:confirm: 'Are you sure you want to remove the selected Namespaces?'
:enabled: 'false'
:onwhen: '1+'
:onwhen: '1+'

37 changes: 37 additions & 0 deletions vmdb/product/toolbars/miq_ae_domains_center_tb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Toolbar config file
#
---
:model: MiqAeDomain
:button_groups:
- :name: miq_ae_domain_vmdb
:items:
- :buttonSelect: miq_ae_domain_vmdb_choice
:image: vmdb
:title: Configuration
:text: Configuration
:items:
- :button: miq_ae_domain_new
:image: new_namespace
:text: 'Add a New Domain'
:title: 'Add a New Domain'
- :button: miq_ae_domain_edit
:image: edit
:text: 'Edit Selected Domains'
:title: 'Select a single Domains to edit'
:url_parms: 'main_div'
:enabled: 'false'
:onwhen: '1'
- :button: miq_ae_domain_delete
:image: remove
:text: 'Remove Domains'
:title: 'Remove selected Domains'
:url_parms: 'main_div'
:confirm: 'Are you sure you want to remove the selected Domains?'
:enabled: 'false'
:onwhen: '1+'
- :separator:
- :button: miq_ae_domain_priority_edit
:image: edit-assign
:text: "Edit Priority Order of Domains"
:title: "Edit Priority Order of Domains"
Loading

0 comments on commit f7e08ad

Please sign in to comment.