Merge pull request #5696 from turbo124/v5-develop

Fixes for resolve user / company
This commit is contained in:
David Bomba 2021-05-14 07:52:17 +10:00 committed by GitHub
commit c2316df642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 20 deletions

View File

@ -453,18 +453,16 @@ class CompanyExport implements ShouldQueue
Storage::disk(config('filesystems.default'))->put($path.$file_name, $tempStream); Storage::disk(config('filesystems.default'))->put($path.$file_name, $tempStream);
// fclose($fp); // fclose($fp);
nlog(Storage::disk(config('filesystems.default'))->url($path.$file_name));
fclose($tempStream); fclose($tempStream);
// $nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
// $nmo->mailable = new DownloadBackup(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company); $nmo->mailable = new DownloadBackup(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company);
// $nmo->to_user = $this->user; $nmo->to_user = $this->user;
// $nmo->settings = $this->company->settings; $nmo->company = $this->company;
// $nmo->company = $this->company; $nmo->settings = $this->company->settings;
// NinjaMailerJob::dispatch($nmo);
NinjaMailerJob::dispatch($nmo);
UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1)); UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1));
} }

View File

@ -21,6 +21,7 @@ use App\Libraries\Google\Google;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Mail\TemplateEmail; use App\Mail\TemplateEmail;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\Company;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Payment; use App\Models\Payment;
use App\Models\SystemLog; use App\Models\SystemLog;
@ -72,6 +73,8 @@ class NinjaMailerJob implements ShouldQueue
/*Set the correct database*/ /*Set the correct database*/
MultiDB::setDb($this->nmo->company->db); MultiDB::setDb($this->nmo->company->db);
$company = Company::where('company_key', $this->nmo->company->company_key)->first();
/* Set the email driver */ /* Set the email driver */
$this->setMailDriver(); $this->setMailDriver();
@ -86,7 +89,7 @@ class NinjaMailerJob implements ShouldQueue
} }
else { else {
$this->nmo->mailable->replyTo($this->nmo->company->owner()->email, $this->nmo->company->owner()->present()->name()); $this->nmo->mailable->replyTo($company->owner()->email, $company->owner()->present()->name());
} }

View File

@ -27,14 +27,17 @@ class DownloadBackup extends Mailable
*/ */
public function build() public function build()
{ {
$company = Company::where('company_key', $this->company->company_key)->first();
return $this->from(config('mail.from.address'), config('mail.from.name')) return $this->from(config('mail.from.address'), config('mail.from.name'))
->subject(ctrans('texts.download_backup_subject')) ->subject(ctrans('texts.download_backup_subject'))
->markdown( ->markdown(
'email.admin.download_files', 'email.admin.download_files',
[ [
'url' => $this->file_path, 'url' => $this->file_path,
'logo' => $this->company->present()->logo, 'logo' => $company->present()->logo,
'whitelabel' => $this->company->account->isPaid() ? true : false, 'whitelabel' => $company->account->isPaid() ? true : false,
'settings' => $company->settings
] ]
); );
} }

View File

@ -432,12 +432,8 @@ class Company extends BaseModel
} }
public function owner() public function owner()
{nlog("in owner"); {
$c = $this->company_users->where('is_owner', true)->first(); return $this->company_users->where('is_owner', true)->first()->user;
nlog($c);
return User::find($c->user_id);
} }
public function resolveRouteBinding($value, $field = null) public function resolveRouteBinding($value, $field = null)

View File

@ -170,12 +170,10 @@ class User extends Authenticatable implements MustVerifyEmail
public function getCompany() public function getCompany()
{ {
if ($this->company) { if ($this->company) {
nlog("company Found");
return $this->company; return $this->company;
} }
if (request()->header('X-API-TOKEN')) { if (request()->header('X-API-TOKEN')) {
nlog("no company - using token to resolve");
$company_token = CompanyToken::with(['company'])->whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first(); $company_token = CompanyToken::with(['company'])->whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first();
return $company_token->company; return $company_token->company;