summaryrefslogtreecommitdiff
path: root/app/models/project.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb42
1 files changed, 9 insertions, 33 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 39e2bb25ae3..0652d187ddd 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -8,10 +8,9 @@ class Project < ActiveRecord::Base
attr_accessible :name, :path, :description, :code, :default_branch, :issues_enabled,
:wall_enabled, :merge_requests_enabled, :wiki_enabled
+ attr_accessor :error_code
- #
# Relations
- #
belongs_to :owner, class_name: "User"
has_many :users, through: :users_projects
has_many :events, dependent: :destroy
@@ -26,11 +25,7 @@ class Project < ActiveRecord::Base
has_many :wikis, dependent: :destroy
has_many :protected_branches, dependent: :destroy
- attr_accessor :error_code
-
- #
# Scopes
- #
scope :public_only, where(private_flag: false)
scope :without_user, lambda { |user| where("id not in (:ids)", ids: user.projects.map(&:id) ) }
@@ -47,7 +42,6 @@ class Project < ActiveRecord::Base
Project.transaction do
project.owner = user
-
project.save!
# Add user as project master
@@ -76,36 +70,19 @@ class Project < ActiveRecord::Base
id && valid?
end
- #
# Validations
- #
- validates :name,
- uniqueness: true,
- presence: true,
- length: { within: 0..255 }
-
- validates :path,
- uniqueness: true,
- presence: true,
+ 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-zA-Z][a-zA-Z0-9_\-\.]*$/,
- message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" },
- length: { within: 0..255 }
-
- validates :description,
- length: { within: 0..2000 }
-
- validates :code,
- presence: true,
- uniqueness: true,
+ message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
+ validates :code, presence: true, uniqueness: true, length: { within: 1..255 },
format: { with: /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/,
- message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" },
- length: { within: 1..255 }
-
- validates :owner, presence: true
+ 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
- validate :repo_name
+ validate :check_limit, :repo_name
def check_limit
unless owner.can_create_project?
@@ -197,4 +174,3 @@ end
# merge_requests_enabled :boolean default(TRUE), not null
# wiki_enabled :boolean default(TRUE), not null
#
-