Maintenance: Ensured HTTP request verbs according to REST paradigm.

This commit is contained in:
Thorsten Eckel 2020-08-31 09:51:56 +02:00
parent f63577633f
commit a7607f574e
12 changed files with 32 additions and 32 deletions

View file

@ -74,7 +74,7 @@ class App.TicketMerge extends App.ControllerModal
# merge tickets # merge tickets
@ajax( @ajax(
id: 'ticket_merge' id: 'ticket_merge'
type: 'GET' type: 'PUT'
url: "#{@apiPath}/ticket_merge/#{@ticket.id}/#{params.master_ticket_number}" url: "#{@apiPath}/ticket_merge/#{@ticket.id}/#{params.master_ticket_number}"
processData: true, processData: true,
success: (data, status, xhr) => success: (data, status, xhr) =>

View file

@ -60,9 +60,9 @@ class App.KnowledgeBaseSidebarLinkedTickets extends App.Controller
# get data # get data
@ajax( @ajax(
id: "links_remove_#{@object.id}_#{@object_type}" id: "links_remove_#{@object.id}_#{@object_type}"
type: 'GET' type: 'DELETE'
url: "#{@apiPath}/links/remove" url: "#{@apiPath}/links/remove"
data: data data: JSON.stringify(data)
processData: true processData: true
success: @fetch success: @fetch
) )

View file

@ -82,9 +82,9 @@ class App.TicketLinkAdd extends App.ControllerModal
# get data # get data
@ajax( @ajax(
id: "links_add_#{@object.id}_#{@object_type}" id: "links_add_#{@object.id}_#{@object_type}"
type: 'GET' type: 'POST'
url: "#{@apiPath}/links/add" url: "#{@apiPath}/links/add"
data: data: JSON.stringify
link_type: params['link_type'] link_type: params['link_type']
link_object_target: @link_object link_object_target: @link_object
link_object_target_value: @object.id link_object_target_value: @object.id

View file

@ -52,9 +52,9 @@ class App.WidgetLink extends App.Controller
# get data # get data
@ajax( @ajax(
id: "links_remove_#{@object.id}_#{@object_type}" id: "links_remove_#{@object.id}_#{@object_type}"
type: 'GET' type: 'DELETE'
url: "#{@apiPath}/links/remove" url: "#{@apiPath}/links/remove"
data: data: JSON.stringify
link_type: link_type link_type: link_type
link_object_source: link_object_source link_object_source: link_object_source
link_object_source_value: link_object_source_value link_object_source_value: link_object_source_value

View file

@ -83,9 +83,9 @@ class App.WidgetLinkKbAnswer extends App.WidgetLink
saveToServer: (id) -> saveToServer: (id) ->
@ajax( @ajax(
id: "links_add_#{@object.id}_#{@object_type}" id: "links_add_#{@object.id}_#{@object_type}"
type: 'GET' type: 'POST'
url: "#{@apiPath}/links/add" url: "#{@apiPath}/links/add"
data: data: JSON.stringify
link_type: 'normal' link_type: 'normal'
link_object_target: 'Ticket' link_object_target: 'Ticket'
link_object_target_value: @object.id link_object_target_value: @object.id

View file

@ -815,9 +815,9 @@ set new attributes of model (remove already available attributes)
@tagAdd: (id, item) -> @tagAdd: (id, item) ->
App.Ajax.request( App.Ajax.request(
type: 'GET' type: 'POST'
url: "#{@apiPath}/tags/add" url: "#{@apiPath}/tags/add"
data: data: JSON.stringify
object: @serverClassName || @className object: @serverClassName || @className
o_id: id o_id: id
item: item item: item
@ -826,9 +826,9 @@ set new attributes of model (remove already available attributes)
@tagRemove: (id, item) -> @tagRemove: (id, item) ->
App.Ajax.request( App.Ajax.request(
type: 'GET' type: 'DELETE'
url: "#{@apiPath}/tags/remove" url: "#{@apiPath}/tags/remove"
data: data: JSON.stringify
object: @serverClassName || @className object: @serverClassName || @className
o_id: id o_id: id
item: item item: item

View file

@ -31,7 +31,7 @@ class TagsController < ApplicationController
} }
end end
# POST /api/v1/tag/add # POST /api/v1/tags/add
def add def add
success = Tag.tag_add( success = Tag.tag_add(
object: params[:object], object: params[:object],
@ -45,7 +45,7 @@ class TagsController < ApplicationController
end end
end end
# DELETE /api/v1/tag/remove # DELETE /api/v1/tags/remove
def remove def remove
success = Tag.tag_remove( success = Tag.tag_remove(
object: params[:object], object: params[:object],

View file

@ -372,7 +372,7 @@ class TicketsController < ApplicationController
} }
end end
# GET /api/v1/ticket_merge/1/1 # PUT /api/v1/ticket_merge/1/1
def ticket_merge def ticket_merge
# check master ticket # check master ticket

View file

@ -3,7 +3,7 @@ Zammad::Application.routes.draw do
# links # links
match api_path + '/links', to: 'links#index', via: :get match api_path + '/links', to: 'links#index', via: :get
match api_path + '/links/add', to: 'links#add', via: :get match api_path + '/links/add', to: 'links#add', via: :post
match api_path + '/links/remove', to: 'links#remove', via: :get match api_path + '/links/remove', to: 'links#remove', via: :delete
end end

View file

@ -2,8 +2,8 @@ Zammad::Application.routes.draw do
api_path = Rails.configuration.api_path api_path = Rails.configuration.api_path
match api_path + '/tags', to: 'tags#list', via: :get match api_path + '/tags', to: 'tags#list', via: :get
match api_path + '/tags/add', to: 'tags#add', via: :get match api_path + '/tags/add', to: 'tags#add', via: :post
match api_path + '/tags/remove', to: 'tags#remove', via: :get match api_path + '/tags/remove', to: 'tags#remove', via: :delete
match api_path + '/tag_search', to: 'tags#search', via: :get match api_path + '/tag_search', to: 'tags#search', via: :get
match api_path + '/tag_list', to: 'tags#admin_list', via: :get match api_path + '/tag_list', to: 'tags#admin_list', via: :get

View file

@ -15,7 +15,7 @@ Zammad::Application.routes.draw do
match api_path + '/ticket_customer', to: 'tickets#ticket_customer', via: :get 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_related/:ticket_id', to: 'tickets#ticket_related', via: :get
match api_path + '/ticket_recent', to: 'tickets#ticket_recent', 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 match api_path + '/ticket_stats', to: 'tickets#stats', via: :get
# ticket overviews # ticket overviews

View file

@ -1923,29 +1923,29 @@ RSpec.describe 'Ticket', type: :request do
) )
authenticated_as(customer) 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) expect(response).to have_http_status(:unauthorized)
authenticated_as(agent) 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(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash) expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to eq('failed') expect(json_response['result']).to eq('failed')
expect(json_response['message']).to eq('No such master ticket number!') 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(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash) expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized') expect(json_response['error']).to eq('Not authorized')
expect(json_response['error_human']).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(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash) expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized') expect(json_response['error']).to eq('Not authorized')
expect(json_response['error_human']).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(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash) expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to eq('success') 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] } agent.group_names_access_map = { group_change_permission.name => %w[read change] }
authenticated_as(agent) 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(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash) expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to eq('success') expect(json_response['result']).to eq('success')