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