feat(Nextcloud sync & optimize)
All checks were successful
Deploy Roxane to Preprod / deploy (push) Successful in 1m18s

This commit is contained in:
2026-01-30 15:27:23 +01:00
parent b8de637b23
commit 9649d99e15
11 changed files with 307 additions and 245 deletions

View File

@@ -2,8 +2,10 @@
namespace App\Console\Commands;
use App\Models\Member;
use App\Services\Dolibarr\DolibarrService;
use App\Services\ISPConfig\ISPConfigMailService;
use App\Services\MemberService;
use App\Services\Nextcloud\NextcloudService;
use Illuminate\Console\Command;
use Illuminate\Http\Client\ConnectionException;
@@ -19,7 +21,8 @@ class HandleExpiredMembersDolibarr extends Command
public function __construct(
protected DolibarrService $dolibarr,
protected ISPConfigMailService $mailService,
protected NextcloudService $nextcloud
protected NextcloudService $nextcloud,
protected MemberService $memberService
)
{
parent::__construct();
@@ -112,6 +115,12 @@ class HandleExpiredMembersDolibarr extends Command
]);
}
// Résilitation Roxane
$roxaneMember = Member::query()->findOrFail($member['id']);
if ($roxaneMember) {
$this->memberService->deactivateMember($roxaneMember);
}
// Désactivation mail
if ($email) {
$this->disableMailAccount($email, $dryRun);

View File

@@ -9,6 +9,7 @@ use Illuminate\Console\Command;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Log;
use Symfony\Component\Console\Command\Command as CommandAlias;
use function Laravel\Prompts\progress;
class SyncNextcloudMembers extends Command
{
@@ -38,7 +39,6 @@ class SyncNextcloudMembers extends Command
: 'Synchronisation Nextcloud → Members'
);
/** index des membres par email */
$members = Member::query()
->where('email', 'like', '%@retzien.fr%')
->when($memberFilter, fn ($q) => $q->where('id', $memberFilter))
@@ -46,19 +46,27 @@ class SyncNextcloudMembers extends Command
->filter(fn (Member $m) => !empty($m->retzien_email))
->keyBy(fn (Member $m) => strtolower($m->retzien_email));
if ($members->isEmpty()) {
$this->warn('Aucun membre à synchroniser');
return CommandAlias::SUCCESS;
}
$this->info("{$members->count()} membres candidats");
$this->info("{$members->count()} membres à synchroniser");
/**Récupération des users Nextcloud */
$userIds = $this->nextcloud->listUsers();
$this->info(count($userIds) . ' comptes Nextcloud trouvés');
$progress = null;
if (!$dryRun) {
$progress = progress(
label: 'Synchronisation des membres',
steps: $members->count()
);
$progress->start();
}
$synced = 0;
foreach ($userIds as $userId) {
@@ -73,19 +81,6 @@ class SyncNextcloudMembers extends Command
$member = $members[$email];
$payload = [
'member_id' => $member->id,
'nextcloud_user_id' => $userId,
'data' => [
'email' => $email,
'quota' => $details['quota'] ?? null,
'groups' => $details['groups'] ?? [],
'enabled' => !($details['enabled'] === false),
'last_login' => $details['lastLogin'] ?? null,
'raw' => $details, // utile pour debug
],
];
if ($dryRun) {
$this->line("[DRY-RUN] {$member->id}{$userId}");
} else {
@@ -94,12 +89,15 @@ class SyncNextcloudMembers extends Command
'member_id' => $member->id,
'nextcloud_user_id' => $userId,
],
$payload
[
'data' => json_encode($details, JSON_THROW_ON_ERROR),
]
);
$progress->advance();
}
$synced++;
} catch (\Throwable $e) {
Log::error('Erreur sync Nextcloud', [
'user_id' => $userId,
@@ -108,6 +106,11 @@ class SyncNextcloudMembers extends Command
}
}
if ($progress) {
$progress->finish();
$this->newLine();
}
$this->info("Synchronisation terminée ({$synced} comptes liés)");
return CommandAlias::SUCCESS;

View File

@@ -6,17 +6,16 @@ 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\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
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;
use Filament\Infolists\Components\TextEntry;
class MemberForm
{
@@ -26,132 +25,180 @@ class MemberForm
->components([
Grid::make()
->schema([
/*
|--------------------------------------------------------------------------
| Colonne principale
|--------------------------------------------------------------------------
*/
Grid::make(1)
->schema([
Section::make('Informations personnelles')
->schema([
TextInput::make('lastname')
->label(Member::getAttributeLabel('lastname'))
->required(),
Tabs::make('MemberTabs')
->tabs([
/*
|--------------------------------------------------------------------------
| TAB : Informations générales
|--------------------------------------------------------------------------
*/
Tabs\Tab::make('Informations générales')
->schema([
Section::make('Informations personnelles')
->collapsible()
->schema([
TextInput::make('lastname')
->label(Member::getAttributeLabel('lastname'))
->required(),
TextInput::make('firstname')
->label(Member::getAttributeLabel('firstname'))
->required(),
TextInput::make('firstname')
->label(Member::getAttributeLabel('firstname'))
->required(),
DatePicker::make('date_of_birth')
->label(Member::getAttributeLabel('date_of_birth')),
DatePicker::make('date_of_birth')
->label(Member::getAttributeLabel('date_of_birth')),
TextInput::make('company')
->label(Member::getAttributeLabel('company')),
])
->columns(2),
TextInput::make('company')
->label(Member::getAttributeLabel('company')),
])
->columns(2),
Section::make('Informations administratives')
->schema([
TextInput::make('keycloak_id')
->label(Member::getAttributeLabel('keycloak_id')),
Section::make('Informations administratives')
->collapsible()
->schema([
TextInput::make('keycloak_id')
->label(Member::getAttributeLabel('keycloak_id')),
Select::make('nature')
->label(Member::getAttributeLabel('nature'))
->options([
'physical' => Member::getAttributeLabel('physical'),
'legal' => Member::getAttributeLabel('legal'),
])
->default('physical')
->required(),
Select::make('nature')
->label(Member::getAttributeLabel('nature'))
->options([
'physical' => Member::getAttributeLabel('physical'),
'legal' => Member::getAttributeLabel('legal'),
])
->default('physical')
->required(),
Select::make('group_id')
->label(Member::getAttributeLabel('group_id'))
->relationship('group', 'name')
->default(null),
])
->columns(2),
Select::make('group_id')
->label(Member::getAttributeLabel('group_id'))
->relationship('group', 'name')
->default(null),
])
->columns(2),
Section::make('Coordonnées')
->schema([
TextInput::make('email')
->label(Member::getAttributeLabel('email'))
->email()
->required(),
Section::make('Coordonnées')
->collapsible()
->schema([
TextInput::make('email')
->label(Member::getAttributeLabel('email'))
->email()
->required(),
TextInput::make('phone1')
->label(Member::getAttributeLabel('phone1'))
->tel(),
TextInput::make('phone1')
->label(Member::getAttributeLabel('phone1'))
->tel(),
TextInput::make('phone2')
->label(Member::getAttributeLabel('phone2'))
->tel(),
TextInput::make('phone2')
->label(Member::getAttributeLabel('phone2'))
->tel(),
TextInput::make('address')
->label(Member::getAttributeLabel('address')),
TextInput::make('address')
->label(Member::getAttributeLabel('address')),
TextInput::make('zipcode')
->label(Member::getAttributeLabel('zipcode')),
TextInput::make('zipcode')
->label(Member::getAttributeLabel('zipcode')),
TextInput::make('city')
->label(Member::getAttributeLabel('city')),
TextInput::make('city')
->label(Member::getAttributeLabel('city')),
TextInput::make('country')
->label(Member::getAttributeLabel('country')),
])
->columns(2),
// Mail Retzien
Section::make('Messagerie ISPConfig Retzien')
->schema([
TextEntry::make('isp_mail_email')
->label('Adresse email')
->state(fn (?Member $record) =>
$record?->ispconfigMail()?->email ?? '—'
),
TextInput::make('country')
->label(Member::getAttributeLabel('country')),
])
->columns(2),
]),
TextEntry::make('isp_mail_user_id')
->label('ID utilisateur ISPConfig (mailuser_id)')
->state(fn (?Member $record) =>
$record?->ispconfigMail()?->ispconfig_service_user_id ?? '—'
),
/*
|--------------------------------------------------------------------------
| TAB : Services/Modules
|--------------------------------------------------------------------------
*/
Tabs\Tab::make('Modules')
->schema([
/*
| Messageries ISPConfig (lecture seule)
*/
Section::make('Messagerie ISPConfig')
->collapsible()
->schema([
RepeatableEntry::make('ispconfig_mails')
->label('')
->state(fn(?Member $record) => $record?->ispconfigs()
->where('type', IspconfigType::MAIL)
->get()
)
->schema([
TextEntry::make('email')
->label('Adresse email'),
TextEntry::make('isp_mail_quota')
->label('Quota')
->state(function (?Member $record) {
$quota = $record?->ispconfigMail()?->data['mailuser']['quota'] ?? null;
TextEntry::make('ispconfig_service_user_id')
->label('ID ISPConfig'),
return $quota
? "{$quota} Mo"
: 'Non défini';
}),
TextEntry::make('data.mailuser.quota')
->label('Quota')
->formatStateUsing(fn($state) => $state ? "{$state} Mo" : 'Non défini'
),
TextEntry::make('isp_mail_domain')
->label('Domaine')
->state(fn (?Member $record) =>
$record?->ispconfigMail()?->data['mailuser']['domain'] ?? 'retzien.fr'
),
])
->columns(2)
->visible(fn (?Member $record) =>
$record?->ispconfigMail() !== null
),
TextEntry::make('data.mailuser.domain')
->label('Domaine')
->default('retzien.fr'),
])
->columns(2),
])
->visible(fn(?Member $record) => $record?->ispconfigs()
->where('type', IspconfigType::MAIL)
->exists()
),
// Hébergement
/*
| Hébergements web ISPConfig
*/
Section::make('Hébergements Web')
->collapsible()
->schema([
RepeatableEntry::make('ispconfigs_web')
->label('')
->state(fn(?Member $record) => $record?->ispconfigs()
->where('type', IspconfigType::WEB)
->get()
)
->schema([
TextEntry::make('data.web_domain.domain')
->label('Domaine'),
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()
TextEntry::make('data.web_domain.ip_address')
->label('Adresse IP'),
TextEntry::make('data.web_domain.disk_quota')
->label('Quota disque')
->formatStateUsing(fn($state) => $state ? "{$state} Mo" : '—'
),
])
->columns(3),
])
->visible(fn(?Member $record) => $record?->ispconfigs()
->where('type', IspconfigType::WEB)
->get() ?? collect()
]))
])
->visible(fn (?Member $record) =>
$record?->ispconfigs()->where('type', IspconfigType::WEB)->exists()
)
// Fin Hébergement
->exists()
),
]),
]),
])
->columnSpan(3),
/*
|--------------------------------------------------------------------------
| Colonne latérale
|--------------------------------------------------------------------------
*/
Grid::make(1)
->schema([
Section::make('Statut')
->collapsible()
->schema([
Select::make('status')
->label(Member::getAttributeLabel('status'))
@@ -169,27 +216,26 @@ class MemberForm
->label(Member::getAttributeLabel('public_membership'))
->required(),
])
->columns(1)
->extraAttributes(['class' => 'sticky top-4 h-fit']),
Section::make('Actions')
->collapsible()
->schema([
Action::make('send-payment-mail')
->icon('heroicon-o-envelope')
->label('Envoyer le mail de paiement')
->action(function(){
$this->data['status'] = 'draft';
$this->create();
}),
Action::make('send-renewal-mail')
->icon('heroicon-o-envelope')
->action(function () {
// Mail de paiement pour nouvelle inscription (Job)
}),
Action::make('send-renewal-mail')
->label('Envoyer un mail de relance')
->action(function(){
$this->data['status'] = 'draft';
$this->create();
})
->icon('heroicon-o-envelope')
->action(function () {
// Mail de relance à créer (Job)
}),
])
->columns(1)
->extraAttributes(['class' => 'sticky top-4 h-fit'])
->extraAttributes(['class' => 'sticky top-4 h-fit']),
])
->columnSpan(1),
])

