Commit 1d889a79fb85a39bf240444b1beaa23efec035c3
1 parent
ff9a2e2a
Exists in
master
and in
4 other branches
Fix group duplication on dashboard and project order in group
Showing
4 changed files
with
15 additions
and
7 deletions
Show diff stats
app/controllers/groups_controller.rb
... | ... | @@ -54,10 +54,12 @@ class GroupsController < ApplicationController |
54 | 54 | end |
55 | 55 | |
56 | 56 | def projects |
57 | - @projects ||= if can?(current_user, :manage_group, @group) | |
58 | - @group.projects.all | |
59 | - else | |
60 | - current_user.projects_sorted_by_activity.where(namespace_id: @group.id) | |
57 | + @projects ||= begin | |
58 | + if can?(current_user, :manage_group, @group) | |
59 | + @group.projects | |
60 | + else | |
61 | + current_user.projects.where(namespace_id: @group.id) | |
62 | + end.sorted_by_activity.all | |
61 | 63 | end |
62 | 64 | end |
63 | 65 | ... | ... |
app/models/project.rb
... | ... | @@ -73,7 +73,7 @@ class Project < ActiveRecord::Base |
73 | 73 | scope :public_only, where(private_flag: false) |
74 | 74 | scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } |
75 | 75 | scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } |
76 | - scope :authorized_for, ->(user) { joins(:users_projects) { where(user_id: user.id) } } | |
76 | + scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } | |
77 | 77 | |
78 | 78 | class << self |
79 | 79 | def active |
... | ... | @@ -285,4 +285,9 @@ class Project < ActiveRecord::Base |
285 | 285 | merge_requests |
286 | 286 | end |
287 | 287 | end |
288 | + | |
289 | + def self.authorized_for user | |
290 | + projects = includes(:users_projects, :namespace) | |
291 | + 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) | |
292 | + end | |
288 | 293 | end | ... | ... |
app/models/user.rb
... | ... | @@ -127,7 +127,8 @@ class User < ActiveRecord::Base |
127 | 127 | def accessed_groups |
128 | 128 | @accessed_groups ||= begin |
129 | 129 | groups = Group.where(id: self.projects.pluck(:namespace_id)).all |
130 | - groups + self.groups | |
130 | + groups = groups + self.groups | |
131 | + groups.uniq | |
131 | 132 | end |
132 | 133 | end |
133 | 134 | end | ... | ... |
app/roles/account.rb