Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Создание ресурсов без глобальной роли #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/ya_acl/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def resources(allow, &block)

def resource(name, allow_roles = [], &block)
raise ArgumentError, 'Options "allow_roles" must be Array' unless allow_roles.is_a? Array
resource_allow_roles = allow_roles << @global_allow_role
resource_allow_roles = allow_roles
resource_allow_roles << @global_allow_role if @global_allow_role
resource = Resource.new(name)
acl.add_resource resource
PrivilegeProxy.new(resource.name, resource_allow_roles, acl, block)
Expand All @@ -58,7 +59,7 @@ def privilege(privilege_name, roles = [], &asserts_block)
proxy = PrivilegeAssertProxy.new(asserts_block, all_allow_roles)
asserts = proxy.asserts
end

all_allow_roles.each do |role|
if asserts[role]
asserts[role].each do |assert|
Expand All @@ -73,7 +74,7 @@ def privilege(privilege_name, roles = [], &asserts_block)

class PrivilegeAssertProxy
attr_reader :asserts

def initialize(block, all_allow_roles)
@all_allow_roles = all_allow_roles
@asserts = {}
Expand Down
18 changes: 16 additions & 2 deletions spec/ya_acl/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
role :admin, :name => 'Administrator'
end
end

acl.role(:admin).should_not be_nil
end

Expand Down Expand Up @@ -42,7 +42,7 @@
end
end
end

acl.check!(:name, :index, [:admin]).should be_true
acl.check!(:name, :index, [:another_admin]).should be_true
acl.check!(:name, :index, [:operator]).should be_true
Expand Down Expand Up @@ -143,4 +143,18 @@
acl.allow?(:name, :update, [:operator], :first => 1, :second => 1).should be_true
acl.allow?(:name, :update, [:operator], :first => 3, :second => 3).should be_false
end

it 'should be work without global role' do
acl = YaAcl::Builder.build do
roles do
role :admin
end

resource :name, [:admin] do
privilege :index
end
end

acl.check!(:name, :index, [:admin]).should be_true
end
end