Permalink
Browse files

moved export to proper models and fixed specs

  • Loading branch information...
1 parent eb9527f commit a0ead8e35b4c7828cdbd122602d9772d435831af @mkristian committed Dec 29, 2012
View
@@ -0,0 +1,28 @@
+# -*- mode: ruby -*-
+
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => [ :spec ]
+
+task :headers do
+ require 'rubygems'
+ require 'copyright_header'
+
+ s = Gem::Specification.load( Dir["*gemspec"].first )
+
+ args = {
+ :license => s.license,
+ :copyright_software => s.name,
+ :copyright_software_description => s.description,
+ :copyright_holders => s.authors,
+ :copyright_years => [Time.now.year],
+ :add_path => 'lib',
+ :output_dir => './'
+ }
+
+ command_line = CopyrightHeader::CommandLine.new( args )
+ command_line.execute
+end
+# vim: syntax=Ruby
View
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.test_files += Dir['spec/**/*_spec.rb']
s.test_files += Dir['features/*.feature']
s.test_files += Dir['features/step_definitions/*.rb']
- s.add_runtime_dependency 'ixtlan-core', '~>0.8.0'
+# s.add_runtime_dependency 'ixtlan-core', '~>0.8.0'
s.add_runtime_dependency 'virtus', '~>0.5'
s.add_development_dependency 'rails', '3.0.9'
s.add_development_dependency 'rspec', '2.6.0'
@@ -105,7 +105,7 @@ def permissions(current_groups, &block)
nodes = []
perm = Permission.new #Node.new(:permission)
perm.resource = resource
- perm.actions = nodes
+ perm.actions = []#nodes
# setup default_groups
default_groups = actions.delete('defaults') || []
@@ -126,15 +126,14 @@ def permissions(current_groups, &block)
actions.each do |action, groups|
group_names = groups.collect { |g| g.is_a?(Hash) ? g.keys : g }.flatten if groups
- node = Acton.new #Node.new(:action)
+ node = Action.new #Node.new(:action)
allowed_groups =
if groups && group_names.member?('*')
group_map.values
else
names = group_map.keys & ((group_names || []) + @superuser)
names.collect { |name| group_map[name] }
end
-
if (deny && allowed_groups.size == 0) || (!deny && allowed_groups.size > 0)
node.name = action
if block
@@ -146,7 +145,7 @@ def permissions(current_groups, &block)
perm.associations = assos if assos && assos.size > 0
end
end
- nodes << node
+ perm.actions << node
elsif deny && allowed_groups.size > 0 && block
assos = block.call(resource, group_map.values)
perm.associations = assos if assos && assos.size > 0
@@ -116,7 +116,7 @@ def self.guard_filters
end
def self.guard
- Rails.application.config.guard
+ ::Rails.application.config.guard
end
def self.allowed?(action, current_groups, reference = nil)
View
@@ -0,0 +1,22 @@
+require 'virtus'
+module Ixtlan
+ module Guard
+ class Action
+ include Virtus
+
+ attribute :name, String
+ attribute :associations, Array[String]
+ end
+ class Permission
+ include Virtus
+
+ attribute :resource, String
+ attribute :actions, Array[Action], :default => []
+ attribute :deny, Boolean, :default => false
+ attribute :associations, Array[String]
+ end
+ #TODO
+ class GuardException < Exception; end
+ class PermissionDenied < GuardException; end
+ end
+end
@@ -1,4 +1,4 @@
-require 'rails'
+require 'rails/railtie'
require 'ixtlan/guard/guard'
require 'ixtlan/guard/guard_rails'
require 'logger'
View
@@ -7,16 +7,21 @@
def assert(expected, perms)
map = {}
expected.each do |e|
- map[e[:permission][:resource]] = e
- if e[:permission][:actions]
- e[:permission][:actions].sort!{ |n,m| n[:action][:name] <=> m[:action][:name] }
+ map[(e[:permission] || e)[:resource]] = e
+ if (e[:permission] || e)[:actions]
+ (e[:permission] || e)[:actions].sort!{ |n,m| n[:action][:name] <=> m[:action][:name] }
end
end
perms.each do |perm|
- if perm[:actions]
- perm[:actions].sort!{ |n,m| n.content[:name] <=> m.content[:name] }
+ attr = perm.attributes
+ attr[ :actions ] = perm.actions.collect do |a|
+ aa = a.attributes
+ aa.delete( :associations ) if aa[ :associations ].nil?
+ {:action => aa}
end
- map[perm[:resource].to_s].should == perm
+ attr[:actions].sort!{ |n,m| n[:action][:name] <=> m[:action][:name] }
+ attr.delete( :associations ) if attr[ :associations ].nil?
+ map[perm[:resource]][:permission].should == attr
end
end
@@ -184,7 +189,7 @@ def group.name
end
perm = subject.permissions([group])do |resource, groups|
if resource == 'regions'
- [:europe, :asia]
+ ["europe", "asia"]
end
end
expected = [
@@ -219,8 +224,8 @@ def group.name
{:permission=>
{:resource=>"regions",
:actions=>
- [{:action=>{:name=>"show", :associations=>[:europe, :asia]}},
- {:action=>{:name=>"create", :associations=>[:europe, :asia]}}],
+ [{:action=>{:name=>"show", :associations=>["europe", "asia"]}},
+ {:action=>{:name=>"create", :associations=>["europe", "asia"]}}],
:deny=>false}},
#allow nothing
{:permission=>{:resource=>"users", :actions=>[], :deny=>false}}]
@@ -47,7 +47,7 @@ def logger.debug(&block)
end
it 'should add associations to node' do
- perms = subject.permissions([Group.new('admin', [:german, :french])]) do |resource, groups|
+ perms = subject.permissions([Group.new('admin', ["german", "french"])]) do |resource, groups|
if groups && groups.first && groups.first.name == 'admin'
groups.first.domains
else
@@ -61,56 +61,56 @@ def logger.debug(&block)
:resource=>"accounts",
:actions=>[{:action=>{
:name=>"destroy",
- :associations=>[:german, :french]}}],
+ :associations=>["german", "french"]}}],
:deny=>false}
}
expected[:allow_all_defaults] = {
:permission=>{
:resource=>"allow_all_defaults",
:actions=>[{:action=>{:name=>"index"}}],
:deny=>true,
- :associations=>[:german, :french]}
+ :associations=>["german", "french"]}
}
expected[:defaults] = {
:permission=>{
:resource=>"defaults",
:actions=>[{:action=>{
:name=>"index",
- :associations=>[:german, :french]}}],
+ :associations=>["german", "french"]}}],
:deny=>false}
}
expected[:no_defaults] = {
:permission=>{
:resource=>"no_defaults",
:actions=>[{:action=>{
:name=>"index",
- :associations=>[:german, :french]}}],
+ :associations=>["german", "french"]}}],
:deny=>false}
}
expected[:only_defaults] = {
:permission=>{
:resource=>"only_defaults",
:actions=>[],
- :associations=>[:german, :french],
+ :associations=>["german", "french"],
:deny=>true}
}
expected[:person]= {
:permission=>{
:resource=>"person",
:actions=> [{:action=>{
:name=>"destroy",
- :associations=>[:german, :french]}},
+ :associations=>["german", "french"]}},
{:action=>{
:name=>"index",
- :associations=>[:german, :french]}}],
+ :associations=>["german", "french"]}}],
:deny=>false}
}
expected[:regions] = {
:permission=>{
:resource=>"regions",
:actions=>[
- {:action=>{:name=>"create", :associations=>[:german, :french]}},
- {:action=>{:name=>"show", :associations=>[:german, :french]}}
+ {:action=>{:name=>"create", :associations=>["german", "french"]}},
+ {:action=>{:name=>"show", :associations=>["german", "french"]}}
],
:deny=>false}
}
@@ -119,12 +119,17 @@ def logger.debug(&block)
:resource=>"users",
:actions=>[],
:deny=>false}
- }
+ }
perms.each do |perm|
- if perm[:actions]
- perm[:actions].sort!{ |n,m| n.content[:name] <=> m.content[:name] }
+ attr = perm.attributes
+ attr[ :actions ] = perm.actions.collect do |a|
+ aa = a.attributes
+ aa.delete( :associations ) if aa[ :associations ].nil?
+ {:action => aa}
end
- expected[perm[:resource].to_sym].should == perm
+ attr[:actions].sort!{ |n,m| n[:action][:name] <=> m[:action][:name] }
+ attr.delete( :associations ) if attr[ :associations ].nil?
+ expected[perm[:resource].to_sym][:permission].should == attr
end
end
end

0 comments on commit a0ead8e

Please sign in to comment.