updade and fix service and request for create user
This commit is contained in:
@@ -93,4 +93,8 @@ HARIM_NEED_GUARANTEE_LETTER_USERNAME=
|
||||
|
||||
BACKUP_TARGET_DIR=
|
||||
BACKUP_USER=
|
||||
BACKUP_PASSWORD=
|
||||
BACKUP_PASSWORD=
|
||||
|
||||
|
||||
HARIM_ENCRYPTION_KEY="TestKey"
|
||||
HARIM_ENCRYPTION_IV="1111000011110101"
|
||||
|
||||
@@ -22,7 +22,7 @@ class PanjareVahedController extends Controller
|
||||
public function receiveNewRequest(ReceiveNewRequest $request): JsonResponse
|
||||
{
|
||||
$iv = config('harim_web_services.Harim_Info.iv');
|
||||
$keyString = config('harim_web_services.Harim_Info.keyString');
|
||||
$keyString = config('harim_web_services.Harim_Info.key');
|
||||
|
||||
$key = hash('sha256',$keyString, true);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Throwable;
|
||||
|
||||
class UserManagementController extends Controller
|
||||
{
|
||||
@@ -38,7 +39,7 @@ class UserManagementController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function store(StoreRequest $request): jsonResponse
|
||||
public function limitStore(StoreRequest $request): jsonResponse
|
||||
{
|
||||
auth()->user()->addActivityComplete(1039);
|
||||
|
||||
@@ -53,17 +54,20 @@ class UserManagementController extends Controller
|
||||
'edarate_ostani_id' => $request->edarate_ostani_id,
|
||||
'edarate_ostani_name' => $request->edarate_ostani_id == null ?
|
||||
null :
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id),
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id)->name_fa,
|
||||
'edarate_shahri_id' => $request->edarate_shahri_id,
|
||||
'edarate_shahri_name' => $request->edarate_shahri_id == null ?
|
||||
null :
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id),
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id)->name_fa,
|
||||
]);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function storeExtra(StoreRequest $request): jsonResponse
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function fullStore(StoreRequest $request): jsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request) {
|
||||
auth()->user()->addActivityComplete(1039);
|
||||
@@ -79,11 +83,11 @@ class UserManagementController extends Controller
|
||||
'edarate_ostani_id' => $request->edarate_ostani_id,
|
||||
'edarate_ostani_name' => $request->edarate_ostani_id == null ?
|
||||
null :
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id),
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id)->name_fa,
|
||||
'edarate_shahri_id' => $request->edarate_shahri_id,
|
||||
'edarate_shahri_name' => $request->edarate_shahri_id == null ?
|
||||
null :
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id),
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id)->name_fa,
|
||||
'first_name' => $request->first_name,
|
||||
'last_name' => $request->last_name,
|
||||
'position' => $request->position,
|
||||
@@ -91,6 +95,7 @@ class UserManagementController extends Controller
|
||||
'degree' => $request->degree,
|
||||
'major' => $request->major,
|
||||
]);
|
||||
|
||||
$user->avatar = $request->has('avatar') ?
|
||||
FileFacade::save($request->avatar, "user/{$user->id}") :
|
||||
null;
|
||||
@@ -101,11 +106,22 @@ class UserManagementController extends Controller
|
||||
|
||||
public function show(User $user): JsonResponse
|
||||
{
|
||||
return $this->successResponse($user->with(['roles', 'permissions'])->get());
|
||||
return $this->successResponse($user);
|
||||
}
|
||||
|
||||
public function userPermissions(User $user): JsonResponse
|
||||
{
|
||||
$role = $user->roles()->pluck('name')->first();
|
||||
$permissions = $user->getAllPermissions()->pluck('name');
|
||||
|
||||
return $this->successResponse([
|
||||
'role' => $role,
|
||||
'permissions' => $permissions,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Throwable
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function update(UpdateRequest $request, User $user): JsonResponse
|
||||
{
|
||||
@@ -122,11 +138,11 @@ class UserManagementController extends Controller
|
||||
'edarate_ostani_id' => $request->edarate_ostani_id,
|
||||
'edarate_ostani_name' => $request->edarate_ostani_id == null ?
|
||||
null :
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id),
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id)->name_fa,
|
||||
'edarate_shahri_id' => $request->edarate_shahri_id,
|
||||
'edarate_shahri_name' => $request->edarate_shahri_id == null ?
|
||||
null :
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id),
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id)->name_fa,
|
||||
'first_name' => $request->first_name,
|
||||
'last_name' => $request->last_name,
|
||||
'position' => $request->position,
|
||||
@@ -139,7 +155,7 @@ class UserManagementController extends Controller
|
||||
if ($user->avatar) {
|
||||
FileFacade::delete($user->avatar, true);
|
||||
}
|
||||
$data['avatar'] = FileFacade::save($request->file('avatar'), "avatar/{$user->id}/");
|
||||
$data['avatar'] = FileFacade::save($request->file('avatar'), "avatars/{$user->id}/");
|
||||
}
|
||||
|
||||
$user->update($data);
|
||||
@@ -148,15 +164,15 @@ class UserManagementController extends Controller
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function destroy(User $user): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($user) {
|
||||
if ($user->avatar) {
|
||||
FileFacade::delete($user->avatar, true);
|
||||
}
|
||||
if ($user->photo) {
|
||||
FileFacade::delete($user->photo, true);
|
||||
}
|
||||
|
||||
$user->roles()->detach();
|
||||
$user->permissions()->detach();
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Requests\V3\Dashboard\UserManagement;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreExrtraRequest extends FormRequest
|
||||
{
|
||||
@@ -23,17 +24,29 @@ class StoreExrtraRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'edarate_ostani_id' => 'nullable|exists:edarate_ostanis,id|required_without:edarate_shahri_id',
|
||||
'edarate_shahri_id' => 'nullable|exists:edarate_shahris,id|required_without:edarate_ostani_id',
|
||||
'edarate_ostani_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_ostani', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_shahri_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_shahri_id'))),
|
||||
],
|
||||
'edarate_shahri_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_shahri', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_ostani_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_ostani_id'))),
|
||||
],
|
||||
'province_id' => 'required|exists:provinces,id',
|
||||
'city_id' => 'exists:cities,id',
|
||||
'username' => 'required|unique:users,username',
|
||||
'national_code' => 'unique:users,national_code',
|
||||
'password' => 'required|string|confirmed|min:8',
|
||||
'national_code' => 'unique:users,national_code|digits:10',
|
||||
'password' => 'required|confirmed|min:8',
|
||||
'first_name' => 'required|string',
|
||||
'last_name' => 'required|string',
|
||||
'position' => 'string',
|
||||
'mobile' => 'required|string',
|
||||
'mobile' => 'required|regex:/^09\d{9}$/|numeric|digits:11',
|
||||
'degree' => 'string',
|
||||
'major' => 'string',
|
||||
'avatar' => 'required|file|mimes:pdf,jpg,jpeg,png',
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Requests\V3\Dashboard\UserManagement;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreRequest extends FormRequest
|
||||
{
|
||||
@@ -23,13 +24,25 @@ class StoreRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'edarate_ostani_id' => 'nullable|exists:edarate_ostanis,id|required_without:edarate_shahri_id',
|
||||
'edarate_shahri_id' => 'nullable|exists:edarate_shahris,id|required_without:edarate_ostani_id',
|
||||
'edarate_ostani_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_ostani', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_shahri_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_shahri_id'))),
|
||||
],
|
||||
'edarate_shahri_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_shahri', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_ostani_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_ostani_id'))),
|
||||
],
|
||||
'province_id' => 'required|exists:provinces,id',
|
||||
'city_id' => 'exists:cities,id',
|
||||
'username' => 'required|unique:users,username',
|
||||
'national_code' => 'unique:users,national_code',
|
||||
'password' => 'required|string|confirmed|min:8',
|
||||
'national_code' => 'unique:users,national_code|digits:10',
|
||||
'password' => 'required|confirmed|min:8',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,21 @@ class UpdateRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'province_id' => 'required|exists:provinces,id',
|
||||
'edarate_ostani_id' => 'nullable|exists:edarate_ostanis,id|required_without:edarate_shahri_id',
|
||||
'edarate_shahri_id' => 'nullable|exists:edarate_shahris,id|required_without:edarate_ostani_id', 'city_id' => 'exists:cities,id',
|
||||
'edarate_ostani_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_ostani', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_shahri_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_shahri_id'))),
|
||||
],
|
||||
'edarate_shahri_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_shahri', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_ostani_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_ostani_id'))),
|
||||
],
|
||||
'city_id' => 'exists:cities,id',
|
||||
'username' => [Rule::unique('users', 'username')->ignore($this->user->id)],
|
||||
'national_code' => ['required', Rule::unique('users', 'national_code')->ignore($this->user->id)],
|
||||
'first_name' => 'required|string',
|
||||
|
||||
@@ -21,7 +21,7 @@ class UserManagementService
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
allowedSelects: ['id', 'username', 'status', 'province_id', 'province_fa', 'city_id', 'city_fa', 'first_name', 'last_name', 'mobile', 'position', 'major', 'setad_id', 'last_login', 'roles', 'edarate_shahri_id', 'edarate_shahri_name', 'national_code', 'name', 'enabled', 'email',
|
||||
allowedSelects: ['id', 'username', 'province_id', 'province_fa', 'city_id', 'city_fa', 'first_name', 'last_name', 'mobile', 'position', 'major', 'setad_id', 'last_login', 'edarate_shahri_id', 'edarate_shahri_name', 'national_code', 'name', 'enabled', 'email',
|
||||
'edarate_ostani_id', 'edarate_ostani_name', 'degree', 'confirmed', 'checked', 'updated_at', 'photo', 'created_at'],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ return [
|
||||
| as the size rules. Feel free to tweak each of these messages here.
|
||||
|
|
||||
*/
|
||||
|
||||
'prohibited' => ':attribute در این حالت مجاز نیست.',
|
||||
"accepted" => ":attribute باید پذیرفته شده باشد.",
|
||||
"active_url" => "آدرس :attribute معتبر نیست",
|
||||
"after" => ":attribute باید بعد از :date باشد.",
|
||||
@@ -286,5 +286,7 @@ return [
|
||||
'forbidden_area' => 'محدوده ممنوعه',
|
||||
'forbidden_area.type' => 'نوع محدوده محدوده',
|
||||
'forbidden_area.coordinates' => 'مختصات محدوده ممنوعه',
|
||||
'edarate_ostani_id' => 'اداره استانی',
|
||||
'edarate_shahri_id' => ' اداره شهری'
|
||||
],
|
||||
];
|
||||
|
||||
@@ -586,19 +586,19 @@ Route::prefix('user_management')
|
||||
->name('user_management.')
|
||||
->controller(UserManagementController::class)
|
||||
->group(function () {
|
||||
// Route::get('/', 'index')->name('index');
|
||||
Route::get('/', 'index')->name('index')->middleware(
|
||||
'permission:full-user-management|limited-user-management');
|
||||
Route::post('/', 'store')->name('store');
|
||||
Route::post('/store_extra', 'storeExtra')->name('storeExtra');
|
||||
Route::post('/limit_store', 'limitStore')->name('limitStore');
|
||||
Route::post('/full_store', 'fullStore')->name('fullStore');
|
||||
Route::get('/{user}', 'show')->name('show');
|
||||
Route::get('/user_permissions/{user}', 'userPermissions')->name('userPermissions');
|
||||
Route::post('/{user}', 'update')->name('update');
|
||||
Route::delete('/{user}', 'destroy')->name('destroy');
|
||||
Route::post('/change_password/{user}', 'changePassword')->name('changePassword');
|
||||
Route::post('/give_permissions_to', 'givePermissionsTo')->name('givePermissionsTo');
|
||||
Route::post('/give_role_to_user','giveRoleToUser')->name('giveRoleToUser');
|
||||
Route::post('/change_confirmed_status', 'changeConfirmedStatus')->name('changeConfirmedStatus');
|
||||
Route::post('/change_user_enabeld','changeUserEnabeld')->name('changeUserEnabeld')->middleware(
|
||||
Route::post('/give_permissions_to/{user}', 'givePermissionsTo')->name('givePermissionsTo');
|
||||
Route::post('/give_role_to_user/{user}','giveRoleToUser')->name('giveRoleToUser');
|
||||
Route::post('/change_confirmed_status/{user}', 'changeConfirmedStatus')->name('changeConfirmedStatus');
|
||||
Route::post('/change_user_enabeld/{user}','changeUserEnabeld')->name('changeUserEnabeld')->middleware(
|
||||
'permission:full-user-management|limited-user-management');
|
||||
Route::get('/activity_report', 'activityReport')->name('activityReport');
|
||||
Route::get('/userActivityLogs', 'userActivityLogs')->name('userActivityLogs');
|
||||
|
||||
Reference in New Issue
Block a user