lib/ixtlan/guard/guard.rb in ixtlan-guard-0.8.3 vs lib/ixtlan/guard/guard.rb in ixtlan-guard-0.9.0

- old
+ new

@@ -1,7 +1,7 @@ require 'ixtlan/guard/guard_config' - +require 'ixtlan/guard/models' module Ixtlan module Guard class Guard attr_reader :superuser @@ -101,13 +101,13 @@ group_map = group_map(current_groups) perms = [] m = @config.map_of_all m.each do |resource, actions| nodes = [] - perm = Node.new(:permission) - perm[:resource] = resource - perm[:actions] = nodes + perm = Permission.new #Node.new(:permission) + perm.resource = resource + perm.actions = []#nodes # setup default_groups default_groups = actions.delete('defaults') || [] default_groups = group_map.keys & (default_groups + @superuser) unless default_groups.member?('*') @@ -120,67 +120,47 @@ # actions # deny = false : default_groups == [] # deny = true : default_groups.member?('*') default_groups.size != 0 || default_groups.member?('*') end - perm[:deny] = deny + perm.deny = deny actions.each do |action, groups| group_names = groups.collect { |g| g.is_a?(Hash) ? g.keys : g }.flatten if groups - node = 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 + node.name = action if block if allowed_groups.size > 0 assos = block.call(resource, allowed_groups) - node[:associations] = assos if assos && assos.size > 0 + node.associations = assos if assos && assos.size > 0 else assos = block.call(resource, group_map.values) - perm[:associations] = assos if assos && assos.size > 0 + 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 + perm.associations = assos if assos && assos.size > 0 end end # TODO is that right like this ? # only default_groups, i.e. no actions !!! if block && actions.size == 0 && deny assos = block.call(resource, group_map.values) - perm[:associations] = assos if assos && assos.size > 0 + perm.associations = assos if assos && assos.size > 0 end perms << perm end perms end end - class Node < Hash - - attr_reader :content - - def initialize(name) - map = super - @content = {} - merge!({ name => @content }) - end - - def []=(k,v) - @content[k] = v - end - def [](k) - @content[k] - end - end - class GuardException < Exception; end - class PermissionDenied < GuardException; end end end