Fix few bugs and tests after refactoring ownership logic

This commit is contained in:
Dmitriy Zaporozhets 2013-01-02 19:32:34 +02:00
parent 00a1f5bc2c
commit d431e43392
19 changed files with 58 additions and 61 deletions

View file

@ -29,21 +29,10 @@ class Ability
rules << project_guest_rules
end
if project.namespace
# If user own project namespace
# (Ex. group owner or account owner)
if project.namespace.owner == user
rules << project_admin_rules
end
else
# For compatibility with global projects
# use projects.owner_id
if project.owner == user
rules << project_admin_rules
end
if project.owner == user
rules << project_admin_rules
end
rules.flatten
end

View file

@ -73,7 +73,7 @@ class Key < ActiveRecord::Base
if is_deploy_key
[project]
else
user.projects
user.authorized_projects
end
end

View file

@ -80,7 +80,7 @@ class Project < ActiveRecord::Base
# Scopes
scope :public_only, where(private_flag: false)
scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) }
scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) }
scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) }
scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) }
scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") }

View file

@ -187,4 +187,9 @@ class User < ActiveRecord::Base
(projects.namespace_id IS NULL AND projects.creator_id = :user_id)",
namespaces: namespaces.map(&:id), user_id: self.id)
end
# Team membership in personal projects
def tm_in_personal_projects
personal_projects.users_projects.where(user_id: self.id)
end
end