From 5c2c815e03902fcf42121c1de0878ef949c541d9 Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Fri, 26 Jul 2024 10:37:12 -0300 Subject: [PATCH 01/45] =?UTF-8?q?Adiciona=20o=20m=C3=A1ximo=20de=20alunos?= =?UTF-8?q?=20da=20turma=20na=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ieducar/modules/Api/Views/TurmaController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ieducar/modules/Api/Views/TurmaController.php b/ieducar/modules/Api/Views/TurmaController.php index e25ee0b840..570512f44e 100644 --- a/ieducar/modules/Api/Views/TurmaController.php +++ b/ieducar/modules/Api/Views/TurmaController.php @@ -228,6 +228,7 @@ protected function getTurmasPorEscola() t.ref_ref_cod_escola as escola_id, t.turma_turno_id as turno_id, t.ref_cod_regente, + t.max_aluno, json_agg( json_build_object( 'serie_id', s.cod_serie, @@ -268,7 +269,7 @@ protected function getTurmasPorEscola() $turmas = $this->fetchPreparedQuery($sql, $params); - $attrs = ['id', 'nome', 'ano', 'escola_id', 'turno_id', 'curso_id', 'series_regras', 'ref_cod_regente', 'updated_at', 'deleted_at']; + $attrs = ['id', 'nome', 'ano', 'escola_id', 'turno_id', 'curso_id', 'series_regras', 'ref_cod_regente', 'max_aluno', 'updated_at', 'deleted_at']; $turmas = Portabilis_Array_Utils::filterSet($turmas, $attrs); foreach ($turmas as $key => $turma) { From 4fb679aea75c4771750460928a6fac4b52069c86 Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Wed, 14 Aug 2024 11:28:28 -0300 Subject: [PATCH 02/45] =?UTF-8?q?Cria=20=C3=A1rea=20de=20publica=C3=A7?= =?UTF-8?q?=C3=A3o=20de=20avisos=20e=20notifica=C3=A7=C3=B5es=20de=20vagas?= =?UTF-8?q?=20dispon=C3=ADveis=20por=20tipo=20de=20usu=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnnouncementPublishController.php | 95 ++++++++++++ .../AnnouncementUserController.php | 74 ++++++++++ app/Http/Controllers/Auth/LoginController.php | 21 +++ app/Http/Requests/AnnouncementRequest.php | 57 +++++++ app/Models/Announcement.php | 37 +++++ app/Models/AnnouncementTipoUsuario.php | 11 ++ app/Models/AnnouncementUser.php | 11 ++ app/Process.php | 2 + ...8_12_223334_create_announcements_table.php | 68 +++++++++ ieducar/lib/App/Model/IedFinder.php | 14 ++ .../announcement/publish/create.blade.php | 123 ++++++++++++++++ .../announcement/publish/index.blade.php | 65 ++++++++ .../views/announcement/user/show.blade.php | 139 ++++++++++++++++++ .../form/select-user-type-multiple.blade.php | 51 +++++++ routes/web.php | 8 + 15 files changed, 776 insertions(+) create mode 100644 app/Http/Controllers/AnnouncementPublishController.php create mode 100644 app/Http/Controllers/AnnouncementUserController.php create mode 100644 app/Http/Requests/AnnouncementRequest.php create mode 100644 app/Models/Announcement.php create mode 100644 app/Models/AnnouncementTipoUsuario.php create mode 100644 app/Models/AnnouncementUser.php create mode 100644 database/migrations/2024_08_12_223334_create_announcements_table.php create mode 100644 resources/views/announcement/publish/create.blade.php create mode 100644 resources/views/announcement/publish/index.blade.php create mode 100644 resources/views/announcement/user/show.blade.php create mode 100644 resources/views/form/select-user-type-multiple.blade.php diff --git a/app/Http/Controllers/AnnouncementPublishController.php b/app/Http/Controllers/AnnouncementPublishController.php new file mode 100644 index 0000000000..1994bd8ab3 --- /dev/null +++ b/app/Http/Controllers/AnnouncementPublishController.php @@ -0,0 +1,95 @@ +menu(Process::ANNOUNCEMENT); + $this->breadcrumb('Publicação de avisos', [ + url('/intranet/educar_configuracoes_index.php') => 'Configurações' + ]); + $announcements = Announcement::query() + ->withTrashed() + ->with([ + 'userTypes' + ]) + ->latest() + ->paginate(); + + return view('announcement.publish.index', [ + 'announcements' => $announcements + ]); + } + + public function update(AnnouncementRequest $request, $announcementId) + { + DB::beginTransaction(); + try { + $announcement = Announcement::query()->withTrashed()->findOrFail($announcementId); + $announcement->fill($request->all()); + $announcement->save(); + $announcement->userTypes()->sync($request->get('tipo_usuario')); + $request->get('active') ? $announcement->restore() : $announcement->delete(); + DB::commit(); + session()->flash('success', 'Edição efetuada com sucesso.'); + } catch (Exception) { + DB::rollBack(); + session()->flash('error', 'Edição não realizada.'); + } + + return redirect()->route('announcement.publish.edit', $announcement); + } + + public function store(AnnouncementRequest $request) + { + DB::beginTransaction(); + try { + $announcement = Announcement::create($request->all()); + $announcement->userTypes()->sync($request->get('tipo_usuario')); + $request->get('active') ? $announcement->restore() : $announcement->delete(); + DB::commit(); + session()->flash('success', 'Cadastro efetuado com sucesso.'); + } catch (Exception) { + DB::rollBack(); + session()->flash('error', 'Cadastro não realizado.'); + } + + return redirect()->route('announcement.publish.index'); + } + + public function create() + { + $this->menu(Process::ANNOUNCEMENT); + $this->breadcrumb('Publicação de avisos', [ + url('/intranet/educar_configuracoes_index.php') => 'Configurações' + ]); + + return view('announcement.publish.create', [ + 'announcement' => new Announcement(), + 'userTypes' => null + ]); + } + + public function edit($announcementId) + { + $this->menu(Process::ANNOUNCEMENT); + $this->breadcrumb('Publicação de avisos', [ + url('/intranet/educar_configuracoes_index.php') => 'Configurações' + ]); + $announcement = Announcement::query()->withTrashed()->findOrFail($announcementId); + $userTypes = $announcement->userTypes->pluck('cod_tipo_usuario'); + + return view('announcement.publish.create', [ + 'announcement' => $announcement, + 'userTypes' => $userTypes + ]); + } +} diff --git a/app/Http/Controllers/AnnouncementUserController.php b/app/Http/Controllers/AnnouncementUserController.php new file mode 100644 index 0000000000..ffef6b79eb --- /dev/null +++ b/app/Http/Controllers/AnnouncementUserController.php @@ -0,0 +1,74 @@ +breadcrumb('Avisos'); + $this->menu(Process::ANNOUNCEMENT); + $announcement = Announcement::query()->latest()->first(); + $announcement->users()->sync([ + $request->user()->getKey() => ['read_at' => now()] + ]); + $schools = null; + if ($announcement->show_vacancy) { + $schools = LegacyEnrollment::query() + ->selectRaw(" + nm_turma, + UPPER(pessoa.nome) as escola, + string_agg(distinct nm_serie, ', ') as serie, + string_agg(distinct nm_curso, ', ') as curso, + max_aluno - COUNT(distinct matricula.cod_matricula) as vagas + ") + ->join('relatorio.view_situacao', function ($join) { + $join->on('view_situacao.cod_matricula', 'ref_cod_matricula') + ->on('view_situacao.cod_turma', 'ref_cod_turma') + ->on('view_situacao.sequencial', 'matricula_turma.sequencial'); + }) + ->join('pmieducar.turma', fn ($join) => $join->on('turma.cod_turma', 'ref_cod_turma')->where('turma.ativo', 1)->where('turma.ano', Carbon::now()->year)) + ->join('pmieducar.escola', fn ($join) => $join->on('cod_escola', 'turma.ref_ref_cod_escola')->where('escola.ativo', 1)) + ->join('cadastro.pessoa', 'idpes', 'escola.ref_idpes') + ->join('pmieducar.matricula', 'matricula.cod_matricula', 'ref_cod_matricula') + ->join('pmieducar.serie', fn ($join) => $join->on('cod_serie', 'matricula.ref_ref_cod_serie')->where('matricula.ativo', 1)) + ->join('pmieducar.curso', fn ($join) => $join->on('cod_curso', 'matricula.ref_cod_curso')->where('curso.ativo', 1)) + ->when(Auth::user()->isSchooling(), fn ($q) => $q->whereIn('cod_escola', Auth::user()->schools()->pluck('id'))) + ->having('max_aluno', '>', DB::raw('COUNT(distinct matricula.cod_matricula)')) + ->orderBy('escola') + ->orderBy('curso') + ->orderBy('serie') + ->orderBy('nm_turma') + ->groupBy('nm_turma', 'max_aluno', 'pessoa.nome') + ->get() + ->groupBy([ + 'escola', + 'curso', + 'serie', + ]); + }; + + return view('announcement.user.show', [ + 'announcement' => $announcement, + 'schools' => $schools + ]); + } + + public function confirm(Request $request) + { + $announcement = Announcement::query()->latest()->first(); + $announcement->users()->sync([ + $request->user()->getKey() => ['confirmed_at' => now()] + ]); + + return redirect('/'); + } +} diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 1d204aa400..4f7862c87e 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; +use App\Models\Announcement; use App\Rules\ReCaptchaV3; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\Request; @@ -77,4 +78,24 @@ public function validateLogin(Request $request) 'password.string' => 'O campo senha é obrigatório.', ]); } + + protected function authenticated(Request $request, $user) + { + $announcement = Announcement::latest()->first(); + + if ($announcement && $announcement->userTypes?->contains($user->ref_cod_tipo_usuario)) { + if ($announcement->repeat_on_login || !$this->userReadAnnouncement($announcement, $user)) { + return redirect()->route('announcement.user.show'); + } + } + } + + private function userReadAnnouncement(Announcement $announcement, $user): bool + { + return $announcement->users() + ->whereKey($user->getKey()) + ->wherePivotNotNull('read_at') + ->exists(); + } + } diff --git a/app/Http/Requests/AnnouncementRequest.php b/app/Http/Requests/AnnouncementRequest.php new file mode 100644 index 0000000000..6c9a8d565b --- /dev/null +++ b/app/Http/Requests/AnnouncementRequest.php @@ -0,0 +1,57 @@ +merge([ + 'repeat_on_login' => $this->has('repeat_on_login'), + 'show_confirmation' => $this->has('show_confirmation'), + 'show_vacancy' => $this->has('show_vacancy'), + 'active' => $this->has('active'), + 'tipo_usuario' => Arr::flatten($this->get('tipo_usuario', [])), + 'created_by_user_id' => $this->user()->getKey() + ]); + } + + public function rules() + { + return [ + 'name' => ['required', 'max:255'], + 'description' => ['required'], + 'repeat_on_login' => ['boolean'], + 'show_confirmation' => ['boolean'], + 'active' => ['boolean', function ($attribute, $value, $fail) { + if ($value) { + $exists = Announcement::query() + ->withoutTrashed() + ->where('id', '<>', $this->route('announcement')) + ->exists(); + + if ($exists) { + $fail('Já existe um aviso ativo.'); + } + } + }], + 'show_vacancy' => ['boolean'], + 'tipo_usuario' => ['required', 'array'], + 'tipo_usuario.*' => ['integer', Rule::exists('tipo_usuario', 'cod_tipo_usuario')], + ]; + } + + public function attributes() + { + return [ + 'description' => 'Conteúdo do aviso', + 'tipo_usuario' => 'Tipos de usuários que serão notificados' + ]; + } +} diff --git a/app/Models/Announcement.php b/app/Models/Announcement.php new file mode 100644 index 0000000000..ccff7c6119 --- /dev/null +++ b/app/Models/Announcement.php @@ -0,0 +1,37 @@ +belongsToMany(LegacyUserType::class, 'announcement_user_types', 'announcement_id', 'user_type_id'); + } + + public function users(): BelongsToMany + { + return $this->belongsToMany(LegacyUser::class, 'announcement_users', 'announcement_id', 'user_id'); + } + + public function createdByUser(): BelongsTo + { + return $this->belongsTo(LegacyUser::class); + } +} diff --git a/app/Models/AnnouncementTipoUsuario.php b/app/Models/AnnouncementTipoUsuario.php new file mode 100644 index 0000000000..7c417f19da --- /dev/null +++ b/app/Models/AnnouncementTipoUsuario.php @@ -0,0 +1,11 @@ +smallIncrements('id'); + $table->string('name'); + $table->text('description')->nullable(); + $table->boolean('repeat_on_login')->default(false); + $table->boolean('show_confirmation')->default(false); + $table->boolean('show_vacancy')->default(false); + $table->unsignedInteger('created_by_user_id')->nullable(); + $table->foreign('created_by_user_id')->references('cod_usuario')->on('pmieducar.usuario')->onDelete('cascade')->onUpdate('cascade'); + $table->softDeletes(); + $table->timestamps(); + }); + + Schema::create('announcement_user_types', function (Blueprint $table) { + $table->id(); + $table->unsignedSmallInteger('announcement_id'); + $table->foreign('announcement_id')->references('id')->on('announcements')->onDelete('cascade')->onUpdate('cascade'); + $table->unsignedInteger('user_type_id'); + $table->foreign('user_type_id')->references('cod_tipo_usuario')->on('pmieducar.tipo_usuario')->onDelete('cascade')->onUpdate('cascade'); + $table->primary([ + 'user_type_id', + 'announcement_id' + ]); + }); + + Schema::create('announcement_users', function (Blueprint $table) { + $table->id(); + $table->unsignedSmallInteger('announcement_id'); + $table->foreign('announcement_id')->references('id')->on('announcements')->onDelete('cascade')->onUpdate('cascade'); + $table->unsignedInteger('user_id'); + $table->foreign('user_id')->references('cod_usuario')->on('pmieducar.usuario')->onDelete('cascade')->onUpdate('cascade'); + $table->timestamp('confirmed_at')->nullable(); + $table->timestamp('read_at')->nullable(); + $table->primary([ + 'user_id', + 'announcement_id' + ]); + }); + + Menu::query()->updateOrCreate(['old' => Process::ANNOUNCEMENT], [ + 'parent_id' => Menu::query()->where('old', Process::CONFIGURATIONS_TOOLS)->firstOrFail()->getKey(), + 'process' => Process::ANNOUNCEMENT, + 'title' => 'Publicação de avisos', + 'order' => 0, + 'parent_old' => Process::CONFIGURATIONS_TOOLS, + 'link' => '/avisos/publicacao', + ]); + } + + public function down(): void + { + Menu::query()->where('old', Process::ANNOUNCEMENT)->delete(); + Schema::dropIfExists('announcement_users'); + Schema::dropIfExists('announcement_user_types'); + Schema::dropIfExists('announcements'); + } +}; diff --git a/ieducar/lib/App/Model/IedFinder.php b/ieducar/lib/App/Model/IedFinder.php index b169ba3467..f8b00c9e01 100644 --- a/ieducar/lib/App/Model/IedFinder.php +++ b/ieducar/lib/App/Model/IedFinder.php @@ -7,6 +7,7 @@ use App\Models\LegacySchool; use App\Models\LegacySchoolClass; use App\Models\LegacySchoolClassStage; +use App\Models\LegacyUserType; use iEducar\Modules\AcademicYear\Exceptions\DisciplineNotLinkedToRegistrationException; use iEducar\Modules\Enrollments\Exceptions\StudentNotEnrolledInSchoolClass; use iEducar\Modules\EvaluationRules\Exceptions\EvaluationRuleNotDefinedInLevel; @@ -111,6 +112,19 @@ public static function getEscolasByUser($instituicaoId) return $query->get()->sortBy('name')->getKeyValueArray('name'); } + /** + * Retorna todos os tipo de usuários. + * + * @return array + */ + public static function getTiposUsuario(bool $hideAdmin = true) + { + return LegacyUserType::query() + ->when($hideAdmin, fn ($q) => $q->where('nivel', '<>', LegacyUserType::LEVEL_ADMIN)) + ->orderBy('nm_tipo') + ->pluck('nm_tipo', 'cod_tipo_usuario'); + } + /** * Retorna um nome de curso, procurando pelo seu código. * diff --git a/resources/views/announcement/publish/create.blade.php b/resources/views/announcement/publish/create.blade.php new file mode 100644 index 0000000000..14df837f25 --- /dev/null +++ b/resources/views/announcement/publish/create.blade.php @@ -0,0 +1,123 @@ +@extends('layout.default') + +@section('content') +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+@endsection + +@prepend('styles') + + +@endprepend + +@prepend('scripts') + + + + + + + + + +@endprepend diff --git a/resources/views/announcement/publish/index.blade.php b/resources/views/announcement/publish/index.blade.php new file mode 100644 index 0000000000..0ccb337ca5 --- /dev/null +++ b/resources/views/announcement/publish/index.blade.php @@ -0,0 +1,65 @@ +@extends('layout.default') + +@inject('presigner', App\Services\UrlPresigner::class) + +@push('styles') + +@endpush + +@section('content') +

Avisos

+ + + + + + + + + + + @forelse($announcements as $announcement) + + @can('modify', \App\Process::ANNOUNCEMENT) + + + + + @else + + + + + @endcan + + + @empty + + + + @endforelse + +
NomeTipos de UsuárioDataStatus
+ {{ $announcement->name }} + + {{ $announcement->userTypes->implode('nm_tipo', ', ') }} + + {{ $announcement->trashed() ? 'Desativado' : 'Ativado' }} + + {{ $announcement->created_at->format('d/m/Y H:i') }} + {{ $announcement->name }}/>{{ $announcement->userTypes->implode('nm_tipo', ', ') }}{{ $announcement->trashed() ? 'Desativado' : 'Ativado' }}{{ $announcement->created_at->format('d/m/Y H:i') }}
Não existe nenhum aviso
+ +
+ +
+
+ {{ $announcements->links() }} +
+
+ + @can('create', \App\Process::ANNOUNCEMENT) +
+ Novo +
+ @endcan +@endsection diff --git a/resources/views/announcement/user/show.blade.php b/resources/views/announcement/user/show.blade.php new file mode 100644 index 0000000000..ddc3f81269 --- /dev/null +++ b/resources/views/announcement/user/show.blade.php @@ -0,0 +1,139 @@ +@extends('layout.default') + +@push('styles') + + +@endpush + +@section('content') +
+ + + + + + + + + @if($announcement->show_vacancy) + + + + + + + @endif + + + @if($announcement->show_vacancy && $schools->isNotEmpty()) + + + + + + + + + + + + @foreach($schools as $schoolName => $courses) + @php + $row1 = 0; + foreach ($courses as $grades) { + foreach ($grades as $schoolClasses) { + foreach ($schoolClasses as $schoolClass) { + $row1++; + } + } + } + $isFirstSchool = true; + @endphp + + @foreach($courses as $courseName => $grades) + @php + $row2 = 0; + foreach ($grades as $schoolClasses) { + foreach ($schoolClasses as $schoolClass) { + $row2++; + } + } + $isFirstCourse = true; + @endphp + + @foreach($grades as $gradeName => $schoolClasses) + @php + $row3 = 0; + foreach ($schoolClasses as $schoolClass) { + $row3++; + } + @endphp + + @foreach($schoolClasses as $schoolClass) + + @if($isFirstSchool) + + @php + $isFirstSchool = false; + @endphp + @endif + @if($isFirstCourse) + + @php + $isFirstCourse = false; + @endphp + @endif + @if($loop->first) + + @endif + + + + @endforeach + @endforeach + @endforeach + @endforeach + +
ESCOLACURSOSÉRIETURMAVAGAS
{{ $schoolName }}{{ $courseName. '|'. $row2 }}{{ $gradeName }}{{ $schoolClass->nm_turma }}{{ $schoolClass->vagas }}
+ @endif + @if($announcement->show_confirmation) +
+
+ +
+ @endif +
+@endsection diff --git a/resources/views/form/select-user-type-multiple.blade.php b/resources/views/form/select-user-type-multiple.blade.php new file mode 100644 index 0000000000..7fcbc87a2f --- /dev/null +++ b/resources/views/form/select-user-type-multiple.blade.php @@ -0,0 +1,51 @@ + + + + +@push('scripts') + + + + +@endpush +@if($userTypes = old('tipo_usuario', $userTypes)) + + @php + $userTypes = collect($userTypes); + + if ($userTypes->isNotEmpty() && is_array($userTypes[0])){ + $userTypes = $userTypes->map(function ($value) { + return $value[0]; + }); + } + @endphp + + @push('scripts') + + @endpush +@endif diff --git a/routes/web.php b/routes/web.php index 37df3d376b..f568e7c518 100644 --- a/routes/web.php +++ b/routes/web.php @@ -134,6 +134,14 @@ Route::get('/arquivo/exportacoes/novo', 'FileExportController@create')->middleware('can:modify:' . Process::DOCUMENT_EXPORT)->name('file.export.create'); Route::post('/arquivo/exportacoes/novo', 'FileExportController@store')->middleware('can:modify:' . Process::DOCUMENT_EXPORT)->name('file.export.store'); + Route::get('/avisos/publicacao', 'AnnouncementPublishController@index')->middleware('can:view:' . Process::ANNOUNCEMENT)->name('announcement.publish.index'); + Route::get('/avisos/publicacao/criar', 'AnnouncementPublishController@create')->middleware('can:create:' . Process::ANNOUNCEMENT)->name('announcement.publish.create'); + Route::post('/avisos/publicacao/criar', 'AnnouncementPublishController@store')->middleware('can:create:' . Process::ANNOUNCEMENT)->name('announcement.publish.store'); + Route::get('/avisos/publicacao/{announcement}/editar', 'AnnouncementPublishController@edit')->middleware('can:modify:' . Process::ANNOUNCEMENT)->name('announcement.publish.edit'); + Route::post('/avisos/publicacao/{announcement}/editar', 'AnnouncementPublishController@update')->middleware('can:modify:' . Process::ANNOUNCEMENT)->name('announcement.publish.update'); + Route::get('/avisos', 'AnnouncementUserController@show')->name('announcement.user.show'); + Route::post('/avisos', 'AnnouncementUserController@confirm')->name('announcement.user.confirm'); + Route::get('/atualiza-data-entrada', 'UpdateRegistrationDateController@index')->middleware('can:view:' . Process::UPDATE_REGISTRATION_DATE)->name('update-registration-date.index'); Route::post('/atualiza-data-entrada', 'UpdateRegistrationDateController@updateStatus')->middleware('can:modify:' . Process::UPDATE_REGISTRATION_DATE)->name('update-registration-date.update-date'); From 27b93fd85bb95f3a9ec24fc57eb26fe1dcd07a50 Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Wed, 14 Aug 2024 13:25:32 -0300 Subject: [PATCH 03/45] =?UTF-8?q?Melhora=20organiza=C3=A7=C3=A3o=20do=20m?= =?UTF-8?q?=C3=A9todo=20de=20salvamento=20dos=20avisos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnnouncementPublishController.php | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/AnnouncementPublishController.php b/app/Http/Controllers/AnnouncementPublishController.php index 1994bd8ab3..14b8f9c8e1 100644 --- a/app/Http/Controllers/AnnouncementPublishController.php +++ b/app/Http/Controllers/AnnouncementPublishController.php @@ -31,17 +31,19 @@ public function index() public function update(AnnouncementRequest $request, $announcementId) { - DB::beginTransaction(); - try { + $announcement = DB::transaction(function () use ($announcementId, $request) { $announcement = Announcement::query()->withTrashed()->findOrFail($announcementId); $announcement->fill($request->all()); $announcement->save(); $announcement->userTypes()->sync($request->get('tipo_usuario')); $request->get('active') ? $announcement->restore() : $announcement->delete(); - DB::commit(); + + return $announcement; + }); + + if ($announcement) { session()->flash('success', 'Edição efetuada com sucesso.'); - } catch (Exception) { - DB::rollBack(); + } else { session()->flash('error', 'Edição não realizada.'); } @@ -50,15 +52,17 @@ public function update(AnnouncementRequest $request, $announcementId) public function store(AnnouncementRequest $request) { - DB::beginTransaction(); - try { + $announcement = DB::transaction(function () use ($request) { $announcement = Announcement::create($request->all()); $announcement->userTypes()->sync($request->get('tipo_usuario')); $request->get('active') ? $announcement->restore() : $announcement->delete(); - DB::commit(); + + return $announcement; + }); + + if ($announcement) { session()->flash('success', 'Cadastro efetuado com sucesso.'); - } catch (Exception) { - DB::rollBack(); + } else { session()->flash('error', 'Cadastro não realizado.'); } From db84ae13e6e02be04e0dd76056605e4a7fae300a Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Wed, 14 Aug 2024 14:27:00 -0300 Subject: [PATCH 04/45] Style code --- .../AnnouncementPublishController.php | 17 +++++---- .../AnnouncementUserController.php | 8 ++--- .../Middleware/AnnouncementMiddleware.php | 35 +++++++++++++++++++ app/Http/Requests/AnnouncementRequest.php | 7 ++-- app/Models/Announcement.php | 2 +- 5 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 app/Http/Middleware/AnnouncementMiddleware.php diff --git a/app/Http/Controllers/AnnouncementPublishController.php b/app/Http/Controllers/AnnouncementPublishController.php index 14b8f9c8e1..0d8bbee723 100644 --- a/app/Http/Controllers/AnnouncementPublishController.php +++ b/app/Http/Controllers/AnnouncementPublishController.php @@ -5,7 +5,6 @@ use App\Http\Requests\AnnouncementRequest; use App\Models\Announcement; use App\Process; -use Exception; use Illuminate\Support\Facades\DB; class AnnouncementPublishController extends Controller @@ -14,18 +13,18 @@ public function index() { $this->menu(Process::ANNOUNCEMENT); $this->breadcrumb('Publicação de avisos', [ - url('/intranet/educar_configuracoes_index.php') => 'Configurações' + url('/intranet/educar_configuracoes_index.php') => 'Configurações', ]); $announcements = Announcement::query() ->withTrashed() ->with([ - 'userTypes' + 'userTypes', ]) ->latest() ->paginate(); return view('announcement.publish.index', [ - 'announcements' => $announcements + 'announcements' => $announcements, ]); } @@ -62,7 +61,7 @@ public function store(AnnouncementRequest $request) if ($announcement) { session()->flash('success', 'Cadastro efetuado com sucesso.'); - } else { + } else { session()->flash('error', 'Cadastro não realizado.'); } @@ -73,12 +72,12 @@ public function create() { $this->menu(Process::ANNOUNCEMENT); $this->breadcrumb('Publicação de avisos', [ - url('/intranet/educar_configuracoes_index.php') => 'Configurações' + url('/intranet/educar_configuracoes_index.php') => 'Configurações', ]); return view('announcement.publish.create', [ 'announcement' => new Announcement(), - 'userTypes' => null + 'userTypes' => null, ]); } @@ -86,14 +85,14 @@ public function edit($announcementId) { $this->menu(Process::ANNOUNCEMENT); $this->breadcrumb('Publicação de avisos', [ - url('/intranet/educar_configuracoes_index.php') => 'Configurações' + url('/intranet/educar_configuracoes_index.php') => 'Configurações', ]); $announcement = Announcement::query()->withTrashed()->findOrFail($announcementId); $userTypes = $announcement->userTypes->pluck('cod_tipo_usuario'); return view('announcement.publish.create', [ 'announcement' => $announcement, - 'userTypes' => $userTypes + 'userTypes' => $userTypes, ]); } } diff --git a/app/Http/Controllers/AnnouncementUserController.php b/app/Http/Controllers/AnnouncementUserController.php index ffef6b79eb..5482f9fede 100644 --- a/app/Http/Controllers/AnnouncementUserController.php +++ b/app/Http/Controllers/AnnouncementUserController.php @@ -18,7 +18,7 @@ public function show(Request $request) $this->menu(Process::ANNOUNCEMENT); $announcement = Announcement::query()->latest()->first(); $announcement->users()->sync([ - $request->user()->getKey() => ['read_at' => now()] + $request->user()->getKey() => ['read_at' => now()], ]); $schools = null; if ($announcement->show_vacancy) { @@ -54,11 +54,11 @@ public function show(Request $request) 'curso', 'serie', ]); - }; + } return view('announcement.user.show', [ 'announcement' => $announcement, - 'schools' => $schools + 'schools' => $schools, ]); } @@ -66,7 +66,7 @@ public function confirm(Request $request) { $announcement = Announcement::query()->latest()->first(); $announcement->users()->sync([ - $request->user()->getKey() => ['confirmed_at' => now()] + $request->user()->getKey() => ['confirmed_at' => now()], ]); return redirect('/'); diff --git a/app/Http/Middleware/AnnouncementMiddleware.php b/app/Http/Middleware/AnnouncementMiddleware.php new file mode 100644 index 0000000000..0cd48762b3 --- /dev/null +++ b/app/Http/Middleware/AnnouncementMiddleware.php @@ -0,0 +1,35 @@ +user()) { + $announcement = Announcement::latest()->first(); + if ($announcement && $announcement->userTypes?->contains($user->ref_cod_tipo_usuario)) { + if ($announcement->show_confirmation && !$this->userConfirmedAnnouncement($announcement, $user)) { + Session::flash('error', 'Confirme a ciência do aviso antes de prosseguir!'); + + return redirect()->route('announcement.user.show'); + } + } + } + + return $next($request); + } + + private function userConfirmedAnnouncement(Announcement $announcement, $user): bool + { + return $announcement->users() + ->whereKey($user->getKey()) + ->wherePivotNotNull('confirmed_at') + ->exists(); + } +} diff --git a/app/Http/Requests/AnnouncementRequest.php b/app/Http/Requests/AnnouncementRequest.php index 6c9a8d565b..38cccf6855 100644 --- a/app/Http/Requests/AnnouncementRequest.php +++ b/app/Http/Requests/AnnouncementRequest.php @@ -9,7 +9,6 @@ class AnnouncementRequest extends FormRequest { - protected function prepareForValidation() { $this->merge([ @@ -18,14 +17,14 @@ protected function prepareForValidation() 'show_vacancy' => $this->has('show_vacancy'), 'active' => $this->has('active'), 'tipo_usuario' => Arr::flatten($this->get('tipo_usuario', [])), - 'created_by_user_id' => $this->user()->getKey() + 'created_by_user_id' => $this->user()->getKey(), ]); } public function rules() { return [ - 'name' => ['required', 'max:255'], + 'name' => ['required', 'max:255'], 'description' => ['required'], 'repeat_on_login' => ['boolean'], 'show_confirmation' => ['boolean'], @@ -51,7 +50,7 @@ public function attributes() { return [ 'description' => 'Conteúdo do aviso', - 'tipo_usuario' => 'Tipos de usuários que serão notificados' + 'tipo_usuario' => 'Tipos de usuários que serão notificados', ]; } } diff --git a/app/Models/Announcement.php b/app/Models/Announcement.php index ccff7c6119..b6412cd4bf 100644 --- a/app/Models/Announcement.php +++ b/app/Models/Announcement.php @@ -17,7 +17,7 @@ class Announcement extends Model 'repeat_on_login', 'show_confirmation', 'show_vacancy', - 'created_by_user_id' + 'created_by_user_id', ]; public function userTypes(): BelongsToMany From dbbd43c42c867021f985be3946eabbbcf9ab98aa Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Wed, 14 Aug 2024 14:27:55 -0300 Subject: [PATCH 05/45] =?UTF-8?q?Cria=20middleware=20para=20avisos=20que?= =?UTF-8?q?=20necessita=20de=20confirma=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Auth/LoginController.php | 24 +++++++++++++++---- app/Http/Kernel.php | 1 + ...8_12_223334_create_announcements_table.php | 11 +++++---- .../views/announcement/user/show.blade.php | 10 +++++--- routes/web.php | 7 +++--- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 4f7862c87e..88af7efb1a 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -83,10 +83,25 @@ protected function authenticated(Request $request, $user) { $announcement = Announcement::latest()->first(); - if ($announcement && $announcement->userTypes?->contains($user->ref_cod_tipo_usuario)) { - if ($announcement->repeat_on_login || !$this->userReadAnnouncement($announcement, $user)) { - return redirect()->route('announcement.user.show'); - } + if (!$announcement || !$announcement->userTypes?->contains($user->ref_cod_tipo_usuario)) { + return null; + } + + if ($announcement->repeat_on_login) { + $this->resetAnnouncementConfirmation($announcement, $user); + + return redirect()->route('announcement.user.show'); + } + + if (!$this->userReadAnnouncement($announcement, $user)) { + return redirect()->route('announcement.user.show'); + } + } + + private function resetAnnouncementConfirmation(Announcement $announcement, $user): void + { + if ($announcement->show_confirmation) { + $announcement->users()->updateExistingPivot($user->getKey(), ['confirmed_at' => null]); } } @@ -97,5 +112,4 @@ private function userReadAnnouncement(Announcement $announcement, $user): bool ->wherePivotNotNull('read_at') ->exists(); } - } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 66e269285f..05453e5370 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -38,6 +38,7 @@ class Kernel extends HttpKernel \Illuminate\View\Middleware\ShareErrorsFromSession::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, \App\Http\Middleware\SetLayoutVariables::class, + \App\Http\Middleware\AnnouncementMiddleware::class, ], 'api' => [ diff --git a/database/migrations/2024_08_12_223334_create_announcements_table.php b/database/migrations/2024_08_12_223334_create_announcements_table.php index 583d555835..71ddd77754 100644 --- a/database/migrations/2024_08_12_223334_create_announcements_table.php +++ b/database/migrations/2024_08_12_223334_create_announcements_table.php @@ -1,12 +1,13 @@ foreign('user_type_id')->references('cod_tipo_usuario')->on('pmieducar.tipo_usuario')->onDelete('cascade')->onUpdate('cascade'); $table->primary([ 'user_type_id', - 'announcement_id' + 'announcement_id', ]); }); @@ -44,7 +45,7 @@ public function up(): void $table->timestamp('read_at')->nullable(); $table->primary([ 'user_id', - 'announcement_id' + 'announcement_id', ]); }); diff --git a/resources/views/announcement/user/show.blade.php b/resources/views/announcement/user/show.blade.php index ddc3f81269..187afcd659 100644 --- a/resources/views/announcement/user/show.blade.php +++ b/resources/views/announcement/user/show.blade.php @@ -58,7 +58,7 @@ @endif - @if($announcement->show_vacancy && $schools->isNotEmpty()) + @if($announcement->show_vacancy) @@ -70,7 +70,7 @@ - @foreach($schools as $schoolName => $courses) + @forelse($schools as $schoolName => $courses) @php $row1 = 0; foreach ($courses as $grades) { @@ -125,7 +125,11 @@ @endforeach @endforeach @endforeach - @endforeach + @empty + + + + @endforelse
Nenhuma escola com vaga encontrada
@endif diff --git a/routes/web.php b/routes/web.php index f568e7c518..e766917cd9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,6 +5,7 @@ use App\Http\Controllers\ExportController; use App\Http\Controllers\SchoolClassController; use App\Http\Controllers\WebController; +use App\Http\Middleware\AnnouncementMiddleware; use App\Process; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; @@ -121,7 +122,7 @@ Route::get('/abre-url-privada', 'OpenPrivateUrlController@open')->name('open_private_url.open'); Route::get('/notificacoes', 'NotificationController@index')->name('notifications.index'); - Route::get('/notificacoes/retorna-notificacoes-usuario', 'NotificationController@getByLoggedUser')->name('notifications.get-by-logged-user'); + Route::get('/notificacoes/retorna-notificacoes-usuario', 'NotificationController@getByLoggedUser')->withoutMiddleware(AnnouncementMiddleware::class)->name('notifications.get-by-logged-user'); Route::get('/notificacoes/quantidade-nao-lidas', 'NotificationController@getNotReadCount')->name('notifications.get-not-read-count'); Route::post('/notificacoes/marca-como-lida', 'NotificationController@markAsRead')->name('notifications.mark-as-read'); Route::post('/notificacoes/marca-todas-como-lidas', 'NotificationController@markAllRead')->name('notifications.mark-all-read'); @@ -139,8 +140,8 @@ Route::post('/avisos/publicacao/criar', 'AnnouncementPublishController@store')->middleware('can:create:' . Process::ANNOUNCEMENT)->name('announcement.publish.store'); Route::get('/avisos/publicacao/{announcement}/editar', 'AnnouncementPublishController@edit')->middleware('can:modify:' . Process::ANNOUNCEMENT)->name('announcement.publish.edit'); Route::post('/avisos/publicacao/{announcement}/editar', 'AnnouncementPublishController@update')->middleware('can:modify:' . Process::ANNOUNCEMENT)->name('announcement.publish.update'); - Route::get('/avisos', 'AnnouncementUserController@show')->name('announcement.user.show'); - Route::post('/avisos', 'AnnouncementUserController@confirm')->name('announcement.user.confirm'); + Route::get('/avisos', 'AnnouncementUserController@show')->withoutMiddleware(AnnouncementMiddleware::class)->name('announcement.user.show'); + Route::post('/avisos', 'AnnouncementUserController@confirm')->withoutMiddleware(AnnouncementMiddleware::class)->name('announcement.user.confirm'); Route::get('/atualiza-data-entrada', 'UpdateRegistrationDateController@index')->middleware('can:view:' . Process::UPDATE_REGISTRATION_DATE)->name('update-registration-date.index'); Route::post('/atualiza-data-entrada', 'UpdateRegistrationDateController@updateStatus')->middleware('can:modify:' . Process::UPDATE_REGISTRATION_DATE)->name('update-registration-date.update-date'); From bee0cc242d716768968752ab8c6342c06b0e8d08 Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Wed, 14 Aug 2024 14:38:59 -0300 Subject: [PATCH 06/45] =?UTF-8?q?Cria=20migration=20do=20menu=20de=20publi?= =?UTF-8?q?ca=C3=A7=C3=A3o=20de=20avisos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...8_12_223334_create_announcements_table.php | 12 --------- ..._223334_create_announcement_menu_table.php | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 database/migrations/data/2024_08_13_223334_create_announcement_menu_table.php diff --git a/database/migrations/2024_08_12_223334_create_announcements_table.php b/database/migrations/2024_08_12_223334_create_announcements_table.php index 71ddd77754..0b3eb84da7 100644 --- a/database/migrations/2024_08_12_223334_create_announcements_table.php +++ b/database/migrations/2024_08_12_223334_create_announcements_table.php @@ -1,7 +1,5 @@ updateOrCreate(['old' => Process::ANNOUNCEMENT], [ - 'parent_id' => Menu::query()->where('old', Process::CONFIGURATIONS_TOOLS)->firstOrFail()->getKey(), - 'process' => Process::ANNOUNCEMENT, - 'title' => 'Publicação de avisos', - 'order' => 0, - 'parent_old' => Process::CONFIGURATIONS_TOOLS, - 'link' => '/avisos/publicacao', - ]); } public function down(): void { - Menu::query()->where('old', Process::ANNOUNCEMENT)->delete(); Schema::dropIfExists('announcement_users'); Schema::dropIfExists('announcement_user_types'); Schema::dropIfExists('announcements'); diff --git a/database/migrations/data/2024_08_13_223334_create_announcement_menu_table.php b/database/migrations/data/2024_08_13_223334_create_announcement_menu_table.php new file mode 100644 index 0000000000..e7bbdb2fbb --- /dev/null +++ b/database/migrations/data/2024_08_13_223334_create_announcement_menu_table.php @@ -0,0 +1,25 @@ +updateOrCreate(['old' => Process::ANNOUNCEMENT], [ + 'parent_id' => Menu::query()->where('old', Process::CONFIGURATIONS_TOOLS)->firstOrFail()->getKey(), + 'process' => Process::ANNOUNCEMENT, + 'title' => 'Publicação de avisos', + 'order' => 0, + 'parent_old' => Process::CONFIGURATIONS_TOOLS, + 'link' => '/avisos/publicacao', + ]); + } + + public function down(): void + { + Menu::query()->where('old', Process::ANNOUNCEMENT)->delete(); + } +}; From 9c0867f8148b73f7659dc1ec34df97b383da9315 Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Mon, 19 Aug 2024 21:24:27 -0300 Subject: [PATCH 07/45] =?UTF-8?q?Incrementa=20vers=C3=A3o=20dos=20assets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/assets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/assets.php b/config/assets.php index ece8ec37b9..1946cf0f25 100644 --- a/config/assets.php +++ b/config/assets.php @@ -14,7 +14,7 @@ | */ - 'version' => '0.1.90', + 'version' => '0.1.91', /* |-------------------------------------------------------------------------- From 5aa2369c61610fbc51b8904bd145fcb6a06a8975 Mon Sep 17 00:00:00 2001 From: Edinei Valdameri Date: Wed, 21 Aug 2024 13:04:27 -0300 Subject: [PATCH 08/45] =?UTF-8?q?Incrementa=20vers=C3=A3o=20do=20assets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/assets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/assets.php b/config/assets.php index 1946cf0f25..d32f7d4fb4 100644 --- a/config/assets.php +++ b/config/assets.php @@ -14,7 +14,7 @@ | */ - 'version' => '0.1.91', + 'version' => '0.1.92', /* |-------------------------------------------------------------------------- From 662b419b95abb1cc7f187d00c954de81c926f195 Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Wed, 21 Aug 2024 17:29:11 -0300 Subject: [PATCH 09/45] =?UTF-8?q?Corrige=20escolas=20do=20usu=C3=A1rio=20l?= =?UTF-8?q?ogado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/AnnouncementUserController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/AnnouncementUserController.php b/app/Http/Controllers/AnnouncementUserController.php index 5482f9fede..35a13f1c83 100644 --- a/app/Http/Controllers/AnnouncementUserController.php +++ b/app/Http/Controllers/AnnouncementUserController.php @@ -41,7 +41,7 @@ public function show(Request $request) ->join('pmieducar.matricula', 'matricula.cod_matricula', 'ref_cod_matricula') ->join('pmieducar.serie', fn ($join) => $join->on('cod_serie', 'matricula.ref_ref_cod_serie')->where('matricula.ativo', 1)) ->join('pmieducar.curso', fn ($join) => $join->on('cod_curso', 'matricula.ref_cod_curso')->where('curso.ativo', 1)) - ->when(Auth::user()->isSchooling(), fn ($q) => $q->whereIn('cod_escola', Auth::user()->schools()->pluck('id'))) + ->when(Auth::user()->isSchooling(), fn ($q) => $q->whereIn('cod_escola', Auth::user()->schools()->pluck('ref_cod_escola'))) ->having('max_aluno', '>', DB::raw('COUNT(distinct matricula.cod_matricula)')) ->orderBy('escola') ->orderBy('curso') From e5c9ccaee376ce869111f0cba870acf0fca95c66 Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Thu, 22 Aug 2024 10:14:35 -0300 Subject: [PATCH 10/45] =?UTF-8?q?Atualiza=20query=20para=20contar=20soment?= =?UTF-8?q?e=20enturma=C3=A7=C3=B5es=20ativas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/AnnouncementUserController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/AnnouncementUserController.php b/app/Http/Controllers/AnnouncementUserController.php index 35a13f1c83..3c8991bec1 100644 --- a/app/Http/Controllers/AnnouncementUserController.php +++ b/app/Http/Controllers/AnnouncementUserController.php @@ -46,6 +46,7 @@ public function show(Request $request) ->orderBy('escola') ->orderBy('curso') ->orderBy('serie') + ->where('matricula_turma.ativo', 1) ->orderBy('nm_turma') ->groupBy('nm_turma', 'max_aluno', 'pessoa.nome') ->get() From ba95a9e767aa9b0d10c67af7bbf03679605e75c4 Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Thu, 22 Aug 2024 10:19:29 -0300 Subject: [PATCH 11/45] Corrige ordem das colunas na listagem --- resources/views/announcement/publish/index.blade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/announcement/publish/index.blade.php b/resources/views/announcement/publish/index.blade.php index 0ccb337ca5..8527c361de 100644 --- a/resources/views/announcement/publish/index.blade.php +++ b/resources/views/announcement/publish/index.blade.php @@ -28,16 +28,16 @@ {{ $announcement->userTypes->implode('nm_tipo', ', ') }} - {{ $announcement->trashed() ? 'Desativado' : 'Ativado' }} + {{ $announcement->created_at->format('d/m/Y H:i') }} - {{ $announcement->created_at->format('d/m/Y H:i') }} + {{ $announcement->trashed() ? 'Desativado' : 'Ativado' }} @else {{ $announcement->name }}/> {{ $announcement->userTypes->implode('nm_tipo', ', ') }} - {{ $announcement->trashed() ? 'Desativado' : 'Ativado' }} {{ $announcement->created_at->format('d/m/Y H:i') }} + {{ $announcement->trashed() ? 'Desativado' : 'Ativado' }} @endcan From 7ec8c96fd957ea9610955191d7650979932dc53e Mon Sep 17 00:00:00 2001 From: Edinei Valdameri Date: Tue, 27 Aug 2024 17:14:37 -0300 Subject: [PATCH 12/45] =?UTF-8?q?Evita=20apresenta=C3=A7=C3=A3o=20de=20err?= =?UTF-8?q?os=20de=20Valida=C3=A7=C3=A3o=20no=20Honey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Exceptions/Handler.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index a417bc568e..4244f893f8 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -7,6 +7,7 @@ use iEducar\Modules\ErrorTracking\Tracker; use iEducar\Support\Exceptions\DisciplinesWithoutInformedHoursException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Validation\ValidationException; use Throwable; class Handler extends ExceptionHandler @@ -19,6 +20,7 @@ class Handler extends ExceptionHandler protected $dontReport = [ App_Model_Exception::class, DisciplinesWithoutInformedHoursException::class, + ValidationException::class, ]; /** From d2969e121f7f4784b3e7cf6375b0bc722adfefcd Mon Sep 17 00:00:00 2001 From: Edinei Valdameri Date: Wed, 28 Aug 2024 09:04:55 -0300 Subject: [PATCH 13/45] =?UTF-8?q?Incrementa=20vers=C3=A3o=20dos=20assets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/assets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/assets.php b/config/assets.php index d32f7d4fb4..28007693d0 100644 --- a/config/assets.php +++ b/config/assets.php @@ -14,7 +14,7 @@ | */ - 'version' => '0.1.92', + 'version' => '0.1.93', /* |-------------------------------------------------------------------------- From d18976bfffbb67579e07b838de201878118f3c40 Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Wed, 28 Aug 2024 17:43:30 -0300 Subject: [PATCH 14/45] Altera forma de salvamento --- .../AnnouncementPublishController.php | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/AnnouncementPublishController.php b/app/Http/Controllers/AnnouncementPublishController.php index 0d8bbee723..f34e189d1f 100644 --- a/app/Http/Controllers/AnnouncementPublishController.php +++ b/app/Http/Controllers/AnnouncementPublishController.php @@ -5,6 +5,7 @@ use App\Http\Requests\AnnouncementRequest; use App\Models\Announcement; use App\Process; +use iEducar\Support\Exceptions\Exception; use Illuminate\Support\Facades\DB; class AnnouncementPublishController extends Controller @@ -30,38 +31,34 @@ public function index() public function update(AnnouncementRequest $request, $announcementId) { - $announcement = DB::transaction(function () use ($announcementId, $request) { + try { + DB::beginTransaction(); $announcement = Announcement::query()->withTrashed()->findOrFail($announcementId); $announcement->fill($request->all()); $announcement->save(); $announcement->userTypes()->sync($request->get('tipo_usuario')); $request->get('active') ? $announcement->restore() : $announcement->delete(); - - return $announcement; - }); - - if ($announcement) { + DB::commit(); session()->flash('success', 'Edição efetuada com sucesso.'); - } else { + } catch (Exception) { + DB::rollBack(); session()->flash('error', 'Edição não realizada.'); } - return redirect()->route('announcement.publish.edit', $announcement); + return redirect()->route('announcement.publish.edit', $announcementId); } public function store(AnnouncementRequest $request) { - $announcement = DB::transaction(function () use ($request) { + try { + DB::beginTransaction(); $announcement = Announcement::create($request->all()); $announcement->userTypes()->sync($request->get('tipo_usuario')); $request->get('active') ? $announcement->restore() : $announcement->delete(); - - return $announcement; - }); - - if ($announcement) { + DB::commit(); session()->flash('success', 'Cadastro efetuado com sucesso.'); - } else { + } catch (Exception) { + DB::rollBack(); session()->flash('error', 'Cadastro não realizado.'); } From 411a20d934b6609806fd60f77b2b3728427fa637 Mon Sep 17 00:00:00 2001 From: Robert Ferraz Date: Wed, 28 Aug 2024 20:46:20 -0300 Subject: [PATCH 15/45] =?UTF-8?q?Protege=20contra=20inje=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20c=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Announcement.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Models/Announcement.php b/app/Models/Announcement.php index b6412cd4bf..cfaa8434bf 100644 --- a/app/Models/Announcement.php +++ b/app/Models/Announcement.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -34,4 +35,13 @@ public function createdByUser(): BelongsTo { return $this->belongsTo(LegacyUser::class); } + + protected function description(): Attribute + { + return Attribute::make( + set: function (string $value) { + return strip_tags($value, '