Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/Reseller/InvitationsController.php
Show All 22 Lines | class InvitationsController extends Controller | ||||
* Remove the specified invitation. | * Remove the specified invitation. | ||||
* | * | ||||
* @param int $id Invitation identifier | * @param int $id Invitation identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function destroy($id) | public function destroy($id) | ||||
{ | { | ||||
$invitation = SignupInvitation::withUserTenant()->find($id); | $invitation = SignupInvitation::withSubjectTenantContext()->find($id); | ||||
if (empty($invitation)) { | if (empty($invitation)) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
$invitation->delete(); | $invitation->delete(); | ||||
return response()->json([ | return response()->json([ | ||||
Show All 21 Lines | class InvitationsController extends Controller | ||||
*/ | */ | ||||
public function index() | public function index() | ||||
{ | { | ||||
$pageSize = 10; | $pageSize = 10; | ||||
$search = request()->input('search'); | $search = request()->input('search'); | ||||
$page = intval(request()->input('page')) ?: 1; | $page = intval(request()->input('page')) ?: 1; | ||||
$hasMore = false; | $hasMore = false; | ||||
$result = SignupInvitation::withUserTenant() | $result = SignupInvitation::withSubjectTenantContext() | ||||
->latest() | ->latest() | ||||
->limit($pageSize + 1) | ->limit($pageSize + 1) | ||||
->offset($pageSize * ($page - 1)); | ->offset($pageSize * ($page - 1)); | ||||
if ($search) { | if ($search) { | ||||
if (strpos($search, '@')) { | if (strpos($search, '@')) { | ||||
$result->where('email', $search); | $result->where('email', $search); | ||||
} else { | } else { | ||||
Show All 25 Lines | class InvitationsController extends Controller | ||||
* Resend the specified invitation. | * Resend the specified invitation. | ||||
* | * | ||||
* @param int $id Invitation identifier | * @param int $id Invitation identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function resend($id) | public function resend($id) | ||||
{ | { | ||||
$invitation = SignupInvitation::withUserTenant()->find($id); | $invitation = SignupInvitation::withSubjectTenantContext()->find($id); | ||||
if (empty($invitation)) { | if (empty($invitation)) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
if ($invitation->isFailed() || $invitation->isSent()) { | if ($invitation->isFailed() || $invitation->isSent()) { | ||||
// Note: The email sending job will be dispatched by the observer | // Note: The email sending job will be dispatched by the observer | ||||
$invitation->status = SignupInvitation::STATUS_NEW; | $invitation->status = SignupInvitation::STATUS_NEW; | ||||
Show All 14 Lines | class InvitationsController extends Controller | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function store(Request $request) | public function store(Request $request) | ||||
{ | { | ||||
$errors = []; | $errors = []; | ||||
$invitations = []; | $invitations = []; | ||||
$envTenantId = \config('app.tenant_id'); | |||||
$subjectTenantId = auth()->user()->tenant_id; | |||||
if (!empty($request->file) && is_object($request->file)) { | if (!empty($request->file) && is_object($request->file)) { | ||||
// Expected a text/csv file with multiple email addresses | // Expected a text/csv file with multiple email addresses | ||||
if (!$request->file->isValid()) { | if (!$request->file->isValid()) { | ||||
$errors = ['file' => [$request->file->getErrorMessage()]]; | $errors = ['file' => [$request->file->getErrorMessage()]]; | ||||
} else { | } else { | ||||
$fh = fopen($request->file->getPathname(), 'r'); | $fh = fopen($request->file->getPathname(), 'r'); | ||||
$line_number = 0; | $line_number = 0; | ||||
$error = null; | $error = null; | ||||
Show All 39 Lines | public function store(Request $request) | ||||
} | } | ||||
if (!empty($errors)) { | if (!empty($errors)) { | ||||
return response()->json(['status' => 'error', 'errors' => $errors], 422); | return response()->json(['status' => 'error', 'errors' => $errors], 422); | ||||
} | } | ||||
$count = 0; | $count = 0; | ||||
foreach ($invitations as $idx => $invitation) { | foreach ($invitations as $idx => $invitation) { | ||||
SignupInvitation::create($invitation); | $inv = SignupInvitation::create($invitation); | ||||
$count++; | $count++; | ||||
// Set the invitation tenant to the reseller tenant | |||||
if ($envTenantId != $subjectTenantId) { | |||||
$inv->tenant_id = $subjectTenantId; | |||||
$inv->save(); | |||||
} | |||||
} | } | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'message' => \trans_choice('app.signup-invitations-created', $count, ['count' => $count]), | 'message' => \trans_choice('app.signup-invitations-created', $count, ['count' => $count]), | ||||
'count' => $count, | 'count' => $count, | ||||
]); | ]); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |