Skip to content

Commit

Permalink
Rework network module (#386)
Browse files Browse the repository at this point in the history
* comment out triggers

* ide-helper

* it's a mess but the result should be a beauty

* update internet accesses table

* remove internet user role

* fixing filter on names

* Comments and minor UI improvements

* added tests

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in 8d97de4 according to the output
from PHP CS Fixer.

Details: #386

* ide:helper

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in 4898a70 according to the output
from PHP CS Fixer.

Details: #386

* Update app/Http/Controllers/Network/AdminInternetController.php

Co-authored-by: Sámuel Szajbély <[email protected]>

* Update app/Http/Controllers/Network/MacAddressController.php

Co-authored-by: Sámuel Szajbély <[email protected]>

* address changes

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in c8ee212 according to the output
from PHP CS Fixer.

Details: #386

* fix router page

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in 92fe6f2 according to the output
from PHP CS Fixer.

Details: #386

* auto approve macs for admins

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in ae43849 according to the output
from PHP CS Fixer.

Details: #386

* composer update

* update ci

* fix merge

* fix locale test

* fix deepsource issues

* fix wrong return type

* configure test email sending and test fault reports

* completed tests

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in 8cdd25e according to the output
from PHP CS Fixer.

Details: #386

* deepsource fix

* send mac status changed mail

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in cf1c302 according to the output
from PHP CS Fixer.

Details: #386

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Sámuel Szajbély <[email protected]>
  • Loading branch information
3 people authored Dec 30, 2023
1 parent db6810e commit ab26f45
Show file tree
Hide file tree
Showing 100 changed files with 4,621 additions and 2,314 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
phpunit:
runs-on: ubuntu-latest
container:
image: kirschbaumdevelopment/laravel-test-runner:8.1
image: kirschbaumdevelopment/laravel-test-runner:8.2

services:
mysql:
Expand All @@ -17,27 +17,27 @@ jobs:
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Install composer dependencies
run: |
composer install --no-scripts
- name: Install composer dependencies
run: |
composer install --no-scripts
- name: Install front-end dependencies
run: |
npm install
npm run dev
- name: Install front-end dependencies
run: |
npm install
npm run dev
- name: Prepare Laravel Application
run: |
cp .env.ci .env
php artisan key:generate
- name: Prepare Laravel Application
run: |
cp .env.ci .env
php artisan key:generate
- name: Set up database
run: |
php artisan migrate:fresh
- name: Set up database
run: |
php artisan migrate:fresh
- name: Run Testsuite
run: vendor/bin/phpunit tests/
- name: Run Testsuite
run: vendor/bin/phpunit tests/
5 changes: 2 additions & 3 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function showTenantRegistrationForm()
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
Expand Down Expand Up @@ -93,7 +93,7 @@ protected function validator(array $data)
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @param array $data
* @return \App\Models\User
*/
public function create(array $data)
Expand All @@ -106,7 +106,6 @@ public function create(array $data)
]);

$user->roles()->attach(Role::firstWhere('name', Role::PRINTER)->id);
$user->roles()->attach(Role::firstWhere('name', Role::INTERNET_USER)->id);
$user->roles()->attach(Role::firstWhere('name', $data['user_type'])->id);

if ($data['user_type'] == Role::TENANT) {
Expand Down
105 changes: 105 additions & 0 deletions app/Http/Controllers/Network/AdminInternetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace App\Http\Controllers\Network;

use App\Http\Controllers\Controller;
use App\Models\Internet\InternetAccess;
use App\Models\Internet\WifiConnection;
use App\Utils\TabulatorPaginator;
use Carbon\Carbon;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;

class AdminInternetController extends Controller
{
/**
* Show the admin internet access page.
*
* @throws AuthorizationException
*/
public function index(): View
{
$this->authorize('handleAny', InternetAccess::class);

return view('network.admin.app', [
'activation_date' => InternetAccess::getInternetDeadline()->format('Y-m-d H:i'),
]);
}

/**
* Return paginated internet access data.
*
* @return LengthAwarePaginator
* @throws AuthorizationException
*/
public function indexInternetAccesses(): LengthAwarePaginator
{
$this->authorize('handleAny', InternetAccess::class);

return TabulatorPaginator::from(
InternetAccess::query()
->join('users as user', 'user.id', '=', 'user_id')
->select('internet_accesses.*')
->with('user')
)
->sortable(['auto_approved_mac_slots', 'has_internet_until', 'user.name'])
->filterable(['auto_approved_mac_slots', 'has_internet_until', 'user.name'])
->paginate();

}

/**
* Get paginated wifi connections data.
* @param Request $request
* @return LengthAwarePaginator
* @throws AuthorizationException
*/
public function indexWifi(Request $request): LengthAwarePaginator
{
$this->authorize('viewAny', WifiConnection::class);

return TabulatorPaginator::from(
WifiConnection::query()
->groupBy(['wifi_username', 'mac_address', 'ip', 'lease_start', 'lease_end', 'note'])
->select(['wifi_username', 'mac_address', 'ip', 'lease_start', 'lease_end', 'note',
DB::raw('COUNT(*) as radius_connections')])
)
->sortable(['wifi_username', 'mac_address', 'ip', 'lease_start'])
->filterable(['wifi_username', 'mac_address', 'ip', 'lease_start'])
->paginate();
}


/**
* Extends the internet access of a user until the given date or until the general internet access deadline.
* @throws AuthorizationException
*
*/
public function extend(Request $request, InternetAccess $internetAccess): Carbon
{
$this->authorize('extend', $internetAccess);

$request->validate([
'has_internet_until' => 'nullable|date',
]);

return $internetAccess->extendInternetAccess($request->get('has_internet_until'));
}

/**
* Revokes the internet access of a user.
* @throws AuthorizationException
*/
public function revoke(Request $request, InternetAccess $internetAccess): Response
{
$this->authorize('extend', $internetAccess);

$internetAccess->update(['has_internet_until' => null]);
return response()->noContent();
}

}
Loading

0 comments on commit ab26f45

Please sign in to comment.