View File

@@ -6,6 +6,31 @@ use App\Enums\IspconfigType;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property int $id
* @property int $member_id
* @property string|null $ispconfig_client_id
* @property string|null $ispconfig_service_user_id
* @property string|null $email
* @property IspconfigType $type
* @property array<array-key, mixed>|null $data
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Member $member
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember whereData($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember whereIspconfigClientId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember whereIspconfigServiceUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember whereMemberId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|IspconfigMember whereUpdatedAt($value)
* @mixin \Eloquent
*/
class IspconfigMember extends Model
{
protected $table = 'ispconfigs_members';

View File

@@ -21,7 +21,7 @@ use Illuminate\Notifications\Notifiable;
* @property string|null $lastname
* @property string|null $firstname
* @property string $email
* @property string|null $retzien_email
* @property string $retzien_email
* @property string|null $company
* @property string|null $date_of_birth
* @property string|null $address
@@ -37,8 +37,12 @@ use Illuminate\Notifications\Notifiable;
* @property string|null $deleted_at
* @property-read string $full_name
* @property-read \App\Models\MemberGroup|null $group
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\IspconfigMember> $ispconfigs
* @property-read int|null $ispconfigs_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Membership> $memberships
* @property-read int|null $memberships_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\NextCloudMember> $nextcloudAccounts
* @property-read int|null $nextcloud_accounts_count
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
* @property-read int|null $notifications_count
* @property-read \App\Models\User|null $user

View File

@@ -2,10 +2,29 @@
namespace App\Models;
use App\Enums\IspconfigType;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property int $id
* @property int $member_id
* @property string|null $nextcloud_user_id
* @property array<array-key, mixed>|null $data
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Member $member
* @method static \Illuminate\Database\Eloquent\Builder<static>|NextCloudMember newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|NextCloudMember newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|NextCloudMember query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|NextCloudMember whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|NextCloudMember whereData($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|NextCloudMember whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|NextCloudMember whereMemberId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|NextCloudMember whereNextcloudUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|NextCloudMember whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|NextCloudMember whereUsername($value)
* @mixin \Eloquent
*/
class NextCloudMember extends Model
{
protected $table = 'nextclouds_members';

View File

@@ -9,6 +9,11 @@ use App\Models\Package;
class MemberService
{
/**
* Register a new member.
* @param array $data
* @return Member
*/
public function registerNewMember(array $data): Member
{
// Check if the member already exists
@@ -52,4 +57,15 @@ class MemberService
return $member;
}
/**
* Disable a member and his subscriptions
*/
public function deactivateMember(Member $member): void
{
// todo: send email to member + admin
$member->update(['status' => 'excluded']);
$member->memberships()->update(['status' => 'expired']);
}
}

View File

@@ -26,7 +26,7 @@ class NextcloudService
}
/**
* Désactive un utilisateur Nextcloud à partir de son email
* Disable user by email
* @throws ConnectionException
*/
public function disableUserByEmail(string $email): void
@@ -46,7 +46,16 @@ class NextcloudService
}
/**
* Trouve le userId Nextcloud à partir de lemail
* Desable user by id
* @throws ConnectionException
*/
public function disableUserById(string $userId): void
{
$response = $this->http->put("/cloud/users/{$userId}/disable");
}
/**
* Find user id by email
*/
protected function findUserIdByEmail(string $email): ?string
{