diff --git a/app/controllers/contracts_controller.rb b/app/controllers/contracts_controller.rb index 6a353fb..27729f7 100644 --- a/app/controllers/contracts_controller.rb +++ b/app/controllers/contracts_controller.rb @@ -5,6 +5,7 @@ class ContractsController < InheritedResources::Base before_filter :find_project before_filter :authorize + before_filter :require_admin, :only => :destroy def create create! { contract_url(@project, resource) } diff --git a/app/views/contracts/edit.html.erb b/app/views/contracts/edit.html.erb index f0d8c54..b4cec00 100644 --- a/app/views/contracts/edit.html.erb +++ b/app/views/contracts/edit.html.erb @@ -1,3 +1,9 @@ +<% if User.current.admin? %> +
+ <%= link_to(l(:button_delete), contract_path(@project, resource), :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del contract-delete') %> +
+<% end %> + <%= content_tag(:h2, h(resource.name)) %> <% semantic_form_for resource, :url => contract_path(@project, resource), :html => {:class => 'tabular'} do |form| %> diff --git a/assets/stylesheets/redmine_contracts.css b/assets/stylesheets/redmine_contracts.css index 2d4bf88..7be6e1d 100644 --- a/assets/stylesheets/redmine_contracts.css +++ b/assets/stylesheets/redmine_contracts.css @@ -15,3 +15,6 @@ html>body .tabular li {overflow:hidden;} .tabular li.required label { color: #484848; } .tabular li.required label span.required {color: #bb0000;} +/* End tabular */ + +a.contract-delete {color: red; } diff --git a/init.rb b/init.rb index abf3866..279d7ca 100644 --- a/init.rb +++ b/init.rb @@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_contracts do requires_redmine_plugin :redmine_rate, :version_or_higher => '0.1.0' project_module :contracts do - permission :manage_budget, {:contracts => [:index, :new, :create, :show, :edit, :update] }, :public => true + permission :manage_budget, {:contracts => [:index, :new, :create, :show, :edit, :update, :destroy] }, :public => true end menu(:project_menu, diff --git a/test/integration/contracts_delete_test.rb b/test/integration/contracts_delete_test.rb new file mode 100644 index 0000000..f46c2f2 --- /dev/null +++ b/test/integration/contracts_delete_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class ContractsDeleteTest < ActionController::IntegrationTest + include Redmine::I18n + + def setup + @project = Project.generate!(:identifier => 'main') + @contract = Contract.generate!(:project => @project, :name => 'A Contract', :payment_terms => 'net_15') + end + + should "allow admins to delete the contract" do + @user = User.generate!(:login => 'admin', :password => 'existing', :password_confirmation => 'existing', :admin => true) + login_as('admin', 'existing') + + visit_contracts_for_project(@project) + click_link @contract.id + assert_response :success + + click_link 'Update' + assert_response :success + assert_template 'contracts/edit' + + assert_select "a[href=?]", contract_path(@project, @contract), :text => /Delete/ + click_link 'Delete' + assert_response :success + assert_template 'contracts/index' + + assert_nil Contract.find_by_id(@contract.id), "Contract not deleted" + end + + should "not allow non-admins to delete the contract" do + visit_contracts_for_project(@project) + click_link @contract.id + assert_response :success + + click_link 'Update' + assert_response :success + assert_template 'contracts/edit' + + assert_select "a", :text => /Delete/, :count => 0 + delete contract_path(@project, @contract) + assert_response :redirect + follow_redirect! + assert_response :success + assert_template 'account/login' # Prompt for login + + assert Contract.find_by_id(@contract.id), "Contract deleted" + end +end