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

@ -9,7 +9,7 @@ class Admin::UsersController < AdminController
def show
@admin_user = User.find(params[:id])
@projects = if @admin_user.projects.empty?
@projects = if @admin_user.authorized_projects.empty?
Project
else
Project.without_user(@admin_user)
@ -98,7 +98,7 @@ class Admin::UsersController < AdminController
def destroy
@admin_user = User.find(params[:id])
if @admin_user.my_own_projects.count > 0
if @admin_user.personal_projects.count > 0
redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return
end
@admin_user.destroy

View file

@ -1,6 +1,6 @@
module NamespacesHelper
def namespaces_options(selected = :current_user, scope = :default)
groups = current_user.namespaces.select {|n| n.type == 'Group'}
groups = current_user.owned_groups.select {|n| n.type == 'Group'}
users = if scope == :all
Namespace.root

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

View file

@ -69,7 +69,7 @@ module Account
def projects_limit_percent
return 100 if projects_limit.zero?
(my_own_projects.count.to_f / projects_limit) * 100
(personal_projects.count.to_f / projects_limit) * 100
end
def recent_push project_id = nil

View file

@ -28,7 +28,10 @@
%span.monospace= project.path_with_namespace + ".git"
%td= project.users_projects.count
%td
= link_to project.chief.name, [:admin, project.chief]
- if project.owner
= link_to project.owner.name, [:admin, project.owner]
- else
(deleted)
%td= last_commit(project)
%td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small"
%td.bgred= link_to 'Destroy', [:admin, project], confirm: "REMOVE #{project.name}? Are you sure?", method: :delete, class: "btn small danger"

View file

@ -106,8 +106,8 @@
%td= link_to group.name, admin_group_path(group)
- if @admin_user.projects.present?
%h5 Projects:
- if @admin_user.personal_projects.present?
%h5 Personal Projects:
%br
%table.zebra-striped
@ -118,7 +118,7 @@
%th
%th
- @admin_user.users_projects.each do |tm|
- @admin_user.tm_in_personal_projects.each do |tm|
- project = tm.project
%tr
%td= link_to project.name_with_namespace, admin_project_path(project)

View file

@ -64,7 +64,7 @@
%legend
Personal projects:
%small.right
%span= current_user.my_own_projects.count
%span= current_user.personal_projects.count
of
%span= current_user.projects_limit
.padded