]> source.dussan.org Git - redmine.git/commitdiff
Use .unscoped when querying and creating builtin objects (#24156).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 3 Dec 2016 08:57:01 +0000 (08:57 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 3 Dec 2016 08:57:01 +0000 (08:57 +0000)
Patch by Holger Just.

git-svn-id: http://svn.redmine.org/redmine/trunk@16049 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/group_builtin.rb
app/models/role.rb
app/models/user.rb

index 9cedb61df6f099d84038c89b232587e5691a073c..29e1d8e2accec7e56ba406e2f92538254dc0974b 100644 (file)
@@ -37,12 +37,12 @@ class GroupBuiltin < Group
   class << self
     def load_instance
       return nil if self == GroupBuiltin
-      instance = order('id').first || create_instance
+      instance = unscoped.order('id').first || create_instance
     end
 
     def create_instance
       raise 'The builtin group already exists.' if exists?
-      instance = new
+      instance = unscoped.new
       instance.lastname = name
       instance.save :validate => false
       raise 'Unable to create builtin group.' if instance.new_record?
index 8b4dbde869f2421eaf34937a702160a0cc3742de..b85d5a6b0135c6dc5a045085ad432585a9682373 100644 (file)
@@ -294,9 +294,9 @@ private
   end
 
   def self.find_or_create_system_role(builtin, name)
-    role = where(:builtin => builtin).first
+    role = unscoped.where(:builtin => builtin).first
     if role.nil?
-      role = create(:name => name) do |r|
+      role = unscoped.create(:name => name) do |r|
         r.builtin = builtin
       end
       raise "Unable to create the #{name} role (#{role.errors.full_messages.join(',')})." if role.new_record?
index 81a2e7c77924c3c08f7819a2bc998639c4070e02..76b54c896935a6e5ee662d5409e6ee7e8d915076 100644 (file)
@@ -750,9 +750,9 @@ class User < Principal
   # Returns the anonymous user.  If the anonymous user does not exist, it is created.  There can be only
   # one anonymous user per database.
   def self.anonymous
-    anonymous_user = AnonymousUser.first
+    anonymous_user = AnonymousUser.unscoped.first
     if anonymous_user.nil?
-      anonymous_user = AnonymousUser.create(:lastname => 'Anonymous', :firstname => '', :login => '', :status => 0)
+      anonymous_user = AnonymousUser.unscoped.create(:lastname => 'Anonymous', :firstname => '', :login => '', :status => 0)
       raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
     end
     anonymous_user