diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 032ade89cf03..83ffb0a96f77 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -117,11 +117,21 @@ class CompanyController extends BaseController /** @var \App\Models\User $user */ $user = auth()->user(); - $companies = Company::whereAccountId($user->company()->account->id); + $companies = Company::where('account_id', $user->company()->account->id); return $this->listResponse($companies); } + public function current() + { + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $company = Company::find($user->company()->id); + + return $this->itemResponse($company); + } + /** * Show the form for creating a new resource. * diff --git a/openapi/api-docs.yaml b/openapi/api-docs.yaml index e7ba23940e7e..78a77d2b2275 100644 --- a/openapi/api-docs.yaml +++ b/openapi/api-docs.yaml @@ -206,12 +206,10 @@ paths: description: "The users email address." type: string example: "demo@invoiceninja.com" - required: true password: description: "The user password. Must meet minimum criteria ~ > 6 characters" type: string example: "Password0" - required: true one_time_password: description: "The one time password if 2FA is enabled" type: string @@ -12061,15 +12059,12 @@ paths: tags: - clients summary: 'List clients' - x-badges: - - color: blue - label: core x-code-samples: - - lang: javascript + - lang: go + label: php source: | - fetch('/example') - .then(response => response.json()) - .then(data => console.log(data)); + $ninja = new InvoiceNinja("your_token"); + $invoices = $ninja->clients->all(); x-custom-element: type: markdown value: | @@ -15139,7 +15134,109 @@ components: example: '123456' readOnly: true company_user: - $ref: '#/components/schemas/CompanyUser' + $ref: '#/components/schemas/CompanyUserRef' + type: object + UserRef: + properties: + id: + description: 'The hashed id of the user' + type: string + example: Opnel5aKBz + readOnly: true + first_name: + description: 'The first name of the user' + type: string + example: Brad + last_name: + description: 'The last name of the user' + type: string + example: Pitt + email: + description: 'The users email address' + type: string + example: brad@pitt.com + phone: + description: 'The users phone number' + type: string + example: 555-1233-23232 + signature: + description: 'The users sign off signature' + type: string + example: 'Have a nice day!' + avatar: + description: 'The users avatar' + type: string + example: 'https://url.to.your/avatar.png' + accepted_terms_version: + description: 'The version of the invoice ninja terms that has been accepted by the user' + type: string + example: 1.0.1 + readOnly: true + oauth_user_id: + description: 'The provider id of the oauth entity' + type: string + example: jkhasdf789as6f675sdf768sdfs + readOnly: true + oauth_provider_id: + description: 'The oauth entity id' + type: string + example: google + readOnly: true + language_id: + description: 'The language id of the user' + type: string + example: 1 + verified_phone_number: + description: 'Boolean flag if the user has their phone verified. Required to settings up 2FA' + type: boolean + example: true + readOnly: true + sms_verification_code: + description: 'The sms verification code for the user. Required to settings up 2FA' + type: string + example: '123456' + readOnly: true + oauth_user_token_expiry: + description: 'The expiry date of the oauth token' + type: string + example: '2022-10-10' + readOnly: true + has_password: + description: 'Boolean flag determining if the user has a password' + type: boolean + example: true + readOnly: true + last_confirmed_email_address: + description: 'The last confirmed email address of the user' + type: string + example: 'bob@gmail.com' + readOnly: true + custom_value1: + description: 'A custom value' + type: string + example: 'Custom value 1' + custom_value2: + description: 'A custom value' + type: string + example: '$1000' + custom_value3: + description: 'A custom value' + type: string + example: 'Custom value 3' + custom_value4: + description: 'A custom value' + type: string + example: 'Custom value 4' + is_deleted: + description: 'Boolean flag determining if the user has been deleted' + type: boolean + example: true + readOnly: true + google_2fa_secret: + description: 'The google 2fa secret for the user' + type: string + example: '123456' + readOnly: true type: object Task: properties: @@ -16365,7 +16462,53 @@ components: company: $ref: '#/components/schemas/Company' user: - $ref: '#/components/schemas/User' + $ref: '#/components/schemas/UserRef' + token: + $ref: '#/components/schemas/CompanyToken' + type: object + CompanyUserRef: + properties: + permissions: + description: 'The user permissionsfor this company in a comma separated list' + type: string + example: 'create_invoice,create_client,view_client' + settings: + description: 'Settings that are used for the flutter applications to store user preferences / metadata' + type: object + readOnly: true + react_settings: + description: 'Dedicated settings object for the react web application' + type: object + readOnly: true + is_owner: + description: 'Determines whether the user owns this company' + type: boolean + example: true + readOnly: true + is_admin: + description: 'Determines whether the user is the admin of this company' + type: boolean + example: true + readOnly: true + is_locked: + description: 'Determines whether the users access to this company has been locked' + type: boolean + example: true + readOnly: true + updated_at: + description: 'The last time the record was modified, format Unix Timestamp' + type: integer + example: '1231232312321' + deleted_at: + description: 'Timestamp when the user was archived, format Unix Timestamp' + type: integer + example: '12312312321' + account: + $ref: '#/components/schemas/Account' + company: + $ref: '#/components/schemas/Company' + user: + $ref: '#/components/schemas/UserRef' token: $ref: '#/components/schemas/CompanyToken' type: object diff --git a/openapi/components/schemas/company_user.yaml b/openapi/components/schemas/company_user.yaml index 1ed7c821e712..82495e5d95be 100644 --- a/openapi/components/schemas/company_user.yaml +++ b/openapi/components/schemas/company_user.yaml @@ -40,7 +40,53 @@ company: $ref: '#/components/schemas/Company' user: - $ref: '#/components/schemas/User' + $ref: '#/components/schemas/UserRef' + token: + $ref: '#/components/schemas/CompanyToken' + type: object + CompanyUserRef: + properties: + permissions: + description: 'The user permissionsfor this company in a comma separated list' + type: string + example: 'create_invoice,create_client,view_client' + settings: + description: 'Settings that are used for the flutter applications to store user preferences / metadata' + type: object + readOnly: true + react_settings: + description: 'Dedicated settings object for the react web application' + type: object + readOnly: true + is_owner: + description: 'Determines whether the user owns this company' + type: boolean + example: true + readOnly: true + is_admin: + description: 'Determines whether the user is the admin of this company' + type: boolean + example: true + readOnly: true + is_locked: + description: 'Determines whether the users access to this company has been locked' + type: boolean + example: true + readOnly: true + updated_at: + description: 'The last time the record was modified, format Unix Timestamp' + type: integer + example: '1231232312321' + deleted_at: + description: 'Timestamp when the user was archived, format Unix Timestamp' + type: integer + example: '12312312321' + account: + $ref: '#/components/schemas/Account' + company: + $ref: '#/components/schemas/Company' + user: + $ref: '#/components/schemas/UserRef' token: $ref: '#/components/schemas/CompanyToken' type: object \ No newline at end of file diff --git a/openapi/components/schemas/user.yaml b/openapi/components/schemas/user.yaml index a73cdce1f8a8..a62d81fcbc4b 100644 --- a/openapi/components/schemas/user.yaml +++ b/openapi/components/schemas/user.yaml @@ -100,5 +100,107 @@ example: '123456' readOnly: true company_user: - $ref: '#/components/schemas/CompanyUser' + $ref: '#/components/schemas/CompanyUserRef' + type: object + UserRef: + properties: + id: + description: 'The hashed id of the user' + type: string + example: Opnel5aKBz + readOnly: true + first_name: + description: 'The first name of the user' + type: string + example: Brad + last_name: + description: 'The last name of the user' + type: string + example: Pitt + email: + description: 'The users email address' + type: string + example: brad@pitt.com + phone: + description: 'The users phone number' + type: string + example: 555-1233-23232 + signature: + description: 'The users sign off signature' + type: string + example: 'Have a nice day!' + avatar: + description: 'The users avatar' + type: string + example: 'https://url.to.your/avatar.png' + accepted_terms_version: + description: 'The version of the invoice ninja terms that has been accepted by the user' + type: string + example: 1.0.1 + readOnly: true + oauth_user_id: + description: 'The provider id of the oauth entity' + type: string + example: jkhasdf789as6f675sdf768sdfs + readOnly: true + oauth_provider_id: + description: 'The oauth entity id' + type: string + example: google + readOnly: true + language_id: + description: 'The language id of the user' + type: string + example: 1 + verified_phone_number: + description: 'Boolean flag if the user has their phone verified. Required to settings up 2FA' + type: boolean + example: true + readOnly: true + sms_verification_code: + description: 'The sms verification code for the user. Required to settings up 2FA' + type: string + example: '123456' + readOnly: true + oauth_user_token_expiry: + description: 'The expiry date of the oauth token' + type: string + example: '2022-10-10' + readOnly: true + has_password: + description: 'Boolean flag determining if the user has a password' + type: boolean + example: true + readOnly: true + last_confirmed_email_address: + description: 'The last confirmed email address of the user' + type: string + example: 'bob@gmail.com' + readOnly: true + custom_value1: + description: 'A custom value' + type: string + example: 'Custom value 1' + custom_value2: + description: 'A custom value' + type: string + example: '$1000' + custom_value3: + description: 'A custom value' + type: string + example: 'Custom value 3' + custom_value4: + description: 'A custom value' + type: string + example: 'Custom value 4' + is_deleted: + description: 'Boolean flag determining if the user has been deleted' + type: boolean + example: true + readOnly: true + google_2fa_secret: + description: 'The google 2fa secret for the user' + type: string + example: '123456' + readOnly: true type: object \ No newline at end of file diff --git a/openapi/paths.yaml b/openapi/paths.yaml index 1b74e64a9ec4..1ea52ab550b4 100644 --- a/openapi/paths.yaml +++ b/openapi/paths.yaml @@ -116,12 +116,10 @@ paths: description: "The users email address." type: string example: "demo@invoiceninja.com" - required: true password: description: "The user password. Must meet minimum criteria ~ > 6 characters" type: string example: "Password0" - required: true one_time_password: description: "The one time password if 2FA is enabled" type: string diff --git a/openapi/paths/clients.yaml b/openapi/paths/clients.yaml index d6b4266c6039..c71bad405308 100644 --- a/openapi/paths/clients.yaml +++ b/openapi/paths/clients.yaml @@ -3,15 +3,12 @@ tags: - clients summary: 'List clients' - x-badges: - - color: blue - label: core x-code-samples: - - lang: javascript + - lang: go + label: php source: | - fetch('/example') - .then(response => response.json()) - .then(data => console.log(data)); + $ninja = new InvoiceNinja("your_token"); + $invoices = $ninja->clients->all(); x-custom-element: type: markdown value: | diff --git a/routes/api.php b/routes/api.php index 6749be50569b..9befaf9a07f8 100644 --- a/routes/api.php +++ b/routes/api.php @@ -184,7 +184,10 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale'] Route::post('client_statement', [ClientStatementController::class, 'statement'])->name('client.statement'); - Route::post('companies/purge/{company}', [MigrationController::class, 'purgeCompany'])->middleware('password_protected'); + +Route::post('companies/purge/{company}', [MigrationController::class, 'purgeCompany'])->middleware('password_protected'); + + Route::post('companies/current', [CompanyController::class, 'current'])->name('companies.current'); Route::post('companies/purge_save_settings/{company}', [MigrationController::class, 'purgeCompanySaveSettings'])->middleware('password_protected'); Route::resource('companies', CompanyController::class); // name = (companies. index / create / show / update / destroy / edit diff --git a/tests/Feature/CompanyTest.php b/tests/Feature/CompanyTest.php index a9c02ef83045..4814cc676c30 100644 --- a/tests/Feature/CompanyTest.php +++ b/tests/Feature/CompanyTest.php @@ -72,6 +72,21 @@ class CompanyTest extends TestCase $this->assertEquals(1, TaxRate::count()); } + public function testCompanyCurrent() + { + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/companies/current"); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals($arr['data']['id'], $this->company->hashed_id); + + } + public function testCompanyLogoInline() { $response = $this->withHeaders([