summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-11-23 09:11:09 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-11-23 09:11:09 +0300
commitab9d02365181df373beffbe7732b36b9b3f7a307 (patch)
tree4dc15b36db8f256f032bb58b889e28850d3c1b0b
parentf17ddeb394ced4322f9b29eada92d5086bdef03b (diff)
downloadgitlab-ce-ab9d02365181df373beffbe7732b36b9b3f7a307.tar.gz
Create dir with namespace. Create namespace with user
-rw-r--r--app/models/namespace.rb7
-rw-r--r--app/models/project.rb7
-rw-r--r--app/models/user.rb7
-rw-r--r--app/observers/user_observer.rb4
-rw-r--r--app/views/admin/users/_form.html.haml9
-rw-r--r--app/views/projects/_new_form.html.haml29
6 files changed, 38 insertions, 25 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 120dac1ce5a..247115351b5 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -10,6 +10,8 @@ class Namespace < ActiveRecord::Base
delegate :name, to: :owner, allow_nil: true, prefix: true
+ after_save :ensure_dir_exist
+
scope :root, where('type IS NULL')
def self.search query
@@ -23,4 +25,9 @@ class Namespace < ActiveRecord::Base
def human_name
owner_name
end
+
+ def ensure_dir_exist
+ namespace_dir_path = File.join(Gitlab.config.git_base_path, code)
+ Dir.mkdir(namespace_dir_path) unless File.exists?(namespace_dir_path)
+ end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 75752125e11..0ffa76cb423 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -67,6 +67,7 @@ class Project < ActiveRecord::Base
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validates :issues_enabled, :wall_enabled, :merge_requests_enabled,
:wiki_enabled, inclusion: { in: [true, false] }
+
validate :check_limit, :repo_name
# Scopes
@@ -89,6 +90,12 @@ class Project < ActiveRecord::Base
project = Project.new params
Project.transaction do
+
+ # Build gitlab-hq code from GitLab HQ name
+ #
+ slug = project.name.dup.parameterize
+ project.code = project.path = slug
+
project.owner = user
project.namespace_id = namespace_id
project.save!
diff --git a/app/models/user.rb b/app/models/user.rb
index cd1dd205569..b50fe3bd02c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -63,11 +63,14 @@ class User < ActiveRecord::Base
validates :bio, length: { within: 0..255 }
validates :extern_uid, :allow_blank => true, :uniqueness => {:scope => :provider}
validates :projects_limit, presence: true, numericality: {greater_than_or_equal_to: 0}
+ validates :username, presence: true
before_validation :generate_password, on: :create
before_save :ensure_authentication_token
alias_attribute :private_token, :authentication_token
+ delegate :code, to: :namespace, allow_nil: true, prefix: true
+
# Scopes
scope :not_in_project, ->(project) { where("id not in (:ids)", ids: project.users.map(&:id) ) }
scope :admins, where(admin: true)
@@ -122,4 +125,8 @@ class User < ActiveRecord::Base
namespaces = namespaces + Group.all if admin
namespaces
end
+
+ def several_namespaces?
+ namespaces.size > 1
+ end
end
diff --git a/app/observers/user_observer.rb b/app/observers/user_observer.rb
index 3834123871c..e96ba28b7fb 100644
--- a/app/observers/user_observer.rb
+++ b/app/observers/user_observer.rb
@@ -1,5 +1,7 @@
class UserObserver < ActiveRecord::Observer
def after_create(user)
+ user.create_namespace(code: user.username, name: user.name)
+
log_info("User \"#{user.name}\" (#{user.email}) was created")
Notify.new_user_email(user.id, user.password).deliver
@@ -10,7 +12,7 @@ class UserObserver < ActiveRecord::Observer
end
def after_save user
- if user.username_changed?
+ if user.username_changed? and user.namespace
user.namespace.update_attributes(code: user.username)
end
end
diff --git a/app/views/admin/users/_form.html.haml b/app/views/admin/users/_form.html.haml
index 7010c2727c6..312398565c9 100644
--- a/app/views/admin/users/_form.html.haml
+++ b/app/views/admin/users/_form.html.haml
@@ -16,6 +16,11 @@
= f.text_field :name
%span.help-inline * required
.clearfix
+ = f.label :username
+ .input
+ = f.text_field :username
+ %span.help-inline * required
+ .clearfix
= f.label :email
.input
= f.text_field :email
@@ -26,11 +31,11 @@
= f.label :force_random_password do
%span Generate random password
.input= f.check_box :force_random_password, {}, true, nil
-
+
%div.password-fields
.clearfix
= f.label :password
- .input= f.password_field :password, disabled: f.object.force_random_password
+ .input= f.password_field :password, disabled: f.object.force_random_password
.clearfix
= f.label :password_confirmation
.input= f.password_field :password_confirmation, disabled: f.object.force_random_password
diff --git a/app/views/projects/_new_form.html.haml b/app/views/projects/_new_form.html.haml
index 978352e7da2..ae7b051a8d3 100644
--- a/app/views/projects/_new_form.html.haml
+++ b/app/views/projects/_new_form.html.haml
@@ -9,27 +9,12 @@
= f.text_field :name, placeholder: "Example Project", class: "xxlarge"
= f.submit 'Create project', class: "btn primary project-submit"
- %hr
- %div.adv_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
- = f.label :path do
- Git Clone
- .input
- .input-prepend
- %span.add-on= Gitlab.config.ssh_path
- = f.text_field :path, placeholder: "example_project", disabled: !@project.new_record?
- %span.add-on= ".git"
+ - if current_user.several_namespaces?
.clearfix
- = f.label :code do
- URL
+ = f.label :namespace_id do
+ %span.cgray Namespace
.input
- .input-prepend
- %span.add-on= web_app_url
- = f.text_field :code, placeholder: "example"
+ = f.select :namespace_id, namespaces_options, {}, {class: 'chosen'}
+ %hr
+ %p.padded
+ All created project are private. You choose who can see project and commit to repository.