diff --git a/app/Factory/GroupSettingFactory.php b/app/Factory/GroupSettingFactory.php new file mode 100644 index 000000000000..20a6c56f398d --- /dev/null +++ b/app/Factory/GroupSettingFactory.php @@ -0,0 +1,31 @@ +name = ''; + $gs->account_id = $company_id; + $gs->user_id = $user_id; + $gs->settings = json_encode([]); + + return $gs; + + } +} \ No newline at end of file diff --git a/app/Http/Controllers/GroupSettingController.php b/app/Http/Controllers/GroupSettingController.php new file mode 100644 index 000000000000..5574108a7fd2 --- /dev/null +++ b/app/Http/Controllers/GroupSettingController.php @@ -0,0 +1,139 @@ +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); + + } +} diff --git a/app/Http/Requests/GroupSetting/CreateGroupSettingRequest.php b/app/Http/Requests/GroupSetting/CreateGroupSettingRequest.php new file mode 100644 index 000000000000..1108eb8ef0a1 --- /dev/null +++ b/app/Http/Requests/GroupSetting/CreateGroupSettingRequest.php @@ -0,0 +1,30 @@ +user()->can('create', GroupSetting::class); + } + +} \ No newline at end of file diff --git a/app/Http/Requests/GroupSetting/DestroyGroupSettingRequest.php b/app/Http/Requests/GroupSetting/DestroyGroupSettingRequest.php new file mode 100644 index 000000000000..3ef0a126296a --- /dev/null +++ b/app/Http/Requests/GroupSetting/DestroyGroupSettingRequest.php @@ -0,0 +1,30 @@ +user()->can('edit', $this->group_setting); + } + +} diff --git a/app/Http/Requests/GroupSetting/EditGroupSettingRequest.php b/app/Http/Requests/GroupSetting/EditGroupSettingRequest.php new file mode 100644 index 000000000000..988506546df9 --- /dev/null +++ b/app/Http/Requests/GroupSetting/EditGroupSettingRequest.php @@ -0,0 +1,41 @@ +user()->can('edit', $this->group_setting); + } + + public function sanitize() + { + $input = $this->all(); + + //$input['id'] = $this->encodePrimaryKey($input['id']); + + //$this->replace($input); + + return $this->all(); + } + +} \ No newline at end of file diff --git a/app/Http/Requests/GroupSetting/ShowGroupSettingRequest.php b/app/Http/Requests/GroupSetting/ShowGroupSettingRequest.php new file mode 100644 index 000000000000..d22c50ca67ff --- /dev/null +++ b/app/Http/Requests/GroupSetting/ShowGroupSettingRequest.php @@ -0,0 +1,30 @@ +user()->can('view', $this->group_setting); + } + +} \ No newline at end of file diff --git a/app/Http/Requests/GroupSetting/StoreGroupSettingRequest.php b/app/Http/Requests/GroupSetting/StoreGroupSettingRequest.php new file mode 100644 index 000000000000..5400e4a5cffb --- /dev/null +++ b/app/Http/Requests/GroupSetting/StoreGroupSettingRequest.php @@ -0,0 +1,59 @@ +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' + ]; + } + + +} \ No newline at end of file diff --git a/app/Http/Requests/GroupSetting/UpdateGroupSettingRequest.php b/app/Http/Requests/GroupSetting/UpdateGroupSettingRequest.php new file mode 100644 index 000000000000..75a6b02d7a80 --- /dev/null +++ b/app/Http/Requests/GroupSetting/UpdateGroupSettingRequest.php @@ -0,0 +1,42 @@ +user()->can('edit', $this->group_setting); + } + + public function rules() + { + + return [ + 'settings' => 'json' + ] + + } + + + +} \ No newline at end of file diff --git a/app/Models/GroupSetting.php b/app/Models/GroupSetting.php index e01b6539050a..8b9fe969e74f 100644 --- a/app/Models/GroupSetting.php +++ b/app/Models/GroupSetting.php @@ -32,6 +32,10 @@ class GroupSetting extends StaticModel 'deleted_at' => 'timestamp', ]; + protected $fillable = [ + 'settings' + ] + public function company() { return $this->belongsTo(Company::class); diff --git a/app/Policies/CompanyGatewayPolicy.php b/app/Policies/CompanyGatewayPolicy.php new file mode 100644 index 000000000000..317c652e87e2 --- /dev/null +++ b/app/Policies/CompanyGatewayPolicy.php @@ -0,0 +1,34 @@ +isAdmin(); + } + +} diff --git a/app/Policies/GroupSettingPolicy.php b/app/Policies/GroupSettingPolicy.php new file mode 100644 index 000000000000..e314eb4eecf1 --- /dev/null +++ b/app/Policies/GroupSettingPolicy.php @@ -0,0 +1,33 @@ +isAdmin(); + } + +} diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 986fdc0fd7ad..c6e7e5f9d342 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -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, ]; /** diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index aa7656c8af49..d16540fe4f43 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -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(); + }); + } diff --git a/app/Repositories/GroupSettingRepository.php b/app/Repositories/GroupSettingRepository.php new file mode 100644 index 000000000000..1f93abb38fa8 --- /dev/null +++ b/app/Repositories/GroupSettingRepository.php @@ -0,0 +1,42 @@ +fill($data); + $group_setting->save(); + + return $group_setting; + } + +} \ No newline at end of file diff --git a/app/Transformers/GroupSettingTransformer.php b/app/Transformers/GroupSettingTransformer.php index 43b4d73a91dc..f4d98b34ae53 100644 --- a/app/Transformers/GroupSettingTransformer.php +++ b/app/Transformers/GroupSettingTransformer.php @@ -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 ?: '', ]; } diff --git a/routes/api.php b/routes/api.php index 80213c8e8041..32af9eb49574 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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