Ability to create project with namespace
This commit is contained in:
parent
96105e214f
commit
2b683b0d0b
10 changed files with 62 additions and 6 deletions
|
@ -74,6 +74,18 @@ module ApplicationHelper
|
||||||
grouped_options_for_select(options, @ref || @project.default_branch)
|
grouped_options_for_select(options, @ref || @project.default_branch)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def namespaces_options
|
||||||
|
groups = current_user.namespaces.select {|n| n.type == 'Group'}
|
||||||
|
users = current_user.namespaces.reject {|n| n.type == 'Group'}
|
||||||
|
|
||||||
|
options = [
|
||||||
|
["Groups", groups.map {|g| [g.human_name, g.id]} ],
|
||||||
|
[ "Users", users.map {|u| [u.human_name, u.id]} ]
|
||||||
|
]
|
||||||
|
|
||||||
|
grouped_options_for_select(options, current_user.namespace.id)
|
||||||
|
end
|
||||||
|
|
||||||
def search_autocomplete_source
|
def search_autocomplete_source
|
||||||
projects = current_user.projects.map{ |p| { label: p.name, url: project_path(p) } }
|
projects = current_user.projects.map{ |p| { label: p.name, url: project_path(p) } }
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,8 @@ class Group < Namespace
|
||||||
def users
|
def users
|
||||||
User.joins(:users_projects).where(users_projects: {project_id: project_ids}).uniq
|
User.joins(:users_projects).where(users_projects: {project_id: project_ids}).uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def human_name
|
||||||
|
name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,4 +17,8 @@ class Namespace < ActiveRecord::Base
|
||||||
def to_param
|
def to_param
|
||||||
code
|
code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def human_name
|
||||||
|
owner_name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,10 +81,13 @@ class Project < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_by_user(params, user)
|
def create_by_user(params, user)
|
||||||
|
namespace_id = params.delete(:namespace_id) || namespace.try(:id)
|
||||||
|
|
||||||
project = Project.new params
|
project = Project.new params
|
||||||
|
|
||||||
Project.transaction do
|
Project.transaction do
|
||||||
project.owner = user
|
project.owner = user
|
||||||
|
project.namespace_id = namespace_id
|
||||||
project.save!
|
project.save!
|
||||||
|
|
||||||
# Add user as project master
|
# Add user as project master
|
||||||
|
|
|
@ -38,13 +38,16 @@ class User < ActiveRecord::Base
|
||||||
devise :database_authenticatable, :token_authenticatable, :lockable,
|
devise :database_authenticatable, :token_authenticatable, :lockable,
|
||||||
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
|
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
|
||||||
|
|
||||||
attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name,
|
attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :username,
|
||||||
:skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password,
|
:skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password,
|
||||||
:extern_uid, :provider, :as => [:default, :admin]
|
:extern_uid, :provider, :as => [:default, :admin]
|
||||||
attr_accessible :projects_limit, :as => :admin
|
attr_accessible :projects_limit, :as => :admin
|
||||||
|
|
||||||
attr_accessor :force_random_password
|
attr_accessor :force_random_password
|
||||||
|
|
||||||
|
# Namespace for personal projects
|
||||||
|
has_one :namespace, class_name: "Namespace", foreign_key: :owner_id, conditions: 'type IS NULL', dependent: :destroy
|
||||||
|
|
||||||
has_many :keys, dependent: :destroy
|
has_many :keys, dependent: :destroy
|
||||||
has_many :projects, through: :users_projects
|
has_many :projects, through: :users_projects
|
||||||
has_many :users_projects, dependent: :destroy
|
has_many :users_projects, dependent: :destroy
|
||||||
|
@ -112,4 +115,11 @@ class User < ActiveRecord::Base
|
||||||
self.password = self.password_confirmation = Devise.friendly_token.first(8)
|
self.password = self.password_confirmation = Devise.friendly_token.first(8)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def namespaces
|
||||||
|
namespaces = []
|
||||||
|
namespaces << self.namespace
|
||||||
|
namespaces = namespaces + Group.all if admin
|
||||||
|
namespaces
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
= link_to authbutton(provider, 32), omniauth_authorize_path(User, provider)
|
= link_to authbutton(provider, 32), omniauth_authorize_path(User, provider)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%fieldset
|
%fieldset
|
||||||
%legend
|
%legend
|
||||||
Private token
|
Private token
|
||||||
|
@ -44,11 +45,25 @@
|
||||||
.input= f.password_field :password
|
.input= f.password_field :password
|
||||||
.clearfix
|
.clearfix
|
||||||
= f.label :password_confirmation
|
= f.label :password_confirmation
|
||||||
.input= f.password_field :password_confirmation
|
.input
|
||||||
.actions
|
= f.password_field :password_confirmation
|
||||||
= f.submit 'Save', class: "btn save-btn"
|
.clearfix
|
||||||
|
.input
|
||||||
|
= f.submit 'Save password', class: "btn save-btn"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%fieldset
|
||||||
|
%legend
|
||||||
|
Username
|
||||||
|
%small.right
|
||||||
|
Changing your username can have unintended side effects!
|
||||||
|
= form_for @user, url: profile_update_path, method: :put do |f|
|
||||||
|
.padded
|
||||||
|
= f.label :username
|
||||||
|
.input
|
||||||
|
= f.text_field :username
|
||||||
|
.input
|
||||||
|
= f.submit 'Save username', class: "btn save-btn"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,12 @@
|
||||||
%hr
|
%hr
|
||||||
%div.adv_settings
|
%div.adv_settings
|
||||||
%h6 Advanced settings:
|
%h6 Advanced settings:
|
||||||
|
- if current_user.namespaces.size > 1
|
||||||
|
.clearfix
|
||||||
|
= f.label :namespace_id do
|
||||||
|
Namespace
|
||||||
|
.input
|
||||||
|
= f.select :namespace_id, namespaces_options, {}, {class: 'chosen'}
|
||||||
.clearfix
|
.clearfix
|
||||||
= f.label :path do
|
= f.label :path do
|
||||||
Git Clone
|
Git Clone
|
||||||
|
|
|
@ -49,7 +49,7 @@ Gitlab::Application.routes.draw do
|
||||||
delete :remove_project
|
delete :remove_project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :projects, constraints: { id: /[^\/]+/ } do
|
resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
|
||||||
member do
|
member do
|
||||||
get :team
|
get :team
|
||||||
put :team_update
|
put :team_update
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20121122150932) do
|
ActiveRecord::Schema.define(:version => 20121123104937) do
|
||||||
|
|
||||||
create_table "events", :force => true do |t|
|
create_table "events", :force => true do |t|
|
||||||
t.string "target_type"
|
t.string "target_type"
|
||||||
|
@ -195,6 +195,7 @@ ActiveRecord::Schema.define(:version => 20121122150932) do
|
||||||
t.datetime "locked_at"
|
t.datetime "locked_at"
|
||||||
t.string "extern_uid"
|
t.string "extern_uid"
|
||||||
t.string "provider"
|
t.string "provider"
|
||||||
|
t.string "username"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||||
|
|
|
@ -36,6 +36,7 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe User do
|
describe User do
|
||||||
describe "Associations" do
|
describe "Associations" do
|
||||||
|
it { should have_one(:namespace) }
|
||||||
it { should have_many(:users_projects).dependent(:destroy) }
|
it { should have_many(:users_projects).dependent(:destroy) }
|
||||||
it { should have_many(:projects) }
|
it { should have_many(:projects) }
|
||||||
it { should have_many(:my_own_projects).class_name('Project') }
|
it { should have_many(:my_own_projects).class_name('Project') }
|
||||||
|
|
Loading…
Add table
Reference in a new issue