Overview
TheApproveResourceAction class handles the approval of pending resource requests. It creates the resource in NetBird, updates the request status, logs the approval, and sends an email notification to the requester.
Constructor Dependencies
The action is instantiated with the following dependency:Service class for interacting with the NetBird API
Method Signature
Parameters
The pending resource request to approve (Eloquent model instance)
The NetBird group ID to associate the resource with
The admin user approving the request (used for audit logging)
Return Value
Side Effects
This action performs the following side effects:- NetBird API Call: Creates the resource in NetBird via
NetbirdService::createResource()using data from the pending request - Database Insert: Creates a new
Resourcerecord with:netbird_id: The ID returned from NetBirduser_id: The ID of the user who originally requested the resourcecreated_by: The name of the user who originally requested the resource
- Database Update: Updates the
PendingResourcerecord:- Sets
statusto'approved' - Sets
decided_atto the current timestamp
- Sets
- Audit Log: Creates a
ResourceLogentry with action typeApproved - Email Notification: Sends a
ResourceDecisionNotificationemail to the requester (if email is available)
Example Usage
Email Notification
The action automatically sends an email notification to the requester if the pending resource has arequested_email value. The email uses the ResourceDecisionNotification mailable with approved: true.
Email notifications are sent asynchronously if your application is configured to use queues. If the email fails to send, the approval operation still succeeds.
Error Scenarios
The approved resource is associated with the original requester (via
user_id and created_by), not the admin who approved it. The admin’s action is tracked in the audit log.Source Reference
Implementation:/home/daytona/workspace/source/app/Actions/ApproveResourceAction.php:27
Email notification helper: /home/daytona/workspace/source/app/Actions/ApproveResourceAction.php:62