authorized_projects and authorized_groups methods for user
This commit is contained in:
parent
83f2a387d6
commit
9df6f7bfad
4 changed files with 26 additions and 16 deletions
|
@ -76,6 +76,11 @@ class Project < ActiveRecord::Base
|
|||
scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") }
|
||||
|
||||
class << self
|
||||
def 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
|
||||
|
||||
def active
|
||||
joins(:issues, :notes, :merge_requests).order("issues.created_at, notes.created_at, merge_requests.created_at DESC")
|
||||
end
|
||||
|
@ -285,9 +290,4 @@ 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
|
||||
|
|
|
@ -124,11 +124,15 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def accessed_groups
|
||||
@accessed_groups ||= begin
|
||||
def authorized_groups
|
||||
@authorized_groups ||= begin
|
||||
groups = Group.where(id: self.projects.pluck(:namespace_id)).all
|
||||
groups = groups + self.groups
|
||||
groups.uniq
|
||||
end
|
||||
end
|
||||
|
||||
def authorized_projects
|
||||
Project.authorized_for(self)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue