Deprecate code for Project. Use title and path

This commit is contained in:
Dmitriy Zaporozhets 2012-11-23 21:11:09 +03:00
parent ab9d023651
commit c50ec72b52
22 changed files with 79 additions and 83 deletions

View file

@ -1,11 +1,13 @@
class Namespace < ActiveRecord::Base
attr_accessible :code, :name, :owner_id
attr_accessible :name, :path
has_many :projects
has_many :projects, dependent: :destroy
belongs_to :owner, class_name: "User"
validates :name, presence: true, uniqueness: true
validates :code, presence: true, uniqueness: true
validates :path, uniqueness: true, presence: true, length: { within: 1..255 },
format: { with: /\A[a-zA-Z][a-zA-Z0-9_\-\.]*\z/,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validates :owner, presence: true
delegate :name, to: :owner, allow_nil: true, prefix: true
@ -15,11 +17,11 @@ class Namespace < ActiveRecord::Base
scope :root, where('type IS NULL')
def self.search query
where("name LIKE :query OR code LIKE :query", query: "%#{query}%")
where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
end
def to_param
code
path
end
def human_name
@ -27,7 +29,7 @@ class Namespace < ActiveRecord::Base
end
def ensure_dir_exist
namespace_dir_path = File.join(Gitlab.config.git_base_path, code)
namespace_dir_path = File.join(Gitlab.config.git_base_path, path)
Dir.mkdir(namespace_dir_path) unless File.exists?(namespace_dir_path)
end
end

View file

@ -27,7 +27,7 @@ class Project < ActiveRecord::Base
include Authority
include Team
attr_accessible :name, :path, :description, :code, :default_branch, :issues_enabled,
attr_accessible :name, :path, :description, :default_branch, :issues_enabled,
:wall_enabled, :merge_requests_enabled, :wiki_enabled, as: [:default, :admin]
attr_accessible :namespace_id, as: :admin
@ -58,16 +58,16 @@ class Project < ActiveRecord::Base
# Validations
validates :owner, presence: true
validates :description, length: { within: 0..2000 }
validates :name, uniqueness: true, presence: true, length: { within: 0..255 }
validates :path, uniqueness: true, presence: true, length: { within: 0..255 },
format: { with: /\A[a-zA-Z][a-zA-Z0-9_\-\.]*\z/,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validates :code, presence: true, uniqueness: true, length: { within: 1..255 },
validates :name, presence: true, length: { within: 0..255 }
validates :path, presence: true, length: { within: 0..255 },
format: { with: /\A[a-zA-Z][a-zA-Z0-9_\-\.]*\z/,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validates :issues_enabled, :wall_enabled, :merge_requests_enabled,
:wiki_enabled, inclusion: { in: [true, false] }
validates_uniqueness_of :name, scope: :namespace_id
validates_uniqueness_of :path, scope: :namespace_id
validate :check_limit, :repo_name
# Scopes
@ -81,20 +81,23 @@ class Project < ActiveRecord::Base
end
def search query
where("projects.name LIKE :query OR projects.code LIKE :query OR projects.path LIKE :query", query: "%#{query}%")
where("projects.name LIKE :query OR projects.path LIKE :query", query: "%#{query}%")
end
def create_by_user(params, user)
namespace_id = params.delete(:namespace_id) || namespace.try(:id)
namespace_id = params.delete(:namespace_id)
namespace_id ||= current_user.namespace_id
project = Project.new params
Project.transaction do
# Build gitlab-hq code from GitLab HQ name
# Parametrize path for project
#
slug = project.name.dup.parameterize
project.code = project.path = slug
# Ex.
# 'GitLab HQ'.parameterize => "gitlab-hq"
#
project.path = project.name.dup.parameterize
project.owner = user
project.namespace_id = namespace_id
@ -149,14 +152,14 @@ class Project < ActiveRecord::Base
def to_param
if namespace
namespace.code + "/" + code
namespace.path + "/" + path
else
code
path
end
end
def web_url
[Gitlab.config.url, code].join("/")
[Gitlab.config.url, path].join("/")
end
def common_notes
@ -213,7 +216,7 @@ class Project < ActiveRecord::Base
def path_with_namespace
if namespace
namespace.code + '/' + path
namespace.path + '/' + path
else
path
end

View file

@ -69,7 +69,8 @@ class User < ActiveRecord::Base
before_save :ensure_authentication_token
alias_attribute :private_token, :authentication_token
delegate :code, to: :namespace, allow_nil: true, prefix: true
delegate :path, to: :namespace, allow_nil: true, prefix: true
delegate :id, to: :namespace, allow_nil: true, prefix: true
# Scopes
scope :not_in_project, ->(project) { where("id not in (:ids)", ids: project.users.map(&:id) ) }
@ -121,7 +122,7 @@ class User < ActiveRecord::Base
def namespaces
namespaces = []
namespaces << self.namespace
namespaces << self.namespace if self.namespace
namespaces = namespaces + Group.all if admin
namespaces
end