-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Attila Vecerek
committed
Feb 23, 2017
1 parent
af8a4e2
commit c4d4d2b
Showing
15 changed files
with
108 additions
and
98 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
app/helpers/application_helper/button/rbac_common_feature_button.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => rbac_common_feature_for_buttons(@feature)) | ||
end | ||
|
||
def visible? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.try!(:source) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
spec/helpers/application_helper/buttons/rbac_common_feature_button_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe ApplicationHelper::Button::RbacCommonFeatureButton do | ||
let(:session) { Hash.new } | ||
let(:view_context) { setup_view_context_with_sandbox({}) } | ||
let(:button) { described_class.new(view_context, {}, {}, {:options => {:feature => feature}}) } | ||
|
||
before { login_as FactoryGirl.create(:user, :features => 'rbac_tenant_add') } | ||
|
||
describe '#role_allows_feature?' do | ||
subject { button.role_allows_feature? } | ||
%w(rbac_tenant_add rbac_project_add).each do |feature| | ||
context 'when user role allows feature' do | ||
let(:feature) { feature } | ||
it { expect(subject).to be_truthy } | ||
end | ||
end | ||
context 'when user role does not allow feature' do | ||
let(:feature) { 'not_allowed_feature' } | ||
it { expect(subject).to be_falsey } | ||
end | ||
end | ||
end |
Oops, something went wrong.