Skip to content

Commit

Permalink
Merge pull request #712 from portabilis/portabilis-patch-2020-06-19
Browse files Browse the repository at this point in the history
[2.3] Portabilis patch 19/06/2020
  • Loading branch information
gustavomendess authored Jun 22, 2020
2 parents 1480725 + 34c7b48 commit 31e769a
Show file tree
Hide file tree
Showing 22 changed files with 360 additions and 119 deletions.
18 changes: 18 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Rules\ReCaptchaV3;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;

Expand Down Expand Up @@ -51,4 +52,21 @@ public function username()
{
return 'login';
}

/**
* Validate the user login request.
*
* @param Request $request
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
public function validateLogin(Request $request)
{
$request->validate([
$this->username() => 'required|string',
'password' => 'required|string',
'grecaptcha' => [new ReCaptchaV3],
]);
}
}
69 changes: 44 additions & 25 deletions app/Http/Controllers/UpdateRegistrationDateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,39 @@ public function updateStatus(UpdateRegistrationDateRequest $request, Registratio
{
$query = LegacyRegistration::active();

$registrations = $this->addFilters($request, $query);

if (count($registrations) == 0) {
return redirect()->route('update-registration-date.index')->with('error', 'Nenhuma matrícula encontrada com os filtros selecionados');
}

if (empty($request->get('confirmation'))) {
return redirect()->route('update-registration-date.index')->withInput()->with('show-confirmation', ['count' => count($registrations)]);
}

DB::beginTransaction();

$newDateRegistration = \DateTime::createFromFormat('d/m/Y', $request->get('nova_data_entrada'));
$newDateEnrollment = \DateTime::createFromFormat('d/m/Y', $request->get('nova_data_enturmacao'));

$result = [];
foreach ($registrations as $registration) {
$result[] = $registrationService->updateRegistrationDate($registration, $newDateRegistration);

if ($newDateEnrollment) {
$registrationService->updateEnrollmentsDate($registration, $newDateEnrollment, !empty($request->get('remanejadas')));
}
}

DB::commit();

return redirect()->route('update-registration-date.index')
->with('success', count($registrations) . ' matrículas atualizadas com sucesso.')
->with('registrations', $result);
}

private function addFilters(UpdateRegistrationDateRequest $request, $query)
{
if ($request->get('ano')) {
$query->where('ano', $request->get('ano'));
}
Expand All @@ -61,36 +94,22 @@ public function updateStatus(UpdateRegistrationDateRequest $request, Registratio
$query->where('ref_ref_cod_serie', $request->get('ref_cod_serie'));
}

$oldData = $request->get('data_antiga') ? \DateTime::createFromFormat('d/m/Y', $request->get('data_antiga')) : null;
if ($request->get('data_antiga')) {
$query->where('data_matricula', $oldData->format('Y-m-d'));
$oldDataRegistration = $request->get('data_entrada_antiga') ? \DateTime::createFromFormat('d/m/Y', $request->get('data_entrada_antiga')) : null;
if ($request->get('data_entrada_antiga')) {
$query->where('data_matricula', $oldDataRegistration->format('Y-m-d'));
}

if ($request->get('situacao')) {
$query->where('aprovado', $request->get('situacao'));
}

$registrations = $query->get();

if (count($registrations) == 0) {
return redirect()->route('update-registration-date.index')->with('error', 'Nenhuma matrícula encontrada com os filtros selecionados');
}

if (empty($request->get('confirmation'))) {
return redirect()->route('update-registration-date.index')->withInput()->with('show-confirmation', ['count' => count($registrations)]);
if ($request->get('data_enturmacao_antiga')) {
$oldDataEnrollment = \DateTime::createFromFormat('d/m/Y', $request->get('data_enturmacao_antiga'));
$query->whereHas('lastEnrollment', function ($enrollmentQuery) use ($oldDataEnrollment) {
$enrollmentQuery->where('data_enturmacao', $oldDataEnrollment);
});
}

DB::beginTransaction();

$newDate = \DateTime::createFromFormat('d/m/Y', $request->get('nova_data'));

foreach ($registrations as $registration) {
$registrationService->updateRegistrationDate($registration, $newDate);
$registrationService->updateEnrollmentsDate($registration, $newDate, $oldData, !empty($request->get('remanejadas')));
if ($request->get('situacao')) {
$query->where('aprovado', $request->get('situacao'));
}

DB::commit();

return redirect()->route('update-registration-date.index')->with('success', count($registrations) . ' matrículas atualizadas com sucesso.');
return $query->get();
}
}
6 changes: 3 additions & 3 deletions app/Http/Requests/UpdateRegistrationDateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function rules()
'date_format:Y',
],
'ref_cod_instituicao' => 'required',
'nova_data' => 'required|date_format:d/m/Y',
'nova_data_entrada' => 'required|date_format:d/m/Y',
];
}

Expand All @@ -33,8 +33,8 @@ public function messages()
'ano.required' => 'O ano é obrigatório.',
'ano.date_format' => 'O campo Ano deve ser um ano válido.',
'ref_cod_instituicao.required' => 'A instituição é obrigatória.',
'nova_data.required' => 'A nova data é obrigatória.',
'nova_data.date_format' => 'A nova data é inválida.',
'nova_data_entrada.required' => 'A nova data é obrigatória.',
'nova_data_entrada.date_format' => 'A nova data é inválida.',
];
}
}
15 changes: 15 additions & 0 deletions app/Models/LegacyOrganization.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class LegacyOrganization extends Model
{
Expand Down Expand Up @@ -39,4 +40,18 @@ class LegacyOrganization extends Model
* @var bool
*/
public $timestamps = false;

