1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Changing error structure, regression fixes for shop/client route

This commit is contained in:
David Bomba 2020-08-12 08:59:28 +10:00
parent 7feae1fd45
commit 3514491300
17 changed files with 31 additions and 36 deletions

View File

@ -134,8 +134,6 @@ class Handler extends ExceptionHandler
return parent::render($request, $exception);
}
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {

View File

@ -93,7 +93,7 @@ class LicenseController extends BaseController
if ($data == Account::RESULT_FAILURE) {
$error = [
'message' => trans('texts.invalid_white_label_license'),
'errors' => []
'errors' => new \stdClass
];
return response()->json($error, 400);
@ -103,7 +103,7 @@ class LicenseController extends BaseController
if ($date < date_create()) {
$error = [
'message' => trans('texts.invalid_white_label_license'),
'errors' => []
'errors' => new \stdClass
];
return response()->json($error, 400);
@ -118,7 +118,7 @@ class LicenseController extends BaseController
$error = [
'message' => trans('texts.bought_white_label'),
'errors' => []
'errors' => new \stdClass
];
return response()->json($error, 200);
@ -126,7 +126,7 @@ class LicenseController extends BaseController
} else {
$error = [
'message' => trans('texts.white_label_license_error'),
'errors' => []
'errors' => new \stdClass
];
return response()->json($error, 400);
@ -135,7 +135,7 @@ class LicenseController extends BaseController
$error = [
'message' => "Invalid license, or invalid environment ".config('ninja.environment'),
'errors' => []
'errors' => new \stdClass
];
return response()->json($error, 400);

View File

@ -57,7 +57,7 @@ class ClientController extends BaseController
$company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
if(!$company->enable_shop_api)
return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
$contact = ClientContact::with('client')
->where('company_id', $company->id)
@ -72,7 +72,7 @@ class ClientController extends BaseController
$company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
if(!$company->enable_shop_api)
return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
app('queue')->createPayloadUsing(function () use ($company) {
return ['db' => $company->db];

View File

@ -57,7 +57,7 @@ class InvoiceController extends BaseController
$company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
if(!$company->enable_shop_api)
return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
$invitation = InvoiceInvitation::with(['invoice'])
->where('company_id', $company->id)
@ -74,7 +74,7 @@ class InvoiceController extends BaseController
$company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
if(!$company->enable_shop_api)
return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
app('queue')->createPayloadUsing(function () use ($company) {
return ['db' => $company->db];

View File

@ -37,7 +37,7 @@ class ProductController extends BaseController
$company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
if(!$company->enable_shop_api)
return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
$products = Product::where('company_id', $company->id);
@ -49,7 +49,7 @@ class ProductController extends BaseController
$company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
if(!$company->enable_shop_api)
return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
$product = Product::where('company_id', $company->id)
->where('product_key', $product_key)

View File

@ -34,7 +34,7 @@ class ProfileController extends BaseController
$company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
if(!$company->enable_shop_api)
return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
return $this->itemResponse($company);
}

View File

@ -30,7 +30,7 @@ class ApiSecretCheck
} else {
$error = [
'message' => 'Invalid secret',
'errors' => []
'errors' => new \stdClass
];
return response()
->json($error, 403)

View File

@ -29,7 +29,7 @@ class ContactSetDb
{
$error = [
'message' => 'Invalid Token',
'errors' => []
'errors' => new \stdClass
];
if ($request->header('X-API-TOKEN') && config('ninja.db.multi_db_enabled')) {

View File

@ -32,7 +32,7 @@ class ContactTokenAuth
if ($request->header('X-API-TOKEN') && ($client_contact = ClientContact::with(['company'])->whereRaw("BINARY `token`= ?", [$request->header('X-API-TOKEN')])->first())) {
$error = [
'message' => 'Authentication disabled for user.',
'errors' => []
'errors' => new \stdClass
];
//client_contact who once existed, but has been soft deleted
@ -43,7 +43,7 @@ class ContactTokenAuth
$error = [
'message' => 'Access is locked.',
'errors' => []
'errors' => new \stdClass
];
//client_contact who has been disabled
@ -58,7 +58,7 @@ class ContactTokenAuth
} else {
$error = [
'message' => 'Invalid token',
'errors' => []
'errors' => new \stdClass
];
return response()->json($error, 403);

View File

@ -32,7 +32,7 @@ class PasswordProtection
{
$error = [
'message' => 'Invalid Password',
'errors' => []
'errors' => new \stdClass
];
if ($request->header('X-API-PASSWORD')) {
@ -47,7 +47,7 @@ class PasswordProtection
} else {
$error = [
'message' => 'Access denied',
'errors' => []
'errors' => new \stdClass
];
return response()->json($error, 412);
}

View File

@ -29,7 +29,7 @@ class SetDb
{
$error = [
'message' => 'Invalid Token',
'errors' => []
'errors' => new \stdClass
];

View File

@ -29,7 +29,7 @@ class SetDbByCompanyKey
{
$error = [
'message' => 'Invalid Token',
'errors' => []
'errors' => new \stdClass
];

View File

@ -28,7 +28,7 @@ class SetDomainNameDb
{
$error = [
'message' => 'Invalid token',
'errors' => []
'errors' => new \stdClass
];
/*
* Use the host name to set the active DB

View File

@ -29,7 +29,7 @@ class SetEmailDb
{
$error = [
'message' => 'Email not set or not found',
'errors' => []
'errors' => new \stdClass
];
if ($request->input('email') && config('ninja.db.multi_db_enabled')) {

View File

@ -28,7 +28,7 @@ class SetInviteDb
{
$error = [
'message' => 'Invalid URL',
'errors' => []
'errors' => new \stdClass
];
/*
* Use the host name to set the active DB

View File

@ -34,7 +34,7 @@ class TokenAuth
$error = [
'message' => 'User inactive',
'errors' => []
'errors' => new \stdClass
];
//user who once existed, but has been soft deleted
if (!$user) {
@ -60,7 +60,7 @@ class TokenAuth
if ($user->company_user->is_locked) {
$error = [
'message' => 'User access locked',
'errors' => []
'errors' => new \stdClass
];
return response()->json($error, 403);
@ -73,7 +73,7 @@ class TokenAuth
} else {
$error = [
'message' => 'Invalid token',
'errors' => []
'errors' => new \stdClass
];
return response()->json($error, 403);

View File

@ -16,7 +16,9 @@ use App\Models\Activity;
use App\Models\Backup;
use App\Models\Client;
use App\Models\CompanyToken;
use App\Models\Credit;
use App\Models\Invoice;
use App\Models\Quote;
use App\Models\User;
use App\Utils\Traits\MakesInvoiceHtml;
use Illuminate\Support\Facades\Log;
@ -64,14 +66,9 @@ class ActivityRepository extends BaseRepository
{
$backup = new Backup();
// if (get_class($entity) == Client::class) {
// $entity->load('company');
// } elseif (get_class($entity) == User::class) {
// } else {
// $entity->load('company', 'client');
// }
if (get_class($entity) == Invoice::class || get_class($entity) == Quote::class || get_class($entity) == Credit::class)
$backup->html_backup = $this->generateEntityHtml($entity->getEntityDesigner(), $entity);
$backup->html_backup = $this->generateEntityHtml($entity->getEntityDesigner(), $entity);
$backup->activity_id = $activity->id;
$backup->json_backup = '';
//$backup->json_backup = $entity->toJson();