Skip to content

Commit 0b9074d

Browse files
authored
Merge pull request #13 from nextdeveloper-nl/dev
Generic policies created for CRUD operations
2 parents a13b02c + 29d3b14 commit 0b9074d

18 files changed

Lines changed: 101 additions & 4 deletions

config/model-binding.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,21 @@
5353
return NextDeveloper\Support\Database\Models\SupportTicketComment::findByRef($value);
5454
},
5555

56+
'supportticket' => function ($value) {
57+
return NextDeveloper\Support\Database\Models\SupportTicket::findByRef($value);
58+
},
59+
60+
'supportticketaudit' => function ($value) {
61+
return NextDeveloper\Support\Database\Models\SupportTicketAudit::findByRef($value);
62+
},
63+
64+
'supporttest' => function ($value) {
65+
return NextDeveloper\Support\Database\Models\SupportTest::findByRef($value);
66+
},
67+
68+
'supportticketcomment' => function ($value) {
69+
return NextDeveloper\Support\Database\Models\SupportTicketComment::findByRef($value);
70+
},
71+
5672
// EDIT AFTER HERE - WARNING: ABOVE THIS LINE MAY BE REGENERATED AND YOU MAY LOSE CODE
5773
];

src/Database/Filters/TestsQueryFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ public function commonActionId($value)
8383

8484
// EDIT AFTER HERE - WARNING: ABOVE THIS LINE MAY BE REGENERATED AND YOU MAY LOSE CODE
8585

86+
8687
}

src/Database/Filters/TicketAuditsQueryFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,5 @@ public function iamUserId($value)
7777

7878
// EDIT AFTER HERE - WARNING: ABOVE THIS LINE MAY BE REGENERATED AND YOU MAY LOSE CODE
7979

80+
8081
}

src/Database/Filters/TicketCommentsQueryFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ public function supportTicketId($value)
8383
// EDIT AFTER HERE - WARNING: ABOVE THIS LINE MAY BE REGENERATED AND YOU MAY LOSE CODE
8484

8585

86+
8687
}

src/Database/Filters/TicketsQueryFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,5 @@ public function iamUserId($value)
144144

145145
// EDIT AFTER HERE - WARNING: ABOVE THIS LINE MAY BE REGENERATED AND YOU MAY LOSE CODE
146146

147+
147148
}

src/Database/Models/Tests.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,5 @@ public static function registerScopes()
146146

147147

148148

149+
149150
}

src/Database/Models/TicketAudits.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,5 @@ public static function registerScopes()
136136

137137

138138

139+
139140
}

src/Database/Models/TicketComments.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,5 @@ public static function registerScopes()
137137
// EDIT AFTER HERE - WARNING: ABOVE THIS LINE MAY BE REGENERATED AND YOU MAY LOSE CODE
138138

139139

140+
140141
}

src/Database/Models/Tickets.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,5 @@ public static function registerScopes()
160160

161161

162162

163+
163164
}

src/Database/Observers/TestsObserver.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Facades\Auth;
77
use NextDeveloper\Commons\Exceptions\NotAllowedException;
88
use NextDeveloper\IAM\Helpers\UserHelper;
9+
use NextDeveloper\Events\Services\Events;
910

1011
/**
1112
* Class TestsObserver
@@ -35,6 +36,8 @@ public function creating(Model $model)
3536
!UserHelper::can('create', $model),
3637
new NotAllowedException('You are not allowed to create this record')
3738
);
39+
40+
Events::fire('creating:NextDeveloper\Support\Tests', $model);
3841
}
3942

4043
/**
@@ -44,6 +47,7 @@ public function creating(Model $model)
4447
*/
4548
public function created(Model $model)
4649
{
50+
Events::fire('created:NextDeveloper\Support\Tests', $model);
4751
}
4852

4953
/**
@@ -54,9 +58,11 @@ public function created(Model $model)
5458
public function saving(Model $model)
5559
{
5660
throw_if(
57-
!UserHelper::can('update', $model),
61+
!UserHelper::can('save', $model),
5862
new NotAllowedException('You are not allowed to save this record')
5963
);
64+
65+
Events::fire('saving:NextDeveloper\Support\Tests', $model);
6066
}
6167

6268
/**
@@ -66,6 +72,7 @@ public function saving(Model $model)
6672
*/
6773
public function saved(Model $model)
6874
{
75+
Events::fire('saved:NextDeveloper\Support\Tests', $model);
6976
}
7077

7178

@@ -78,6 +85,8 @@ public function updating(Model $model)
7885
!UserHelper::can('update', $model),
7986
new NotAllowedException('You are not allowed to update this record')
8087
);
88+
89+
Events::fire('updating:NextDeveloper\Support\Tests', $model);
8190
}
8291

8392
/**
@@ -87,6 +96,7 @@ public function updating(Model $model)
8796
*/
8897
public function updated(Model $model)
8998
{
99+
Events::fire('updated:NextDeveloper\Support\Tests', $model);
90100
}
91101

92102

@@ -99,6 +109,8 @@ public function deleting(Model $model)
99109
!UserHelper::can('delete', $model),
100110
new NotAllowedException('You are not allowed to delete this record')
101111
);
112+
113+
Events::fire('deleting:NextDeveloper\Support\Tests', $model);
102114
}
103115

104116
/**
@@ -108,6 +120,7 @@ public function deleting(Model $model)
108120
*/
109121
public function deleted(Model $model)
110122
{
123+
Events::fire('deleted:NextDeveloper\Support\Tests', $model);
111124
}
112125

113126
/**
@@ -121,6 +134,8 @@ public function restoring(Model $model)
121134
!UserHelper::can('restore', $model),
122135
new NotAllowedException('You are not allowed to restore this record')
123136
);
137+
138+
Events::fire('restoring:NextDeveloper\Support\Tests', $model);
124139
}
125140

126141
/**
@@ -130,6 +145,7 @@ public function restoring(Model $model)
130145
*/
131146
public function restored(Model $model)
132147
{
148+
Events::fire('restored:NextDeveloper\Support\Tests', $model);
133149
}
134150
// EDIT AFTER HERE - WARNING: ABOVE THIS LINE MAY BE REGENERATED AND YOU MAY LOSE CODE
135151
}

0 commit comments

Comments
 (0)