Skip to content

Commit

Permalink
Refactor buttons in ops' rbac_tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila Vecerek committed Feb 17, 2017
1 parent e803f86 commit 2623819
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ApplicationHelper::Button::RbacCommonFeatureButton < ApplicationHelper::Button::GenericFeatureButton
delegate :rbac_common_feature_for_buttons, :to => :@view_context

def role_allows_feature?
role_allows?(:feature => @feature || self[:child_id])
end

def visible?
true
end
end
9 changes: 2 additions & 7 deletions app/helpers/application_helper/button/tenant_add.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
class ApplicationHelper::Button::TenantAdd < ApplicationHelper::Button::GenericFeatureButton
class ApplicationHelper::Button::TenantAdd < ApplicationHelper::Button::RbacCommonFeatureButton
needs :@record
delegate :role_allows?, :rbac_common_feature_for_buttons, :to => :@view_context

def role_allows_feature?
role_allows?(:feature => rbac_common_feature_for_buttons(self[:child_id]))
end

def visible?
true
!@record.project?
end
end
6 changes: 2 additions & 4 deletions app/helpers/application_helper/button/tenant_edit.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class ApplicationHelper::Button::TenantEdit < ApplicationHelper::Button::Basic
needs :@record

class ApplicationHelper::Button::TenantEdit < ApplicationHelper::Button::RbacCommonFeatureButton
def disabled?
@record.source
@record&.source
end
end
9 changes: 6 additions & 3 deletions app/helpers/application_helper/toolbar/miq_group_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ class ApplicationHelper::Toolbar::MiqGroupCenter < ApplicationHelper::Toolbar::B
:rbac_group_edit,
'pficon pficon-edit fa-lg',
t = N_('Edit this Group'),
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_group_delete,
'pficon pficon-delete fa-lg',
t = N_('Delete this Group'),
t,
:url_parms => "&refresh=y",
:confirm => N_("Are you sure you want to delete this Group?")),
:confirm => N_("Are you sure you want to delete this Group?"),
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand All @@ -34,7 +36,8 @@ class ApplicationHelper::Toolbar::MiqGroupCenter < ApplicationHelper::Toolbar::B
t = proc do
_('Edit \'%{customer_name}\' Tags for this Group') % {:customer_name => @view_context.session[:customer_name]}
end,
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand Down
15 changes: 10 additions & 5 deletions app/helpers/application_helper/toolbar/miq_groups_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ class ApplicationHelper::Toolbar::MiqGroupsCenter < ApplicationHelper::Toolbar::
:rbac_group_add,
'pficon pficon-add-circle-o fa-lg',
t = N_('Add a new Group'),
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_group_edit,
'pficon pficon-edit fa-lg',
N_('Select a single Group to edit'),
N_('Edit the selected Group'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1"),
:onwhen => "1",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_group_delete,
'pficon pficon-delete fa-lg',
Expand All @@ -27,13 +29,15 @@ class ApplicationHelper::Toolbar::MiqGroupsCenter < ApplicationHelper::Toolbar::
:url_parms => "main_div",
:confirm => N_("Delete all selected Groups?"),
:enabled => false,
:onwhen => "1+"),
:onwhen => "1+",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
separator,
button(
:rbac_group_seq_edit,
'pficon pficon-edit fa-lg',
t = N_('Edit Sequence of User Groups for LDAP Look Up'),
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand All @@ -55,7 +59,8 @@ class ApplicationHelper::Toolbar::MiqGroupsCenter < ApplicationHelper::Toolbar::
t,
:url_parms => "main_div",
:enabled => false,
:onwhen => "1+"),
:onwhen => "1+",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand Down
9 changes: 6 additions & 3 deletions app/helpers/application_helper/toolbar/tenant_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ class ApplicationHelper::Toolbar::TenantCenter < ApplicationHelper::Toolbar::Bas
:rbac_tenant_manage_quotas,
'pficon pficon-edit fa-lg',
t = N_('Manage Quotas'),
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_tenant_delete,
'pficon pficon-delete fa-lg',
t = N_('Delete this item'),
t,
:url_parms => "&refresh=y",
:confirm => N_("Are you sure you want to delete this item and all of it's children?")),
:confirm => N_("Are you sure you want to delete this item and all of it's children?"),
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand All @@ -56,7 +58,8 @@ class ApplicationHelper::Toolbar::TenantCenter < ApplicationHelper::Toolbar::Bas
t = proc do
_('Edit \'%{customer_name}\' Tags for this Tenant') % {:customer_name => @view_context.session[:customer_name]}
end,
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand Down
12 changes: 8 additions & 4 deletions app/helpers/application_helper/toolbar/tenants_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ApplicationHelper::Toolbar::TenantsCenter < ApplicationHelper::Toolbar::Ba
N_('Edit the selected item'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1"),
:onwhen => "1",
:klass => ApplicationHelper::Button::TenantEdit),
button(
:rbac_tenant_delete,
'pficon pficon-delete fa-lg',
Expand All @@ -22,15 +23,17 @@ class ApplicationHelper::Toolbar::TenantsCenter < ApplicationHelper::Toolbar::Ba
:url_parms => "main_div",
:confirm => N_("Delete all selected items and all of their children?"),
:enabled => false,
:onwhen => "1+"),
:onwhen => "1+",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_tenant_manage_quotas,
'pficon pficon-edit fa-lg',
N_('Select a single item to manage quotas'),
N_('Manage Quotas for the Selected Item'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1"),
:onwhen => "1",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand All @@ -52,7 +55,8 @@ class ApplicationHelper::Toolbar::TenantsCenter < ApplicationHelper::Toolbar::Ba
t,
:url_parms => "main_div",
:enabled => false,
:onwhen => "1+"),
:onwhen => "1+",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand Down
12 changes: 8 additions & 4 deletions app/helpers/application_helper/toolbar/user_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ class ApplicationHelper::Toolbar::UserCenter < ApplicationHelper::Toolbar::Basic
:rbac_user_edit,
'pficon pficon-edit fa-lg',
t = N_('Edit this User'),
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_user_copy,
'fa fa-files-o fa-lg',
t = N_('Copy this User to a new User'),
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_user_delete,
'pficon pficon-delete fa-lg',
t = N_('Delete this User'),
t,
:url_parms => "&refresh=y",
:confirm => N_("Are you sure you want to delete this User?")),
:confirm => N_("Are you sure you want to delete this User?"),
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand All @@ -39,7 +42,8 @@ class ApplicationHelper::Toolbar::UserCenter < ApplicationHelper::Toolbar::Basic
t = proc do
_('Edit \'%{customer_name}\' Tags for this User') % {:customer_name => @view_context.session[:customer_name]}
end,
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand Down
9 changes: 6 additions & 3 deletions app/helpers/application_helper/toolbar/user_role_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ class ApplicationHelper::Toolbar::UserRoleCenter < ApplicationHelper::Toolbar::B
:rbac_role_edit,
'pficon pficon-edit fa-lg',
t = N_('Edit this Role'),
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_role_copy,
'fa fa-files-o fa-lg',
t = N_('Copy this Role to a new Role'),
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_role_delete,
'pficon pficon-delete fa-lg',
t = N_('Delete this Role'),
t,
:url_parms => "&refresh=y",
:confirm => N_("Are you sure you want to delete this Role?")),
:confirm => N_("Are you sure you want to delete this Role?"),
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand Down
12 changes: 8 additions & 4 deletions app/helpers/application_helper/toolbar/user_roles_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ class ApplicationHelper::Toolbar::UserRolesCenter < ApplicationHelper::Toolbar::
:rbac_role_add,
'pficon pficon-add-circle-o fa-lg',
t = N_('Add a new Role'),
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_role_edit,
'pficon pficon-edit fa-lg',
N_('Select a single Role to edit'),
N_('Edit the selected Role'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1"),
:onwhen => "1",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_role_copy,
'fa fa-files-o fa-lg',
N_('Select a single Role to copy'),
N_('Copy the selected Role to a new Role'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1"),
:onwhen => "1",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_role_delete,
'pficon pficon-delete fa-lg',
Expand All @@ -35,7 +38,8 @@ class ApplicationHelper::Toolbar::UserRolesCenter < ApplicationHelper::Toolbar::
:url_parms => "main_div",
:confirm => N_("Delete all selected Roles?"),
:enabled => false,
:onwhen => "1+"),
:onwhen => "1+",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand Down
15 changes: 10 additions & 5 deletions app/helpers/application_helper/toolbar/users_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ class ApplicationHelper::Toolbar::UsersCenter < ApplicationHelper::Toolbar::Basi
:rbac_user_add,
'pficon pficon-add-circle-o fa-lg',
t = N_('Add a new User'),
t),
t,
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_user_edit,
'pficon pficon-edit fa-lg',
N_('Select a single User to edit'),
N_('Edit the selected User'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1"),
:onwhen => "1",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_user_copy,
'fa fa-files-o fa-lg',
N_('Select a single User to copy'),
N_('Copy the selected User to a new User'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1"),
:onwhen => "1",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
button(
:rbac_user_delete,
'pficon pficon-delete fa-lg',
Expand All @@ -35,7 +38,8 @@ class ApplicationHelper::Toolbar::UsersCenter < ApplicationHelper::Toolbar::Basi
:url_parms => "main_div",
:confirm => N_("Delete all selected Users?"),
:enabled => false,
:onwhen => "1+"),
:onwhen => "1+",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand All @@ -57,7 +61,8 @@ class ApplicationHelper::Toolbar::UsersCenter < ApplicationHelper::Toolbar::Basi
t,
:url_parms => "main_div",
:enabled => false,
:onwhen => "1+"),
:onwhen => "1+",
:klass => ApplicationHelper::Button::RbacCommonFeatureButton),
]
),
])
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/application_helper/toolbar_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,6 @@ def hide_button_ops(id)
when :diagnostics_tree
return false
when :rbac_tree
return true unless role_allows?(:feature => rbac_common_feature_for_buttons(id))
return true if %w(rbac_project_add rbac_tenant_add).include?(id) && @record.project?
return false
when :vmdb_tree
return !["db_connections", "db_details", "db_indexes", "db_settings"].include?(@sb[:active_tab])
Expand Down

0 comments on commit 2623819

Please sign in to comment.