BigW Consortium Gitlab

Commit d431e433 by Dmitriy Zaporozhets

Fix few bugs and tests after refactoring ownership logic

parent 00a1f5bc
...@@ -9,7 +9,7 @@ class Admin::UsersController < AdminController ...@@ -9,7 +9,7 @@ class Admin::UsersController < AdminController
def show def show
@admin_user = User.find(params[:id]) @admin_user = User.find(params[:id])
@projects = if @admin_user.projects.empty? @projects = if @admin_user.authorized_projects.empty?
Project Project
else else
Project.without_user(@admin_user) Project.without_user(@admin_user)
...@@ -98,7 +98,7 @@ class Admin::UsersController < AdminController ...@@ -98,7 +98,7 @@ class Admin::UsersController < AdminController
def destroy def destroy
@admin_user = User.find(params[:id]) @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 redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return
end end
@admin_user.destroy @admin_user.destroy
......
module NamespacesHelper module NamespacesHelper
def namespaces_options(selected = :current_user, scope = :default) 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 users = if scope == :all
Namespace.root Namespace.root
......
...@@ -29,20 +29,9 @@ class Ability ...@@ -29,20 +29,9 @@ class Ability
rules << project_guest_rules rules << project_guest_rules
end 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 if project.owner == user
rules << project_admin_rules rules << project_admin_rules
end end
end
rules.flatten rules.flatten
end end
......
...@@ -73,7 +73,7 @@ class Key < ActiveRecord::Base ...@@ -73,7 +73,7 @@ class Key < ActiveRecord::Base
if is_deploy_key if is_deploy_key
[project] [project]
else else
user.projects user.authorized_projects
end end
end end
......
...@@ -80,7 +80,7 @@ class Project < ActiveRecord::Base ...@@ -80,7 +80,7 @@ class Project < ActiveRecord::Base
# Scopes # Scopes
scope :public_only, where(private_flag: false) 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 :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) }
scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } 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") } 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 ...@@ -187,4 +187,9 @@ class User < ActiveRecord::Base
(projects.namespace_id IS NULL AND projects.creator_id = :user_id)", (projects.namespace_id IS NULL AND projects.creator_id = :user_id)",
namespaces: namespaces.map(&:id), user_id: self.id) namespaces: namespaces.map(&:id), user_id: self.id)
end end
# Team membership in personal projects
def tm_in_personal_projects
personal_projects.users_projects.where(user_id: self.id)
end
end end
...@@ -69,7 +69,7 @@ module Account ...@@ -69,7 +69,7 @@ module Account
def projects_limit_percent def projects_limit_percent
return 100 if projects_limit.zero? return 100 if projects_limit.zero?
(my_own_projects.count.to_f / projects_limit) * 100 (personal_projects.count.to_f / projects_limit) * 100
end end
def recent_push project_id = nil def recent_push project_id = nil
......
...@@ -28,7 +28,10 @@ ...@@ -28,7 +28,10 @@
%span.monospace= project.path_with_namespace + ".git" %span.monospace= project.path_with_namespace + ".git"
%td= project.users_projects.count %td= project.users_projects.count
%td %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= last_commit(project)
%td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small" %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" %td.bgred= link_to 'Destroy', [:admin, project], confirm: "REMOVE #{project.name}? Are you sure?", method: :delete, class: "btn small danger"
......
...@@ -106,8 +106,8 @@ ...@@ -106,8 +106,8 @@
%td= link_to group.name, admin_group_path(group) %td= link_to group.name, admin_group_path(group)
- if @admin_user.projects.present? - if @admin_user.personal_projects.present?
%h5 Projects: %h5 Personal Projects:
%br %br
%table.zebra-striped %table.zebra-striped
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
%th %th
%th %th
- @admin_user.users_projects.each do |tm| - @admin_user.tm_in_personal_projects.each do |tm|
- project = tm.project - project = tm.project
%tr %tr
%td= link_to project.name_with_namespace, admin_project_path(project) %td= link_to project.name_with_namespace, admin_project_path(project)
......
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
%legend %legend
Personal projects: Personal projects:
%small.right %small.right
%span= current_user.my_own_projects.count %span= current_user.personal_projects.count
of of
%span= current_user.projects_limit %span= current_user.projects_limit
.padded .padded
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
# Example Request: # Example Request:
# GET /projects # GET /projects
get do get do
@projects = paginate current_user.projects @projects = paginate current_user.authorized_projects
present @projects, with: Entities::Project present @projects, with: Entities::Project
end end
......
...@@ -37,7 +37,7 @@ FactoryGirl.define do ...@@ -37,7 +37,7 @@ FactoryGirl.define do
end end
factory :namespace do factory :namespace do
sequence(:name) { |n| "group#{n}" } sequence(:name) { |n| "namespace#{n}" }
path { name.downcase.gsub(/\s/, '_') } path { name.downcase.gsub(/\s/, '_') }
owner owner
end end
......
...@@ -4,7 +4,7 @@ describe Gitlab::API do ...@@ -4,7 +4,7 @@ describe Gitlab::API do
include ApiHelpers include ApiHelpers
let(:user) { create(:user) } 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) } let!(:issue) { create(:issue, author: user, assignee: user, project: project) }
before { project.add_access(user, :read) } before { project.add_access(user, :read) }
......
...@@ -4,7 +4,7 @@ describe Gitlab::API do ...@@ -4,7 +4,7 @@ describe Gitlab::API do
include ApiHelpers include ApiHelpers
let(:user) { create(:user ) } 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") } let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") }
before { project.add_access(user, :read) } before { project.add_access(user, :read) }
......
...@@ -4,7 +4,7 @@ describe Gitlab::API do ...@@ -4,7 +4,7 @@ describe Gitlab::API do
include ApiHelpers include ApiHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project) { create(:project, owner: user) } let!(:project) { create(:project, namespace: user.namespace ) }
let!(:milestone) { create(:milestone, project: project) } let!(:milestone) { create(:milestone, project: project) }
before { project.add_access(user, :read) } before { project.add_access(user, :read) }
......
...@@ -4,7 +4,7 @@ describe Gitlab::API do ...@@ -4,7 +4,7 @@ describe Gitlab::API do
include ApiHelpers include ApiHelpers
let(:user) { create(:user) } 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!(:issue) { create(:issue, project: project, author: user) }
let!(:snippet) { create(:snippet, project: project, author: user) } let!(:snippet) { create(:snippet, project: project, author: user) }
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) } let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
......
...@@ -5,7 +5,7 @@ describe "Projects" do ...@@ -5,7 +5,7 @@ describe "Projects" do
describe "GET /projects/show" do describe "GET /projects/show" do
before do before do
@project = create(:project, owner: @user) @project = create(:project, namespace: @user.namespace)
@project.add_access(@user, :read) @project.add_access(@user, :read)
visit project_path(@project) visit project_path(@project)
...@@ -37,7 +37,7 @@ describe "Projects" do ...@@ -37,7 +37,7 @@ describe "Projects" do
describe "PUT /projects/:id" do describe "PUT /projects/:id" do
before do before do
@project = create(:project, owner: @user) @project = create(:project, namespace: @user.namespace)
@project.add_access(@user, :admin, :read) @project.add_access(@user, :admin, :read)
visit edit_project_path(@project) visit edit_project_path(@project)
...@@ -58,7 +58,7 @@ describe "Projects" do ...@@ -58,7 +58,7 @@ describe "Projects" do
describe "DELETE /projects/:id" do describe "DELETE /projects/:id" do
before do before do
@project = create(:project, owner: @user) @project = create(:project, namespace: @user.namespace)
@project.add_access(@user, :read, :admin) @project.add_access(@user, :read, :admin)
visit edit_project_path(@project) visit edit_project_path(@project)
end end
......
...@@ -38,7 +38,7 @@ RSpec.configure do |config| ...@@ -38,7 +38,7 @@ RSpec.configure do |config|
stub_gitolite! stub_gitolite!
# !!! Observers disabled by default in tests # !!! Observers disabled by default in tests
ActiveRecord::Base.observers.disable(:all) #ActiveRecord::Base.observers.disable(:all)
# ActiveRecord::Base.observers.enable(:all) # ActiveRecord::Base.observers.enable(:all)
# Use tmp dir for FS manipulations # 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