mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
fix migration and api changes
This commit is contained in:
@ -25,11 +25,6 @@ class MailSender extends Model
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function setSettingsAttribute($value)
|
||||
{
|
||||
$this->attributes['settings'] = json_encode($value);
|
||||
}
|
||||
|
||||
public function scopeWhereOrder($query, $orderByField, $orderBy)
|
||||
{
|
||||
$query->orderBy($orderByField, $orderBy);
|
||||
|
||||
@ -32,62 +32,54 @@ class CreateMailSendersTable extends Migration
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
$users = User::where('role', 'super admin')->get();
|
||||
|
||||
if ($user) {
|
||||
$users = User::where('role', 'super admin')->get();
|
||||
foreach ($users as $user) {
|
||||
BouncerFacade::allow($user)->toManage(MailSender::class);
|
||||
}
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user->allow('view-mail-sender');
|
||||
$user->allow('create-mail-sender');
|
||||
$user->allow('edit-mail-sender');
|
||||
$user->allow('delete-mail-sender');
|
||||
BouncerFacade::allow($user)->toOwn(MailSender::class);
|
||||
$companies = Company::all();
|
||||
|
||||
$companies->map(function ($company) {
|
||||
if (env('MAIL_DRIVER') == 'smtp') {
|
||||
$settings = [
|
||||
'MAIL_HOST' => env('MAIL_HOST'),
|
||||
'MAIL_PORT' => env('MAIL_PORT'),
|
||||
'MAIL_USERNAME' => env('MAIL_USERNAME'),
|
||||
'MAIL_PASSWORD' => env('MAIL_PASSWORD'),
|
||||
'MAIL_ENCRYPTION' => env('MAIL_ENCRYPTION')
|
||||
];
|
||||
$this->createSender($settings, $company->id);
|
||||
}
|
||||
|
||||
$companies = Company::all();
|
||||
if (env('MAIL_DRIVER') == 'mail' || env('MAIL_DRIVER') == 'sendmail') {
|
||||
$this->createSender(null, $company->id);
|
||||
}
|
||||
|
||||
$companies->map(function ($company) {
|
||||
if (env('MAIL_DRIVER') == 'smtp') {
|
||||
$settings = [
|
||||
'MAIL_HOST' => env('MAIL_HOST'),
|
||||
'MAIL_PORT' => env('MAIL_PORT'),
|
||||
'MAIL_USERNAME' => env('MAIL_USERNAME'),
|
||||
'MAIL_PASSWORD' => env('MAIL_PASSWORD'),
|
||||
'MAIL_ENCRYPTION' => env('MAIL_ENCRYPTION')
|
||||
];
|
||||
$this->insertData($settings, $company->id);
|
||||
}
|
||||
if (env('MAIL_DRIVER') == 'mailgun') {
|
||||
$settings = [
|
||||
'MAILGUN_DOMAIN' => env('MAILGUN_DOMAIN'),
|
||||
'MAILGUN_SECRET' => env('MAILGUN_SECRET'),
|
||||
'MAILGUN_ENDPOINT' => env('MAILGUN_ENDPOINT'),
|
||||
];
|
||||
$this->createSender($settings, $company->id);
|
||||
}
|
||||
|
||||
if (env('MAIL_DRIVER') == 'mail' || env('MAIL_DRIVER') == 'sendmail') {
|
||||
$this->insertData(null, $company->id);
|
||||
}
|
||||
|
||||
if (env('MAIL_DRIVER') == 'mailgun') {
|
||||
$settings = [
|
||||
'MAILGUN_DOMAIN' => env('MAILGUN_DOMAIN'),
|
||||
'MAILGUN_SECRET' => env('MAILGUN_SECRET'),
|
||||
'MAILGUN_ENDPOINT' => env('MAILGUN_ENDPOINT'),
|
||||
];
|
||||
$this->insertData($settings, $company->id);
|
||||
}
|
||||
|
||||
if (env('MAIL_DRIVER') == 'ses') {
|
||||
$settings = [
|
||||
'MAIL_HOST' => env('MAIL_HOST'),
|
||||
'MAIL_PORT' => env('MAIL_PORT'),
|
||||
'MAIL_ENCRYPTION' => env('MAIL_ENCRYPTION'),
|
||||
'MAILGUN_DOMAIN' => env('MAILGUN_DOMAIN'),
|
||||
'SES_KEY' => env('SES_KEY'),
|
||||
'SES_SECRET' => env('SES_SECRET'),
|
||||
];
|
||||
$this->insertData($settings, $company->id);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (env('MAIL_DRIVER') == 'ses') {
|
||||
$settings = [
|
||||
'MAIL_HOST' => env('MAIL_HOST'),
|
||||
'MAIL_PORT' => env('MAIL_PORT'),
|
||||
'MAIL_ENCRYPTION' => env('MAIL_ENCRYPTION'),
|
||||
'MAILGUN_DOMAIN' => env('MAILGUN_DOMAIN'),
|
||||
'SES_KEY' => env('SES_KEY'),
|
||||
'SES_SECRET' => env('SES_SECRET'),
|
||||
];
|
||||
$this->createSender($settings, $company->id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function insertData($settings, $company_id)
|
||||
public function createSender($settings, $company_id)
|
||||
{
|
||||
$data = [
|
||||
'name' => env('MAIL_DRIVER'),
|
||||
|
||||
@ -68,7 +68,7 @@ export const useMailSenderStore = (useWindow = false) => {
|
||||
fetchMailSenders(params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/mail-sender`, { params })
|
||||
.get(`/api/v1/mail-senders`, { params })
|
||||
.then((response) => {
|
||||
this.mailSenders = response.data.data
|
||||
resolve(response)
|
||||
@ -83,7 +83,7 @@ export const useMailSenderStore = (useWindow = false) => {
|
||||
fetchMailSender(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/mail-sender/${id}`)
|
||||
.get(`/api/v1/mail-senders/${id}`)
|
||||
.then((response) => {
|
||||
this.currentMailSender = response.data.data
|
||||
if (response.data.data.settings) {
|
||||
@ -116,7 +116,7 @@ export const useMailSenderStore = (useWindow = false) => {
|
||||
const notificationStore = useNotificationStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post('/api/v1/mail-sender', data)
|
||||
.post('/api/v1/mail-senders', data)
|
||||
.then((response) => {
|
||||
this.mailSenders.push(response.data.data)
|
||||
notificationStore.showNotification({
|
||||
@ -136,7 +136,7 @@ export const useMailSenderStore = (useWindow = false) => {
|
||||
const notificationStore = useNotificationStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.put(`/api/v1/mail-sender/${data.id}`, data)
|
||||
.put(`/api/v1/mail-senders/${data.id}`, data)
|
||||
.then((response) => {
|
||||
if (response.data) {
|
||||
let pos = this.mailSenders.findIndex(
|
||||
@ -160,7 +160,7 @@ export const useMailSenderStore = (useWindow = false) => {
|
||||
deleteMailSender(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.delete(`/api/v1/mail-sender/${id}`)
|
||||
.delete(`/api/v1/mail-senders/${id}`)
|
||||
.then((response) => {
|
||||
if (response.data.success) {
|
||||
let index = this.mailSenders.findIndex(
|
||||
|
||||
@ -403,14 +403,12 @@ Route::prefix('/v1')->group(function () {
|
||||
// Mails
|
||||
//----------------------------------
|
||||
|
||||
Route::apiResource('mail-sender', MailSenderController::class);
|
||||
Route::apiResource('mail-senders', MailSenderController::class);
|
||||
|
||||
Route::get('/mail-drivers', [MailConfigurationController::class, 'getMailDrivers']);
|
||||
|
||||
Route::post('/mail-test', [MailConfigurationController::class, 'TestMailDriver']);
|
||||
|
||||
Route::get('mail-senders', GetAllMailSendersController::class);
|
||||
|
||||
Route::get('/company/mail/config', GetCompanyMailConfigurationController::class);
|
||||
|
||||
Route::apiResource('notes', NotesController::class);
|
||||
|
||||
Reference in New Issue
Block a user