lib/permissive/has_permissions.rb in permissive-0.2.7.alpha vs lib/permissive/has_permissions.rb in permissive-0.2.8.alpha

- old
+ new

@@ -47,11 +47,10 @@ proxy_owner.permissions.push(permission) else permission.save! end permission - # raise 'set' end def can?(*args) options = args.extract_options! options.assert_valid_keys(:in, :on) @@ -81,12 +80,13 @@ end def bits_for(scope, permissions) on = Permissive::PermissionDefinition.normalize_scope(proxy_owner.class, scope) permissions.flatten.map do |permission| - proxy_owner.class.permissions[on].try(:permissions).try(:[], permission.to_s.underscore.gsub('/', '_').to_sym) || raise(Permissive::InvalidPermissionError.new("#{proxy_owner.class.name} does not have a#{'n' if permission.to_s[0, 1].downcase =~ /[aeiou]/} #{permission} permission#{" on #{on}" if on}")) - end + permission = permission.to_s.underscore.gsub('/', '_').to_sym + proxy_owner.class.permissions[on].try(:permissions).try(:[], permission) || proxy_owner.class.permissions[:global].try(:permissions).try(:[], permission)# || raise(Permissive::InvalidPermissionError.new("#{proxy_owner.class.name} does not have a#{'n' if permission.to_s[0, 1].downcase =~ /[aeiou]/} #{permission} permission#{" on #{on}" if on}")) + end.compact end private :bits_for end delegate :can!, :can?, :revoke, :to => :permissions @@ -115,10 +115,11 @@ scope = Permissive::PermissionDefinition.normalize_scope(self.class, options[:on]) else scope = :global end permissions = permissions.split('_and_') - if permissions.all? {|permission| self.class.permissions[scope].permissions.has_key?(permission.downcase.to_sym) } + if permissions.all? {|permission| self.class.permissions[scope].permissions.has_key?(permission.downcase.to_sym) || + self.class.permissions[:global].permissions.has_key?(permission.downcase.to_sym) } if revoke class_eval <<-end_eval def #{method}(scope = nil) revoke(#{[permissions, args].flatten.join(', ').inspect}, :on => scope) end