diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c7d9d49c..1107df0d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - OpenAPI endpoint to fetch accounting data - Updated OpenAPI documentation - OpenAPI users endpoint offer ability to filter by created_after +- OpenAPI users endpoint return gender, organization and address - Fix a bug: providing an array of attributes to filter OpenApi data, results in error - Fix a bug: unable to manage stocks on new products - Fix a bug: unsupported param[] syntax in OpenAPI diff --git a/app/doc/open_api/v1/users_doc.rb b/app/doc/open_api/v1/users_doc.rb index b1772e18f..94f21ef38 100644 --- a/app/doc/open_api/v1/users_doc.rb +++ b/app/doc/open_api/v1/users_doc.rb @@ -28,6 +28,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc "created_at": "2016-05-04T17:21:48.403+02:00", "external_id": "J5821-4" "full_name": "xxxx xxxx", + "gender": "man", + "organization": true, + "address": "2 impasse xxxxxx, BRUXELLES", "group": { "id": 1, "name": "standard, association", @@ -40,6 +43,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc "created_at": "2016-05-03T15:21:13.125+02:00", "external_id": "J5846-4" "full_name": "xxxxx xxxxx", + "gender": "woman", + "organization": true, + "address": "Grenoble", "group": { "id": 2, "name": "étudiant, - de 25 ans, enseignant, demandeur d'emploi", @@ -52,6 +58,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc "created_at": "2016-05-03T13:51:03.223+02:00", "external_id": "J5900-1" "full_name": "xxxxxxx xxxx", + "gender": "man", + "organization": false, + "address": "21 rue des xxxxxx", "group": { "id": 1, "name": "standard, association", @@ -64,6 +73,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc "created_at": "2016-05-03T12:24:38.724+02:00", "external_id": "P4172-4" "full_name": "xxx xxxxxxx", + "gender": "woman", + "organization": false, + "address": "147 rue xxxxxx, 75000 PARIS, France", "group": { "id": 1, "name": "standard, association", @@ -82,6 +94,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc "created_at": "2016-05-04T17:21:48.403+02:00", "external_id": "J5500-4" "full_name": "xxxx xxxxxx", + "gender": "man", + "organization": true, + "address": "38100", "group": { "id": 1, "name": "standard, association", @@ -94,6 +109,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc "created_at": "2016-05-03T15:21:13.125+02:00", "external_id": null, "full_name": "xxxxx xxxxxx", + "gender": "woman", + "organization": true, + "address": "", "group": { "id": 2, "name": "étudiant, - de 25 ans, enseignant, demandeur d'emploi", diff --git a/app/models/invoicing_profile.rb b/app/models/invoicing_profile.rb index 3edcee79e..c8c0fb4d9 100644 --- a/app/models/invoicing_profile.rb +++ b/app/models/invoicing_profile.rb @@ -33,4 +33,14 @@ class InvoicingProfile < ApplicationRecord # if first_name or last_name is nil, the empty string will be used as a temporary replacement "#{(first_name || '').humanize.titleize} #{(last_name || '').humanize.titleize}" end + + def invoicing_address + if organization&.address + organization.address.address + elsif address + address.address + else + '' + end + end end diff --git a/app/services/invoices/recipient_service.rb b/app/services/invoices/recipient_service.rb index 4a8abe281..fc57073a1 100644 --- a/app/services/invoices/recipient_service.rb +++ b/app/services/invoices/recipient_service.rb @@ -18,13 +18,7 @@ class Invoices::RecipientService # Get the street address of the recipient for the given invoice. def address(invoice) - if invoice.invoicing_profile&.organization&.address - invoice.invoicing_profile.organization.address.address - elsif invoice.invoicing_profile&.address - invoice.invoicing_profile.address.address - else - '' - end + invoice.invoicing_profile&.invoicing_address end # Get the optional data in profile_custom_fields, if the recipient is an organization diff --git a/app/views/open_api/v1/users/_user.json.jbuilder b/app/views/open_api/v1/users/_user.json.jbuilder index aa25e890e..086fa7fdc 100644 --- a/app/views/open_api/v1/users/_user.json.jbuilder +++ b/app/views/open_api/v1/users/_user.json.jbuilder @@ -1,8 +1,10 @@ # frozen_string_literal: true json.extract! user, :id, :email, :created_at, :external_id - json.full_name user.profile.full_name if user.association(:profile).loaded? +json.gender user.statistic_profile.gender ? 'man' : 'woman' +json.organization !user.invoicing_profile.organization.nil? +json.address user.invoicing_profile.invoicing_address if user.association(:group).loaded? json.group do diff --git a/test/integration/open_api/users_test.rb b/test/integration/open_api/users_test.rb index 40eb80e7e..2d8176ac8 100644 --- a/test/integration/open_api/users_test.rb +++ b/test/integration/open_api/users_test.rb @@ -17,6 +17,9 @@ class OpenApi::UsersTest < ActionDispatch::IntegrationTest users = json_response(response.body) assert_equal User.count, users[:users].length assert_not_nil(users[:users].detect { |u| u[:external_id] == 'J5821-4' }) + assert(users[:users].all? { |u| %w[man woman].include?(u[:gender]) }) + assert(users[:users].all? { |u| u[:organization] != User.find(u[:id]).invoicing_profile.organization.nil? }) + assert(users[:users].any? { |u| u[:address].present? }) end test 'list all users with pagination' do