From 19d628dd239f03e950a41c4498131f9b2a221909 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 22 Jun 2013 13:39:34 +0300 Subject: [PATCH] Set default order to authorized_project and authorized_groups --- app/models/project.rb | 2 +- app/models/user.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index c1405a70b..4beba83df 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -100,7 +100,7 @@ class Project < ActiveRecord::Base scope :in_team, ->(team) { where("projects.id IN (:ids)", ids: team.projects.map(&:id)) } scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } scope :in_group_namespace, -> { joins(:group) } - scope :sorted_by_activity, -> { order("projects.last_activity_at DESC") } + scope :sorted_by_activity, -> { reorder("projects.last_activity_at DESC") } scope :personal, ->(user) { where(namespace_id: user.namespace_id) } scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) } scope :public_only, -> { where(public: true) } diff --git a/app/models/user.rb b/app/models/user.rb index 30f5aae0b..cf42d7360 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -231,7 +231,7 @@ class User < ActiveRecord::Base def authorized_groups @authorized_groups ||= begin group_ids = (groups.pluck(:id) + own_groups.pluck(:id) + authorized_projects.pluck(:namespace_id)) - Group.where(id: group_ids) + Group.where(id: group_ids).order('namespaces.name ASC') end end @@ -240,7 +240,7 @@ class User < ActiveRecord::Base def authorized_projects @authorized_projects ||= begin project_ids = (owned_projects.pluck(:id) + groups_projects.pluck(:id) + projects.pluck(:id)).uniq - Project.where(id: project_ids).includes(:namespace) + Project.where(id: project_ids).joins(:namespace).order('namespaces.name ASC') end end -- 2.11.0