Fixed issue #903 - member_ids missing in organization list API endpoint.
This commit is contained in:
parent
b00dc74e8e
commit
c662df0d11
5 changed files with 22 additions and 25 deletions
|
@ -91,8 +91,11 @@ curl http://localhost/api/v1/organizations -v -u #{login}:#{password}
|
|||
}, status: :ok
|
||||
return
|
||||
end
|
||||
|
||||
render json: organizations
|
||||
list = []
|
||||
organizations.each { |organization|
|
||||
list.push organization.attributes_with_association_ids
|
||||
}
|
||||
render json: list
|
||||
end
|
||||
|
||||
=begin
|
||||
|
@ -293,7 +296,7 @@ curl http://localhost/api/v1/organization/{id} -v -u #{login}:#{password} -H "Co
|
|||
|
||||
list = []
|
||||
organization_all.each { |organization|
|
||||
list.push organization.attributes
|
||||
list.push organization.attributes_with_association_ids
|
||||
}
|
||||
render json: list, status: :ok
|
||||
end
|
||||
|
|
|
@ -428,7 +428,7 @@ class UsersController < ApplicationController
|
|||
|
||||
list = []
|
||||
user_all.each { |user|
|
||||
list.push user.attributes
|
||||
list.push user.attributes_with_association_ids
|
||||
}
|
||||
render json: list, status: :ok
|
||||
end
|
||||
|
|
|
@ -15,7 +15,6 @@ class Organization < ApplicationModel
|
|||
load 'organization/search_index.rb'
|
||||
include Organization::SearchIndex
|
||||
|
||||
has_and_belongs_to_many :users
|
||||
has_many :members, class_name: 'User'
|
||||
validates :name, presence: true
|
||||
|
||||
|
@ -34,11 +33,4 @@ class Organization < ApplicationModel
|
|||
domain.downcase!
|
||||
end
|
||||
|
||||
def cache_delete
|
||||
super
|
||||
|
||||
# delete asset caches
|
||||
key = "Organization::member_ids::#{id}"
|
||||
Cache.delete(key)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,22 +33,14 @@ returns
|
|||
data[ app_model_user ] = {}
|
||||
end
|
||||
if !data[ app_model_organization ][ id ]
|
||||
local_attributes = attributes
|
||||
local_attributes = attributes_with_association_ids
|
||||
|
||||
# set temp. current attributes to assets pool to prevent
|
||||
# loops, will be updated with lookup attributes later
|
||||
data[ app_model_organization ][ id ] = local_attributes
|
||||
|
||||
# get organizations
|
||||
key = "Organization::member_ids::#{id}"
|
||||
local_member_ids = Cache.get(key)
|
||||
if !local_member_ids
|
||||
local_member_ids = member_ids
|
||||
Cache.write(key, local_member_ids)
|
||||
end
|
||||
local_attributes['member_ids'] = local_member_ids
|
||||
if local_member_ids
|
||||
local_member_ids.each { |local_user_id|
|
||||
if local_attributes['member_ids']
|
||||
local_attributes['member_ids'].each { |local_user_id|
|
||||
next if data[ app_model_user ][ local_user_id ]
|
||||
user = User.lookup(id: local_user_id)
|
||||
next if !user
|
||||
|
|
|
@ -419,7 +419,7 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_equal(result_user1['id'], result[0]['id'])
|
||||
assert_equal("Customer#{firstname}", result[0]['firstname'])
|
||||
assert_equal('Customer Last', result[0]['lastname'])
|
||||
assert_not(result[0]['role_ids'])
|
||||
assert(result[0]['role_ids'])
|
||||
assert_not(result[0]['roles'])
|
||||
|
||||
get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&expand=true", {}, @headers.merge('Authorization' => credentials)
|
||||
|
@ -538,6 +538,7 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_response(200)
|
||||
result = JSON.parse(@response.body)
|
||||
assert_equal(result.class, Array)
|
||||
assert_equal(result[0]['member_ids'].class, Array)
|
||||
assert(result.length >= 3)
|
||||
|
||||
get '/api/v1/organizations?limit=40&page=1&per_page=2', {}, @headers.merge('Authorization' => credentials)
|
||||
|
@ -546,7 +547,9 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_equal(Array, result.class)
|
||||
organizations = Organization.order(:id).limit(2)
|
||||
assert_equal(organizations[0].id, result[0]['id'])
|
||||
assert_equal(organizations[0].member_ids, result[0]['member_ids'])
|
||||
assert_equal(organizations[1].id, result[1]['id'])
|
||||
assert_equal(organizations[1].member_ids, result[1]['member_ids'])
|
||||
assert_equal(2, result.count)
|
||||
|
||||
get '/api/v1/organizations?limit=40&page=2&per_page=2', {}, @headers.merge('Authorization' => credentials)
|
||||
|
@ -555,7 +558,10 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_equal(Array, result.class)
|
||||
organizations = Organization.order(:id).limit(4)
|
||||
assert_equal(organizations[2].id, result[0]['id'])
|
||||
assert_equal(organizations[2].member_ids, result[0]['member_ids'])
|
||||
assert_equal(organizations[3].id, result[1]['id'])
|
||||
assert_equal(organizations[3].member_ids, result[1]['member_ids'])
|
||||
|
||||
assert_equal(2, result.count)
|
||||
|
||||
# show/:id
|
||||
|
@ -563,12 +569,16 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_response(200)
|
||||
result = JSON.parse(@response.body)
|
||||
assert_equal(result.class, Hash)
|
||||
assert_equal(result['member_ids'].class, Array)
|
||||
assert_not(result['members'])
|
||||
assert_equal(result['name'], 'Rest Org')
|
||||
|
||||
get "/api/v1/organizations/#{@organization2.id}", {}, @headers.merge('Authorization' => credentials)
|
||||
assert_response(200)
|
||||
result = JSON.parse(@response.body)
|
||||
assert_equal(result.class, Hash)
|
||||
assert_equal(result['member_ids'].class, Array)
|
||||
assert_not(result['members'])
|
||||
assert_equal(result['name'], 'Rest Org #2')
|
||||
|
||||
# search as agent
|
||||
|
@ -578,7 +588,7 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
|||
result = JSON.parse(@response.body)
|
||||
assert_equal(Array, result.class)
|
||||
assert_equal('Zammad Foundation', result[0]['name'])
|
||||
assert_not(result[0]['member_ids'])
|
||||
assert(result[0]['member_ids'])
|
||||
assert_not(result[0]['members'])
|
||||
|
||||
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}&expand=true", {}, @headers.merge('Authorization' => credentials)
|
||||
|
|
Loading…
Reference in a new issue