Skip to content

Commit 214c3ad

Browse files
committed
Added Role and Perm CRUD with events.
Need to add tests now and then most of the functionalities are done. Little bit of tweaking on dashboard is also pending.
1 parent 9967ee0 commit 214c3ad

22 files changed

+703
-5
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateTokensTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('tokens', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->string('token', 20);
19+
$table->string('type', 100)->default('user_activation');
20+
$table->unsignedInteger('user_id');
21+
$table->timestamp('created_at')->nullable();
22+
$table->timestamp('expiry_at')->nullable();
23+
24+
$table->foreign('user_id')->references('id')->on('users')
25+
->onUpdate('cascade')->onDelete('cascade');
26+
});
27+
}
28+
29+
/**
30+
* Reverse the migrations.
31+
*
32+
* @return void
33+
*/
34+
public function down()
35+
{
36+
Schema::dropIfExists('tokens');
37+
}
38+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
@extends('inferno-foundation::html')
2+
@section('title', 'Manage permissions')
3+
4+
@section('breadcrumb')
5+
<section class="content-header">
6+
<h1>Manage permissions<small>Manage permissions of the application</small></h1>
7+
<ol class="breadcrumb">
8+
<li><a href="{{route('home')}}"><i class="fa fa-dashboard"></i> Home</a></li>
9+
<li class="active">Permissions</li>
10+
</ol>
11+
</section>
12+
@endsection
13+
14+
@section('content')
15+
<div class="row">
16+
<div class="col-sm-8">
17+
{{--Box--}}
18+
<div class="box box-primary">
19+
<div class="box-header with-border">
20+
<h3 class="box-title">Permissions</h3>
21+
</div>
22+
<!-- /.box-header -->
23+
<div class="box-body">
24+
<table class="table table-bordered table-striped table-hover">
25+
<thead>
26+
<tr>
27+
<td>#</td>
28+
<td>Name</td>
29+
<td></td>
30+
</tr>
31+
</thead>
32+
<tbody>
33+
@foreach($permissions as $permission)
34+
<tr>
35+
<td>{{$permission->id}}</td>
36+
<td>{{ucwords($permission->name)}}</td>
37+
<td class="col-sm-3">
38+
<div class="pull-left">
39+
<a href="{{route('edit-permission', $permission->id)}}" class="btn btn-primary btn-xs">
40+
<i class="fa fa-edit"></i> Edit
41+
</a>
42+
</div>
43+
<div class="pull-left gap-left gap-10">
44+
<confirm-modal
45+
btn-text='<i class="fa fa-trash"></i> Delete'
46+
btn-class="btn-danger"
47+
url="{{url('api/v1/delete-permission')}}"
48+
:post-data="{{json_encode(['id' => $permission->id])}}"
49+
:refresh="true"
50+
message="Are you sure you want to delete role {{$permission->name}}?">
51+
</confirm-modal>
52+
</div>
53+
</td>
54+
</tr>
55+
@endforeach
56+
</tbody>
57+
</table>
58+
59+
{{$permissions->render()}}
60+
</div>
61+
<!-- /.box-body -->
62+
</div>
63+
{{--End box--}}
64+
</div>
65+
66+
<div class="col-sm-4">
67+
{{--Box--}}
68+
<div class="box box-primary">
69+
<div class="box-header with-border">
70+
<h3 class="box-title">Add a new Permission</h3>
71+
</div>
72+
<form action="{{route('save-permission')}}" method="post" id="perm-save-form">
73+
<!-- /.box-header -->
74+
<div class="box-body">
75+
{{csrf_field()}}
76+
<div class="form-group">
77+
<label for="">Name:</label>
78+
<input type="text"
79+
placeholder="Enter permission name"
80+
name="name"
81+
value="{{old('name')}}"
82+
class="form-control">
83+
<div class="HelpText error">{{$errors->first('name')}}</div>
84+
</div>
85+
</div>
86+
<!-- /.box-body -->
87+
88+
<div class="box-footer">
89+
<button type="submit" class="btn btn-success">Submit</button>
90+
</div>
91+
</form>
92+
</div>
93+
{{--End box--}}
94+
</div>
95+
</div>
96+
@endsection

