change user class migrate to admin

This commit is contained in:
xiaomlove
2023-01-07 19:34:59 +08:00
parent 02058237f1
commit 2cef77a7f2
11 changed files with 122 additions and 20 deletions

View File

@@ -67,6 +67,9 @@ class UserProfile extends ViewRecord
$actions[] = $this->buildResetPasswordAction();
$actions[] = $this->buildEnableDisableAction();
$actions[] = $this->buildEnableDisableDownloadPrivilegesAction();
if (user_can('user-change-class')) {
$actions[] = $this->buildChangeClassAction();
}
if (user_can('user-delete')) {
$actions[] = $this->buildDeleteAction();
}
@@ -355,4 +358,32 @@ class UserProfile extends ViewRecord
->where('expired_at', '>', Carbon::now())
->count();
}
private function buildChangeClassAction(): Actions\Action
{
return Actions\Action::make('change_class')
->label(__('admin.resources.user.actions.change_class_btn'))
->form([
Forms\Components\Select::make('class')
->options(User::listClass())
->default($this->record->class)
->label(__('user.labels.class'))
->required()
,
Forms\Components\TextInput::make('reason')
->label(__('admin.resources.user.actions.enable_disable_reason'))
->placeholder(__('admin.resources.user.actions.enable_disable_reason_placeholder'))
,
])
->action(function ($data) {
$userRep = $this->getRep();
try {
$userRep->changeClass(Auth::user(), $this->record, $data['class'], $data['reason']);
$this->notify('success', 'Success!');
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
} catch (\Exception $exception) {
$this->notify('danger', $exception->getMessage());
}
});
}
}