mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add email history tracking
This commit is contained in:
parent
e1e99cbd9e
commit
88423df8cb
65
app/Http/Controllers/EmailHistoryController.php
Normal file
65
app/Http/Controllers/EmailHistoryController.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Quote;
|
||||
use App\Models\Client;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\SystemLog;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Http\Requests\Email\ClientEmailHistoryRequest;
|
||||
use App\Http\Requests\Email\EntityEmailHistoryRequest;
|
||||
|
||||
class EmailHistoryController extends BaseController
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function clientHistory(ClientEmailHistoryRequest $request, Client $client)
|
||||
{
|
||||
$data = SystemLog::where('client_id', $client->id)
|
||||
->where('category_id', SystemLog::CATEGORY_MAIL)
|
||||
->orderBy('id','DESC')
|
||||
->map(function ($system_log){
|
||||
if($system_log->log['history'] ?? false) {
|
||||
return json_decode($system_log->log['history'], true);
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json($data, 200);
|
||||
|
||||
}
|
||||
|
||||
public function entityHistory(EntityEmailHistoryRequest $request)
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$data = SystemLog::where('company_id', $user->company()->id)
|
||||
->where('category_id', SystemLog::CATEGORY_MAIL)
|
||||
->whereJsonContains('log->history->entity_id', $this->encodePrimaryKey($request->entity_id))
|
||||
->orderBy('id', 'DESC')
|
||||
->map(function ($system_log) {
|
||||
if($system_log->log['history'] ?? false) {
|
||||
return json_decode($system_log->log['history'], true);
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json($data, 200);
|
||||
|
||||
}
|
||||
}
|
55
app/Http/Requests/Email/ClientEmailHistoryRequest.php
Normal file
55
app/Http/Requests/Email/ClientEmailHistoryRequest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\Email;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ClientEmailHistoryRequest extends Request
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
private string $error_message = '';
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user->can('view', $this->client);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
public function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
}
|
62
app/Http/Requests/Email/EntityEmailHistoryRequest.php
Normal file
62
app/Http/Requests/Email/EntityEmailHistoryRequest.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\Email;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class EntityEmailHistoryRequest extends Request
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
private string $error_message = '';
|
||||
private string $entity_plural = '';
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
//handle authorization in controller
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return [
|
||||
'entity' => 'bail|required|string|in:invoice,quote,credit,recurring_invoice,purchase_order',
|
||||
'entity_id' => ['bail','required',Rule::exists($this->entity_plural, 'id')->where('company_id', $user->company()->id)],
|
||||
];
|
||||
}
|
||||
|
||||
public function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
$this->entity_plural = Str::plural($input['entity']) ?? '';
|
||||
$input['entity_id'] = $this->decodePrimaryKey($input['entity_id']);
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
}
|
@ -58,6 +58,7 @@ use App\Http\Controllers\TaskStatusController;
|
||||
use App\Http\Controllers\Bank\YodleeController;
|
||||
use App\Http\Controllers\CompanyUserController;
|
||||
use App\Http\Controllers\PaymentTermController;
|
||||
use App\Http\Controllers\EmailHistoryController;
|
||||
use App\Http\Controllers\GroupSettingController;
|
||||
use App\Http\Controllers\OneTimeTokenController;
|
||||
use App\Http\Controllers\SubscriptionController;
|
||||
@ -202,6 +203,8 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale']
|
||||
Route::post('documents/bulk', [DocumentController::class, 'bulk'])->name('documents.bulk');
|
||||
|
||||
Route::post('emails', [EmailController::class, 'send'])->name('email.send')->middleware('user_verified');
|
||||
Route::post('emails/clientHistory/{client}', [EmailHistoryController::class, 'clientHistory'])->name('email.clientHistory');
|
||||
Route::post('emails/entityHistory', [EmailHistoryController::class, 'entityHistory'])->name('email.entityHistory');
|
||||
|
||||
Route::resource('expenses', ExpenseController::class); // name = (expenses. index / create / show / update / destroy / edit
|
||||
Route::put('expenses/{expense}/upload', [ExpenseController::class, 'upload']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user