Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make prjconf routes resourceful #8496

Merged
merged 2 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/app/views/webui/project/prjconf.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%h3= @pagetitle
- if User.possibly_nobody.can_modify?(@project)
= render partial: 'webui/shared/editor', locals: { text: @content, mode: 'prjconf',
save: { url: save_project_config_path, method: :post,
data: { project: @project.name, submit: 'config' } } }
save: { url: project_config_path, method: :put,
data: { project_name: @project.name, submit: 'config' } } }
- else
= render partial: 'webui/shared/editor', locals: { text: @content, mode: 'prjconf', style: { read_only: true } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%h3= @pagetitle
- if User.possibly_nobody.can_modify?(@project)
= render partial: 'webui/shared/editor', locals: { text: @content, mode: 'prjconf',
save: { url: save_project_config_path, method: :post,
data: { project: @project.name, submit: 'config' } } }
save: { url: project_config_path, method: :put,
data: { project_name: @project.name, submit: 'config' } } }
- else
= render partial: 'webui/shared/editor', locals: { text: @content, mode: 'prjconf', style: { read_only: true } }
9 changes: 4 additions & 5 deletions src/api/config/routes/webui_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,6 @@
end
end

controller 'webui/projects/project_configuration' do
get 'project/prjconf/:project' => :show, constraints: cons, as: :project_config
post 'project/save_prjconf/:project' => :update, constraints: cons, as: :save_project_config
end

controller 'webui/project' do
get 'project/' => :index, as: 'projects'
get 'project/list_public' => :index, as: 'project_list_public'
Expand Down Expand Up @@ -249,6 +244,9 @@
controller 'webui/projects/maintenance_incidents' do
get 'project/maintenance_incidents/:project', to: redirect('/projects/%{project}/maintenance_incidents')
end
controller 'webui/projects/project_configuration' do
get 'project/prjconf/:project', to: redirect('/projects/%{project}/prjconf')
end
# \For backward compatibility

resources :projects, only: [], param: :name do
Expand All @@ -258,6 +256,7 @@
resource :ssl_certificate, controller: 'webui/projects/ssl_certificate', only: [:show], constraints: cons
resource :pulse, controller: 'webui/projects/pulse', only: [:show], constraints: cons
resource :meta, controller: 'webui/projects/meta', only: [:show, :update], constraints: cons
resource :prjconf, controller: 'webui/projects/project_configuration', only: [:show, :update], as: :config, constraints: cons
resource :rebuild_time, controller: 'webui/projects/rebuild_times', only: [:show], constraints: cons do
get 'rebuild_time_png'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
end

it { expect { get :show, params: { project: apache_project } }.not_to raise_error }
it { expect { get :show, params: { project_name: apache_project.name } }.not_to raise_error }
end

context 'Can not load project config' do
Expand All @@ -27,7 +27,7 @@
}
end

it { expect { get :show, params: { project: apache_project } }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { get :show, params: { project_name: apache_project.name } }.to raise_error(ActiveRecord::RecordNotFound) }
end
end

Expand All @@ -41,7 +41,7 @@
allow(::ProjectConfigurationService::ProjectConfigurationUpdater).to receive(:new) {
-> { OpenStruct.new(saved?: true) }
}
post :update, params: { project: user.home_project.name, config: 'save config' }
post :update, params: { project_name: user.home_project.name, config: 'save config' }
end

it { expect(flash[:success]).to eq('Config successfully saved!') }
Expand All @@ -53,7 +53,7 @@
allow(::ProjectConfigurationService::ProjectConfigurationUpdater).to receive(:new) {
-> { OpenStruct.new(saved?: false, errors: 'yay') }
}
post :update, params: { project: user.home_project.name, config: '' }
post :update, params: { project_name: user.home_project.name, config: '' }
end

it { expect(flash[:error]).not_to be_nil }
Expand All @@ -62,7 +62,7 @@

context 'cannot save with an unauthorized user' do
before do
post :update, params: { project: another_project.name, config: 'save config' }
post :update, params: { project_name: another_project.name, config: 'save config' }
end

it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this Project.') }
Expand All @@ -71,7 +71,7 @@
end

context 'with a non existing project' do
let(:post_update) { post :update, params: { project: 'non:existing:project', config: 'save config' } }
let(:post_update) { post :update, params: { project_name: 'non:existing:project', config: 'save config' } }

it 'raise a RecordNotFound Exception' do
expect { post_update }.to raise_error ActiveRecord::RecordNotFound
Expand Down