Skip to content
Open
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
3 changes: 2 additions & 1 deletion lib/ya_acl/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 Down
16 changes: 15 additions & 1 deletion spec/ya_acl/builder_spec.rb
Original file line number Diff line number Diff line change
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