/**
* @inheritDoc
*/
protected static function boot()
{
parent::boot();

static::creating(function ($model) {
if (config('legacy.app.uppercase_names')) {
$model->fantasia = Str::upper($model->fantasia);
}
});
}
}
4 changes: 4 additions & 0 deletions app/Models/LegacyPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ protected static function boot()
$model->origem_gravacao = 'M';
$model->operacao = 'I';
$model->slug = Str::lower(Str::slug($model->nome, ' '));

if (config('legacy.app.uppercase_names')) {
$model->nome = Str::upper($model->nome);
}
});
}

Expand Down
72 changes: 72 additions & 0 deletions app/Rules/ReCaptchaV3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\Rules;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use Illuminate\Contracts\Validation\Rule;
use Throwable;

class ReCaptchaV3 implements Rule
{
/**
* Create a new rule instance.
*
* @return boolean
*/
public function passes($attribute, $value)
{
if (!$this->checkConfig()) {
return true;
}

$client = new Client();

try {
$response = $client->post('https://www.google.com/recaptcha/api/siteverify', [
'query' => [
'secret' => config('legacy.app.recaptcha_v3.private_key'),
'response' => $value,
'remoteip' => request()->ip(),
],
]);

return $this->getScore($response) >= config('legacy.app.recaptcha_v3.minimum_score');
} catch (BadResponseException $e) {
return false;
} catch (Throwable $e) {
return true;
}
}

/**
* Retorna o score do recaptcha
*
* @param $response
* @return float
*/
private function getScore($response)
{
return json_decode($response->getBody()->getContents(), true)['score'];
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'A verificação do reCAPTCHA falhou';
}

/**
* Verifica se as configurações do recaptcha estão presentes
*
* @return bool
*/
private function checkConfig()
{
return config('legacy.app.recaptcha_v3.public_key') && config('legacy.app.recaptcha_v3.private_key');
}
}
3 changes: 2 additions & 1 deletion app/Services/EnrollmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ private function getSequenceSchoolClass(
*/
private function getAvailableTimeService()
{
return new AvailableTimeService();
$availableTimeService = new AvailableTimeService();
return $availableTimeService->onlySchoolClassesInformedOnCensus();
}

/**
Expand Down
33 changes: 15 additions & 18 deletions app/Services/RegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,38 +195,35 @@ public function updateRegistrationDate(LegacyRegistration $registration, DateTim

$registration->data_matricula = $date;
$registration->save();

return $registration;
}

/**
* Atualiza a date de enturmação de todas as enturmações de uma matrícula
*
* @param LegacyRegistration $registration
* @param DateTime $date
* @param DateTime|null $oldData
* @param boolean $relocated
*/
public function updateEnrollmentsDate(LegacyRegistration $registration, DateTime $date, $oldData, $relocated)
public function updateEnrollmentsDate(LegacyRegistration $registration, DateTime $date, $relocated)
{
$date = $date->format('Y-m-d');

foreach ($registration->enrollments as $enrollment) {
if ($oldData && $enrollment->data_enturmacao->format('Y-m-d') != $oldData->format('Y-m-d')) {
continue;
}
$enrollment = $registration->lastEnrollment;

if (!$relocated && $enrollment->remanejado) {
continue;
}
if (!$relocated && $enrollment->remanejado) {
return;
}

$auditoria = new clsModulesAuditoriaGeral('update_enrollment_date', $enrollment->getKey());
$auditoria->usuario_id = $this->user->getKey();
$auditoria->alteracao(
['data_enturmacao' => $enrollment->data_enturmacao],
['data_enturmacao' => $date]
);
$auditoria = new clsModulesAuditoriaGeral('update_enrollment_date', $enrollment->getKey());
$auditoria->usuario_id = $this->user->getKey();
$auditoria->alteracao(
['data_enturmacao' => $enrollment->data_enturmacao],
['data_enturmacao' => $date]
);

$enrollment->data_enturmacao = $date;
$enrollment->save();
}
$enrollment->data_enturmacao = $date;
$enrollment->save();
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Software livre de gestão escolar",
"type": "project",
"license": "GPL-2.0-or-later",
"version": "2.3.2",
"version": "2.3.3",
"keywords": [
"Portabilis",
"i-Educar"
Expand Down
Loading

0 comments on commit 31e769a

Please sign in to comment.