Skip to content

Commit

Permalink
Merge pull request #262 from ControlPanel-gg/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
AVMG20 authored Nov 3, 2021
2 parents b3d73e3 + 79b1be6 commit 93fdab5
Show file tree
Hide file tree
Showing 40 changed files with 1,126 additions and 642 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function datatable()

return datatables($query)
->addColumn('actions', function (Configuration $configuration) {
return '<button data-content="Edit" data-toggle="popover" data-trigger="hover" data-placement="top" onclick="configuration.parse(\'' . $configuration->key . '\',\'' . $configuration->value . '\')" data-content="Edit" data-trigger="hover" data-toggle="tooltip" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></button> ';
return '<button data-content="Edit" data-toggle="popover" data-trigger="hover" data-placement="top" onclick="configuration.parse(\'' . $configuration->key . '\',\'' . $configuration->value . '\',\'' . $configuration->type . '\')" data-content="Edit" data-trigger="hover" data-toggle="tooltip" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></button> ';
})
->editColumn('created_at', function (Configuration $configuration) {
return $configuration->created_at ? $configuration->created_at->diffForHumans() : '';
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Admin/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ public function success(Request $laravelRequest)
$user->increment('credits', $paypalProduct->quantity);

//update server limit
if (Configuration::getValueByKey('SERVER_LIMIT_AFTER_IRL_PURCHASE', 10) !== 0) {
if ($user->server_limit < Configuration::getValueByKey('SERVER_LIMIT_AFTER_IRL_PURCHASE', 10)) {
$user->update(['server_limit' => 10]);
if (Configuration::getValueByKey('SERVER_LIMIT_AFTER_IRL_PURCHASE') !== 0) {
if ($user->server_limit < Configuration::getValueByKey('SERVER_LIMIT_AFTER_IRL_PURCHASE')) {
$user->update(['server_limit' => Configuration::getValueByKey('SERVER_LIMIT_AFTER_IRL_PURCHASE')]);
}
}

//update role
if ($user->role == 'member') {
$user->update(['role' => 'client']);
Expand Down
14 changes: 9 additions & 5 deletions app/Http/Controllers/Admin/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Configuration;
use App\Models\Product;
use Exception;
use Illuminate\Contracts\Foundation\Application;
Expand Down Expand Up @@ -51,6 +52,7 @@ public function store(Request $request)
"swap" => "required|numeric|max:1000000|min:0",
"description" => "required|string|max:191",
"disk" => "required|numeric|max:1000000|min:5",
"minimum_credits" => "required|numeric|max:1000000|min:-1",
"io" => "required|numeric|max:1000000|min:0",
"databases" => "required|numeric|max:1000000|min:0",
"backups" => "required|numeric|max:1000000|min:0",
Expand All @@ -73,7 +75,8 @@ public function store(Request $request)
public function show(Product $product)
{
return view('admin.products.show', [
'product' => $product
'product' => $product,
'minimum_credits' => Configuration::getValueByKey("MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER"),
]);
}

Expand Down Expand Up @@ -108,6 +111,7 @@ public function update(Request $request, Product $product): RedirectResponse
"description" => "required|string|max:191",
"disk" => "required|numeric|max:1000000|min:5",
"io" => "required|numeric|max:1000000|min:0",
"minimum_credits" => "required|numeric|max:1000000|min:-1",
"databases" => "required|numeric|max:1000000|min:0",
"backups" => "required|numeric|max:1000000|min:0",
"allocations" => "required|numeric|max:1000000|min:0",
Expand All @@ -125,7 +129,8 @@ public function update(Request $request, Product $product): RedirectResponse
* @param Product $product
* @return RedirectResponse
*/
public function disable(Request $request, Product $product) {
public function disable(Request $request, Product $product)
{
$product->update(['disabled' => !$product->disabled]);

return redirect()->route('admin.products.index')->with('success', 'product has been updated!');
Expand Down Expand Up @@ -181,12 +186,11 @@ public function dataTable()
' . csrf_field() . '
' . method_field("PATCH") . '
<div class="custom-control custom-switch">
<input '.$checked.' name="disabled" onchange="this.form.submit()" type="checkbox" class="custom-control-input" id="switch'.$product->id.'">
<label class="custom-control-label" for="switch'.$product->id.'"></label>
<input ' . $checked . ' name="disabled" onchange="this.form.submit()" type="checkbox" class="custom-control-input" id="switch' . $product->id . '">
<label class="custom-control-label" for="switch' . $product->id . '"></label>
</div>
</form>
';

})
->editColumn('created_at', function (Product $product) {
return $product->created_at ? $product->created_at->diffForHumans() : '';
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@ public function notify(Request $request)
return redirect()->route('admin.users.notifications')->with('success', 'Notification sent!');
}

/**
* @param User $user
* @return RedirectResponse
*/
public function toggleSuspended(User $user){
try {
!$user->isSuspended() ? $user->suspend() : $user->unSuspend();
} catch (Exception $exception) {
return redirect()->back()->with('error', $exception->getMessage());
}

return redirect()->back()->with('success', 'User has been updated!');
}

/**
*
* @throws Exception
Expand Down Expand Up @@ -252,10 +266,17 @@ public function dataTable()
return $user->last_seen ? $user->last_seen->diffForHumans() : '';
})
->addColumn('actions', function (User $user) {
$suspendColor = $user->isSuspended() ? "btn-success" : "btn-warning";
$suspendIcon = $user->isSuspended() ? "fa-play-circle" : "fa-pause-circle";
$suspendText = $user->isSuspended() ? "Unsuspend" : "Suspend";
return '
<a data-content="Login as user" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.loginas', $user->id) . '" class="btn btn-sm btn-primary mr-1"><i class="fas fa-sign-in-alt"></i></a>
<a data-content="Show" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.show', $user->id) . '" class="btn btn-sm text-white btn-warning mr-1"><i class="fas fa-eye"></i></a>
<a data-content="Edit" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.edit', $user->id) . '" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a>
<form class="d-inline" method="post" action="' . route('admin.users.togglesuspend', $user->id) . '">
' . csrf_field() . '
<button data-content="'.$suspendText.'" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm '.$suspendColor.' text-white mr-1"><i class="far '.$suspendIcon.'"></i></button>
</form>
<form class="d-inline" onsubmit="return submitResult();" method="post" action="' . route('admin.users.destroy', $user->id) . '">
' . csrf_field() . '
' . method_field("DELETE") . '
Expand Down
30 changes: 28 additions & 2 deletions app/Http/Controllers/Admin/VoucherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Events\UserUpdateCreditsEvent;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Models\Voucher;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
Expand Down Expand Up @@ -115,6 +116,13 @@ public function destroy(Voucher $voucher)
return redirect()->back()->with('success', 'voucher has been removed!');
}

public function users(Voucher $voucher)
{
return view('admin.vouchers.users', [
'voucher' => $voucher
]);
}

/**
* @param Request $request
* @return JsonResponse
Expand Down Expand Up @@ -144,7 +152,7 @@ public function redeem(Request $request)
]);

if ($request->user()->credits + $voucher->credits >= 99999999) throw ValidationException::withMessages([
'code' => "You can't redeem this voucher because you would exceed the ".CREDITS_DISPLAY_NAME." limit"
'code' => "You can't redeem this voucher because you would exceed the " . CREDITS_DISPLAY_NAME . " limit"
]);

#redeem voucher
Expand All @@ -153,17 +161,35 @@ public function redeem(Request $request)
event(new UserUpdateCreditsEvent($request->user()));

return response()->json([
'success' => "{$voucher->credits} ".CREDITS_DISPLAY_NAME." have been added to your balance!"
'success' => "{$voucher->credits} " . CREDITS_DISPLAY_NAME . " have been added to your balance!"
]);
}

public function usersDataTable(Voucher $voucher)
{
$users = $voucher->users();

return datatables($users)
->editColumn('name', function (User $user) {
return '<a class="text-info" target="_blank" href="' . route('admin.users.show', $user->id) . '">' . $user->name . '</a>';
})
->addColumn('credits', function (User $user) {
return '<i class="fas fa-coins mr-2"></i> ' . $user->credits();
})
->addColumn('last_seen', function (User $user) {
return $user->last_seen ? $user->last_seen->diffForHumans() : '';
})
->rawColumns(['name', 'credits', 'last_seen'])
->make();
}
public function dataTable()
{
$query = Voucher::query();

return datatables($query)
->addColumn('actions', function (Voucher $voucher) {
return '
<a data-content="Users" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.vouchers.users', $voucher->id) . '" class="btn btn-sm btn-primary mr-1"><i class="fas fa-users"></i></a>
<a data-content="Edit" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.vouchers.edit', $voucher->id) . '" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a>
<form class="d-inline" onsubmit="return submitResult();" method="post" action="' . route('admin.vouchers.destroy', $voucher->id) . '">
Expand Down
28 changes: 25 additions & 3 deletions app/Http/Controllers/Api/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
use App\Models\DiscordUser;
use App\Models\User;
use App\Notifications\DynamicNotification;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\HtmlString;
use Illuminate\Validation\ValidationException;
use Spatie\ValidationRules\Rules\Delimited;

class NotificationController extends Controller
Expand Down Expand Up @@ -55,19 +57,21 @@ public function view(int $userId, $notificationId)
*
* @param Request $request
* @return JsonResponse
* @throws ValidationException
*/
public function send(Request $request)
{
$data = $request->validate([
"via" => ["required", new Delimited("in:mail,database")],
"all" => "required_without:users|boolean",
"users" => ["required_without:all", new Delimited("exists:users,id")],
"users" => ["required_without:all"],
"title" => "required|string|min:1",
"content" => "required|string|min:1"
]);
$via = explode(",", $data["via"]);
$mail = null;
$database = null;

if (in_array("database", $via)) {
$database = [
"title" => $data["title"],
Expand All @@ -79,10 +83,28 @@ public function send(Request $request)
->subject($data["title"])
->line(new HtmlString($data["content"]));
}

$all = $data["all"] ?? false;
$users = $all ? User::all() : User::whereIn("id", explode(",", $data["users"]))->get();
if ($all) {
$users = User::all();
} else {
$userIds = explode(",", $data["users"]);
$users = User::query()
->whereIn("id", $userIds)
->orWhereHas('discordUser', function (Builder $builder) use ($userIds) {
$builder->whereIn('id', $userIds);
})
->get();
}

if ($users->count() == 0) {
throw ValidationException::withMessages([
'users' => ['No users found!'],
]);
}

Notification::send($users, new DynamicNotification($via, $database, $mail));
return response()->json(["message" => "Notification successfully sent."]);
return response()->json(["message" => "Notification successfully sent.", 'user_count' => $users->count()]);
}

/**
Expand Down
23 changes: 18 additions & 5 deletions app/Http/Controllers/Api/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
use App\Models\Server;
use Exception;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Spatie\QueryBuilder\QueryBuilder;

class ServerController extends Controller
{
public const ALLOWED_INCLUDES = ['product', 'user'];
public const ALLOWED_FILTERS = ['name', 'suspended', 'identifier', 'pterodactyl_id', 'user_id', 'product_id'];

/**
* Display a listing of the resource.
*
Expand All @@ -19,21 +25,28 @@ class ServerController extends Controller
*/
public function index(Request $request)
{
return Server::with('product')->paginate($request->query('per_page') ?? 50);
}
$query = QueryBuilder::for(Server::class)
->allowedIncludes(self::ALLOWED_INCLUDES)
->allowedFilters(self::ALLOWED_FILTERS);

return $query->paginate($request->input('per_page') ?? 50);
}

/**
* Display the specified resource.
*
* @param Server $server
* @return Server
*
* @return Server|Collection|Model
*/
public function show(Server $server)
{
return $server->load('product');
}
$query = QueryBuilder::for(Server::class)
->where('id', '=', $server->id)
->allowedIncludes(self::ALLOWED_INCLUDES);

return $query->firstOrFail();
}

/**
* Remove the specified resource from storage.
Expand Down
Loading

0 comments on commit 93fdab5

Please sign in to comment.