Create dir with namespace. Create namespace with user
This commit is contained in:
parent
f17ddeb394
commit
ab9d023651
6 changed files with 39 additions and 26 deletions
|
@ -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
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue