mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Stubs for group settings controller
This commit is contained in:
parent
7c69de5ebb
commit
2f657aaac8
31
app/Factory/GroupSettingFactory.php
Normal file
31
app/Factory/GroupSettingFactory.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?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\Factory;
|
||||
|
||||
use App\Models\GroupSetting;
|
||||
|
||||
class GroupSettingFactory
|
||||
{
|
||||
|
||||
public static function create(int $company_id, int $user_id) :GroupSetting
|
||||
{
|
||||
|
||||
$gs = new GroupSetting;
|
||||
$gs->name = '';
|
||||
$gs->account_id = $company_id;
|
||||
$gs->user_id = $user_id;
|
||||
$gs->settings = json_encode([]);
|
||||
|
||||
return $gs;
|
||||
|
||||
}
|
||||
}
|
139
app/Http/Controllers/GroupSettingController.php
Normal file
139
app/Http/Controllers/GroupSettingController.php
Normal file
@ -0,0 +1,139 @@
|
||||
<?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\Controllers;
|
||||
|
||||
|
||||
use App\Factory\GroupSettingFactory;
|
||||
use App\Http\Requests\GroupSetting\CreateGroupSettingRequest;
|
||||
use App\Http\Requests\GroupSetting\DestroyGroupSettingRequest;
|
||||
use App\Http\Requests\GroupSetting\EditGroupSettingRequest;
|
||||
use App\Http\Requests\GroupSetting\ShowGroupSettingRequest;
|
||||
use App\Http\Requests\GroupSetting\StoreGroupSettingRequest;
|
||||
use App\Http\Requests\GroupSetting\UpdateGroupSettingRequest;
|
||||
use App\Models\GroupSetting;
|
||||
use App\Repositories\GroupSettingRepository;
|
||||
use App\Transformers\GroupSettingTransformer;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GroupSettingController extends BaseController
|
||||
{
|
||||
use DispatchesJobs;
|
||||
|
||||
protected $entity_type = GroupSetting::class;
|
||||
|
||||
protected $entity_transformer = GroupSettingTransformer::class;
|
||||
|
||||
protected $group_setting_repo;
|
||||
|
||||
public function __construct(GroupSettingRepository $group_setting_repo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->group_setting_repo = $group_setting_repo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$group_settings = GroupSetting::whereCompanyId(auth()->user()->company()->id);
|
||||
|
||||
return $this->listResponse($group_settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(CreateGroupSettingRequest $request)
|
||||
{
|
||||
$group_setting = GroupSettingFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
return $this->itemResponse($group_setting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\SignupRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreGroupSettingRequest $request)
|
||||
{
|
||||
//need to be careful here as we may also receive some
|
||||
//supporting attributes such as logo which need to be handled outside of the
|
||||
//settings object
|
||||
$group_setting = GroupSettingFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
|
||||
|
||||
return $this->itemResponse($group_setting);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(ShowGroupSettingRequest $request, GroupSetting $group_setting)
|
||||
{
|
||||
return $this->itemResponse($group_setting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(EditGroupSettingRequest $request, GroupSetting $group_setting)
|
||||
{
|
||||
return $this->itemResponse($group_setting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateGroupSettingRequest $request, GroupSetting $group_setting)
|
||||
{
|
||||
|
||||
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
|
||||
|
||||
return $this->itemResponse($group_setting);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(DestroyGroupSettingRequest $request, GroupSetting $group_setting)
|
||||
{
|
||||
$group_setting->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
|
||||
}
|
||||
}
|
30
app/Http/Requests/GroupSetting/CreateGroupSettingRequest.php
Normal file
30
app/Http/Requests/GroupSetting/CreateGroupSettingRequest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?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\GroupSetting;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\GroupSetting;
|
||||
|
||||
class CreateGroupSettingRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('create', GroupSetting::class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?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\GroupSetting;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\GroupSetting;
|
||||
|
||||
class DestroyGroupSettingRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('edit', $this->group_setting);
|
||||
}
|
||||
|
||||
}
|
41
app/Http/Requests/GroupSetting/EditGroupSettingRequest.php
Normal file
41
app/Http/Requests/GroupSetting/EditGroupSettingRequest.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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\GroupSetting;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\GroupSetting;
|
||||
|
||||
class EditGroupSettingRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('edit', $this->group_setting);
|
||||
}
|
||||
|
||||
public function sanitize()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
//$input['id'] = $this->encodePrimaryKey($input['id']);
|
||||
|
||||
//$this->replace($input);
|
||||
|
||||
return $this->all();
|
||||
}
|
||||
|
||||
}
|
30
app/Http/Requests/GroupSetting/ShowGroupSettingRequest.php
Normal file
30
app/Http/Requests/GroupSetting/ShowGroupSettingRequest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?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\GroupSetting;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\GroupSetting;
|
||||
|
||||
class ShowGroupSettingRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('view', $this->group_setting);
|
||||
}
|
||||
|
||||
}
|
59
app/Http/Requests/GroupSetting/StoreGroupSettingRequest.php
Normal file
59
app/Http/Requests/GroupSetting/StoreGroupSettingRequest.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?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\GroupSetting;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\GroupSetting;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class StoreGroupSettingRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
|
||||
return auth()->user()->can('create', GroupSetting::class);
|
||||
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
return [
|
||||
'name' => 'required',
|
||||
'settings' => 'json',
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function sanitize()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'settings' => 'settings must be a valid json structure'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
42
app/Http/Requests/GroupSetting/UpdateGroupSettingRequest.php
Normal file
42
app/Http/Requests/GroupSetting/UpdateGroupSettingRequest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?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\GroupSetting;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateGroupSettingRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('edit', $this->group_setting);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
return [
|
||||
'settings' => 'json'
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -32,6 +32,10 @@ class GroupSetting extends StaticModel
|
||||
'deleted_at' => 'timestamp',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'settings'
|
||||
]
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
|
34
app/Policies/CompanyGatewayPolicy.php
Normal file
34
app/Policies/CompanyGatewayPolicy.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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\Policies;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* Class ClientPolicy
|
||||
* @package App\Policies
|
||||
*/
|
||||
class CompanyGatewayPolicy extends EntityPolicy
|
||||
{
|
||||
/**
|
||||
* Checks if the user has create permissions
|
||||
*
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public function create(User $user) : bool
|
||||
{
|
||||
return $user->isAdmin();
|
||||
}
|
||||
|
||||
}
|
33
app/Policies/GroupSettingPolicy.php
Normal file
33
app/Policies/GroupSettingPolicy.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?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\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* Class ClientPolicy
|
||||
* @package App\Policies
|
||||
*/
|
||||
class GroupSettingPolicy extends EntityPolicy
|
||||
{
|
||||
/**
|
||||
* Checks if the user has create permissions
|
||||
*
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public function create(User $user) : bool
|
||||
{
|
||||
return $user->isAdmin();
|
||||
}
|
||||
|
||||
}
|
@ -14,6 +14,8 @@ namespace App\Providers;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\GroupSetting;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Product;
|
||||
@ -23,7 +25,9 @@ use App\Models\RecurringQuote;
|
||||
use App\Models\User;
|
||||
use App\Policies\ActivityPolicy;
|
||||
use App\Policies\ClientPolicy;
|
||||
use App\Policies\CompanyGatewayPolicy;
|
||||
use App\Policies\CompanyPolicy;
|
||||
use App\Policies\GroupSettingPolicy;
|
||||
use App\Policies\InvoicePolicy;
|
||||
use App\Policies\PaymentPolicy;
|
||||
use App\Policies\ProductPolicy;
|
||||
@ -53,6 +57,8 @@ class AuthServiceProvider extends ServiceProvider
|
||||
RecurringQuote::class => RecurringQuotePolicy::class,
|
||||
Quote::class => QuotePolicy::class,
|
||||
User::class => UserPolicy::class,
|
||||
GroupSetting::class => GroupSettingPolicy::class,
|
||||
CompanyGateway::class => CompanyGatewayPolicy::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -11,13 +11,14 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\GroupSetting;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
@ -125,6 +126,10 @@ class RouteServiceProvider extends ServiceProvider
|
||||
return \App\Models\Proposal::where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
||||
});
|
||||
|
||||
Route::bind('groupo_setting', function ($value) {
|
||||
return \App\Models\GroupSetting::where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
42
app/Repositories/GroupSettingRepository.php
Normal file
42
app/Repositories/GroupSettingRepository.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?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\Repositories;
|
||||
|
||||
use App\Models\GroupSetting;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class GroupSettingRepository
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
/**
|
||||
* Gets the class name.
|
||||
*
|
||||
* @return string The class name.
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
|
||||
return GroupSetting::class;
|
||||
|
||||
}
|
||||
|
||||
public function save($data, GroupSetting $group_setting) :?GroupSetting
|
||||
{
|
||||
|
||||
$group_setting->fill($data);
|
||||
$group_setting->save();
|
||||
|
||||
return $group_setting;
|
||||
}
|
||||
|
||||
}
|
@ -40,7 +40,7 @@ class GroupSettingTransformer extends EntityTransformer
|
||||
{
|
||||
return [
|
||||
'id' => $this->encodePrimaryKey($group_setting->id),
|
||||
'name' => $group_setting->name ?: '',
|
||||
'name' => (string)$group_setting->name ?: '',
|
||||
'settings' => $group_setting->settings ?: '',
|
||||
];
|
||||
}
|
||||
|
@ -76,6 +76,8 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi
|
||||
|
||||
Route::resource('company_gateways', 'CompanyGatewayController');
|
||||
|
||||
Route::resource('group_settings', 'GroupSettingController');
|
||||
|
||||
Route::post('refresh', 'Auth\LoginController@refresh');
|
||||
/*
|
||||
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
|
||||
|
Loading…
Reference in New Issue
Block a user