resources/views/manage-roles.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<td>{{$role->id}}</td>
3737
<td>{{ucwords($role->name)}}</td>
3838
<td class="col-sm-3">
39-
@if($role->id != 1 && $role->id != 2)
39+
@if($role->name != 'admin' && $role->name != 'auth user')
4040
<div class="pull-left">
4141
<a href="{{route('edit-role', $role->id)}}" class="btn btn-primary btn-xs">
4242
<i class="fa fa-edit"></i> Edit

resources/views/partials/sidebar.blade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
</li>
3636
@stack('sidebar-links')
3737

38+
@role('admin')
3839
<li class="{{ Request::is('admin/*') ? 'active' : '' }} treeview">
3940
<a href="#">
4041
<i class="fa fa-user"></i> <span>Administration</span>
@@ -46,8 +47,12 @@
4647
<li class="{{ Request::is('admin/user/roles') ? 'active' : '' }}">
4748
<a href="{{route('manage-roles')}}"><i class="fa fa-circle-o"></i> Manage Roles</a>
4849
</li>
50+
<li class="{{ Request::is('admin/user/permissions') ? 'active' : '' }}">
51+
<a href="{{route('manage-permissions')}}"><i class="fa fa-circle-o"></i> Manage Permissions</a>
52+
</li>
4953
</ul>
5054
</li>
55+
@endrole
5156

5257
<li class="{{ Request::is('activities') ? 'active' : '' }} treeview">
5358
<a href="{{route('user-activities')}}"><i class="fa fa-line-chart"></i><span>My activities</span></a>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@extends('inferno-foundation::html')
2+
@section('title', 'Edit permission')
3+
4+
@section('breadcrumb')
5+
<section class="content-header">
6+
<h1>Edit permission<small></small></h1>
7+
<ol class="breadcrumb">
8+
<li><a href="{{route('home')}}"><i class="fa fa-dashboard"></i> Home</a></li>
9+
<li><a href="{{route('manage-permissions')}}"><i class="fa fa-user"></i> Permissions</a></li>
10+
<li class="active">Edit permission</li>
11+
</ol>
12+
</section>
13+
@endsection
14+
15+
@section('content')
16+
<div class="row">
17+
<div class="col-sm-6">
18+
{{--Box--}}
19+
<div class="box box-primary">
20+
<div class="box-header with-border">
21+
<h3 class="box-title">Edit role "{{ucwords($permission->name)}}"</h3>
22+
</div>
23+
<!-- /.box-header -->
24+
<div class="box-body">
25+
<form action="{{route('update-permission')}}" method="post" id="update-role-form">
26+
{{csrf_field()}}
27+
28+
<input type="hidden" name="id" value="{{$permission->id}}">
29+
30+
<div class="form-group">
31+
<label for="">Name</label>
32+
<input type="text"
33+
name="name"
34+
class="form-control"
35+
value="{{ucwords($permission->name)}}"
36+
placeholder="Enter permission name">
37+
<div class="HelpText error">{{$errors->first('name')}}</div>
38+
</div>
39+
40+
<div class="form-group">
41+
<button class="btn btn-success">
42+
<i class="fa fa-save"></i> Save
43+
</button>
44+
</div>
45+
</form>
46+
</div>
47+
<!-- /.box-body -->
48+
</div>
49+
{{--End box--}}
50+
</div>
51+
52+
<div class="col-sm-4">
53+
54+
</div>
55+
</div>
56+
@endsection

