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 | 74 | grouped_options_for_select(options, @ref || @project.default_branch) |
| 75 | 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 | 89 | def search_autocomplete_source |
| 78 | 90 | projects = current_user.projects.map{ |p| { label: p.name, url: project_path(p) } } |
| 79 | 91 | ... | ... |
app/models/group.rb
app/models/namespace.rb
app/models/project.rb
| ... | ... | @@ -81,10 +81,13 @@ class Project < ActiveRecord::Base |
| 81 | 81 | end |
| 82 | 82 | |
| 83 | 83 | def create_by_user(params, user) |
| 84 | + namespace_id = params.delete(:namespace_id) || namespace.try(:id) | |
| 85 | + | |
| 84 | 86 | project = Project.new params |
| 85 | 87 | |
| 86 | 88 | Project.transaction do |
| 87 | 89 | project.owner = user |
| 90 | + project.namespace_id = namespace_id | |
| 88 | 91 | project.save! |
| 89 | 92 | |
| 90 | 93 | # Add user as project master | ... | ... |
app/models/user.rb
| ... | ... | @@ -38,13 +38,16 @@ class User < ActiveRecord::Base |
| 38 | 38 | devise :database_authenticatable, :token_authenticatable, :lockable, |
| 39 | 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 | 42 | :skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password, |
| 43 | 43 | :extern_uid, :provider, :as => [:default, :admin] |
| 44 | 44 | attr_accessible :projects_limit, :as => :admin |
| 45 | 45 | |
| 46 | 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 | 51 | has_many :keys, dependent: :destroy |
| 49 | 52 | has_many :projects, through: :users_projects |
| 50 | 53 | has_many :users_projects, dependent: :destroy |
| ... | ... | @@ -112,4 +115,11 @@ class User < ActiveRecord::Base |
| 112 | 115 | self.password = self.password_confirmation = Devise.friendly_token.first(8) |
| 113 | 116 | end |
| 114 | 117 | end |
| 118 | + | |
| 119 | + def namespaces | |
| 120 | + namespaces = [] | |
| 121 | + namespaces << self.namespace | |
| 122 | + namespaces = namespaces + Group.all if admin | |
| 123 | + namespaces | |
| 124 | + end | |
| 115 | 125 | end | ... | ... |
app/views/profile/account.html.haml
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | = link_to authbutton(provider, 32), omniauth_authorize_path(User, provider) |
| 9 | 9 | |
| 10 | 10 | |
| 11 | + | |
| 11 | 12 | %fieldset |
| 12 | 13 | %legend |
| 13 | 14 | Private token |
| ... | ... | @@ -44,11 +45,25 @@ |
| 44 | 45 | .input= f.password_field :password |
| 45 | 46 | .clearfix |
| 46 | 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 | 12 | %hr |
| 13 | 13 | %div.adv_settings |
| 14 | 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 | 21 | .clearfix |
| 16 | 22 | = f.label :path do |
| 17 | 23 | Git Clone | ... | ... |
config/routes.rb
| ... | ... | @@ -49,7 +49,7 @@ Gitlab::Application.routes.draw do |
| 49 | 49 | delete :remove_project |
| 50 | 50 | end |
| 51 | 51 | end |
| 52 | - resources :projects, constraints: { id: /[^\/]+/ } do | |
| 52 | + resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do | |
| 53 | 53 | member do |
| 54 | 54 | get :team |
| 55 | 55 | put :team_update | ... | ... |
db/schema.rb
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | # |
| 12 | 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 | 16 | create_table "events", :force => true do |t| |
| 17 | 17 | t.string "target_type" |
| ... | ... | @@ -195,6 +195,7 @@ ActiveRecord::Schema.define(:version => 20121122150932) do |
| 195 | 195 | t.datetime "locked_at" |
| 196 | 196 | t.string "extern_uid" |
| 197 | 197 | t.string "provider" |
| 198 | + t.string "username" | |
| 198 | 199 | end |
| 199 | 200 | |
| 200 | 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 | 36 | |
| 37 | 37 | describe User do |
| 38 | 38 | describe "Associations" do |
| 39 | + it { should have_one(:namespace) } | |
| 39 | 40 | it { should have_many(:users_projects).dependent(:destroy) } |
| 40 | 41 | it { should have_many(:projects) } |
| 41 | 42 | it { should have_many(:my_own_projects).class_name('Project') } | ... | ... |