This commit is contained in:
Kekskurse 2019-11-26 17:29:59 +01:00
parent f48da1a642
commit f3596ce761
3 changed files with 53 additions and 2 deletions

View file

@ -5,6 +5,8 @@ namespace App\Http\Controllers\API;
use App\Exceptions\HTTPException; use App\Exceptions\HTTPException;
use App\Jobs\Mails\ValidateMailAddressJob; use App\Jobs\Mails\ValidateMailAddressJob;
use App\Models\App;
use App\Models\Invite;
use App\Models\Mail; use App\Models\Mail;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -15,6 +17,41 @@ use TaGeSo\APIResponse\Response;
class AdminController extends BaseController class AdminController extends BaseController
{ {
public function listAllApps(Request $request, Response $response) {
if(!Auth::check()) {
abort(401);
}
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$apps = App::all();
return $response->withData(\App\Http\Resources\API\App::collection($apps));
}
public function saveAppProperties(Request $request, Response $response, $id) {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$app = App::query()->where("id", "=", $id)->first("*");
$app->auto_accept = (bool)$request->input("autoAccept", false);
$app->testing_warning = (bool)$request->input("testingWarning", false);
$app->untrusted_warning = (bool)$request->input("untrustedWarning", false);
$app->show_on_webpage = (bool)$request->input("showOnWebpage", false);
$app->hidden_in_app_list = (bool)$request->input("hideInAppList", false);
$app->user_cant_remove_app = (bool)$request->input("userCantRemoveApp", false);
$app->stop_auto_redirect = (bool)$request->input("stopAutoRedirect", false);
$app->saveOrFail();
return $response;
}
public function listAllUsers(Request $request, Response $response) { public function listAllUsers(Request $request, Response $response) {
if(!Auth::check()) { if(!Auth::check()) {
abort(401); abort(401);
@ -93,10 +130,19 @@ class AdminController extends BaseController
} }
} }
$mail->saveOrFail(); $mail->saveOrFail();
$response->setStatusCode(200); $response->setStatusCode(200);
return $response; return $response;
} }
public function listInvites(Request $request, Response $response) {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$invites = Invite::query()->get();
return $response->withData($invites);
}
} }

View file

@ -77,7 +77,7 @@ class AppController extends BaseController
$app = \App\Models\App::query()->where("id", "=", (int)$id)->firstOrFail(); $app = \App\Models\App::query()->where("id", "=", (int)$id)->firstOrFail();
if($app->user_id == Auth::user()->id) { if($app->user_id == Auth::user()->id || Auth::user()->admin) {
return $response->withData(new AppForOwner($app)); return $response->withData(new AppForOwner($app));
} }

View file

@ -89,6 +89,11 @@ $router->group(['prefix' => 'api'], function () use ($router) {
$router->put("/user/{id}", ["uses" => "API\AdminController@saveUserDetails"]); $router->put("/user/{id}", ["uses" => "API\AdminController@saveUserDetails"]);
$router->post("/mail/{id}/resend", ["uses" => "API\AdminController@resendValidationMail"]); $router->post("/mail/{id}/resend", ["uses" => "API\AdminController@resendValidationMail"]);
$router->put("/mail/{id}/status", ["uses" => "API\AdminController@changeMailStatus"]); $router->put("/mail/{id}/status", ["uses" => "API\AdminController@changeMailStatus"]);
$router->get("/app", ["uses" => "API\AdminController@listAllApps"]);
$router->put("/app/{id}/properties", ["uses" => "API\AdminController@saveAppProperties"]);
$router->group(['prefix' => 'invite'], function () use ($router) {
$router->get("", ["uses" => "API\AdminController@listInvites"]);
});
}); });
}); });
}); });