From 9a0ea1350131368b9b723f1a9581bbfffe7c43f8 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Tue, 16 Aug 2016 16:29:19 -0700 Subject: [PATCH] factor in global permissions --- app/policies/base_policy.rb | 4 ++-- app/policies/global_policy.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 app/policies/global_policy.rb diff --git a/app/policies/base_policy.rb b/app/policies/base_policy.rb index 12f60d8f76e..5a5b99c81c8 100644 --- a/app/policies/base_policy.rb +++ b/app/policies/base_policy.rb @@ -4,6 +4,8 @@ class BasePolicy end def self.class_for(subject) + return GlobalPolicy if subject.nil? + subject.class.ancestors.each do |klass| next unless klass.name @@ -59,8 +61,6 @@ class BasePolicy private def collect_rules(&b) - return Set.new if @subject.nil? - @can = Set.new @cannot = Set.new yield diff --git a/app/policies/global_policy.rb b/app/policies/global_policy.rb new file mode 100644 index 00000000000..94a2906444a --- /dev/null +++ b/app/policies/global_policy.rb @@ -0,0 +1,7 @@ +class GlobalPolicy < BasePolicy + def rules + return unless @user + can! :create_group if @user.can_create_group + can! :read_users_list + end +end