|
2 | 2 |
|
3 | 3 | namespace ProcessMaker\Http\Controllers\Api; |
4 | 4 |
|
| 5 | +use Illuminate\Database\Eloquent\ModelNotFoundException; |
5 | 6 | use Illuminate\Http\Request; |
| 7 | +use Illuminate\Support\Facades\Notification; |
6 | 8 | use Illuminate\Validation\Rule; |
7 | 9 | use ProcessMaker\Exception\ValidationException; |
8 | 10 | use ProcessMaker\Http\Controllers\Controller; |
9 | 11 | use ProcessMaker\Http\Resources\ApiCollection; |
10 | 12 | use ProcessMaker\Jobs\DevLinkInstall; |
11 | 13 | use ProcessMaker\Models\Bundle; |
12 | 14 | use ProcessMaker\Models\BundleAsset; |
| 15 | +use ProcessMaker\Models\BundleInstance; |
13 | 16 | use ProcessMaker\Models\BundleSetting; |
14 | 17 | use ProcessMaker\Models\DevLink; |
15 | 18 | use ProcessMaker\Models\Setting; |
| 19 | +use ProcessMaker\Models\User; |
| 20 | +use ProcessMaker\Notifications\BundleUpdatedNotification; |
16 | 21 |
|
17 | 22 | class DevLinkController extends Controller |
18 | 23 | { |
@@ -154,12 +159,34 @@ public function updateBundle(Request $request, Bundle $bundle) |
154 | 159 |
|
155 | 160 | public function increaseBundleVersion(Bundle $bundle) |
156 | 161 | { |
| 162 | + $bundle->notifyBundleUpdated(); |
| 163 | + |
157 | 164 | $bundle->version = $bundle->version + 1; |
158 | 165 | $bundle->saveOrFail(); |
159 | 166 |
|
160 | 167 | return $bundle; |
161 | 168 | } |
162 | 169 |
|
| 170 | + public function bundleUpdated($bundleId, $token) |
| 171 | + { |
| 172 | + try { |
| 173 | + $bundle = Bundle::where('remote_id', $bundleId)->firstOrFail(); |
| 174 | + } catch (ModelNotFoundException $e) { |
| 175 | + return response()->json(['error' => 'Bundle not found'], 403); |
| 176 | + } |
| 177 | + |
| 178 | + $storedToken = $bundle->webhook_token; |
| 179 | + |
| 180 | + if ($token !== $storedToken) { |
| 181 | + return response()->json(['error' => 'Invalid token'], 403); |
| 182 | + } |
| 183 | + $adminUsers = User::where('is_administrator', true)->get(); |
| 184 | + |
| 185 | + Notification::send($adminUsers, new BundleUpdatedNotification($bundle)); |
| 186 | + |
| 187 | + return $bundle; |
| 188 | + } |
| 189 | + |
163 | 190 | public function deleteBundle(Bundle $bundle) |
164 | 191 | { |
165 | 192 | $bundle->delete(); |
@@ -198,6 +225,14 @@ public function reinstallBundle(Request $request, Bundle $bundle) |
198 | 225 | ]; |
199 | 226 | } |
200 | 227 |
|
| 228 | + public function addBundleInstance(Request $request, Bundle $bundle) |
| 229 | + { |
| 230 | + BundleInstance::create([ |
| 231 | + 'bundle_id' => $bundle->id, |
| 232 | + 'instance_url' => $request->input('instance_url'), |
| 233 | + ]); |
| 234 | + } |
| 235 | + |
201 | 236 | public function exportLocalBundle(Bundle $bundle) |
202 | 237 | { |
203 | 238 | return ['payloads' => $bundle->export()]; |
|
0 commit comments