Commit 0e1635a68a2a3f9c74ca52f2b5c19d63428faf2c

Authored by Dmitriy Zaporozhets
1 parent e92b563a

Fixing requests after namespaces. Fixed admin bug with access to project

app/controllers/admin/projects_controller.rb
... ... @@ -42,4 +42,14 @@ class Admin::ProjectsController < AdminController
42 42  
43 43 redirect_to projects_url, notice: 'Project was successfully deleted.'
44 44 end
  45 +
  46 + protected
  47 +
  48 + def project
  49 + id = params[:project_id] || params[:id]
  50 + id = id.split("/") if id.include?("/")
  51 +
  52 + @project ||= Project.find_by_path(id)
  53 + @project || render_404
  54 + end
45 55 end
... ...
app/helpers/application_helper.rb
... ... @@ -88,7 +88,7 @@ module ApplicationHelper
88 88 [ "Users", users.map {|u| [u.human_name, u.id]} ]
89 89 ]
90 90  
91   - if selected == :current_user
  91 + if selected == :current_user && current_user.namespace
92 92 selected = current_user.namespace.id
93 93 end
94 94  
... ...
app/observers/user_observer.rb
1 1 class UserObserver < ActiveRecord::Observer
2 2 def after_create(user)
3   - user.create_namespace(code: user.username, name: user.name)
  3 + user.create_namespace(path: user.username, name: user.name)
4 4  
5 5 log_info("User \"#{user.name}\" (#{user.email}) was created")
6 6  
... ... @@ -13,7 +13,7 @@ class UserObserver &lt; ActiveRecord::Observer
13 13  
14 14 def after_save user
15 15 if user.username_changed? and user.namespace
16   - user.namespace.update_attributes(code: user.username)
  16 + user.namespace.update_attributes(path: user.username)
