[#4177] Added a link to delete a contract for admin users only.
This commit is contained in:
@@ -5,6 +5,7 @@ class ContractsController < InheritedResources::Base
|
|||||||
|
|
||||||
before_filter :find_project
|
before_filter :find_project
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
before_filter :require_admin, :only => :destroy
|
||||||
|
|
||||||
def create
|
def create
|
||||||
create! { contract_url(@project, resource) }
|
create! { contract_url(@project, resource) }
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
<% if User.current.admin? %>
|
||||||
|
<div class="contextual">
|
||||||
|
<%= link_to(l(:button_delete), contract_path(@project, resource), :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del contract-delete') %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= content_tag(:h2, h(resource.name)) %>
|
<%= content_tag(:h2, h(resource.name)) %>
|
||||||
|
|
||||||
<% semantic_form_for resource, :url => contract_path(@project, resource), :html => {:class => 'tabular'} do |form| %>
|
<% semantic_form_for resource, :url => contract_path(@project, resource), :html => {:class => 'tabular'} do |form| %>
|
||||||
|
|||||||
@@ -15,3 +15,6 @@ html>body .tabular li {overflow:hidden;}
|
|||||||
.tabular li.required label { color: #484848; }
|
.tabular li.required label { color: #484848; }
|
||||||
.tabular li.required label span.required {color: #bb0000;}
|
.tabular li.required label span.required {color: #bb0000;}
|
||||||
|
|
||||||
|
/* End tabular */
|
||||||
|
|
||||||
|
a.contract-delete {color: red; }
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_contracts do
|
|||||||
requires_redmine_plugin :redmine_rate, :version_or_higher => '0.1.0'
|
requires_redmine_plugin :redmine_rate, :version_or_higher => '0.1.0'
|
||||||
|
|
||||||
project_module :contracts do
|
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
|
end
|
||||||
|
|
||||||
menu(:project_menu,
|
menu(:project_menu,
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user