resources/views/role-edit.blade.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@extends('inferno-foundation::html')
2+
@section('title', 'Edit role')
3+
4+
@section('breadcrumb')
5+
<section class="content-header">
6+
<h1>Edit role<small></small></h1>
7+
<ol class="breadcrumb">
8+
<li><a href="{{route('home')}}"><i class="fa fa-dashboard"></i> Home</a></li>
9+
<li><a href="{{route('manage-roles')}}"><i class="fa fa-user"></i> Role</a></li>
10+
<li class="active">Edit role</li>
11+
</ol>
12+
</section>
13+
@endsection
14+
15+
@section('content')
16+
<div class="row">
17+
<div class="col-sm-6">
18+
{{--Box--}}
19+
<div class="box box-primary">
20+
<div class="box-header with-border">
21+
<h3 class="box-title">Edit role "{{ucwords($role->name)}}"</h3>
22+
</div>
23+
<!-- /.box-header -->
24+
<div class="box-body">
25+
<form action="{{route('update-role')}}" method="post" id="update-role-form">
26+
{{csrf_field()}}
27+
28+
<input type="hidden" name="id" value="{{$role->id}}">
29+
30+
<div class="form-group">
31+
<label for="">Name</label>
32+
<input type="text"
33+
name="name"
34+
class="form-control"
35+
value="{{ucwords($role->name)}}"
36+
placeholder="Enter role name">
37+
<div class="HelpText error">{{$errors->first('name')}}</div>
38+
</div>
39+
40+
<div class="form-group">
41+
<button class="btn btn-success">
42+
<i class="fa fa-save"></i> Save
43+
</button>
44+
</div>
45+
</form>
46+
</div>
47+
<!-- /.box-body -->
48+
</div>
49+
{{--End box--}}
50+
</div>
51+
52+
<div class="col-sm-4">
53+
54+
</div>
55+
</div>
56+
@endsection
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Inferno\Foundation\Events\Permissions;
4+
5+
use Spatie\Permission\Models\Permission;
6+
7+
class PermissionCreated
8+
{
9+
10+
/**
11+
* PermissionCreated constructor.
12+
*/
13+
public function __construct(Permission $permission)
14+
{
15+
$this->permission = $permission;
16+
}
17+
18+
public function getName()
19+
{
20+
return $this->permission->name;
21+
}
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Inferno\Foundation\Events\Permissions;
4+
5+
use Spatie\Permission\Models\Permission;
6+
7+
class PermissionDeleted
8+
{
9+
private $permission;
10+
11+
/**
12+
* PermissionDeleted constructor.
13+
*/
14+
public function __construct(Permission $permission)
15+
{
16+
$this->permission = $permission;
17+
}
18+
19+
public function getName()
20+
{
21+
return $this->permission->name;
22+
}
23+
}

src/Events/Roles/RoleCreated.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Inferno\Foundation\Events\Roles;
4+
5+
use Spatie\Permission\Models\Role;
6+
7+
class RoleCreated
8+
{
9+
private $role;
10+
11+
/**
12+
* RoleCreated constructor.
13+
*/
14+
public function __construct(Role $role)
15+
{
16+
$this->role = $role;
17+
}
18+
19+
public function getName()
20+
{
21+
return $this->role->name;
22+
}
23+
}

src/Events/Roles/RoleDeleted.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Inferno\Foundation\Events\Roles;
4+
5+
use Spatie\Permission\Models\Role;
6+
7+
class RoleDeleted
8+
{
9+
private $role;
10+
11+
/**
12+
* RoleDeleted constructor.
13+
*/
14+
public function __construct(Role $role)
15+
{
16+
$this->role = $role;
17+
}
18+
19+
public function getName()
20+
{
21+
return $this->role->name;
22+
}
23+
}

src/Events/User/Deleted.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Inferno\Foundation\Events\User;
4+
5+
use App\User;
6+
7+
class Deleted
8+
{
9+
private $user;
10+
11+
function __construct(User $user)
12+
{
13+
$this->user = $user;
14+
}
15+
16+
public function getName()
17+
{
18+
return $this->user->name;
19+
}
20+
}

0 commit comments

Comments
 (0)