Commit ab9d02365181df373beffbe7732b36b9b3f7a307
1 parent
f17ddeb3
Exists in
master
and in
4 other branches
Create dir with namespace. Create namespace with user
Showing
6 changed files
with
38 additions
and
25 deletions
Show diff stats
app/models/namespace.rb
| @@ -10,6 +10,8 @@ class Namespace < ActiveRecord::Base | @@ -10,6 +10,8 @@ class Namespace < ActiveRecord::Base | ||
| 10 | 10 | ||
| 11 | delegate :name, to: :owner, allow_nil: true, prefix: true | 11 | delegate :name, to: :owner, allow_nil: true, prefix: true |
| 12 | 12 | ||
| 13 | + after_save :ensure_dir_exist | ||
| 14 | + | ||
| 13 | scope :root, where('type IS NULL') | 15 | scope :root, where('type IS NULL') |
| 14 | 16 | ||
| 15 | def self.search query | 17 | def self.search query |
| @@ -23,4 +25,9 @@ class Namespace < ActiveRecord::Base | @@ -23,4 +25,9 @@ class Namespace < ActiveRecord::Base | ||
| 23 | def human_name | 25 | def human_name |
| 24 | owner_name | 26 | owner_name |
| 25 | end | 27 | end |
| 28 | + | ||
| 29 | + def ensure_dir_exist | ||
| 30 | + namespace_dir_path = File.join(Gitlab.config.git_base_path, code) | ||
| 31 | + Dir.mkdir(namespace_dir_path) unless File.exists?(namespace_dir_path) | ||
| 32 | + end | ||
| 26 | end | 33 | end |
app/models/project.rb
| @@ -67,6 +67,7 @@ class Project < ActiveRecord::Base | @@ -67,6 +67,7 @@ class Project < ActiveRecord::Base | ||
| 67 | message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } | 67 | message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } |
| 68 | validates :issues_enabled, :wall_enabled, :merge_requests_enabled, | 68 | validates :issues_enabled, :wall_enabled, :merge_requests_enabled, |
| 69 | :wiki_enabled, inclusion: { in: [true, false] } | 69 | :wiki_enabled, inclusion: { in: [true, false] } |
| 70 | + | ||
| 70 | validate :check_limit, :repo_name | 71 | validate :check_limit, :repo_name |
| 71 | 72 | ||
| 72 | # Scopes | 73 | # Scopes |
| @@ -89,6 +90,12 @@ class Project < ActiveRecord::Base | @@ -89,6 +90,12 @@ class Project < ActiveRecord::Base | ||
| 89 | project = Project.new params | 90 | project = Project.new params |
| 90 | 91 | ||
| 91 | Project.transaction do | 92 | Project.transaction do |
| 93 | + | ||
| 94 | + # Build gitlab-hq code from GitLab HQ name | ||
| 95 | + # | ||
| 96 | + slug = project.name.dup.parameterize | ||
| 97 | + project.code = project.path = slug | ||
| 98 | + | ||
| 92 | project.owner = user | 99 | project.owner = user |
| 93 | project.namespace_id = namespace_id | 100 | project.namespace_id = namespace_id |
| 94 | project.save! | 101 | project.save! |
app/models/user.rb
| @@ -63,11 +63,14 @@ class User < ActiveRecord::Base | @@ -63,11 +63,14 @@ class User < ActiveRecord::Base | ||
| 63 | validates :bio, length: { within: 0..255 } | 63 | validates :bio, length: { within: 0..255 } |
| 64 | validates :extern_uid, :allow_blank => true, :uniqueness => {:scope => :provider} | 64 | validates :extern_uid, :allow_blank => true, :uniqueness => {:scope => :provider} |
| 65 | validates :projects_limit, presence: true, numericality: {greater_than_or_equal_to: 0} | 65 | validates :projects_limit, presence: true, numericality: {greater_than_or_equal_to: 0} |
| 66 | + validates :username, presence: true | ||
| 66 | 67 | ||
| 67 | before_validation :generate_password, on: :create | 68 | before_validation :generate_password, on: :create |
| 68 | before_save :ensure_authentication_token | 69 | before_save :ensure_authentication_token |
| 69 | alias_attribute :private_token, :authentication_token | 70 | alias_attribute :private_token, :authentication_token |
| 70 | 71 | ||
| 72 | + delegate :code, to: :namespace, allow_nil: true, prefix: true | ||
| 73 | + | ||
| 71 | # Scopes | 74 | # Scopes |
| 72 | scope :not_in_project, ->(project) { where("id not in (:ids)", ids: project.users.map(&:id) ) } | 75 | scope :not_in_project, ->(project) { where("id not in (:ids)", ids: project.users.map(&:id) ) } |
| 73 | scope :admins, where(admin: true) | 76 | scope :admins, where(admin: true) |
| @@ -122,4 +125,8 @@ class User < ActiveRecord::Base | @@ -122,4 +125,8 @@ class User < ActiveRecord::Base | ||
| 122 | namespaces = namespaces + Group.all if admin | 125 | namespaces = namespaces + Group.all if admin |
| 123 | namespaces | 126 | namespaces |
| 124 | end | 127 | end |
| 128 | + | ||
| 129 | + def several_namespaces? | ||
| 130 | + namespaces.size > 1 | ||
| 131 | + end | ||
| 125 | end | 132 | end |
app/observers/user_observer.rb
| 1 | class UserObserver < ActiveRecord::Observer | 1 | class UserObserver < ActiveRecord::Observer |
| 2 | def after_create(user) | 2 | def after_create(user) |
| 3 | + user.create_namespace(code: user.username, name: user.name) | ||
| 4 | + | ||
| 3 | log_info("User \"#{user.name}\" (#{user.email}) was created") | 5 | log_info("User \"#{user.name}\" (#{user.email}) was created") |
| 4 | 6 | ||
| 5 | Notify.new_user_email(user.id, user.password).deliver | 7 | Notify.new_user_email(user.id, user.password).deliver |
| @@ -10,7 +12,7 @@ class UserObserver < ActiveRecord::Observer | @@ -10,7 +12,7 @@ class UserObserver < ActiveRecord::Observer | ||
| 10 | end | 12 | end |
| 11 | 13 | ||
| 12 | def after_save user | 14 | def after_save user |
| 13 | - if user.username_changed? | 15 | + if user.username_changed? and user.namespace |
| 14 | user.namespace.update_attributes(code: user.username) | 16 | user.namespace.update_attributes(code: user.username) |
| 15 | end | 17 | end |
| 16 | end | 18 | end |
app/views/admin/users/_form.html.haml
| @@ -16,6 +16,11 @@ | @@ -16,6 +16,11 @@ | ||
| 16 | = f.text_field :name | 16 | = f.text_field :name |
| 17 | %span.help-inline * required | 17 | %span.help-inline * required |
| 18 | .clearfix | 18 | .clearfix |
| 19 | + = f.label :username | ||
| 20 | + .input | ||
| 21 | + = f.text_field :username | ||
| 22 | + %span.help-inline * required | ||
| 23 | + .clearfix | ||
| 19 | = f.label :email | 24 | = f.label :email |
| 20 | .input | 25 | .input |
| 21 | = f.text_field :email | 26 | = f.text_field :email |
| @@ -26,11 +31,11 @@ | @@ -26,11 +31,11 @@ | ||
| 26 | = f.label :force_random_password do | 31 | = f.label :force_random_password do |
| 27 | %span Generate random password | 32 | %span Generate random password |
| 28 | .input= f.check_box :force_random_password, {}, true, nil | 33 | .input= f.check_box :force_random_password, {}, true, nil |
| 29 | - | 34 | + |
| 30 | %div.password-fields | 35 | %div.password-fields |
| 31 | .clearfix | 36 | .clearfix |
| 32 | = f.label :password | 37 | = f.label :password |
| 33 | - .input= f.password_field :password, disabled: f.object.force_random_password | 38 | + .input= f.password_field :password, disabled: f.object.force_random_password |
| 34 | .clearfix | 39 | .clearfix |
| 35 | = f.label :password_confirmation | 40 | = f.label :password_confirmation |
| 36 | .input= f.password_field :password_confirmation, disabled: f.object.force_random_password | 41 | .input= f.password_field :password_confirmation, disabled: f.object.force_random_password |
app/views/projects/_new_form.html.haml
| @@ -9,27 +9,12 @@ | @@ -9,27 +9,12 @@ | ||
| 9 | = f.text_field :name, placeholder: "Example Project", class: "xxlarge" | 9 | = f.text_field :name, placeholder: "Example Project", class: "xxlarge" |
| 10 | = f.submit 'Create project', class: "btn primary project-submit" | 10 | = f.submit 'Create project', class: "btn primary project-submit" |
| 11 | 11 | ||
| 12 | - %hr | ||
| 13 | - %div.adv_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'} | ||
| 21 | - .clearfix | ||
| 22 | - = f.label :path do | ||
| 23 | - Git Clone | ||
| 24 | - .input | ||
| 25 | - .input-prepend | ||
| 26 | - %span.add-on= Gitlab.config.ssh_path | ||
| 27 | - = f.text_field :path, placeholder: "example_project", disabled: !@project.new_record? | ||
| 28 | - %span.add-on= ".git" | 12 | + - if current_user.several_namespaces? |
| 29 | .clearfix | 13 | .clearfix |
| 30 | - = f.label :code do | ||
| 31 | - URL | 14 | + = f.label :namespace_id do |
| 15 | + %span.cgray Namespace | ||
| 32 | .input | 16 | .input |
| 33 | - .input-prepend | ||
| 34 | - %span.add-on= web_app_url | ||
| 35 | - = f.text_field :code, placeholder: "example" | 17 | + = f.select :namespace_id, namespaces_options, {}, {class: 'chosen'} |
| 18 | + %hr | ||
| 19 | + %p.padded | ||
| 20 | + All created project are private. You choose who can see project and commit to repository. |