Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
681aa578
Unverified
Commit
681aa578
authored
Oct 11, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding additional api routes and implementing their api controlleur
parent
b6ce3745
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
3 deletions
+104
-3
PermissionsController.php
Modules/User/Http/Controllers/Api/PermissionsController.php
+26
-0
RoleController.php
Modules/User/Http/Controllers/Api/RoleController.php
+66
-1
apiRoutes.php
Modules/User/Http/apiRoutes.php
+12
-2
No files found.
Modules/User/Http/Controllers/Api/PermissionsController.php
0 → 100644
View file @
681aa578
<?php
namespace
Modules\User\Http\Controllers\Api
;
use
Illuminate\Routing\Controller
;
use
Modules\User\Permissions\PermissionManager
;
class
PermissionsController
extends
Controller
{
/**
* @var PermissionManager
*/
private
$permissionManager
;
public
function
__construct
(
PermissionManager
$permissionManager
)
{
$this
->
permissionManager
=
$permissionManager
;
}
public
function
index
()
{
return
response
()
->
json
([
'permissions'
=>
$this
->
permissionManager
->
all
(),
]);
}
}
Modules/User/Http/Controllers/Api/RoleController.php
View file @
681aa578
...
...
@@ -2,9 +2,14 @@
namespace
Modules\User\Http\Controllers\Api
;
use
Cartalyst\Sentinel\Roles\EloquentRole
;
use
Illuminate\Http\Request
;
use
Illuminate\Routing\Controller
;
use
Modules\User\Http\Requests\CreateRoleRequest
;
use
Modules\User\Http\Requests\UpdateRoleRequest
;
use
Modules\User\Permissions\PermissionManager
;
use
Modules\User\Repositories\RoleRepository
;
use
Modules\User\Transformers\FullRoleTransformer
;
use
Modules\User\Transformers\RoleTransformer
;
class
RoleController
extends
Controller
...
...
@@ -13,14 +18,74 @@ class RoleController extends Controller
* @var RoleRepository
*/
private
$role
;
/**
* @var PermissionManager
*/
private
$permissions
;
public
function
__construct
(
RoleRepository
$role
)
public
function
__construct
(
RoleRepository
$role
,
PermissionManager
$permissions
)
{
$this
->
role
=
$role
;
$this
->
permissions
=
$permissions
;
}
public
function
index
(
Request
$request
)
{
return
RoleTransformer
::
collection
(
$this
->
role
->
serverPaginationFilteringFor
(
$request
));
}
public
function
find
(
EloquentRole
$role
)
{
return
new
FullRoleTransformer
(
$role
->
load
(
'users'
));
}
public
function
findNew
(
EloquentRole
$role
)
{
return
new
FullRoleTransformer
(
$role
);
}
public
function
store
(
CreateRoleRequest
$request
)
{
$data
=
$this
->
mergeRequestWithPermissions
(
$request
);
$this
->
role
->
create
(
$data
);
return
response
()
->
json
([
'errors'
=>
false
,
'message'
=>
trans
(
'user::messages.role created'
),
]);
}
public
function
update
(
EloquentRole
$role
,
UpdateRoleRequest
$request
)
{
$data
=
$this
->
mergeRequestWithPermissions
(
$request
);
$this
->
role
->
update
(
$role
->
id
,
$data
);
return
response
()
->
json
([
'errors'
=>
false
,
'message'
=>
trans
(
'user::messages.role updated'
),
]);
}
public
function
destroy
(
EloquentRole
$role
)
{
$this
->
role
->
delete
(
$role
->
id
);
return
response
()
->
json
([
'errors'
=>
false
,
'message'
=>
trans
(
'user::messages.role deleted'
),
]);
}
/**
* @param Request $request
* @return array
*/
private
function
mergeRequestWithPermissions
(
Request
$request
)
{
$permissions
=
$this
->
permissions
->
clean
(
$request
->
get
(
'permissions'
));
return
array_merge
(
$request
->
all
(),
[
'permissions'
=>
$permissions
]);
}
}
Modules/User/Http/apiRoutes.php
View file @
681aa578
...
...
@@ -18,20 +18,30 @@ $router->group(['prefix' => '/user', 'middleware' => ['api.token', 'auth.admin']
'uses'
=>
'RoleController@store'
,
'middleware'
=>
'token-can:user.roles.create'
,
]);
$router
->
post
(
'roles/{role}'
,
[
$router
->
post
(
'roles/
find/
{role}'
,
[
'as'
=>
'api.user.role.find'
,
'uses'
=>
'RoleController@find'
,
'middleware'
=>
'token-can:user.roles.edit'
,
]);
$router
->
post
(
'roles/find-new'
,
[
'as'
=>
'api.user.role.find-new'
,
'uses'
=>
'RoleController@findNew'
,
'middleware'
=>
'token-can:user.roles.edit'
,
]);
$router
->
post
(
'roles/{role}/edit'
,
[
'as'
=>
'api.user.role.update'
,
'uses'
=>
'RoleController@update'
,
'middleware'
=>
'token-can:user.roles.edit'
,
]);
$router
->
delete
(
'roles/{role}'
,
[
'as'
=>
'api.user.role.destroy'
,
'uses'
=>
'RoleController@destroy'
,
'middleware'
=>
'token-can:user.roles.destroy'
,
]);
$router
->
get
(
'permissions'
,
[
'as'
=>
'api.user.permissions.index'
,
'uses'
=>
'PermissionsController@index'
,
'middleware'
=>
'token-can:user.roles.index'
,
]);
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment