Overview
TheRequestResourceAction class handles the creation of pending resource requests. When users don’t have permission to create resources directly, they can submit a request for admin approval. This action creates the pending request, logs it, and notifies administrators.
This action does not have any constructor dependencies. It can be instantiated directly without dependency injection.
Method Signature
Parameters
The name of the requested resource
The network address of the requested resource
Optional description of the requested resource. Can be
nullWhether the resource should be enabled when created
The user submitting the request
Return Value
Returns the created
PendingResource Eloquent model instance with the following attributes:The auto-generated database ID
The requested resource name
The requested resource address
The requested resource description
Whether the resource should be enabled
The ID of the requesting user
The name of the requesting user
The email of the requesting user
The request status (always
'pending' for new requests)Side Effects
This action performs the following side effects:- Database Insert: Creates a new
PendingResourcerecord with status'pending' - Audit Log: Creates a
ResourceLogentry with action typeRequested - Email Notification: Sends a
ResourceApprovalRequestemail to the admin (if configured)
This action does not interact with the NetBird API. The resource is only created in NetBird after admin approval via
ApproveResourceAction.Example Usage
Email Notification
The action automatically sends an email notification to the administrator configured inconfig('netbird.admin_email'). The email uses the ResourceApprovalRequest mailable to inform the admin of the pending request.
Email notifications are sent asynchronously if your application is configured to use queues. If the email fails to send, the request creation still succeeds.
Request Lifecycle
After creation, the pending request can be:- Approved via
ApproveResourceAction- Creates the resource in NetBird - Denied via
DenyResourceAction- Marks the request as denied - Cancelled via
CancelResourceRequestAction- Deletes the pending request
Error Scenarios
This action has minimal error scenarios since it primarily performs database inserts:- Database errors: Will throw an exception if the database insert fails
- Email errors: Will not prevent the request creation from succeeding (emails are typically queued)
Source Reference
Implementation:/home/daytona/workspace/source/app/Actions/RequestResourceAction.php:19
Email notification helper: /home/daytona/workspace/source/app/Actions/RequestResourceAction.php:50