mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Implement Support for PHP 7.4 (#3102)
* Fixes for company factor * Add dates to create test data * Fixes for transformers, use faker to generate random dates * Bump to PHP 7.4git add app/Http/Requests/User/DetachCompanyUserRequest.php * Fixes for route model binding
This commit is contained in:
parent
9702dc741c
commit
a7048ee61d
@ -13,7 +13,7 @@ group: deprecated-2017Q4
|
||||
|
||||
php:
|
||||
- 7.3
|
||||
# - 7.4snapshot
|
||||
# - 7.4
|
||||
# - nightly
|
||||
|
||||
addons:
|
||||
|
@ -19,6 +19,7 @@ use App\Models\PaymentType;
|
||||
use App\Models\User;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@ -47,6 +48,8 @@ class CreateTestData extends Command
|
||||
parent::__construct();
|
||||
|
||||
$this->invoice_repo = $invoice_repo;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -274,9 +277,12 @@ class CreateTestData extends Command
|
||||
|
||||
private function createInvoice($client)
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$invoice = InvoiceFactory::create($client->company->id,$client->user->id);//stub the company and user_id
|
||||
$invoice->client_id = $client->id;
|
||||
|
||||
$invoice->date = $faker->date();
|
||||
|
||||
$invoice->line_items = $this->buildLineItems();
|
||||
$invoice->uses_inclusive_Taxes = false;
|
||||
|
||||
|
@ -28,7 +28,7 @@ class CompanyFactory
|
||||
$company->company_key = $this->createHash();
|
||||
$company->settings = CompanySettings::defaults();
|
||||
$company->db = config('database.default');
|
||||
$company->custom_fields = (object) ['custom1' => '1', 'custom2' => '2', 'custom3'=>3];
|
||||
$company->custom_fields = (object) ['custom1' => '1', 'custom2' => '2', 'custom3'=>'3'];
|
||||
$company->domain = '';
|
||||
|
||||
return $company;
|
||||
|
@ -40,6 +40,16 @@ class ActivityController extends BaseController
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Parameter(ref="#/components/parameters/index"),
|
||||
* @OA\Parameter(
|
||||
* name="rows",
|
||||
* in="path",
|
||||
* description="The number of activities to return",
|
||||
* example="50",
|
||||
* @OA\Schema(
|
||||
* type="number",
|
||||
* format="integer",
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="A list of actvities",
|
||||
@ -62,12 +72,12 @@ class ActivityController extends BaseController
|
||||
* )
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
$default_activities = isset($request->input('rows')) ? $request->input('rows') : 50;
|
||||
$activities = Activity::orderBy('created_at', 'DESC')->company()
|
||||
->take(50);
|
||||
|
||||
->take($default_activities);
|
||||
|
||||
|
||||
return $this->listResponse($activities);
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Parsedown;
|
||||
|
||||
class TemplateController extends BaseController
|
||||
{
|
||||
@ -107,6 +108,26 @@ class TemplateController extends BaseController
|
||||
* format="string",
|
||||
* ),
|
||||
* ),
|
||||
* @OA\RequestBody(
|
||||
* description="The template subject and body",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(
|
||||
* type="object",
|
||||
* @OA\Property(
|
||||
* property="subject",
|
||||
* description="The email template subject",
|
||||
* type="string",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="body",
|
||||
* description="The email template body",
|
||||
* type="string",
|
||||
* ),
|
||||
* )
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="The template response",
|
||||
@ -135,9 +156,13 @@ class TemplateController extends BaseController
|
||||
|
||||
$entity_obj = $class::find($entity_id)->company();
|
||||
|
||||
$markdown = request()->input('text');
|
||||
$subject = request()->input('subject');
|
||||
$body = ;
|
||||
|
||||
return response()->json($markdown, 200);
|
||||
$body = Parsedown::instance()->text(request()->input('body'));
|
||||
$subject = Parsedown::instance()->text(request()->input('subject'));
|
||||
|
||||
return response()->json($body, 200);
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,18 +11,19 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Factory\UserFactory;
|
||||
use App\Filters\UserFilters;
|
||||
use App\Http\Controllers\Traits\VerifiesUserEmail;
|
||||
use App\Http\Requests\User\CreateUserRequest;
|
||||
use App\Http\Requests\User\DestroyUserRequest;
|
||||
use App\Http\Requests\User\DetachCompanyUserRequest;
|
||||
use App\Http\Requests\User\EditUserRequest;
|
||||
use App\Http\Requests\User\ShowUserRequest;
|
||||
use App\Http\Requests\User\StoreUserRequest;
|
||||
use App\Http\Requests\User\UpdateUserRequest;
|
||||
use App\Jobs\Company\CreateCompanyToken;
|
||||
use App\Models\User;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Repositories\UserRepository;
|
||||
use App\Transformers\UserTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -528,4 +529,100 @@ class UserController extends BaseController
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Attach an existing user to a company.
|
||||
*
|
||||
* @OA\Post(
|
||||
* path="/api/v1/users/{user}/attachToCompany",
|
||||
* operationId="attachUser",
|
||||
* tags={"users"},
|
||||
* summary="Attach an existing user to a company",
|
||||
* description="Attach an existing user to a company",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\RequestBody(ref="#/components/schemas/CompanyUser"),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Returns the saved User object",
|
||||
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/CompanyUser"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
*
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
*/
|
||||
public function attach(AttachCompanyUserRequest $request, User $user)
|
||||
{
|
||||
|
||||
$company = auth()->user()->company();
|
||||
|
||||
$user->companies()->attach($company->id, $request->all());
|
||||
|
||||
$ct = CreateCompanyToken::dispatchNow($company, $user, 'User token created by'.auth()->user()->present()->user());
|
||||
|
||||
return $this->itemResponse($user->fresh());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach an existing user to a company.
|
||||
*
|
||||
* @OA\Delete(
|
||||
* path="/api/v1/users/{user}/detachFromCompany",
|
||||
* operationId="detachUser",
|
||||
* tags={"users"},
|
||||
* summary="Detach an existing user to a company",
|
||||
* description="Detach an existing user from a company",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Success response",
|
||||
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
*
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
*/
|
||||
public function detach(DetachCompanyUserRequest $request, User $user)
|
||||
{
|
||||
$company_user = CompanyUser::whereUserId($user->id)
|
||||
->whereCompanyId(auth()->user()->id)->first();
|
||||
|
||||
$company_user->token->delete();
|
||||
$company_user->delete();
|
||||
|
||||
return response()->json(['message' => 'User detached from company'], 200);
|
||||
|
||||
}
|
||||
}
|
||||
|
45
app/Http/Requests/User/AttachCompanyUserRequest.php
Normal file
45
app/Http/Requests/User/AttachCompanyUserRequest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\User;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class AttachCompanyUserRequest extends Request
|
||||
{
|
||||
use MakesHash;
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->isAdmin();
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
|
||||
$this->replace([
|
||||
'is_admin' => isset($request->input('is_admin')) ? $request->input('is_admin') : false,
|
||||
'permissions' => isset($request->input('permissions')) ? $request->input('permissions') : '',
|
||||
'settings' => isset($request->input('settings')) ? $request->input('settings') : json_encode(DefaultSettings::userSettings()),
|
||||
'is_locked' => isset($request->input('is_locked')) ? $request->input('is_locked') : false,
|
||||
'is_owner' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
32
app/Http/Requests/User/DetachCompanyUserRequest.php
Normal file
32
app/Http/Requests/User/DetachCompanyUserRequest.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\User;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class DetachCompanyUserRequest extends Request
|
||||
{
|
||||
use MakesHash;
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->isAdmin();
|
||||
}
|
||||
|
||||
}
|
@ -51,5 +51,16 @@ class ClientGatewayToken extends BaseModel
|
||||
{
|
||||
return $this->hasOne(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the model for a bound value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
*/
|
||||
public function resolveRouteBinding($value)
|
||||
{
|
||||
return $this
|
||||
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
||||
}
|
||||
}
|
@ -23,7 +23,10 @@ class UserPresenter extends EntityPresenter
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
return $this->entity->first_name . ' ' . $this->entity->last_name;
|
||||
$first_name = isset($this->entity->first_name) ? $this->entity->first_name : '';
|
||||
$last_name = isset($this->entity->last_name) ? $this->entity->last_name : '';
|
||||
|
||||
return $first_name . ' ' . $last_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ class GatewayTransformer extends EntityTransformer
|
||||
'provider' => (string)$gateway->provider ?: '',
|
||||
'visible' => (bool)$gateway->visible,
|
||||
'sort_order' => (int)$gateway->sort_order,
|
||||
'default_gateway_type_id' => (bool)$gateway->default_gateway_type_id,
|
||||
'default_gateway_type_id' => (int)$gateway->default_gateway_type_id,
|
||||
'site_url' => (string)$gateway->site_url ?: '',
|
||||
'is_offsite' => (bool)$gateway->is_offsite,
|
||||
'is_secure' => (bool)$gateway->is_secure,
|
||||
|
@ -115,8 +115,8 @@ $(function() {
|
||||
columns: [
|
||||
|
||||
{data: 'checkbox', name: 'checkbox', title: '<input type="checkbox" class="select_all" >', searchable: false, orderable: false},
|
||||
{data: 'invoice_number', name: 'invoice_number', title: '{{ctrans('texts.invoice_number')}}', visible: true},
|
||||
{data: 'invoice_date', name: 'invoice_date', title: '{{ctrans('texts.invoice_date')}}', visible: true},
|
||||
{data: 'number', name: 'number', title: '{{ctrans('texts.invoice_number')}}', visible: true},
|
||||
{data: 'date', name: 'date', title: '{{ctrans('texts.invoice_date')}}', visible: true},
|
||||
{data: 'amount', name: 'amount', title: '{{ctrans('texts.total')}}', visible: true},
|
||||
{data: 'balance', name: 'balance', title: '{{ctrans('texts.balance')}}', visible: true},
|
||||
{data: 'due_date', name: 'due_date', title: '{{ctrans('texts.due_date')}}', visible: true},
|
||||
|
@ -70,6 +70,9 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi
|
||||
|
||||
// Route::resource('users', 'UserController')->middleware('password_protected'); // name = (users. index / create / show / update / destroy / edit
|
||||
Route::resource('users', 'UserController'); // name = (users. index / create / show / update / destroy / edit
|
||||
Route::post('users/{user}/attachToCompany', 'UserController@attach');
|
||||
Route::delete('users/{user}/detachFromCompany','UserController@detach');
|
||||
|
||||
|
||||
Route::post('users/bulk', 'UserController@bulk')->name('users.bulk')->middleware('password_protected');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user