Skip to content

Commit

Permalink
[NF] - doctrine to eloquent controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrobin committed Sep 23, 2020
1 parent b101140 commit 1768d08
Show file tree
Hide file tree
Showing 51 changed files with 842 additions and 1,671 deletions.
1 change: 0 additions & 1 deletion .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ IDENTITY_DEFAULT_VLAN=1

#######################################################################################
# See config/ixp.php
IXP_MULTIIXP_ENABLED=false
IXP_RESELLER_ENABLED=true
IXP_AS112_UI_ACTIVE=true

Expand Down
1 change: 0 additions & 1 deletion .env.vagrant
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ IDENTITY_DEFAULT_VLAN=1

IXP_API_JSONEXPORTSCHEMA_PUBLIC=true

IXP_MULTIIXP_ENABLED=false
IXP_RESELLER_ENABLED=false
IXP_AS112_UI_ACTIVE=true

Expand Down
2 changes: 2 additions & 0 deletions .idea/IXP-Manager.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
use Illuminate\Http\Request;
use Illuminate\View\View;

use IXP\Models\{Aggregators\VirtualInterfaceAggregator,
Aggregators\VlanInterfaceAggregator,
use IXP\Models\{
Aggregators\VirtualInterfaceAggregator,
Customer,
Infrastructure,
Location,
VirtualInterface,
Vlan,
VlanInterface};
VlanInterface
};

use IXP\Services\Grapher\Graph as Graph;

Expand Down
45 changes: 26 additions & 19 deletions app/Http/Controllers/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace IXP\Http\Controllers;

/*
* Copyright (C) 2009 - 2019 Internet Neutral Exchange Association Company Limited By Guarantee.
* Copyright (C) 2009 - 2020 Internet Neutral Exchange Association Company Limited By Guarantee.
* All Rights Reserved.
*
* This file is part of IXP Manager.
Expand All @@ -23,40 +23,45 @@
* http://www.gnu.org/licenses/gpl-2.0.html
*/

use Auth, D2EM;
use Auth;

use Entities\{
Customer as CustomerEntity,
User as UserEntity
use Illuminate\Http\{
JsonResponse,
Response
};

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\View as FacadeView;

use Illuminate\View\View;

use IXP\Models\{
Customer,
User
};

/**
* Content Controller
*
* @author Barry O'Donovan <[email protected]>
* @author Yann Robin <[email protected]>
* @category Controller
* @copyright Copyright (C) 2009 - 2019 Internet Neutral Exchange Association Company Limited By Guarantee
* @copyright Copyright (C) 2009 - 2020 Internet Neutral Exchange Association Company Limited By Guarantee
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL V2.0
*/
class ContentController extends Controller {

class ContentController extends Controller
{
/**
* Display the appropriate static content page (if permissions match)
*
* @param int $priv Required privilege for access to the content
* @param string $page Page to display
*
* @return View
*/
public function index( int $priv, string $page ): View {

public function index( int $priv, string $page ): View
{
// check privilege:
if( $priv != UserEntity::AUTH_PUBLIC ) {
if( $priv !== User::AUTH_PUBLIC ) {
if( Auth::guest() || Auth::user()->getPrivs() < $priv ) {
abort( 403, 'Unauthorized' );
}
Expand All @@ -77,9 +82,11 @@ public function index( int $priv, string $page ): View {
* Alias for public only content
*
* @param string $page Page to display
*
* @return View
*/
public function public( string $page ): View {
public function public( string $page ): View
{
return $this->index( 0, $page );
}

Expand All @@ -88,12 +95,13 @@ public function public( string $page ): View {
*
* @param int $priv Required privilege for access to the content
* @param string $page Page to display
*
* @return View|Response|JsonResponse
*/
public function members( int $priv, string $page )
{
// check privilege:
if( $priv != UserEntity::AUTH_PUBLIC ) {
if( $priv !== User::AUTH_PUBLIC ) {
if( Auth::guest() || Auth::user()->getPrivs() < $priv ) {
abort( 403, 'Unauthorized' );
}
Expand All @@ -105,7 +113,7 @@ public function members( int $priv, string $page )
$page .= '.html';
}

list( $page, $format ) = explode( '.', $page );
[ $page, $format ] = explode( '.', $page );

// sanitise page name:
$page = "content/members/{$priv}/" . preg_replace( '/[^a-z0-9\-_]/', '', $page );
Expand All @@ -114,13 +122,12 @@ public function members( int $priv, string $page )
abort( 404, 'Requested page not found' );
}

$r = response()->view( $page, [ 'customers' => D2EM::getRepository( CustomerEntity::class )->getCurrentActive() ], 200 );
$r = response()->view( $page, [ 'customers' => Customer::currentActive() ], 200 );

if( $format == 'json' ) {
if( $format === 'json' ) {
$r->header( 'Content-Type', 'application/json' );
}

return $r;
}

}
60 changes: 19 additions & 41 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

namespace IXP\Http\Controllers;

/*
* Copyright (C) 2009 - 2019 Internet Neutral Exchange Association Company Limited By Guarantee.
* Copyright (C) 2009 - 2020 Internet Neutral Exchange Association Company Limited By Guarantee.
* All Rights Reserved.
*
* This file is part of IXP Manager.
Expand All @@ -20,27 +22,23 @@
*
* http://www.gnu.org/licenses/gpl-2.0.html
*/

namespace IXP\Http\Controllers;

use Auth, D2EM;

use Entities\{
Customer as CustomerEntity,
User as UserEntity
};
use Auth;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;

use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

use IXP\Models\{
Customer,
User
};

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;


/**
* Checks if reseller mode is enabled.
*
Expand All @@ -55,23 +53,6 @@ protected function resellerMode(): bool
return (bool)config( 'ixp.reseller.enabled', false );
}

/**
* Checks if multi IXP mode is enabled.
*
* To enable multi IXP mode set the env variable IXP_MULTIIXP_ENABLED
*
* NB: this functionality is deprecated in IXP Manager v4.0 and will be
* removed piecemeal.
*
* @see https://github.com/inex/IXP-Manager/wiki/Multi-IXP-Functionality
*
* @return bool
*/
protected function multiIXP(): bool
{
return (bool)config( 'ixp.multiixp.enabled', false );
}

/**
* Checks if as112 is activated in the UI.
*
Expand All @@ -93,7 +74,7 @@ protected function as112UiActive(): bool
*
* @return bool
*/
protected function logoManagementEnabled()
protected function logoManagementEnabled(): bool
{
return !(bool)config( 'ixp_fe.frontend.disabled.logo' );
}
Expand All @@ -106,7 +87,7 @@ protected function logoManagementEnabled()
*
* @return string
*/
protected function getIp()
protected function getIp(): string
{
foreach( [ 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ] as $key ) {
if( array_key_exists( $key, $_SERVER ) === true ) {
Expand All @@ -129,26 +110,23 @@ protected function getIp()
*
* @throws
*/
protected function getAllowedPrivs()
protected function getAllowedPrivs(): array
{
$privs = UserEntity::$PRIVILEGES_TEXT_NONSUPERUSER;
$privs = User::$PRIVILEGES_TEXT_NONSUPERUSER;

// If we add a user via the customer overview users list
if( request()->is( 'user/add*' ) && request()->input( "cust" ) ) {

/** @var $c CustomerEntity */
if( ( $c = D2EM::getRepository( CustomerEntity::class )->find( request()->input( "cust" ) ) ) ) {
if( request()->cust && request()->is( 'user/add*' ) ) {
if( ( $c = Customer::find( request()->cust ) ) ) {
// Internal customer and SuperUser
if( $c->isTypeInternal() && Auth::getUser()->isSuperUser() ){
$privs = UserEntity::$PRIVILEGES_TEXT;
if( Auth::getUser()->isSuperUser() && $c->typeInternal() ){
$privs = User::$PRIVILEGES_TEXT;
}
}
// If we add a user and we are a SuperUser
} elseif( Auth::getUser()->isSuperUser() && ( request()->is( 'user/add*' ) || request()->is( 'customer-to-user/add*' ) ) ) {
$privs = UserEntity::$PRIVILEGES_TEXT;
$privs = User::$PRIVILEGES_TEXT;
}

return $privs;
}

}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Customer/CustomerTagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function feInit(): void
*
* @return array
*/
protected function listGetData( $id = null ): array
protected function listGetData( ?int $id = null ): array
{
$feParams = $this->feParams;
return CustomerTag::when( $id , function( Builder $q, $id ) {
Expand Down Expand Up @@ -144,7 +144,7 @@ protected function createPrepareForm(): array
*
* @return array
*/
protected function editPrepareForm( $id ): array
protected function editPrepareForm( int $id ): array
{
$this->object = CustomerTag::findOrFail( $id );

Expand Down
7 changes: 3 additions & 4 deletions app/Http/Controllers/FilteredPrefixesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
*/
class FilteredPrefixesController extends Controller
{

/**
* Get the list
*
* @param Request $r
* @param Customer $customer
Expand All @@ -70,12 +70,11 @@ public function list( Request $r, Customer $customer ) : View

// if we are using the sync queue runner, it will have completed
$filteredPrefixes = Cache::get( 'filtered-prefixes-' . $customer->id, false );
};
}

return view( 'filtered-prefixes.view' )->with([
'customer' => $customer,
'filteredPrefixes' => $filteredPrefixes,
]);
}

}
}
Loading

0 comments on commit 1768d08

Please sign in to comment.