17 17 end
18 18 end
19 19  
... ...
lib/api/projects.rb
... ... @@ -38,10 +38,7 @@ module Gitlab
38 38 # Example Request
39 39 # POST /projects
40 40 post do
41   - params[:code] ||= params[:name]
42   - params[:path] ||= params[:name]
43   - attrs = attributes_for_keys [:path,
44   - :name,
  41 + attrs = attributes_for_keys [:name,
45 42 :description,
46 43 :default_branch,
47 44 :issues_enabled,
... ...
spec/controllers/commits_controller_spec.rb
... ... @@ -13,7 +13,7 @@ describe CommitsController do
13 13 describe "GET show" do
14 14 context "as atom feed" do
15 15 it "should render as atom" do
16   - get :show, project_id: project.code, id: "master.atom"
  16 + get :show, project_id: project.path, id: "master.atom"
17 17 response.should be_success
18 18 response.content_type.should == 'application/atom+xml'
19 19 end
... ...
spec/factories.rb
... ... @@ -12,7 +12,7 @@ FactoryGirl.define do
12 12 factory :user, aliases: [:author, :assignee, :owner] do
13 13 email { Faker::Internet.email }
14 14 name
15   - username 'john'
  15 + username { Faker::Internet.user_name }
16 16 password "123456"
17 17 password_confirmation { password }
18 18  
... ...
spec/mailers/notify_spec.rb
... ... @@ -169,9 +169,7 @@ describe Notify do
169 169 end
170 170  
171 171 describe 'project access changed' do
172   - let(:project) { create(:project,
173   - path: "Fuu",
174   - code: "Fuu") }
  172 + let(:project) { create(:project) }
175 173 let(:user) { create(:user) }
176 174 let(:users_project) { create(:users_project,
177 175 project: project,
... ...
spec/observers/user_observer_spec.rb
... ... @@ -13,7 +13,12 @@ describe UserObserver do
13 13 end
14 14  
15 15 context 'when a new user is created' do
16   - let(:user) { double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local', username: 'root') }
  16 + let(:user) { double(:user, id: 42,
  17 + password: 'P@ssword!',
  18 + name: 'John',
  19 + email: 'u@mail.local',
  20 + username: 'root',
  21 + create_namespace: true) }
17 22 let(:notification) { double :notification }
18 23  
19 24 it 'sends an email' do
... ...
spec/observers/users_project_observer_spec.rb
... ... @@ -2,9 +2,7 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe UsersProjectObserver do
4 4 let(:user) { create(:user) }
5   - let(:project) { create(:project,
6   - code: "Fuu",
7   - path: "Fuu" ) }
  5 + let(:project) { create(:project) }
8 6 let(:users_project) { create(:users_project,
9 7 project: project,
10 8 user: user )}
... ...
spec/requests/admin/admin_hooks_spec.rb
... ... @@ -2,9 +2,7 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe "Admin::Hooks" do
4 4 before do
5   - @project = create(:project,
6   - name: "LeGiT",
7   - code: "LGT")
  5 + @project = create(:project)
8 6 login_as :admin
9 7  
10 8 @system_hook = create(:system_hook)
... ...
spec/requests/admin/admin_projects_spec.rb
... ... @@ -39,8 +39,8 @@ describe &quot;Admin::Projects&quot; do
39 39 end
40 40  
41 41 it "should have project edit page" do
42   - page.should have_content("Project name")
43   - page.should have_content("URL")
  42 + page.should have_content("Edit project")
  43 + page.should have_button("Save Project")
44 44 end
45 45  
46 46 describe "Update project" do
... ... @@ -60,39 +60,6 @@ describe &quot;Admin::Projects&quot; do
60 60 end
61 61 end
62 62  
63   - describe "GET /admin/projects/new" do
64   - before do
65   - visit admin_projects_path
66   - click_link "New Project"
67   - end
68   -
69   - it "should be correct path" do
70   - current_path.should == new_admin_project_path
71   - end
72   -
73   - it "should have labels for new project" do
74   - page.should have_content("Project name is")
75   - end
76   - end
77   -
78   - describe "POST /admin/projects" do
79   - before do
80   - visit new_admin_project_path
81   - fill_in 'project_name', with: 'NewProject'
82   - expect { click_button "Create project" }.to change { Project.count }.by(1)
83   - @project = Project.last
84   - end
85   -
86   - it "should be correct path" do
87   - current_path.should == admin_project_path(@project)
88   - end
89   -
90   - it "should show project" do
91   - page.should have_content(@project.name)
92   - page.should have_content(@project.path)
93   - end
94   - end
95   -
96 63 describe "Add new team member" do
97 64 before do
98 65 @new_user = create(:user)
... ...
spec/requests/admin/admin_users_spec.rb
... ... @@ -23,6 +23,7 @@ describe &quot;Admin::Users&quot; do
23 23 @password = "123ABC"
24 24 visit new_admin_user_path
25 25 fill_in "user_name", with: "Big Bang"
  26 + fill_in "user_username", with: "bang"
26 27 fill_in "user_email", with: "bigbang@mail.com"
27 28 fill_in "user_password", with: @password
28 29 fill_in "user_password_confirmation", with: @password
... ...
spec/requests/api/milestones_spec.rb
... ... @@ -11,7 +11,7 @@ describe Gitlab::API do
11 11  
12 12 describe "GET /projects/:id/milestones" do
13 13 it "should return project milestones" do
14   - get api("/projects/#{project.code}/milestones", user)
  14 + get api("/projects/#{project.path}/milestones", user)
15 15 response.status.should == 200
16 16 json_response.should be_an Array
17 17 json_response.first['title'].should == milestone.title
... ... @@ -20,7 +20,7 @@ describe Gitlab::API do
20 20  
21 21 describe "GET /projects/:id/milestones/:milestone_id" do
22 22 it "should return a project milestone by id" do
23   - get api("/projects/#{project.code}/milestones/#{milestone.id}", user)
  23 + get api("/projects/#{project.path}/milestones/#{milestone.id}", user)
24 24 response.status.should == 200
25 25 json_response['title'].should == milestone.title
26 26 end
... ... @@ -28,7 +28,7 @@ describe Gitlab::API do
28 28  
29 29 describe "POST /projects/:id/milestones" do
30 30 it "should create a new project milestone" do
31   - post api("/projects/#{project.code}/milestones", user),
  31 + post api("/projects/#{project.path}/milestones", user),
32 32 title: 'new milestone'
33 33 response.status.should == 201
34 34 json_response['title'].should == 'new milestone'
... ... @@ -38,7 +38,7 @@ describe Gitlab::API do
38 38  
39 39 describe "PUT /projects/:id/milestones/:milestone_id" do
40 40 it "should update a project milestone" do
41   - put api("/projects/#{project.code}/milestones/#{milestone.id}", user),
  41 + put api("/projects/#{project.path}/milestones/#{milestone.id}", user),
42 42 title: 'updated title'
43 43 response.status.should == 200
44 44 json_response['title'].should == 'updated title'
... ...
spec/requests/api/projects_spec.rb
... ... @@ -53,7 +53,6 @@ describe Gitlab::API do
53 53  
54 54 it "should assign attributes to project" do
55 55 project = attributes_for(:project, {
56   - path: project.name.parameterize,
57 56 description: Faker::Lorem.sentence,
58 57 default_branch: 'stable',
59 58 issues_enabled: false,
... ... @@ -257,7 +256,7 @@ describe Gitlab::API do
257 256 describe "POST /projects/:id/snippets" do
258 257 it "should create a new project snippet" do
259 258 post api("/projects/#{project.path}/snippets", user),
260   - title: 'api test', file_name: 'sample.rb', path: 'test'
  259 + title: 'api test', file_name: 'sample.rb', code: 'test'
261 260 response.status.should == 201
262 261 json_response['title'].should == 'api test'
263 262 end
... ... @@ -266,10 +265,10 @@ describe Gitlab::API do
266 265 describe "PUT /projects/:id/snippets/:shippet_id" do
267 266 it "should update an existing project snippet" do
268 267 put api("/projects/#{project.path}/snippets/#{snippet.id}", user),
269   - path: 'updated path'
  268 + code: 'updated code'
270 269 response.status.should == 200
271 270 json_response['title'].should == 'example'
272   - snippet.reload.content.should == 'updated path'
  271 + snippet.reload.content.should == 'updated code'
273 272 end
274 273 end
275 274  
... ...