Automation administration dashboard
* Manual automations * Scheduled automations * Incoming webhook triggers * Domain-event trigger foundation * Ordered automation steps * Queued execution * Run status and execution history * Per-step execution logs * Continue-or-stop-on-failure control * Email actions * Outgoing webhook actions * Application log actions * Delay actions * Secure incoming webhook secrets * Automation trigger and action registries * Extensible action and trigger contracts * Scheduled automation Artisan command * Administration navigation * Automation permissions * Module registration and boot test
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Modules\Automation\Http\Controllers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Automation\Models\Automation;
|
||||
use Modules\Automation\Services\AutomationRunner;
|
||||
final class AutomationApiController extends Controller
|
||||
{
|
||||
public function trigger(Request $request,Automation $automation,AutomationRunner $runner): JsonResponse
|
||||
{
|
||||
abort_unless($automation->trigger_type==='webhook',404); $secret=(string)($automation->trigger_config['secret']??'');
|
||||
if($secret!=='') abort_unless(hash_equals($secret,(string)$request->header('X-Automation-Secret')),401,'Invalid automation secret.');
|
||||
$run=$runner->dispatch($automation,$request->all(),'webhook'); return response()->json(['data'=>['execution_id'=>$run->execution_id,'status'=>$run->status]],202);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Modules\Automation\Http\Controllers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Modules\Automation\Contracts\ActionRegistry;
|
||||
use Modules\Automation\Contracts\TriggerRegistry;
|
||||
use Modules\Automation\Models\Automation;
|
||||
use Modules\Automation\Models\AutomationRun;
|
||||
use Modules\Automation\Services\AutomationRunner;
|
||||
final class AutomationController extends Controller
|
||||
{
|
||||
public function index(TriggerRegistry $triggers,ActionRegistry $actions): View
|
||||
{
|
||||
return view('automation::admin.index',['automations'=>Automation::withCount(['steps','runs'])->latest()->paginate(20),'recentRuns'=>AutomationRun::with('automation')->latest()->limit(15)->get(),'triggers'=>$triggers->all(),'actions'=>$actions->all()]);
|
||||
}
|
||||
public function store(Request $request,TriggerRegistry $triggers): RedirectResponse
|
||||
{
|
||||
$data=$request->validate(['name'=>['required','string','max:255'],'description'=>['nullable','string'],'trigger_type'=>['required','string'],'status'=>['required','in:draft,active,paused'],'next_run_at'=>['nullable','date'],'trigger_config'=>['nullable','json']]);
|
||||
abort_unless($triggers->has($data['trigger_type']),422,'Unknown trigger type.');
|
||||
$data['trigger_config']=filled($data['trigger_config']??null)?json_decode($data['trigger_config'],true,512,JSON_THROW_ON_ERROR):[]; $data['stop_on_failure']=$request->boolean('stop_on_failure'); $data['created_by']=$request->user()->id;
|
||||
Automation::create($data); return back()->with('status','Automation created.');
|
||||
}
|
||||
public function addStep(Request $request,Automation $automation,ActionRegistry $actions): RedirectResponse
|
||||
{
|
||||
$data=$request->validate(['action_type'=>['required','string'],'name'=>['nullable','string','max:255'],'configuration'=>['nullable','json']]);
|
||||
abort_unless(array_key_exists($data['action_type'],$actions->all()),422,'Unknown action type.');
|
||||
$automation->steps()->create(['position'=>(int)$automation->steps()->max('position')+1,'action_type'=>$data['action_type'],'name'=>$data['name']??null,'configuration'=>filled($data['configuration']??null)?json_decode($data['configuration'],true,512,JSON_THROW_ON_ERROR):[],'is_enabled'=>true]);
|
||||
return back()->with('status','Automation step added.');
|
||||
}
|
||||
public function run(Automation $automation,AutomationRunner $runner): RedirectResponse { $run=$runner->dispatch($automation,['initiated_by'=>request()->user()->id],'manual'); return back()->with('status',"Automation queued as {$run->execution_id}."); }
|
||||
public function toggle(Automation $automation): RedirectResponse { $automation->update(['status'=>$automation->status==='active'?'paused':'active']); return back()->with('status','Automation status updated.'); }
|
||||
public function destroy(Automation $automation): RedirectResponse { $automation->delete(); return back()->with('status','Automation deleted.'); }
|
||||
}
|
||||
Reference in New Issue
Block a user