Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/Admin/UsersController.php
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | public function reset2FA(Request $request, $id) | ||||
// Note: we do select first, so the observer can delete | // Note: we do select first, so the observer can delete | ||||
// 2FA preferences from Roundcube database, so don't | // 2FA preferences from Roundcube database, so don't | ||||
// be tempted to replace first() with delete() below | // be tempted to replace first() with delete() below | ||||
$entitlement = $user->entitlements()->where('sku_id', $sku->id)->first(); | $entitlement = $user->entitlements()->where('sku_id', $sku->id)->first(); | ||||
$entitlement->delete(); | $entitlement->delete(); | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'message' => __('app.user-reset-2fa-success'), | 'message' => \trans('app.user-reset-2fa-success'), | ||||
]); | |||||
} | |||||
/** | |||||
* Set/Add a SKU for the user | |||||
* | |||||
* @param \Illuminate\Http\Request $request The API request. | |||||
* @param string $id User identifier | |||||
* @param string $sku SKU title | |||||
* | |||||
* @return \Illuminate\Http\JsonResponse The response | |||||
*/ | |||||
public function setSku(Request $request, $id, $sku) | |||||
{ | |||||
// For now we allow adding the 'beta' SKU only | |||||
if ($sku != 'beta') { | |||||
return $this->errorResponse(404); | |||||
} | |||||
$user = User::find($id); | |||||
if (!$this->checkTenant($user)) { | |||||
return $this->errorResponse(404); | |||||
} | |||||
if (!$this->guard()->user()->canUpdate($user)) { | |||||
return $this->errorResponse(403); | |||||
} | |||||
$sku = Sku::withObjectTenantContext($user)->where('title', $sku)->first(); | |||||
if (!$sku) { | |||||
return $this->errorResponse(404); | |||||
} | |||||
if ($user->entitlements()->where('sku_id', $sku->id)->first()) { | |||||
return $this->errorResponse(422, \trans('app.user-set-sku-already-exists')); | |||||
} | |||||
$user->assignSku($sku); | |||||
$entitlement = $user->entitlements()->where('sku_id', $sku->id)->first(); | |||||
return response()->json([ | |||||
'status' => 'success', | |||||
'message' => \trans('app.user-set-sku-success'), | |||||
'sku' => [ | |||||
'cost' => $entitlement->cost, | |||||
'name' => $sku->name, | |||||
'id' => $sku->id, | |||||
] | |||||
]); | ]); | ||||
} | } | ||||
/** | /** | ||||
* Display information on the user account specified by $id. | * Display information on the user account specified by $id. | ||||
* | * | ||||
* @param int $id The account to show information for. | * @param int $id The account to show information for. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | public function suspend(Request $request, $id) | ||||
if (!$this->guard()->user()->canUpdate($user)) { | if (!$this->guard()->user()->canUpdate($user)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$user->suspend(); | $user->suspend(); | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'message' => __('app.user-suspend-success'), | 'message' => \trans('app.user-suspend-success'), | ||||
]); | ]); | ||||
} | } | ||||
/** | /** | ||||
* Un-Suspend the user | * Un-Suspend the user | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request The API request. | * @param \Illuminate\Http\Request $request The API request. | ||||
* @param string $id User identifier | * @param string $id User identifier | ||||
Show All 11 Lines | public function unsuspend(Request $request, $id) | ||||
if (!$this->guard()->user()->canUpdate($user)) { | if (!$this->guard()->user()->canUpdate($user)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$user->unsuspend(); | $user->unsuspend(); | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'message' => __('app.user-unsuspend-success'), | 'message' => \trans('app.user-unsuspend-success'), | ||||
]); | ]); | ||||
} | } | ||||
/** | /** | ||||
* Update user data. | * Update user data. | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request The API request. | * @param \Illuminate\Http\Request $request The API request. | ||||
* @param string $id User identifier | * @param string $id User identifier | ||||
Show All 31 Lines | public function update(Request $request, $id) | ||||
$settings = $request->only(array_keys($rules)); | $settings = $request->only(array_keys($rules)); | ||||
if (!empty($settings)) { | if (!empty($settings)) { | ||||
$user->setSettings($settings); | $user->setSettings($settings); | ||||
} | } | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'message' => __('app.user-update-success'), | 'message' => \trans('app.user-update-success'), | ||||
]); | ]); | ||||
} | } | ||||
} | } |