OSDN Git Service

Set default order to authorized_project and authorized_groups
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Sat, 22 Jun 2013 10:39:34 +0000 (13:39 +0300)
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Sat, 22 Jun 2013 10:39:34 +0000 (13:39 +0300)
app/models/project.rb
app/models/user.rb

index c1405a7..4beba83 100644 (file)
@@ -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) }
index 30f5aae..cf42d73 100644 (file)
@@ -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