-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #776 from portabilis/portabilis-patch-2021-08-02
[2.6] Portabilis patch 02/08/2021
- Loading branch information
Showing
87 changed files
with
2,257 additions
and
1,424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Jobs\BatchDisableUsersWithDaysGoneSinceLastAccess; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Contracts\Bus\Dispatcher; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class DisableUsersWithAccessExpired extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'disable:users-with-access-expired'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Disable users with access expired'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle() | ||
{ | ||
$job = new BatchDisableUsersWithDaysGoneSinceLastAccess(DB::getDefaultConnection()); | ||
app(Dispatcher::class)->dispatch($job); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Services\DisableUsersWithDaysGoneSinceLastAccessService; | ||
use App\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Config\Repository; | ||
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class BatchDisableUsersWithDaysGoneSinceLastAccess implements ShouldQueue, ShouldBeUniqueUntilProcessing | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
private $databaseConnection; | ||
|
||
public function __construct($databaseConnection) | ||
{ | ||
$this->databaseConnection = $databaseConnection; | ||
} | ||
|
||
public function handle(Repository $config) | ||
{ | ||
DB::setDefaultConnection($this->databaseConnection); | ||
$expirationPeriod = $config->get('legacy.app.user_accounts.max_days_without_login_to_disable_user'); | ||
|
||
if (empty($expirationPeriod) === false) { | ||
$this->disableUsersWithDaysGoneSinceLastAccess($expirationPeriod); | ||
} | ||
} | ||
|
||
private function disableUsersWithDaysGoneSinceLastAccess($expirationPeriod): void | ||
{ | ||
$users = (new User())->getActiveUsersNotAdmin(); | ||
|
||
foreach ($users as $user) { | ||
$disableUsersWithDaysGoneSinceLastAccessService = app(DisableUsersWithDaysGoneSinceLastAccessService::class); | ||
$disableUsersWithDaysGoneSinceLastAccessService->execute($user); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class LegacyAccess extends Model | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $table = 'portal.acesso'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $primaryKey = 'cod_acesso'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $timestamps = false; | ||
|
||
protected $dates = ['data_hora']; | ||
|
||
public function getLastAccess() | ||
{ | ||
return $this->query() | ||
->orderBy('data_hora', 'DESC') | ||
->first(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use App\Models\LegacyEmployee; | ||
use Carbon\Carbon; | ||
use Illuminate\Contracts\Hashing\Hasher; | ||
|
||
class ChangeUserPasswordService | ||
{ | ||
private $validateUserPasswordService; | ||
private $hash; | ||
private $carbon; | ||
|
||
public function __construct(ValidateUserPasswordService $validateUserPasswordService, Hasher $hash, Carbon $carbon) | ||
{ | ||
$this->validateUserPasswordService = $validateUserPasswordService; | ||
$this->hash = $hash; | ||
$this->carbon = $carbon; | ||
} | ||
|
||
public function execute(LegacyEmployee $legacyEmployee, string $password) | ||
{ | ||
$this->validate($password, $legacyEmployee->getPasswordAttribute()); | ||
$legacyEmployee->setPasswordAttribute($this->hash->make($password)); | ||
$legacyEmployee->force_reset_password = false; | ||
$legacyEmployee->data_troca_senha = $this->carbon->nowWithSameTz(); | ||
$legacyEmployee->save(); | ||
} | ||
|
||
public function validate(string $newPassword, string $oldPassword) | ||
{ | ||
$this->validateUserPasswordService->execute($newPassword, $oldPassword); | ||
} | ||
} |
Oops, something went wrong.