Skip to content

Commit

Permalink
Disallow used supply item deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
sanak committed May 15, 2024
1 parent 1d94371 commit 1831110
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/controllers/supply_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,21 @@ def update
end

def destroy
find_supply_item.destroy
respond_to do |format|
format.html { redirect_to project_supply_items_path(@project) }
format.api { render_api_ok }
@supply_item = find_supply_item
if @supply_item.issues.empty?
@supply_item.destroy
respond_to do |format|
format.html { redirect_to project_supply_items_path(@project) }
format.api { render_api_ok }
end
else
respond_to do |format|
format.html do
flash[:error] = l(:error_can_not_delete_supply_item)
redirect_to project_supply_items_path(@project)
end
format.api {head :unprocessable_entity}
end
end
end

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ en:
permission_view_supply_items: View supply items
permission_view_issue_supply_items: View issue supply items
permission_manage_issue_supply_items: Manage issue supply items
error_can_not_delete_supply_item: "This supply item contains issues and cannot be deleted."
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ ja:
permission_view_supply_items: 資材の項目を閲覧
permission_view_issue_supply_items: チケットの資材項目を閲覧
permission_manage_issue_supply_items: チケットの資材項目を管理
error_can_not_delete_supply_item: 'この資材は使用中です。削除できません。'

0 comments on commit 1831110

Please sign in to comment.