1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/Http/Controllers/GroupSettingController.php

229 lines
6.8 KiB
PHP
Raw Normal View History

2019-10-05 00:58:51 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2019-10-05 00:58:51 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2019-10-05 00:58:51 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-10-05 00:58:51 +02:00
*/
namespace App\Http\Controllers;
use App\Factory\GroupSettingFactory;
2023-04-29 01:44:34 +02:00
use App\Filters\GroupSettingFilters;
2019-10-05 00:58:51 +02:00
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\Http\Requests\GroupSetting\UploadGroupSettingRequest;
use App\Models\Account;
2019-10-05 00:58:51 +02:00
use App\Models\GroupSetting;
use App\Repositories\GroupSettingRepository;
use App\Transformers\GroupSettingTransformer;
use App\Utils\Traits\MakesHash;
2021-01-18 12:06:26 +01:00
use App\Utils\Traits\SavesDocuments;
2019-10-07 23:17:55 +02:00
use App\Utils\Traits\Uploadable;
2019-10-05 00:58:51 +02:00
use Illuminate\Foundation\Bus\DispatchesJobs;
2020-10-28 11:10:49 +01:00
use Illuminate\Http\Response;
2019-10-05 00:58:51 +02:00
class GroupSettingController extends BaseController
{
use DispatchesJobs;
2019-10-07 23:17:55 +02:00
use Uploadable;
use MakesHash;
2021-01-18 12:06:26 +01:00
use SavesDocuments;
2019-10-05 00:58:51 +02:00
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;
}
2023-04-29 01:56:27 +02:00
/**
* Show the form for creating a new resource.
*
* @param GroupSettingFilters $filters
2024-06-16 00:30:25 +02:00
* @return Response| \Illuminate\Http\JsonResponse
2023-04-29 01:56:27 +02:00
*
*/
2023-04-29 01:44:34 +02:00
public function index(GroupSettingFilters $filters)
2019-10-05 00:58:51 +02:00
{
2023-04-29 01:44:34 +02:00
$group_settings = GroupSetting::filter($filters);
2019-10-05 00:58:51 +02:00
return $this->listResponse($group_settings);
}
/**
* Show the form for creating a new resource.
*
2020-10-28 11:10:49 +01:00
* @param CreateGroupSettingRequest $request
2024-06-16 00:30:25 +02:00
* @return Response| \Illuminate\Http\JsonResponse
2019-10-07 06:13:50 +02:00
*
2023-04-29 01:56:27 +02:00
*/
2019-10-05 00:58:51 +02:00
public function create(CreateGroupSettingRequest $request)
{
2023-04-29 01:56:27 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
$group_setting = GroupSettingFactory::create($user->company()->id, $user->id);
2019-10-05 00:58:51 +02:00
return $this->itemResponse($group_setting);
}
/**
* Store a newly created resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param StoreGroupSettingRequest $request
2024-06-16 00:30:25 +02:00
* @return Response| \Illuminate\Http\JsonResponse
2019-10-07 06:13:50 +02:00
*
2019-10-05 00:58:51 +02:00
*/
public function store(StoreGroupSettingRequest $request)
{
2023-04-29 01:56:27 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
$group_setting = GroupSettingFactory::create($user->company()->id, $user->id);
2019-10-05 00:58:51 +02:00
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
2019-10-07 23:17:55 +02:00
$this->uploadLogo($request->file('company_logo'), $group_setting->company, $group_setting);
2019-10-05 00:58:51 +02:00
return $this->itemResponse($group_setting);
}
/**
* Display the specified resource.
*
2020-10-28 11:10:49 +01:00
* @param ShowGroupSettingRequest $request
* @param GroupSetting $group_setting
2024-06-16 00:30:25 +02:00
* @return Response| \Illuminate\Http\JsonResponse
2019-10-07 06:13:50 +02:00
*
2019-10-05 00:58:51 +02:00
*/
public function show(ShowGroupSettingRequest $request, GroupSetting $group_setting)
{
return $this->itemResponse($group_setting);
}
/**
* Show the form for editing the specified resource.
*
2020-10-28 11:10:49 +01:00
* @param EditGroupSettingRequest $request
* @param GroupSetting $group_setting
2024-06-16 00:30:25 +02:00
* @return Response| \Illuminate\Http\JsonResponse
2019-10-07 06:13:50 +02:00
*
2019-10-05 00:58:51 +02:00
*/
public function edit(EditGroupSettingRequest $request, GroupSetting $group_setting)
{
return $this->itemResponse($group_setting);
}
/**
* Update the specified resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param UpdateGroupSettingRequest $request
* @param GroupSetting $group_setting
2024-06-16 00:30:25 +02:00
* @return Response| \Illuminate\Http\JsonResponse
2019-10-07 06:13:50 +02:00
*
2019-10-05 00:58:51 +02:00
*/
public function update(UpdateGroupSettingRequest $request, GroupSetting $group_setting)
{
2023-08-24 00:56:20 +02:00
/** Need this to prevent settings from being overwritten */
2023-10-26 04:57:44 +02:00
if(!$request->file('company_logo')) {
2023-08-24 00:56:20 +02:00
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
2023-10-26 04:57:44 +02:00
}
2019-10-07 23:17:55 +02:00
$this->uploadLogo($request->file('company_logo'), $group_setting->company, $group_setting);
if ($request->has('documents')) {
$this->saveDocuments($request->input('documents'), $group_setting, $request->input('is_public', true));
}
2021-01-18 12:06:26 +01:00
return $this->itemResponse($group_setting);
2019-10-05 00:58:51 +02:00
}
/**
* Remove the specified resource from storage.
*
2020-10-28 11:10:49 +01:00
* @param DestroyGroupSettingRequest $request
* @param GroupSetting $group_setting
2024-06-16 00:30:25 +02:00
* @return Response| \Illuminate\Http\JsonResponse
2019-10-07 06:13:50 +02:00
*
*
2020-10-28 11:10:49 +01:00
* @throws \Exception
2019-10-05 00:58:51 +02:00
*/
public function destroy(DestroyGroupSettingRequest $request, GroupSetting $group_setting)
{
$group_setting->delete();
return $this->itemResponse($group_setting->fresh());
2019-10-05 00:58:51 +02:00
}
2020-06-24 01:39:49 +02:00
/**
* Perform bulk actions on the list view.
2020-06-24 01:39:49 +02:00
*
2024-06-16 00:30:25 +02:00
* @return Response| \Illuminate\Http\JsonResponse
2020-06-24 01:39:49 +02:00
*
*/
public function bulk()
{
$action = request()->input('action');
$ids = request()->input('ids');
2023-04-29 13:10:26 +02:00
$group_settings = GroupSetting::withTrashed()->whereIn('id', $this->transformKeys($ids))->company();
2020-06-24 01:39:49 +02:00
2023-04-29 13:10:26 +02:00
if ($group_settings->count() == 0) {
2021-01-24 23:24:13 +01:00
return response()->json(['message' => ctrans('texts.no_group_settings_found')]);
2020-06-24 01:39:49 +02:00
}
2023-04-29 01:56:27 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
2020-06-24 01:39:49 +02:00
/*
* Send the other actions to the switch
*/
2023-04-29 13:10:26 +02:00
$group_settings->cursor()->each(function ($group, $key) use ($action, $user) {
2023-04-29 01:56:27 +02:00
if ($user->can('edit', $group)) {
2020-06-24 01:39:49 +02:00
$this->group_setting_repo->{$action}($group);
}
});
/* Need to understand which permission are required for the given bulk action ie. view / edit */
return $this->listResponse(GroupSetting::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
}
/**
* Update the specified resource in storage.
*
* @param UploadGroupSettingRequest $request
* @param GroupSetting $group_setting
2024-06-16 00:30:25 +02:00
* @return Response| \Illuminate\Http\JsonResponse
*
*/
public function upload(UploadGroupSettingRequest $request, GroupSetting $group_setting)
{
if (! $this->checkFeature(Account::FEATURE_DOCUMENTS)) {
return $this->featureFailure();
}
if ($request->has('documents')) {
$this->saveDocuments($request->file('documents'), $group_setting, $request->input('is_public', true));
}
return $this->itemResponse($group_setting->fresh());
}
2019-10-05 00:58:51 +02:00
}