diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-11-29 16:43:09 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-11-29 16:43:09 +0200 |
commit | 1d889a79fb85a39bf240444b1beaa23efec035c3 (patch) | |
tree | edb79292c362b8ef91d74cf2f0fda791ff3d7f21 | |
parent | ff9a2e2a9399bf1d190de7fab2d1d26b70433b19 (diff) | |
download | gitlab-ce-1d889a79fb85a39bf240444b1beaa23efec035c3.tar.gz |
Fix group duplication on dashboard and project order in group
-rw-r--r-- | app/controllers/groups_controller.rb | 10 | ||||
-rw-r--r-- | app/models/project.rb | 7 | ||||
-rw-r--r-- | app/models/user.rb | 3 | ||||
-rw-r--r-- | app/roles/account.rb | 2 |
4 files changed, 15 insertions, 7 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 6fd5de8abf9..cfa7e89f7f2 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -54,10 +54,12 @@ class GroupsController < ApplicationController end def projects - @projects ||= if can?(current_user, :manage_group, @group) - @group.projects.all - else - current_user.projects_sorted_by_activity.where(namespace_id: @group.id) + @projects ||= begin + if can?(current_user, :manage_group, @group) + @group.projects + else + current_user.projects.where(namespace_id: @group.id) + end.sorted_by_activity.all end end diff --git a/app/models/project.rb b/app/models/project.rb index 8df662db9a0..68d09cae345 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -73,7 +73,7 @@ class Project < ActiveRecord::Base scope :public_only, where(private_flag: false) scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } - scope :authorized_for, ->(user) { joins(:users_projects) { where(user_id: user.id) } } + scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } class << self def active @@ -285,4 +285,9 @@ class Project < ActiveRecord::Base merge_requests end end + + def self.authorized_for user + projects = includes(:users_projects, :namespace) + projects = projects.where("users_projects.user_id = :user_id or projects.owner_id = :user_id or namespaces.owner_id = :user_id", user_id: user.id) + end end diff --git a/app/models/user.rb b/app/models/user.rb index d43e3cbb6b6..4ec4c277141 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -127,7 +127,8 @@ class User < ActiveRecord::Base def accessed_groups @accessed_groups ||= begin groups = Group.where(id: self.projects.pluck(:namespace_id)).all - groups + self.groups + groups = groups + self.groups + groups.uniq end end end diff --git a/app/roles/account.rb b/app/roles/account.rb index 6df11d64527..8157898fef1 100644 --- a/app/roles/account.rb +++ b/app/roles/account.rb @@ -80,7 +80,7 @@ module Account end def projects_sorted_by_activity - projects.order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") + projects.sorted_by_activity end def namespaces |