summaryrefslogtreecommitdiffstats
path: root/app/models/principal.rb
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-06-29 14:42:54 +0000
committerGo MAEDA <maeda@farend.jp>2023-06-29 14:42:54 +0000
commit945a82b5c0aad6bd6af656865015277d3e0e612b (patch)
treed6bf1c4e7fdf2bb5d32b55ae7e5c0477b31377c9 /app/models/principal.rb
parentebf3fb3b4fa53f3bc6f9cbbcd529c6b296d4f6fc (diff)
downloadredmine-945a82b5c0aad6bd6af656865015277d3e0e612b.tar.gz
redmine-945a82b5c0aad6bd6af656865015277d3e0e612b.zip
<=> operator should return nil when invoked with an incomparable object (#38772).
Patch by Go MAEDA. git-svn-id: https://svn.redmine.org/redmine/trunk@22269 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/principal.rb')
-rw-r--r--app/models/principal.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/models/principal.rb b/app/models/principal.rb
index e62b5f320..4cce97e26 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -151,9 +151,11 @@ class Principal < ActiveRecord::Base
end
def <=>(principal)
- if principal.nil?
- -1
- elsif self.class.name == principal.class.name
+ # avoid an error when sorting members without roles (#10053)
+ return -1 if principal.nil?
+ return nil unless principal.is_a?(Principal)
+
+ if self.class.name == principal.class.name
self.to_s.casecmp(principal.to_s)
else
# groups after users