Commit d431e433 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix few bugs and tests after refactoring ownership logic

parent 00a1f5bc
......@@ -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
......
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
......
......@@ -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
......
......@@ -73,7 +73,7 @@ class Key < ActiveRecord::Base
if is_deploy_key
[project]
else
user.projects
user.authorized_projects
end
end
......
......@@ -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") }
......
......@@ -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
......@@ -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
......
......@@ -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"
......
......@@ -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)
......
......@@ -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
......
......@@ -9,7 +9,7 @@ module Gitlab
# Example Request:
# GET /projects
get do
@projects = paginate current_user.projects
@projects = paginate current_user.authorized_projects
present @projects, with: Entities::Project
end
......
......@@ -37,7 +37,7 @@ FactoryGirl.define do
end
factory :namespace do
sequence(:name) { |n| "group#{n}" }
sequence(:name) { |n| "namespace#{n}" }
path { name.downcase.gsub(/\s/, '_') }
owner
end
......
......@@ -4,7 +4,7 @@ describe Gitlab::API do
include ApiHelpers
let(:user) { create(:user) }
let!(:project) { create(:project, owner: user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, author: user, assignee: user, project: project) }
before { project.add_access(user, :read) }
......
......@@ -4,7 +4,7 @@ describe Gitlab::API do
include ApiHelpers
let(:user) { create(:user ) }
let!(:project) { create(:project, owner: user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") }
before { project.add_access(user, :read) }
......
......@@ -4,7 +4,7 @@ describe Gitlab::API do
include ApiHelpers
let(:user) { create(:user) }
let!(:project) { create(:project, owner: user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:milestone) { create(:milestone, project: project) }
before { project.add_access(user, :read) }
......
......@@ -4,7 +4,7 @@ describe Gitlab::API do
include ApiHelpers
let(:user) { create(:user) }
let!(:project) { create(:project, owner: user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, project: project, author: user) }
let!(:snippet) { create(:snippet, project: project, author: user) }
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
......
This diff is collapsed.
......@@ -5,7 +5,7 @@ describe "Projects" do
describe "GET /projects/show" do
before do
@project = create(:project, owner: @user)
@project = create(:project, namespace: @user.namespace)
@project.add_access(@user, :read)
visit project_path(@project)
......@@ -37,7 +37,7 @@ describe "Projects" do
describe "PUT /projects/:id" do
before do
@project = create(:project, owner: @user)
@project = create(:project, namespace: @user.namespace)
@project.add_access(@user, :admin, :read)
visit edit_project_path(@project)
......@@ -58,7 +58,7 @@ describe "Projects" do
describe "DELETE /projects/:id" do
before do
@project = create(:project, owner: @user)
@project = create(:project, namespace: @user.namespace)
@project.add_access(@user, :read, :admin)
visit edit_project_path(@project)
end
......
......@@ -38,7 +38,7 @@ RSpec.configure do |config|
stub_gitolite!
# !!! Observers disabled by default in tests
ActiveRecord::Base.observers.disable(:all)
#ActiveRecord::Base.observers.disable(:all)
# ActiveRecord::Base.observers.enable(:all)
# Use tmp dir for FS manipulations
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment