Skip to content

Commit

Permalink
Merge pull request #182 from ayooby/master
Browse files Browse the repository at this point in the history
Admin roles feature
  • Loading branch information
AlirezaAlgo committed Mar 13, 2016
2 parents fa2630f + d0f97a4 commit 81edb23
Show file tree
Hide file tree
Showing 21 changed files with 517 additions and 72 deletions.
31 changes: 19 additions & 12 deletions src/Serverfireteam/Panel/PanelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function register()
{
$this->publishes([
__DIR__.'/config/elfinder.php' => config_path('elfinder.php'),
]);
]);

// register zofe\rapyd
$this->app->register('Zofe\Rapyd\RapydServiceProvider');
Expand All @@ -26,9 +26,15 @@ public function register()
$this->app->register('Maatwebsite\Excel\ExcelServiceProvider');

// Barryvdh\Elfinder\ElfinderServiceProvider
$this->app->register('Barryvdh\Elfinder\ElfinderServiceProvider');
$this->app->register('Barryvdh\Elfinder\ElfinderServiceProvider');


$this->app['router']->middleware('PanelAuth', 'Serverfireteam\Panel\libs\AuthMiddleware');

//middleware Permission
$this->app['router']->middleware(
'PermissionPanel', 'Serverfireteam\Panel\libs\PermissionCheckMiddleware'
);

// set config for Auth

Expand Down Expand Up @@ -56,17 +62,17 @@ public function register()

$this->app['panel::createmodel'] = $this->app->share(function()
{
$fileSystem = new Filesystem();
$fileSystem = new Filesystem();

return new \Serverfireteam\Panel\Commands\CreateModelCommand($fileSystem);
});
return new \Serverfireteam\Panel\Commands\CreateModelCommand($fileSystem);
});

$this->app['panel::createcontroller'] = $this->app->share(function()
{
$fileSystem = new Filesystem();
$fileSystem = new Filesystem();

return new \Serverfireteam\Panel\Commands\CreateControllerPanelCommand($fileSystem);
});
return new \Serverfireteam\Panel\Commands\CreateControllerPanelCommand($fileSystem);
});

$this->commands('panel::createmodel');

Expand All @@ -78,27 +84,28 @@ public function register()

$this->publishes([
__DIR__ . '/../../../public' => public_path('packages/serverfireteam/panel')
]);
]);

$this->publishes([
__DIR__.'/config/panel.php' => config_path('panel.php'),
]);
]);
}

public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../views', 'panelViews');
$this->publishes([
__DIR__.'/../../views' => base_path('resources/views/vendor/panelViews'),
]);
]);

include __DIR__."/../../routes.php";

$this->loadTranslationsFrom(base_path() . '/vendor/serverfireteam/panel/src/lang', 'panel');
$this->loadTranslationsFrom(base_path() . '/vendor/serverfireteam/panel/src/lang', 'panel');
$this->loadTranslationsFrom(base_path() . '/vendor/serverfireteam/rapyd-laravel/lang', 'rapyd');

AliasLoader::getInstance()->alias('Serverfireteam', 'Serverfireteam\Panel\Serverfireteam');


}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Serverfireteam/Panel/config/panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

),
'panelControllers' => array(
'Admin', 'Link'
'Admin',
'Permission',
'Role',
'Link'
),
'logo'=>'packages/serverfireteam/panel/img/logo.png' // logo of Panel

Expand Down
5 changes: 4 additions & 1 deletion src/Serverfireteam/Panel/libs/PanelElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
return array(

'controllers' => array(
'Admin' , 'Link'
'Admin' ,
'Link' ,
'Permission',
'Role'
),
);
53 changes: 53 additions & 0 deletions src/Serverfireteam/Panel/libs/PermissionCheckMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Serverfireteam\Panel\libs;

use Lang;
use Closure;
use Gate;

use Serverfireteam\Panel\Admin;

class PermissionCheckMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/

protected $app;
public function handle($request, Closure $next)
{

$admin= Admin::find((\Auth::guard('panel')->user()->id));

$urlSegments = $request->segments();

if ($admin->hasRole('super')){

return $next($request);
}else{
if (key_exists(2 , $urlSegments)){

$PermissionToCheck = $urlSegments[1].$urlSegments[2];

if($admin->hasPermission($PermissionToCheck)){

return $next($request);
}else{
/**
* Show Access denied page to User
*/

abort(403);
}
}
return $next($request);

}

}
}
16 changes: 12 additions & 4 deletions src/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ class AdminController extends CrudController{
public function all($entity){
parent::all($entity);

$this->filter = \DataFilter::source(new Admin());
$this->filter = \DataFilter::source(Admin::with('roles'));
$this->filter->add('id', 'ID', 'text');
$this->filter->add('name', 'Name', 'text');
$this->filter->add('firstname', 'First name', 'text');
$this->filter->add('last_name', 'Last Name', 'text');
$this->filter->add('email', 'Email', 'text');
$this->filter->submit('search');
$this->filter->reset('reset');
$this->filter->build();

$this->grid = \DataGrid::source($this->filter);
$this->grid->add('id','ID', true)->style("width:100px");
$this->grid->add('first_name','first name');
$this->grid->add('{{ $first_name }} {{ $last_name}}','first name');
$this->grid->add('email','Email');
$this->grid->add('{{ implode(", ", $roles->lists("name")->all()) }}', 'Role');

$this->addStylesToGrid();
return $this->returnView();
}
Expand All @@ -49,7 +54,10 @@ public function edit($entity){
$this->edit->add('email','Email', 'text')->rule('required|min:5');
$this->edit->add('first_name', 'firstname', 'text');
$this->edit->add('last_name', 'lastname', 'text');
$this->edit->add('password', 'password', 'password')->rule('required');
$this->edit->add('password', 'password', 'password')->rule('required');
$this->edit->add('roles','Roles','checkboxgroup')->options(Role::lists('name', 'id')->all());

return $this->returnEditView();
}

}
8 changes: 4 additions & 4 deletions src/controllers/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ public function returnView()
throw new \Exception('This url is not set yet!');
} else {
return \View::make('panelViews::all', array(
'grid' => $this->grid,
'filter' => $this->filter,
'grid' => $this->grid,
'filter' => $this->filter,
'title' => $this->entity ,
'current_entity' => $this->entity,
'import_message' => (\Session::has('import_message')) ? \Session::get('import_message') : ''
'current_entity' => $this->entity,
'import_message' => (\Session::has('import_message')) ? \Session::get('import_message') : ''
));
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/controllers/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function all($entity) {

$this->filter = \DataFilter::source(new Link());
$this->filter->add('id', 'ID', 'text');
$this->filter->add('name', 'Name', 'text');
$this->filter->add('display', 'Display', 'text');
$this->filter->submit('search');
$this->filter->reset('reset');
$this->filter->build();
Expand All @@ -39,14 +39,18 @@ public function edit($entity) {
return ( class_exists( $appHelper->getNameSpace() . $link['url'] ));
});

$helpMessage = trans('rapyd::rapyd.links_help');
$helpMessage = \Lang::get('panel::fields.links_help');

$this->edit->label('Edit Links');
$this->edit->link("rapyd-demo/filter", "Articles", "TR")->back();
$this->edit->add('display', 'Display', 'text');
$this->edit->add('url', 'link', 'text');
$this->edit->add('display', 'Display', 'text')->rule('required');
$this->edit->add('url', 'link', 'text')->rule('required');

$this->addHelperMessage($helpMessage);
$this->edit->saved(function () use ($entity) {
$this->edit->message(\Lang::get('panel::fields.dataSavedSuccessfull'));
$this->edit->link('panel/Permission/all', \Lang::get('panel::fields.back'));
});
$this->addHelperMessage($helpMessage);

return $this->returnEditView();
}
Expand Down
44 changes: 22 additions & 22 deletions src/controllers/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@

class MainController extends Controller {


public function entityUrl($entity, $methods){


$appHelper = new libs\AppHelper();

$urls = Link::getMainUrls();
$urls = Link::getMainUrls();

if ( in_array($entity, $urls)){
$controller_path = 'Serverfireteam\Panel\\'.$entity.'Controller';
$controller_path = 'Serverfireteam\Panel\\'.$entity.'Controller';
} else {
$panel_path = \Config::get('panel.controllers');
if ( isset($panel_path) ){
$controller_path = '\\'.$panel_path.'\\'.$entity.'Controller';
} else {
$controller_path = $appHelper->getNameSpace().'Http\Controllers\\'.$entity.'Controller';
}
}
try{
$controller = \App::make($controller_path);
}catch(\Exception $ex){
throw new \Exception("Can not found the Controller ( $controller_path ) ");
}

if (!method_exists($controller, $methods)){
throw new \Exception('Controller does not implement the CrudController methods!');
} else {
return $controller->callAction($methods, array('entity' => $entity));
}
$controller_path = '\\'.$panel_path.'\\'.$entity.'Controller';
} else {
$controller_path = $appHelper->getNameSpace().'Http\Controllers\\'.$entity.'Controller';
}
}

try{
$controller = \App::make($controller_path);
}catch(\Exception $ex){
throw new \Exception("Can not found the Controller ( $controller_path ) ");
}

if (!method_exists($controller, $methods)){
throw new \Exception('Controller does not implement the CrudController methods!');
} else {
return $controller->callAction($methods, array('entity' => $entity));
}

}
}
}


52 changes: 52 additions & 0 deletions src/controllers/PermissionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Serverfireteam\Panel;

use Serverfireteam\Panel\CrudController;

class PermissionController extends CrudController {

public function all($entity) {

parent::all($entity);

$this->filter = \DataFilter::source(new Permission());
$this->filter->add('id', 'ID', 'text');
$this->filter->add('name', 'Name', 'text');
$this->filter->submit('search');
$this->filter->reset('reset');
$this->filter->build();

$this->grid = \DataGrid::source($this->filter);
$this->grid->add('id', 'ID', true)->style("width:100px");
$this->grid->add('name', 'Url')->style('width:100px');
$this->grid->add('label', 'Description');

$this->addStylesToGrid();

return $this->returnView();
}

public function edit($entity) {

parent::edit($entity);

$this->edit = \DataEdit::source(new Permission());

$helpMessage = (\Lang::get('panel::fields.roleHelp'));

$this->edit->label('Edit Permission');
$this->edit->link("rapyd-demo/filter", "Articles", "TR")->back();
$this->edit->add('name', 'Url', 'text')->rule('required');
$this->edit->add('label', 'Description', 'text')->rule('required');

$this->edit->saved(function () use ($entity) {
$this->edit->message('Awesome, Data Saved successfully');
$this->edit->link('panel/Permission/all', 'Back');
});

$this->addHelperMessage($helpMessage);

return $this->returnEditView();
}
}
9 changes: 6 additions & 3 deletions src/controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ public function postEdit() {
$inputs = Input::all();
$admin->update($inputs);
$admin->save();
return \View('panelViews::editProfile')->with(array('admin' => $admin,
'message' => \Lang::get('panel::fields.successfullEditProfile'),
'demo_status' => $demo));
return \View('panelViews::editProfile')->with(
array(
'admin' => $admin,
'message' => \Lang::get('panel::fields.successfullEditProfile'),
'demo_status' => $demo)
);
}
}
Loading

0 comments on commit 81edb23

Please sign in to comment.