From a7607f574e14fc46c8187619c90e0cd717d78a95 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 31 Aug 2020 09:51:56 +0200 Subject: [PATCH] Maintenance: Ensured HTTP request verbs according to REST paradigm. --- .../app/controllers/agent_ticket_merge.coffee | 2 +- .../sidebar/linked_tickets.coffee | 4 ++-- .../app/controllers/ticket_link_add.coffee | 4 ++-- .../app/controllers/widget/link.coffee | 4 ++-- .../controllers/widget/link/kb_answer.coffee | 4 ++-- .../app/models/_application_model.coffee | 18 +++++++++--------- app/controllers/tags_controller.rb | 4 ++-- app/controllers/tickets_controller.rb | 2 +- config/routes/link.rb | 4 ++-- config/routes/tag.rb | 4 ++-- config/routes/ticket.rb | 2 +- spec/requests/ticket_spec.rb | 12 ++++++------ 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_merge.coffee b/app/assets/javascripts/app/controllers/agent_ticket_merge.coffee index 46ac8e447..470b1fb9b 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.coffee @@ -74,7 +74,7 @@ class App.TicketMerge extends App.ControllerModal # merge tickets @ajax( id: 'ticket_merge' - type: 'GET' + type: 'PUT' url: "#{@apiPath}/ticket_merge/#{@ticket.id}/#{params.master_ticket_number}" processData: true, success: (data, status, xhr) => diff --git a/app/assets/javascripts/app/controllers/knowledge_base/sidebar/linked_tickets.coffee b/app/assets/javascripts/app/controllers/knowledge_base/sidebar/linked_tickets.coffee index 86386ef0a..aff24ca8d 100644 --- a/app/assets/javascripts/app/controllers/knowledge_base/sidebar/linked_tickets.coffee +++ b/app/assets/javascripts/app/controllers/knowledge_base/sidebar/linked_tickets.coffee @@ -60,9 +60,9 @@ class App.KnowledgeBaseSidebarLinkedTickets extends App.Controller # get data @ajax( id: "links_remove_#{@object.id}_#{@object_type}" - type: 'GET' + type: 'DELETE' url: "#{@apiPath}/links/remove" - data: data + data: JSON.stringify(data) processData: true success: @fetch ) diff --git a/app/assets/javascripts/app/controllers/ticket_link_add.coffee b/app/assets/javascripts/app/controllers/ticket_link_add.coffee index ac9db0c51..56a2645e1 100644 --- a/app/assets/javascripts/app/controllers/ticket_link_add.coffee +++ b/app/assets/javascripts/app/controllers/ticket_link_add.coffee @@ -82,9 +82,9 @@ class App.TicketLinkAdd extends App.ControllerModal # get data @ajax( id: "links_add_#{@object.id}_#{@object_type}" - type: 'GET' + type: 'POST' url: "#{@apiPath}/links/add" - data: + data: JSON.stringify link_type: params['link_type'] link_object_target: @link_object link_object_target_value: @object.id diff --git a/app/assets/javascripts/app/controllers/widget/link.coffee b/app/assets/javascripts/app/controllers/widget/link.coffee index 9b6ce92c9..0265c71d5 100644 --- a/app/assets/javascripts/app/controllers/widget/link.coffee +++ b/app/assets/javascripts/app/controllers/widget/link.coffee @@ -52,9 +52,9 @@ class App.WidgetLink extends App.Controller # get data @ajax( id: "links_remove_#{@object.id}_#{@object_type}" - type: 'GET' + type: 'DELETE' url: "#{@apiPath}/links/remove" - data: + data: JSON.stringify link_type: link_type link_object_source: link_object_source link_object_source_value: link_object_source_value diff --git a/app/assets/javascripts/app/controllers/widget/link/kb_answer.coffee b/app/assets/javascripts/app/controllers/widget/link/kb_answer.coffee index edeb6688c..2027a4f3c 100644 --- a/app/assets/javascripts/app/controllers/widget/link/kb_answer.coffee +++ b/app/assets/javascripts/app/controllers/widget/link/kb_answer.coffee @@ -83,9 +83,9 @@ class App.WidgetLinkKbAnswer extends App.WidgetLink saveToServer: (id) -> @ajax( id: "links_add_#{@object.id}_#{@object_type}" - type: 'GET' + type: 'POST' url: "#{@apiPath}/links/add" - data: + data: JSON.stringify link_type: 'normal' link_object_target: 'Ticket' link_object_target_value: @object.id diff --git a/app/assets/javascripts/app/models/_application_model.coffee b/app/assets/javascripts/app/models/_application_model.coffee index 9f0a17a81..5a9771b14 100644 --- a/app/assets/javascripts/app/models/_application_model.coffee +++ b/app/assets/javascripts/app/models/_application_model.coffee @@ -802,9 +802,9 @@ set new attributes of model (remove already available attributes) @tagGet: (id, key, callback) -> App.Ajax.request( - id: key - type: 'GET' - url: "#{@apiPath}/tags" + id: key + type: 'GET' + url: "#{@apiPath}/tags" data: object: @serverClassName || @className o_id: id @@ -815,9 +815,9 @@ set new attributes of model (remove already available attributes) @tagAdd: (id, item) -> App.Ajax.request( - type: 'GET' - url: "#{@apiPath}/tags/add" - data: + type: 'POST' + url: "#{@apiPath}/tags/add" + data: JSON.stringify object: @serverClassName || @className o_id: id item: item @@ -826,9 +826,9 @@ set new attributes of model (remove already available attributes) @tagRemove: (id, item) -> App.Ajax.request( - type: 'GET' - url: "#{@apiPath}/tags/remove" - data: + type: 'DELETE' + url: "#{@apiPath}/tags/remove" + data: JSON.stringify object: @serverClassName || @className o_id: id item: item diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 064fe1026..6ab890228 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -31,7 +31,7 @@ class TagsController < ApplicationController } end - # POST /api/v1/tag/add + # POST /api/v1/tags/add def add success = Tag.tag_add( object: params[:object], @@ -45,7 +45,7 @@ class TagsController < ApplicationController end end - # DELETE /api/v1/tag/remove + # DELETE /api/v1/tags/remove def remove success = Tag.tag_remove( object: params[:object], diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 60edd6fc9..1f51e5b36 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -372,7 +372,7 @@ class TicketsController < ApplicationController } end - # GET /api/v1/ticket_merge/1/1 + # PUT /api/v1/ticket_merge/1/1 def ticket_merge # check master ticket diff --git a/config/routes/link.rb b/config/routes/link.rb index c86ec2ddc..febc42eea 100644 --- a/config/routes/link.rb +++ b/config/routes/link.rb @@ -3,7 +3,7 @@ Zammad::Application.routes.draw do # links match api_path + '/links', to: 'links#index', via: :get - match api_path + '/links/add', to: 'links#add', via: :get - match api_path + '/links/remove', to: 'links#remove', via: :get + match api_path + '/links/add', to: 'links#add', via: :post + match api_path + '/links/remove', to: 'links#remove', via: :delete end diff --git a/config/routes/tag.rb b/config/routes/tag.rb index 4c95024e5..dfe026d46 100644 --- a/config/routes/tag.rb +++ b/config/routes/tag.rb @@ -2,8 +2,8 @@ Zammad::Application.routes.draw do api_path = Rails.configuration.api_path match api_path + '/tags', to: 'tags#list', via: :get - match api_path + '/tags/add', to: 'tags#add', via: :get - match api_path + '/tags/remove', to: 'tags#remove', via: :get + match api_path + '/tags/add', to: 'tags#add', via: :post + match api_path + '/tags/remove', to: 'tags#remove', via: :delete match api_path + '/tag_search', to: 'tags#search', via: :get match api_path + '/tag_list', to: 'tags#admin_list', via: :get diff --git a/config/routes/ticket.rb b/config/routes/ticket.rb index 60ac8832f..ac261fe20 100644 --- a/config/routes/ticket.rb +++ b/config/routes/ticket.rb @@ -15,7 +15,7 @@ Zammad::Application.routes.draw do match api_path + '/ticket_customer', to: 'tickets#ticket_customer', via: :get match api_path + '/ticket_related/:ticket_id', to: 'tickets#ticket_related', via: :get match api_path + '/ticket_recent', to: 'tickets#ticket_recent', via: :get - match api_path + '/ticket_merge/:slave_ticket_id/:master_ticket_number', to: 'tickets#ticket_merge', via: :get + match api_path + '/ticket_merge/:slave_ticket_id/:master_ticket_number', to: 'tickets#ticket_merge', via: :put match api_path + '/ticket_stats', to: 'tickets#stats', via: :get # ticket overviews diff --git a/spec/requests/ticket_spec.rb b/spec/requests/ticket_spec.rb index 4af02f2d8..d44aa6088 100644 --- a/spec/requests/ticket_spec.rb +++ b/spec/requests/ticket_spec.rb @@ -1923,29 +1923,29 @@ RSpec.describe 'Ticket', type: :request do ) authenticated_as(customer) - get "/api/v1/ticket_merge/#{ticket2.id}/#{ticket1.id}", params: {}, as: :json + put "/api/v1/ticket_merge/#{ticket2.id}/#{ticket1.id}", params: {}, as: :json expect(response).to have_http_status(:unauthorized) authenticated_as(agent) - get "/api/v1/ticket_merge/#{ticket2.id}/#{ticket1.id}", params: {}, as: :json + put "/api/v1/ticket_merge/#{ticket2.id}/#{ticket1.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response['result']).to eq('failed') expect(json_response['message']).to eq('No such master ticket number!') - get "/api/v1/ticket_merge/#{ticket3.id}/#{ticket1.number}", params: {}, as: :json + put "/api/v1/ticket_merge/#{ticket3.id}/#{ticket1.number}", params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(json_response).to be_a_kind_of(Hash) expect(json_response['error']).to eq('Not authorized') expect(json_response['error_human']).to eq('Not authorized') - get "/api/v1/ticket_merge/#{ticket1.id}/#{ticket3.number}", params: {}, as: :json + put "/api/v1/ticket_merge/#{ticket1.id}/#{ticket3.number}", params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(json_response).to be_a_kind_of(Hash) expect(json_response['error']).to eq('Not authorized') expect(json_response['error_human']).to eq('Not authorized') - get "/api/v1/ticket_merge/#{ticket1.id}/#{ticket2.number}", params: {}, as: :json + put "/api/v1/ticket_merge/#{ticket1.id}/#{ticket2.number}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response['result']).to eq('success') @@ -1975,7 +1975,7 @@ RSpec.describe 'Ticket', type: :request do agent.group_names_access_map = { group_change_permission.name => %w[read change] } authenticated_as(agent) - get "/api/v1/ticket_merge/#{ticket1.id}/#{ticket2.number}", params: {}, as: :json + put "/api/v1/ticket_merge/#{ticket1.id}/#{ticket2.number}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response['result']).to eq('success')