|
@@ -78,6 +78,10 @@ class ReclamationController extends Controller
|
|
|
$this->acceptSearch($q, $request);
|
|
$this->acceptSearch($q, $request);
|
|
|
$this->setSortAndOrderBy($model, $request);
|
|
$this->setSortAndOrderBy($model, $request);
|
|
|
|
|
|
|
|
|
|
+ if (hasRole(Role::BRIGADIER)) {
|
|
|
|
|
+ $q->where('brigadier_id', auth()->id());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$this->applyStableSorting($q);
|
|
$this->applyStableSorting($q);
|
|
|
$this->data['reclamations'] = $q->paginate($this->data['per_page'])->withQueryString();
|
|
$this->data['reclamations'] = $q->paginate($this->data['per_page'])->withQueryString();
|
|
|
|
|
|
|
@@ -123,6 +127,8 @@ class ReclamationController extends Controller
|
|
|
|
|
|
|
|
public function show(Request $request, Reclamation $reclamation)
|
|
public function show(Request $request, Reclamation $reclamation)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->ensureCanViewReclamation($reclamation);
|
|
|
|
|
+
|
|
|
$this->data['brigadiers'] = User::query()->where('role', Role::BRIGADIER)->get()->pluck('name', 'id');
|
|
$this->data['brigadiers'] = User::query()->where('role', Role::BRIGADIER)->get()->pluck('name', 'id');
|
|
|
$this->data['reclamation'] = $reclamation;
|
|
$this->data['reclamation'] = $reclamation;
|
|
|
$this->data['previous_url'] = $this->resolvePreviousUrl(
|
|
$this->data['previous_url'] = $this->resolvePreviousUrl(
|
|
@@ -171,6 +177,9 @@ class ReclamationController extends Controller
|
|
|
|
|
|
|
|
public function uploadPhotoBefore(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
public function uploadPhotoBefore(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->ensureHasRole([Role::ADMIN, Role::MANAGER]);
|
|
|
|
|
+ $this->ensureCanViewReclamation($reclamation);
|
|
|
|
|
+
|
|
|
$data = $request->validate([
|
|
$data = $request->validate([
|
|
|
'photo.*' => 'mimes:jpeg,jpg,png|max:8192',
|
|
'photo.*' => 'mimes:jpeg,jpg,png|max:8192',
|
|
|
]);
|
|
]);
|
|
@@ -193,6 +202,8 @@ class ReclamationController extends Controller
|
|
|
|
|
|
|
|
public function uploadPhotoAfter(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
public function uploadPhotoAfter(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->ensureCanViewReclamation($reclamation);
|
|
|
|
|
+
|
|
|
$data = $request->validate([
|
|
$data = $request->validate([
|
|
|
'photo.*' => 'mimes:jpeg,jpg,png|max:8192',
|
|
'photo.*' => 'mimes:jpeg,jpg,png|max:8192',
|
|
|
]);
|
|
]);
|
|
@@ -215,6 +226,9 @@ class ReclamationController extends Controller
|
|
|
|
|
|
|
|
public function deletePhotoBefore(Request $request, Reclamation $reclamation, File $file, FileService $fileService)
|
|
public function deletePhotoBefore(Request $request, Reclamation $reclamation, File $file, FileService $fileService)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->ensureHasRole([Role::ADMIN, Role::MANAGER]);
|
|
|
|
|
+ $this->ensureCanViewReclamation($reclamation);
|
|
|
|
|
+
|
|
|
$reclamation->photos_before()->detach($file);
|
|
$reclamation->photos_before()->detach($file);
|
|
|
Storage::disk('public')->delete($file->path);
|
|
Storage::disk('public')->delete($file->path);
|
|
|
$file->delete();
|
|
$file->delete();
|
|
@@ -223,6 +237,9 @@ class ReclamationController extends Controller
|
|
|
|
|
|
|
|
public function deletePhotoAfter(Request $request, Reclamation $reclamation, File $file, FileService $fileService)
|
|
public function deletePhotoAfter(Request $request, Reclamation $reclamation, File $file, FileService $fileService)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->ensureHasRole([Role::ADMIN, Role::MANAGER]);
|
|
|
|
|
+ $this->ensureCanViewReclamation($reclamation);
|
|
|
|
|
+
|
|
|
$reclamation->photos_after()->detach($file);
|
|
$reclamation->photos_after()->detach($file);
|
|
|
Storage::disk('public')->delete($file->path);
|
|
Storage::disk('public')->delete($file->path);
|
|
|
$file->delete();
|
|
$file->delete();
|
|
@@ -231,6 +248,9 @@ class ReclamationController extends Controller
|
|
|
|
|
|
|
|
public function uploadDocument(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
public function uploadDocument(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->ensureHasRole([Role::ADMIN, Role::MANAGER]);
|
|
|
|
|
+ $this->ensureCanViewReclamation($reclamation);
|
|
|
|
|
+
|
|
|
$data = $request->validate([
|
|
$data = $request->validate([
|
|
|
'document.*' => 'file',
|
|
'document.*' => 'file',
|
|
|
]);
|
|
]);
|
|
@@ -255,6 +275,9 @@ class ReclamationController extends Controller
|
|
|
|
|
|
|
|
public function deleteDocument(Request $request, Reclamation $reclamation, File $file)
|
|
public function deleteDocument(Request $request, Reclamation $reclamation, File $file)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->ensureHasRole([Role::ADMIN]);
|
|
|
|
|
+ $this->ensureCanViewReclamation($reclamation);
|
|
|
|
|
+
|
|
|
$reclamation->documents()->detach($file);
|
|
$reclamation->documents()->detach($file);
|
|
|
Storage::disk('public')->delete($file->path);
|
|
Storage::disk('public')->delete($file->path);
|
|
|
$file->delete();
|
|
$file->delete();
|
|
@@ -263,6 +286,9 @@ class ReclamationController extends Controller
|
|
|
|
|
|
|
|
public function uploadAct(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
public function uploadAct(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->ensureHasRole([Role::ADMIN, Role::MANAGER, Role::BRIGADIER, Role::WAREHOUSE_HEAD]);
|
|
|
|
|
+ $this->ensureCanViewReclamation($reclamation);
|
|
|
|
|
+
|
|
|
$data = $request->validate([
|
|
$data = $request->validate([
|
|
|
'acts.*' => 'file',
|
|
'acts.*' => 'file',
|
|
|
]);
|
|
]);
|
|
@@ -287,6 +313,9 @@ class ReclamationController extends Controller
|
|
|
|
|
|
|
|
public function deleteAct(Request $request, Reclamation $reclamation, File $file)
|
|
public function deleteAct(Request $request, Reclamation $reclamation, File $file)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->ensureHasRole([Role::ADMIN]);
|
|
|
|
|
+ $this->ensureCanViewReclamation($reclamation);
|
|
|
|
|
+
|
|
|
$reclamation->acts()->detach($file);
|
|
$reclamation->acts()->detach($file);
|
|
|
Storage::disk('public')->delete($file->path);
|
|
Storage::disk('public')->delete($file->path);
|
|
|
$file->delete();
|
|
$file->delete();
|
|
@@ -504,6 +533,21 @@ class ReclamationController extends Controller
|
|
|
{
|
|
{
|
|
|
GenerateFilesPack::dispatch($reclamation, $reclamation->photos_after, auth()->user()->id, 'Фото после');
|
|
GenerateFilesPack::dispatch($reclamation, $reclamation->photos_after, auth()->user()->id, 'Фото после');
|
|
|
return redirect()->route('reclamations.show', ['reclamation' => $reclamation, 'previous_url' => $request->get('previous_url')])
|
|
return redirect()->route('reclamations.show', ['reclamation' => $reclamation, 'previous_url' => $request->get('previous_url')])
|
|
|
- ->with(['success' => 'Задача архивации создана!']); }
|
|
|
|
|
|
|
+ ->with(['success' => 'Задача архивации создана!']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function ensureCanViewReclamation(Reclamation $reclamation): void
|
|
|
|
|
+ {
|
|
|
|
|
+ if (hasRole(Role::BRIGADIER) && (int)$reclamation->brigadier_id !== (int)auth()->id()) {
|
|
|
|
|
+ abort(403);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function ensureHasRole(array $roles): void
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!count(array_intersect($roles, Role::effectiveRoles((string)auth()->user()?->role)))) {
|
|
|
|
|
+ abort(403);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|