Commit 57baa49bc3c71cc8084d925415e44ad1b8ad73a9
1 parent
29158ea3
Exists in
master
and in
4 other branches
project path & code regexp validation
Showing
5 changed files
with
9 additions
and
10 deletions
Show diff stats
app/models/project.rb
| @@ -16,6 +16,8 @@ class Project < ActiveRecord::Base | @@ -16,6 +16,8 @@ class Project < ActiveRecord::Base | ||
| 16 | validates :path, | 16 | validates :path, |
| 17 | :uniqueness => true, | 17 | :uniqueness => true, |
| 18 | :presence => true, | 18 | :presence => true, |
| 19 | + :format => { :with => /^[a-zA-Z0-9_\-]*$/, | ||
| 20 | + :message => "only letters, digits & '_' '-' allowed" }, | ||
| 19 | :length => { :within => 0..255 } | 21 | :length => { :within => 0..255 } |
| 20 | 22 | ||
| 21 | validates :description, | 23 | validates :description, |
| @@ -24,14 +26,15 @@ class Project < ActiveRecord::Base | @@ -24,14 +26,15 @@ class Project < ActiveRecord::Base | ||
| 24 | validates :code, | 26 | validates :code, |
| 25 | :presence => true, | 27 | :presence => true, |
| 26 | :uniqueness => true, | 28 | :uniqueness => true, |
| 27 | - :length => { :within => 3..12 } | 29 | + :format => { :with => /^[a-zA-Z0-9_\-]*$/, |
| 30 | + :message => "only letters, digits & '_' '-' allowed" }, | ||
| 31 | + :length => { :within => 3..16 } | ||
| 28 | 32 | ||
| 29 | validates :owner, | 33 | validates :owner, |
| 30 | :presence => true | 34 | :presence => true |
| 31 | 35 | ||
| 32 | validate :check_limit | 36 | validate :check_limit |
| 33 | 37 | ||
| 34 | - before_save :format_code | ||
| 35 | after_destroy :destroy_gitosis_project | 38 | after_destroy :destroy_gitosis_project |
| 36 | after_save :update_gitosis_project | 39 | after_save :update_gitosis_project |
| 37 | 40 | ||
| @@ -47,10 +50,6 @@ class Project < ActiveRecord::Base | @@ -47,10 +50,6 @@ class Project < ActiveRecord::Base | ||
| 47 | notes.where(:noteable_type => ["", nil]) | 50 | notes.where(:noteable_type => ["", nil]) |
| 48 | end | 51 | end |
| 49 | 52 | ||
| 50 | - def format_code | ||
| 51 | - read_attribute(:code).downcase.strip.gsub(' ', '') | ||
| 52 | - end | ||
| 53 | - | ||
| 54 | def update_gitosis_project | 53 | def update_gitosis_project |
| 55 | Gitosis.new.configure do |c| | 54 | Gitosis.new.configure do |c| |
| 56 | c.update_project(path, gitosis_writers) | 55 | c.update_project(path, gitosis_writers) |
config/initializers/rails_footnotes.rb
config/routes.rb
| @@ -32,7 +32,7 @@ Gitlab::Application.routes.draw do | @@ -32,7 +32,7 @@ Gitlab::Application.routes.draw do | ||
| 32 | get "tree/:commit_id/:path" => "projects#tree", | 32 | get "tree/:commit_id/:path" => "projects#tree", |
| 33 | :as => :tree_file, | 33 | :as => :tree_file, |
| 34 | :constraints => { | 34 | :constraints => { |
| 35 | - :id => /[a-zA-Z0-9]+/, | 35 | + :id => /[a-zA-Z0-9_\-]+/, |
| 36 | :commit_id => /[a-zA-Z0-9]+/, | 36 | :commit_id => /[a-zA-Z0-9]+/, |
| 37 | :path => /.*/ | 37 | :path => /.*/ |
| 38 | } | 38 | } |
spec/requests/admin/admin_projects_spec.rb
| @@ -88,7 +88,7 @@ describe "Admin::Projects" do | @@ -88,7 +88,7 @@ describe "Admin::Projects" do | ||
| 88 | visit new_admin_project_path | 88 | visit new_admin_project_path |
| 89 | fill_in 'Name', :with => 'NewProject' | 89 | fill_in 'Name', :with => 'NewProject' |
| 90 | fill_in 'Code', :with => 'NPR' | 90 | fill_in 'Code', :with => 'NPR' |
| 91 | - fill_in 'Path', :with => '/tmp/legit_test/legit' | 91 | + fill_in 'Path', :with => 'legit_1' |
| 92 | expect { click_button "Save" }.to change { Project.count }.by(1) | 92 | expect { click_button "Save" }.to change { Project.count }.by(1) |
| 93 | @project = Project.last | 93 | @project = Project.last |
| 94 | end | 94 | end |
spec/requests/projects_spec.rb
| @@ -39,7 +39,7 @@ describe "Projects" do | @@ -39,7 +39,7 @@ describe "Projects" do | ||
| 39 | visit new_project_path | 39 | visit new_project_path |
| 40 | fill_in 'Name', :with => 'NewProject' | 40 | fill_in 'Name', :with => 'NewProject' |
| 41 | fill_in 'Code', :with => 'NPR' | 41 | fill_in 'Code', :with => 'NPR' |
| 42 | - fill_in 'Path', :with => '/tmp/legit_test/legit' | 42 | + fill_in 'Path', :with => 'newproject' |
| 43 | expect { click_button "Create Project" }.to change { Project.count }.by(1) | 43 | expect { click_button "Create Project" }.to change { Project.count }.by(1) |
| 44 | @project = Project.last | 44 | @project = Project.last |
| 45 | end | 45 | end |