feat(Handle Expired members script)
This commit is contained in:
@@ -33,6 +33,8 @@ class HandleExpiredMembersDolibarr extends Command
|
||||
|
||||
$expiredMembers = $members->filter(fn ($m) => $m['status'] === 'expired');
|
||||
|
||||
dd($expiredMembers);
|
||||
|
||||
$this->info("{$expiredMembers->count()} adhérent(s) expiré(s)");
|
||||
|
||||
foreach ($expiredMembers as $member) {
|
||||
@@ -54,7 +56,7 @@ class HandleExpiredMembersDolibarr extends Command
|
||||
{
|
||||
$email = $member['email'] ?? null;
|
||||
|
||||
$this->info("👤 {$member['id']} - {$email}");
|
||||
$this->info("{$member['id']} - {$email}");
|
||||
|
||||
// 1. Résiliation Dolibarr
|
||||
$this->dolibarr->setMemberStatus($member['id'], 'resilie');
|
||||
@@ -86,6 +88,7 @@ class HandleExpiredMembersDolibarr extends Command
|
||||
'disablepop3' => 'y',
|
||||
]);
|
||||
|
||||
$this->info("📧 Mail désactivé");
|
||||
$this->info("Mail désactivé");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Filament\Resources\Members\Schemas;
|
||||
|
||||
use App\Enums\IspconfigType;
|
||||
use App\Models\Member;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
@@ -12,6 +14,8 @@ use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Infolists\Components\RepeatableEntry;
|
||||
use Filament\Infolists\Components\Actions;
|
||||
|
||||
|
||||
class MemberForm
|
||||
@@ -91,7 +95,7 @@ class MemberForm
|
||||
->label(Member::getAttributeLabel('country')),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
// Mail Retzien
|
||||
Section::make('Messagerie ISPConfig Retzien')
|
||||
->schema([
|
||||
TextEntry::make('isp_mail_email')
|
||||
@@ -126,6 +130,23 @@ class MemberForm
|
||||
->visible(fn (?Member $record) =>
|
||||
$record?->ispconfigMail() !== null
|
||||
),
|
||||
|
||||
// Hébergement
|
||||
|
||||
Section::make('Hébergements Web')
|
||||
->schema([
|
||||
Placeholder::make('ispconfigs_web_display')
|
||||
->label('')
|
||||
->content(fn (?Member $record) => view('filament.components.ispconfig-web-list', [
|
||||
'ispconfigs' => $record?->ispconfigs()
|
||||
->where('type', IspconfigType::WEB)
|
||||
->get() ?? collect()
|
||||
]))
|
||||
])
|
||||
->visible(fn (?Member $record) =>
|
||||
$record?->ispconfigs()->where('type', IspconfigType::WEB)->exists()
|
||||
)
|
||||
// Fin Hébergement
|
||||
])
|
||||
->columnSpan(3),
|
||||
Grid::make(1)
|
||||
|
||||
@@ -136,7 +136,7 @@ class Member extends Model
|
||||
->first();
|
||||
}
|
||||
|
||||
public function ispconfigWeb(): ?IspconfigMember
|
||||
public function ispconfigsWeb(): ?IspconfigMember
|
||||
{
|
||||
return $this->ispconfigs()
|
||||
->where('type', IspconfigType::WEB)
|
||||
|
||||
@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Http;
|
||||
class DolibarrService
|
||||
{
|
||||
protected string $baseUrl;
|
||||
protected string $htaccessUrl;
|
||||
protected string $username;
|
||||
protected string $password;
|
||||
protected string $apiKey;
|
||||
@@ -16,6 +17,7 @@ class DolibarrService
|
||||
public function __construct()
|
||||
{
|
||||
$this->baseUrl = config('services.dolibarr.base_url');
|
||||
$this->htaccessUrl = config('services.dolibarr.htaccess_url');
|
||||
$this->username = config('services.dolibarr.username');
|
||||
$this->password = config('services.dolibarr.password');
|
||||
$this->apiKey = config('services.dolibarr.api_key');
|
||||
|
||||
@@ -2,25 +2,70 @@
|
||||
|
||||
namespace App\Services\Nextcloud;
|
||||
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NextcloudService
|
||||
{
|
||||
public function disableUserByEmail(string $email): bool
|
||||
{
|
||||
$username = $this->getUsernameFromEmail($email);
|
||||
protected PendingRequest $http;
|
||||
|
||||
return Http::withBasicAuth(
|
||||
config('services.nextcloud.username'),
|
||||
public function __construct()
|
||||
{
|
||||
$this->http = Http::withBasicAuth(
|
||||
config('services.nextcloud.user'),
|
||||
config('services.nextcloud.password')
|
||||
)->put(
|
||||
config('services.nextcloud.base_url') . "/ocs/v1.php/cloud/users/{$username}/disable",
|
||||
[]
|
||||
)->successful();
|
||||
)
|
||||
->withHeaders([
|
||||
'OCS-APIRequest' => 'true',
|
||||
'Accept' => 'application/json',
|
||||
])
|
||||
->baseUrl(config('services.nextcloud.url') . '/ocs/v1.php');
|
||||
}
|
||||
|
||||
protected function getUsernameFromEmail(string $email): string
|
||||
/**
|
||||
* Désactive un utilisateur Nextcloud à partir de son email
|
||||
*/
|
||||
public function disableUserByEmail(string $email): void
|
||||
{
|
||||
return strstr($email, '@', true);
|
||||
$userId = $this->findUserIdByEmail($email);
|
||||
|
||||
if (!$userId) {
|
||||
Log::warning("Utilisateur Nextcloud introuvable", ['email' => $email]);
|
||||
return;
|
||||
}
|
||||
|
||||
$response = $this->http->put("/cloud/users/{$userId}/disable");
|
||||
|
||||
if (!$response->successful()) {
|
||||
throw new \RuntimeException("Erreur désactivation Nextcloud {$userId}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trouve le userId Nextcloud à partir de l’email
|
||||
*/
|
||||
protected function findUserIdByEmail(string $email): ?string
|
||||
{
|
||||
$response = $this->http->get('/cloud/users');
|
||||
|
||||
if (!$response->successful()) {
|
||||
throw new \RuntimeException('Erreur récupération utilisateurs Nextcloud');
|
||||
}
|
||||
|
||||
$users = $response->json('ocs.data.users') ?? [];
|
||||
|
||||
foreach ($users as $userId) {
|
||||
$details = $this->http->get("/cloud/users/{$userId}");
|
||||
|
||||
if (
|
||||
$details->successful() &&
|
||||
($details->json('ocs.data.email') === $email)
|
||||
) {
|
||||
return $userId;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user