Commit 2b683b0d0bf90c84b33ec4ed5c70e3bc787094e2
1 parent
96105e21
Exists in
master
and in
4 other branches
Ability to create project with namespace
Showing
10 changed files
with
62 additions
and
6 deletions
Show diff stats
app/helpers/application_helper.rb
@@ -74,6 +74,18 @@ module ApplicationHelper | @@ -74,6 +74,18 @@ module ApplicationHelper | ||
74 | grouped_options_for_select(options, @ref || @project.default_branch) | 74 | grouped_options_for_select(options, @ref || @project.default_branch) |
75 | end | 75 | end |
76 | 76 | ||
77 | + def namespaces_options | ||
78 | + groups = current_user.namespaces.select {|n| n.type == 'Group'} | ||
79 | + users = current_user.namespaces.reject {|n| n.type == 'Group'} | ||
80 | + | ||
81 | + options = [ | ||
82 | + ["Groups", groups.map {|g| [g.human_name, g.id]} ], | ||
83 | + [ "Users", users.map {|u| [u.human_name, u.id]} ] | ||
84 | + ] | ||
85 | + | ||
86 | + grouped_options_for_select(options, current_user.namespace.id) | ||
87 | + end | ||
88 | + | ||
77 | def search_autocomplete_source | 89 | def search_autocomplete_source |
78 | projects = current_user.projects.map{ |p| { label: p.name, url: project_path(p) } } | 90 | projects = current_user.projects.map{ |p| { label: p.name, url: project_path(p) } } |
79 | 91 |
app/models/group.rb
@@ -14,4 +14,8 @@ class Group < Namespace | @@ -14,4 +14,8 @@ class Group < Namespace | ||
14 | def users | 14 | def users |
15 | User.joins(:users_projects).where(users_projects: {project_id: project_ids}).uniq | 15 | User.joins(:users_projects).where(users_projects: {project_id: project_ids}).uniq |
16 | end | 16 | end |
17 | + | ||
18 | + def human_name | ||
19 | + name | ||
20 | + end | ||
17 | end | 21 | end |
app/models/namespace.rb
app/models/project.rb
@@ -81,10 +81,13 @@ class Project < ActiveRecord::Base | @@ -81,10 +81,13 @@ class Project < ActiveRecord::Base | ||
81 | end | 81 | end |
82 | 82 | ||
83 | def create_by_user(params, user) | 83 | def create_by_user(params, user) |
84 | + namespace_id = params.delete(:namespace_id) || namespace.try(:id) | ||
85 | + | ||
84 | project = Project.new params | 86 | project = Project.new params |
85 | 87 | ||
86 | Project.transaction do | 88 | Project.transaction do |
87 | project.owner = user | 89 | project.owner = user |
90 | + project.namespace_id = namespace_id | ||
88 | project.save! | 91 | project.save! |
89 | 92 | ||
90 | # Add user as project master | 93 | # Add user as project master |
app/models/user.rb
@@ -38,13 +38,16 @@ class User < ActiveRecord::Base | @@ -38,13 +38,16 @@ class User < ActiveRecord::Base | ||
38 | devise :database_authenticatable, :token_authenticatable, :lockable, | 38 | devise :database_authenticatable, :token_authenticatable, :lockable, |
39 | :recoverable, :rememberable, :trackable, :validatable, :omniauthable | 39 | :recoverable, :rememberable, :trackable, :validatable, :omniauthable |
40 | 40 | ||
41 | - attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, | 41 | + attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :username, |
42 | :skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password, | 42 | :skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password, |
43 | :extern_uid, :provider, :as => [:default, :admin] | 43 | :extern_uid, :provider, :as => [:default, :admin] |
44 | attr_accessible :projects_limit, :as => :admin | 44 | attr_accessible :projects_limit, :as => :admin |
45 | 45 | ||
46 | attr_accessor :force_random_password | 46 | attr_accessor :force_random_password |
47 | 47 | ||
48 | + # Namespace for personal projects | ||
49 | + has_one :namespace, class_name: "Namespace", foreign_key: :owner_id, conditions: 'type IS NULL', dependent: :destroy | ||
50 | + | ||
48 | has_many :keys, dependent: :destroy | 51 | has_many :keys, dependent: :destroy |
49 | has_many :projects, through: :users_projects | 52 | has_many :projects, through: :users_projects |
50 | has_many :users_projects, dependent: :destroy | 53 | has_many :users_projects, dependent: :destroy |
@@ -112,4 +115,11 @@ class User < ActiveRecord::Base | @@ -112,4 +115,11 @@ class User < ActiveRecord::Base | ||
112 | self.password = self.password_confirmation = Devise.friendly_token.first(8) | 115 | self.password = self.password_confirmation = Devise.friendly_token.first(8) |
113 | end | 116 | end |
114 | end | 117 | end |
118 | + | ||
119 | + def namespaces | ||
120 | + namespaces = [] | ||
121 | + namespaces << self.namespace | ||
122 | + namespaces = namespaces + Group.all if admin | ||
123 | + namespaces | ||
124 | + end | ||
115 | end | 125 | end |
app/views/profile/account.html.haml
@@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
8 | = link_to authbutton(provider, 32), omniauth_authorize_path(User, provider) | 8 | = link_to authbutton(provider, 32), omniauth_authorize_path(User, provider) |
9 | 9 | ||
10 | 10 | ||
11 | + | ||
11 | %fieldset | 12 | %fieldset |
12 | %legend | 13 | %legend |
13 | Private token | 14 | Private token |
@@ -44,11 +45,25 @@ | @@ -44,11 +45,25 @@ | ||
44 | .input= f.password_field :password | 45 | .input= f.password_field :password |
45 | .clearfix | 46 | .clearfix |
46 | = f.label :password_confirmation | 47 | = f.label :password_confirmation |
47 | - .input= f.password_field :password_confirmation | ||
48 | - .actions | ||
49 | - = f.submit 'Save', class: "btn save-btn" | 48 | + .input |
49 | + = f.password_field :password_confirmation | ||
50 | + .clearfix | ||
51 | + .input | ||
52 | + = f.submit 'Save password', class: "btn save-btn" | ||
50 | 53 | ||
51 | 54 | ||
52 | 55 | ||
56 | +%fieldset | ||
57 | + %legend | ||
58 | + Username | ||
59 | + %small.right | ||
60 | + Changing your username can have unintended side effects! | ||
61 | + = form_for @user, url: profile_update_path, method: :put do |f| | ||
62 | + .padded | ||
63 | + = f.label :username | ||
64 | + .input | ||
65 | + = f.text_field :username | ||
66 | + .input | ||
67 | + = f.submit 'Save username', class: "btn save-btn" | ||
53 | 68 | ||
54 | 69 |
app/views/projects/_new_form.html.haml
@@ -12,6 +12,12 @@ | @@ -12,6 +12,12 @@ | ||
12 | %hr | 12 | %hr |
13 | %div.adv_settings | 13 | %div.adv_settings |
14 | %h6 Advanced settings: | 14 | %h6 Advanced settings: |
15 | + - if current_user.namespaces.size > 1 | ||
16 | + .clearfix | ||
17 | + = f.label :namespace_id do | ||
18 | + Namespace | ||
19 | + .input | ||
20 | + = f.select :namespace_id, namespaces_options, {}, {class: 'chosen'} | ||
15 | .clearfix | 21 | .clearfix |
16 | = f.label :path do | 22 | = f.label :path do |
17 | Git Clone | 23 | Git Clone |
config/routes.rb
@@ -49,7 +49,7 @@ Gitlab::Application.routes.draw do | @@ -49,7 +49,7 @@ Gitlab::Application.routes.draw do | ||
49 | delete :remove_project | 49 | delete :remove_project |
50 | end | 50 | end |
51 | end | 51 | end |
52 | - resources :projects, constraints: { id: /[^\/]+/ } do | 52 | + resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do |
53 | member do | 53 | member do |
54 | get :team | 54 | get :team |
55 | put :team_update | 55 | put :team_update |
db/schema.rb
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | # | 11 | # |
12 | # It's strongly recommended to check this file into your version control system. | 12 | # It's strongly recommended to check this file into your version control system. |
13 | 13 | ||
14 | -ActiveRecord::Schema.define(:version => 20121122150932) do | 14 | +ActiveRecord::Schema.define(:version => 20121123104937) do |
15 | 15 | ||
16 | create_table "events", :force => true do |t| | 16 | create_table "events", :force => true do |t| |
17 | t.string "target_type" | 17 | t.string "target_type" |
@@ -195,6 +195,7 @@ ActiveRecord::Schema.define(:version => 20121122150932) do | @@ -195,6 +195,7 @@ ActiveRecord::Schema.define(:version => 20121122150932) do | ||
195 | t.datetime "locked_at" | 195 | t.datetime "locked_at" |
196 | t.string "extern_uid" | 196 | t.string "extern_uid" |
197 | t.string "provider" | 197 | t.string "provider" |
198 | + t.string "username" | ||
198 | end | 199 | end |
199 | 200 | ||
200 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true | 201 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true |
spec/models/user_spec.rb
@@ -36,6 +36,7 @@ require 'spec_helper' | @@ -36,6 +36,7 @@ require 'spec_helper' | ||
36 | 36 | ||
37 | describe User do | 37 | describe User do |
38 | describe "Associations" do | 38 | describe "Associations" do |
39 | + it { should have_one(:namespace) } | ||
39 | it { should have_many(:users_projects).dependent(:destroy) } | 40 | it { should have_many(:users_projects).dependent(:destroy) } |
40 | it { should have_many(:projects) } | 41 | it { should have_many(:projects) } |
41 | it { should have_many(:my_own_projects).class_name('Project') } | 42 | it { should have_many(:my_own_projects).class_name('Project') } |