Improved user/org search.
This commit is contained in:
parent
ef7a8a3277
commit
50c1633124
4 changed files with 130 additions and 41 deletions
|
@ -255,10 +255,10 @@ curl http://localhost/api/v1/organization/{id} -v -u #{login}:#{password} -H "Co
|
||||||
end
|
end
|
||||||
|
|
||||||
# build result list
|
# build result list
|
||||||
if !params[:full]
|
if params[:label]
|
||||||
organizations = []
|
organizations = []
|
||||||
organization_all.each { |organization|
|
organization_all.each { |organization|
|
||||||
a = { id: organization.id, label: organization.name }
|
a = { id: organization.id, label: organization.name, value: organization.name }
|
||||||
organizations.push a
|
organizations.push a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,6 +267,7 @@ curl http://localhost/api/v1/organization/{id} -v -u #{login}:#{password} -H "Co
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if params[:full]
|
||||||
organization_ids = []
|
organization_ids = []
|
||||||
assets = {}
|
assets = {}
|
||||||
organization_all.each { |organization|
|
organization_all.each { |organization|
|
||||||
|
@ -281,6 +282,13 @@ curl http://localhost/api/v1/organization/{id} -v -u #{login}:#{password} -H "Co
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
list = []
|
||||||
|
organization_all.each { |organization|
|
||||||
|
list.push organization.attributes
|
||||||
|
}
|
||||||
|
render json: list, status: :ok
|
||||||
|
end
|
||||||
|
|
||||||
# GET /api/v1/organizations/history/1
|
# GET /api/v1/organizations/history/1
|
||||||
def history
|
def history
|
||||||
|
|
||||||
|
|
|
@ -361,7 +361,7 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# build result list
|
# build result list
|
||||||
if !params[:full]
|
if params[:label]
|
||||||
users = []
|
users = []
|
||||||
user_all.each { |user|
|
user_all.each { |user|
|
||||||
realname = user.firstname.to_s + ' ' + user.lastname.to_s
|
realname = user.firstname.to_s + ' ' + user.lastname.to_s
|
||||||
|
@ -377,6 +377,7 @@ class UsersController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if params[:full]
|
||||||
user_ids = []
|
user_ids = []
|
||||||
assets = {}
|
assets = {}
|
||||||
user_all.each { |user|
|
user_all.each { |user|
|
||||||
|
@ -391,6 +392,13 @@ class UsersController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
list = []
|
||||||
|
user_all.each { |user|
|
||||||
|
list.push user.attributes
|
||||||
|
}
|
||||||
|
render json: list, status: :ok
|
||||||
|
end
|
||||||
|
|
||||||
# @path [GET] /users/recent
|
# @path [GET] /users/recent
|
||||||
#
|
#
|
||||||
# @tag Search
|
# @tag Search
|
||||||
|
|
|
@ -280,7 +280,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal(Ticket::Article::Type.lookup(name: 'note').id, article_result['type_id'])
|
assert_equal(Ticket::Article::Type.lookup(name: 'note').id, article_result['type_id'])
|
||||||
|
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
get "/api/v1/tickets/search?query=\"#{CGI.escape(title)}\"", {}, @headers.merge('Authorization' => credentials)
|
get "/api/v1/tickets/search?query=#{CGI.escape(title)}", {}, @headers.merge('Authorization' => credentials)
|
||||||
assert_response(200)
|
assert_response(200)
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
|
@ -595,7 +595,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal(Ticket::Article::Type.lookup(name: 'note').id, article_result['type_id'])
|
assert_equal(Ticket::Article::Type.lookup(name: 'note').id, article_result['type_id'])
|
||||||
|
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
get "/api/v1/tickets/search?query=\"#{CGI.escape(title)}\"", {}, @headers.merge('Authorization' => credentials)
|
get "/api/v1/tickets/search?query=#{CGI.escape(title)}", {}, @headers.merge('Authorization' => credentials)
|
||||||
assert_response(200)
|
assert_response(200)
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
|
|
|
@ -290,16 +290,47 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
# create user with customer role
|
# create user with customer role
|
||||||
role = Role.lookup(name: 'Customer')
|
role = Role.lookup(name: 'Customer')
|
||||||
params = { firstname: 'Agent First', lastname: 'Agent Last', email: 'new_agent_by_agent@example.com', role_ids: [ role.id ] }
|
params = { firstname: 'Customer First', lastname: 'Customer Last', email: 'new_agent_by_agent@example.com', role_ids: [ role.id ] }
|
||||||
post '/api/v1/users', params.to_json, @headers.merge('Authorization' => credentials)
|
post '/api/v1/users', params.to_json, @headers.merge('Authorization' => credentials)
|
||||||
assert_response(201)
|
assert_response(201)
|
||||||
result = JSON.parse(@response.body)
|
result_user1 = JSON.parse(@response.body)
|
||||||
assert(result)
|
assert(result_user1)
|
||||||
user = User.find(result['id'])
|
user = User.find(result_user1['id'])
|
||||||
assert_not(user.role?('Admin'))
|
assert_not(user.role?('Admin'))
|
||||||
assert_not(user.role?('Agent'))
|
assert_not(user.role?('Agent'))
|
||||||
assert(user.role?('Customer'))
|
assert(user.role?('Customer'))
|
||||||
|
|
||||||
|
# search as agent
|
||||||
|
Scheduler.worker(true)
|
||||||
|
get "/api/v1/users/search?query=#{CGI.escape('First')}", {}, @headers.merge('Authorization' => credentials)
|
||||||
|
assert_response(200)
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Array, result.class)
|
||||||
|
assert_equal(result_user1['id'], result[0]['id'])
|
||||||
|
assert_equal('Customer First', result[0]['firstname'])
|
||||||
|
assert_equal('Customer Last', result[0]['lastname'])
|
||||||
|
assert_not(result[0]['role_ids'])
|
||||||
|
assert_not(result[0]['roles'])
|
||||||
|
|
||||||
|
get "/api/v1/users/search?query=#{CGI.escape('First')}&expand=true", {}, @headers.merge('Authorization' => credentials)
|
||||||
|
assert_response(200)
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Array, result.class)
|
||||||
|
assert_equal(result_user1['id'], result[0]['id'])
|
||||||
|
assert_equal('Customer First', result[0]['firstname'])
|
||||||
|
assert_equal('Customer Last', result[0]['lastname'])
|
||||||
|
assert(result[0]['role_ids'])
|
||||||
|
assert(result[0]['roles'])
|
||||||
|
|
||||||
|
get "/api/v1/users/search?query=#{CGI.escape('First')}&label=true", {}, @headers.merge('Authorization' => credentials)
|
||||||
|
assert_response(200)
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Array, result.class)
|
||||||
|
assert_equal(result_user1['id'], result[0]['id'])
|
||||||
|
assert_equal('Customer First Customer Last <new_agent_by_agent@example.com>', result[0]['label'])
|
||||||
|
assert_equal('Customer First Customer Last <new_agent_by_agent@example.com>', result[0]['value'])
|
||||||
|
assert_not(result[0]['role_ids'])
|
||||||
|
assert_not(result[0]['roles'])
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'user index and create with customer1' do
|
test 'user index and create with customer1' do
|
||||||
|
@ -338,6 +369,10 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
||||||
post '/api/v1/users', params.to_json, @headers.merge('Authorization' => credentials)
|
post '/api/v1/users', params.to_json, @headers.merge('Authorization' => credentials)
|
||||||
assert_response(401)
|
assert_response(401)
|
||||||
|
|
||||||
|
# search
|
||||||
|
Scheduler.worker(true)
|
||||||
|
get "/api/v1/users/search?query=#{CGI.escape('First')}", {}, @headers.merge('Authorization' => credentials)
|
||||||
|
assert_response(401)
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'user index with customer2' do
|
test 'user index with customer2' do
|
||||||
|
@ -364,6 +399,10 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal(result.class, Hash)
|
assert_equal(result.class, Hash)
|
||||||
assert(result['error'])
|
assert(result['error'])
|
||||||
|
|
||||||
|
# search
|
||||||
|
Scheduler.worker(true)
|
||||||
|
get "/api/v1/users/search?query=#{CGI.escape('First')}", {}, @headers.merge('Authorization' => credentials)
|
||||||
|
assert_response(401)
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'organization index with agent' do
|
test 'organization index with agent' do
|
||||||
|
@ -381,15 +420,41 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
||||||
get "/api/v1/organizations/#{@organization.id}", {}, @headers.merge('Authorization' => credentials)
|
get "/api/v1/organizations/#{@organization.id}", {}, @headers.merge('Authorization' => credentials)
|
||||||
assert_response(200)
|
assert_response(200)
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal( result.class, Hash)
|
assert_equal(result.class, Hash)
|
||||||
assert_equal( result['name'], 'Rest Org')
|
assert_equal(result['name'], 'Rest Org')
|
||||||
|
|
||||||
get "/api/v1/organizations/#{@organization2.id}", {}, @headers.merge('Authorization' => credentials)
|
get "/api/v1/organizations/#{@organization2.id}", {}, @headers.merge('Authorization' => credentials)
|
||||||
assert_response(200)
|
assert_response(200)
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal( result.class, Hash)
|
assert_equal(result.class, Hash)
|
||||||
assert_equal( result['name'], 'Rest Org #2')
|
assert_equal(result['name'], 'Rest Org #2')
|
||||||
|
|
||||||
|
# search as agent
|
||||||
|
Scheduler.worker(true)
|
||||||
|
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}", {}, @headers.merge('Authorization' => credentials)
|
||||||
|
assert_response(200)
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Array, result.class)
|
||||||
|
assert_equal('Zammad Foundation', result[0]['name'])
|
||||||
|
assert_not(result[0]['member_ids'])
|
||||||
|
assert_not(result[0]['members'])
|
||||||
|
|
||||||
|
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}&expand=true", {}, @headers.merge('Authorization' => credentials)
|
||||||
|
assert_response(200)
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Array, result.class)
|
||||||
|
assert_equal('Zammad Foundation', result[0]['name'])
|
||||||
|
assert(result[0]['member_ids'])
|
||||||
|
assert(result[0]['members'])
|
||||||
|
|
||||||
|
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}&label=true", {}, @headers.merge('Authorization' => credentials)
|
||||||
|
assert_response(200)
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Array, result.class)
|
||||||
|
assert_equal('Zammad Foundation', result[0]['label'])
|
||||||
|
assert_equal('Zammad Foundation', result[0]['value'])
|
||||||
|
assert_not(result[0]['member_ids'])
|
||||||
|
assert_not(result[0]['members'])
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'organization index with customer1' do
|
test 'organization index with customer1' do
|
||||||
|
@ -407,15 +472,19 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
||||||
get "/api/v1/organizations/#{@organization.id}", {}, @headers.merge('Authorization' => credentials)
|
get "/api/v1/organizations/#{@organization.id}", {}, @headers.merge('Authorization' => credentials)
|
||||||
assert_response(200)
|
assert_response(200)
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal( result.class, Hash)
|
assert_equal(result.class, Hash)
|
||||||
assert_equal( result['name'], nil)
|
assert_equal(result['name'], nil)
|
||||||
|
|
||||||
get "/api/v1/organizations/#{@organization2.id}", {}, @headers.merge('Authorization' => credentials)
|
get "/api/v1/organizations/#{@organization2.id}", {}, @headers.merge('Authorization' => credentials)
|
||||||
assert_response(200)
|
assert_response(200)
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal( result.class, Hash)
|
assert_equal(result.class, Hash)
|
||||||
assert_equal( result['name'], nil)
|
assert_equal(result['name'], nil)
|
||||||
|
|
||||||
|
# search
|
||||||
|
Scheduler.worker(true)
|
||||||
|
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}", {}, @headers.merge('Authorization' => credentials)
|
||||||
|
assert_response(401)
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'organization index with customer2' do
|
test 'organization index with customer2' do
|
||||||
|
@ -433,15 +502,19 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
||||||
get "/api/v1/organizations/#{@organization.id}", {}, @headers.merge('Authorization' => credentials)
|
get "/api/v1/organizations/#{@organization.id}", {}, @headers.merge('Authorization' => credentials)
|
||||||
assert_response(200)
|
assert_response(200)
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal( result.class, Hash)
|
assert_equal(result.class, Hash)
|
||||||
assert_equal( result['name'], 'Rest Org')
|
assert_equal(result['name'], 'Rest Org')
|
||||||
|
|
||||||
get "/api/v1/organizations/#{@organization2.id}", {}, @headers.merge('Authorization' => credentials)
|
get "/api/v1/organizations/#{@organization2.id}", {}, @headers.merge('Authorization' => credentials)
|
||||||
assert_response(401)
|
assert_response(401)
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal( result.class, Hash)
|
assert_equal(result.class, Hash)
|
||||||
assert_equal( result['name'], nil)
|
assert_equal(result['name'], nil)
|
||||||
|
|
||||||
|
# search
|
||||||
|
Scheduler.worker(true)
|
||||||
|
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}", {}, @headers.merge('Authorization' => credentials)
|
||||||
|
assert_response(401)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue