diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 1f9f676c63b4ea1a93ba307f868710c0b387b8eb..4b4337961612c0fd7df7d8c0dfc5e9a60c201d13 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -10,7 +10,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController end def show - @deployments = environment.deployments.order(id: :desc).page(params[:page]).per(30) + @deployments = environment.deployments.order(id: :desc).page(params[:page]) end def new @@ -44,6 +44,6 @@ class Projects::EnvironmentsController < Projects::ApplicationController end def environment - @environment ||= project.environments.find_by!(id: params[:id]) + @environment ||= project.environments.find(params[:id]) end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 32e4567468264222a9ff99b1ede62a350583143f..734b152605bb1e202f18ba8d6604e3d4eaf83e8b 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -251,7 +251,8 @@ class Ability :create_container_image, :update_container_image, :create_environment, - :create_deployment + :create_deployment, + :update_deployment ] end @@ -270,7 +271,6 @@ class Ability :push_code_to_protected_branches, :update_project_snippet, :update_environment, - :update_deployment, :admin_milestone, :admin_project_snippet, :admin_project_member, diff --git a/app/views/projects/environments/_form.html.haml b/app/views/projects/environments/_form.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..c07f4bd510ca81b928b7301f56e06818db80aac2 --- /dev/null +++ b/app/views/projects/environments/_form.html.haml @@ -0,0 +1,7 @@ += form_for @environment, url: namespace_project_environments_path(@project.namespace, @project), html: { class: 'col-lg-9' } do |f| + = form_errors(@environment) + .form-group + = f.label :name, 'Name', class: 'label-light' + = f.text_field :name, required: true, class: 'form-control' + = f.submit 'Create environment', class: 'btn btn-create' + = link_to 'Cancel', namespace_project_environments_path(@project.namespace, @project), class: 'btn btn-cancel' diff --git a/app/views/projects/environments/new.html.haml b/app/views/projects/environments/new.html.haml index 533f624c4e2f3ad1b1372e104c0c41524e1878ae..54465828ba9efebafe63b8409ee8453fb66b143e 100644 --- a/app/views/projects/environments/new.html.haml +++ b/app/views/projects/environments/new.html.haml @@ -1,16 +1,9 @@ -- @no_container = true -- page_title "New Environment" -= render "projects/pipelines/head" +- page_title 'New Environment' .row.prepend-top-default.append-bottom-default .col-lg-3 %h4.prepend-top-0 New Environment + %p Environments allow you to track deployments of your application - = form_for @environment, url: namespace_project_environments_path(@project.namespace, @project), html: { class: "col-lg-9" } do |f| - = form_errors(@environment) - .form-group - = f.label :name, 'Environment name', class: 'label-light' - = f.text_field :name, required: true, class: 'form-control' - = f.submit 'Create environment', class: 'btn btn-create' - = link_to "Cancel", namespace_project_environments_path(@project.namespace, @project), class: "btn btn-cancel" + = render 'form' diff --git a/app/views/projects/environments/show.html.haml b/app/views/projects/environments/show.html.haml index b41b1651a8162dd4826d2735bd1079e50c3fb049..069b77b5adf9d800aad2defd4729780e6378312a 100644 --- a/app/views/projects/environments/show.html.haml +++ b/app/views/projects/environments/show.html.haml @@ -10,7 +10,7 @@ .col-md-3 .nav-controls - if can?(current_user, :update_environment, @environment) - = link_to 'Destroy', namespace_project_environment_path(@project.namespace, @project, @environment), data: { confirm: 'Are you sure?' }, class: 'btn btn-danger', method: :delete + = link_to 'Destroy', namespace_project_environment_path(@project.namespace, @project, @environment), data: { confirm: 'Are you sure you want to delete this environment?' }, class: 'btn btn-danger', method: :delete - if @deployments.blank? %ul.content-list.environments diff --git a/spec/features/environments_spec.rb b/spec/features/environments_spec.rb index b73bb30e2162b672b7915ae3cb15380a8ebabf3c..8002b793986d9877f237eafcd5b54b5ab42964f9 100644 --- a/spec/features/environments_spec.rb +++ b/spec/features/environments_spec.rb @@ -107,7 +107,7 @@ describe 'Environments' do context 'for valid name' do before do - fill_in('Environment name', with: 'production') + fill_in('Name', with: 'production') click_on 'Create environment' end @@ -118,7 +118,7 @@ describe 'Environments' do context 'for invalid name' do before do - fill_in('Environment name', with: 'name with spaces') + fill_in('Name', with: 'name with spaces') click_on 'Create environment' end @@ -140,7 +140,9 @@ describe 'Environments' do before { visit namespace_project_environment_path(project.namespace, project, environment) } - context 'when logged as developer' do + context 'when logged as master' do + let(:role) { :master } + before { click_link 'Destroy' } it 'does not have environment' do @@ -148,8 +150,8 @@ describe 'Environments' do end end - context 'when logged as reporter' do - let(:role) { :reporter } + context 'when logged as developer' do + let(:role) { :developer } it 'does not have a Destroy link' do expect(page).not_to have_link('Destroy')