/** * Method to add a note to a ticket. * * @param int $ticketID * @param string $token * * @return \Illuminate\Http\Response */ public function addNote($ticketID, $token) { $submittor = false; $ticket = Ticket::find($ticketID); $AshAuthorisedBy = Request::get('AshAuthorisedBy'); if ($AshAuthorisedBy == 'TokenIP') { $account = Account::find($ticket->ip_contact_account_ip); $submittor = trans('ash.basic.ip') . ' ' . trans('ash.communication.contact'); } if ($AshAuthorisedBy == 'TokenDomain') { $account = Account::find($ticket->domain_contact_account_id); $submittor = trans('ash.basic.domain') . ' ' . trans('ash.communication.contact'); } $brand = empty($account) ? Brand::getSystemBrand() : $account->brand; if (empty($brand) || empty($submittor)) { abort(500); } $changeStatus = Input::get('changeStatus'); if ($changeStatus == 'IGNORED' || $changeStatus == 'RESOLVED') { $ticket->contact_status_id = $changeStatus; $ticket->save(); } $text = Input::get('text'); if (empty($text) || strlen($text) < 1) { $message = 'noteEmpty'; } else { $message = 'noteAdded'; $note = new Note(); $note->ticket_id = $ticket->id; $note->submitter = $submittor; $note->text = $text; $note->save(); } return view('ash')->with('brand', $brand)->with('ticket', $ticket)->with('allowedChanges', $this->allowedStatusChanges($ticket))->with('token', $token)->with('message', $message); }
public function testSetSystemAccount() { $this->initDB(); $exitCode = Artisan::call('account:edit', ['id' => $this->account->id, '--systemaccount' => true]); $this->assertEquals($exitCode, 0); $this->assertContains('The account has been updated', Artisan::output()); $this->assertTrue((bool) Account::find($this->account->id)->systemaccount); }
/** * @param $name * * @return mixed */ protected function findAccountByName($name) { $account = Account::where('id', $name)->orWhere('name', $name)->first(); if ($account === null) { $account = Account::find(['name' => 'Default'])->first(); if ($account === null) { $account = Account::all()->first(); } $this->info(sprintf("No account was found for given account name so '%s' was used", $account->name)); } return $account; }
/** * {@inheritdoc}. */ protected function handleOptions($model) { $this->updateFieldWithOption($model, 'first_name'); $this->updateFieldWithOption($model, 'last_name'); $this->updateFieldWithOption($model, 'email'); $this->handleLanguageUpdate($model); $this->handleEnableDisable($model); if (!empty($this->option('account'))) { $newAccount = Account::find($this->option('account')); if (null === $newAccount) { $this->error('Unable to find account with this criteria'); return false; } $model->account_id = $newAccount->id; } $this->handlePasswordUpdate($model); return true; }
/** * Sends out mail notifications for a specific $customerReference * * @param array $notifications * @return boolean Returns if succeeded or not */ public function send($notifications) { foreach ($notifications as $customerReference => $notificationTypes) { $mails = []; $tickets = []; $accounts = []; foreach ($notificationTypes as $notificationType => $tickets) { foreach ($tickets as $ticket) { $token['ip'] = $ticket->ash_token_ip; $token['domain'] = $ticket->ash_topen_domain; $ashUrl = config('main.ash.url') . 'collect/' . $ticket->id . '/'; $this->addIodefObject($ticket, $token[$notificationType], $ashUrl); $box = ['ticket_notification_type' => $notificationType, 'ip_contact_ash_link' => $ashUrl . $token['ip'], 'domain_contact_ash_link' => $ashUrl . $token['domain'], 'ticket_number' => $ticket->id, 'ticket_ip' => $ticket->ip, 'ticket_domain' => $ticket->domain, 'ticket_type_name' => trans("types.type.{$ticket->type_id}.name"), 'ticket_type_description' => trans("types.type.{$ticket->type_id}.description"), 'ticket_class_name' => trans("classifications.{$ticket->class_id}.name"), 'ticket_event_count' => $ticket->events->count()]; /* * Even that all these tickets relate to the same customer reference, the contacts might be * changed (added addresses, etc) for a specific ticket. To make sure people only get their own * notificiations we aggregate them here before sending. */ if ($notificationType == 'ip') { $recipient = $ticket->ip_contact_email; $mails[$recipient][] = $box; $accounts[$recipient] = Account::find($ticket->ip_contact_account_id); } if ($notificationType == 'domain') { $recipient = $ticket->domain_contact_email; $mails[$recipient][] = $box; $accounts[$recipient] = Account::find($ticket->domain_contact_account_id); } } } foreach ($mails as $recipient => $boxes) { if (!empty($boxes)) { // create a new message $message = Swift_Message::newInstance(); // create the src url for the active brand logo if (!empty($accounts[$recipient])) { $account = $accounts[$recipient]; } else { $account = Account::getSystemAccount(); } $logo_url = URL::to('/ash/logo/' . $account->brand_id); $brand = $account->brand; $replacements = ['boxes' => $boxes, 'ticket_count' => count($tickets), 'logo_src' => $logo_url]; $subject = config("{$this->configBase}.templates.subject"); $htmlmail = config("{$this->configBase}.templates.html_mail"); $plainmail = config("{$this->configBase}.templates.plain_mail"); // render the default templates $htmlmail = view(['template' => $htmlmail], $replacements)->render(); $plainmail = view(['template' => $plainmail], $replacements)->render(); // if the current brand has custom mail template, use them if ($brand->mail_custom_template) { // defensive programming, doubble check the templates $validator = \Validator::make(['html' => $brand->mail_template_html, 'plain' => $brand->mail_template_plain], ['html' => 'required|bladetemplate', 'plain' => 'required|bladetemplate']); if ($validator->passes()) { try { // only use the templates if they pass the validation $htmloutput = view(['template' => $brand->mail_template_html], $replacements)->render(); $plainoutput = view(['template' => $brand->mail_template_plain], $replacements)->render(); // no errors occurred while rendering $htmlmail = $htmloutput; $plainmail = $plainoutput; } catch (\ErrorException $e) { Log::warning("Incorrect template, falling back to default: " . $e->getMessage()); } } } $iodef = new Iodef\Writer(); $iodef->formatOutput = true; $iodef->write([['name' => 'IODEF-Document', 'attributes' => $this->iodefDocument->getAttributes(), 'value' => $this->iodefDocument]]); $XmlAttachmentData = $iodef->outputMemory(); if (!empty(Config::get('mail.smime.enabled')) && Config::get('mail.smime.enabled') === true && !empty(Config::get('mail.smime.certificate')) && !empty(Config::get('mail.smime.key')) && is_file(Config::get('mail.smime.certificate')) && is_file(Config::get('mail.smime.key'))) { $smimeSigner = Swift_Signers_SMimeSigner::newInstance(); $smimeSigner->setSignCertificate(Config::get('mail.smime.certificate'), Config::get('mail.smime.key')); $message->attachSigner($smimeSigner); } $message->setFrom([Config::get('main.notifications.from_address') => Config::get('main.notifications.from_name')]); if (!empty(Config::get('mail.override_address'))) { $message->setTo([Config::get('mail.override_address')]); } else { $message->setTo([$recipient]); } if (!empty(Config::get('main.notifications.bcc_enabled'))) { $message->setBcc([Config::get('main.notifications.bcc_address')]); } $message->setPriority(1); $message->setSubject($subject); $message->setBody($htmlmail, 'text/html'); $message->addPart($plainmail, 'text/plain'); $message->attach(Swift_Attachment::newInstance($XmlAttachmentData, 'iodef.xml', 'text/xml')); $transport = Swift_SmtpTransport::newInstance(); $transport->setHost(config('mail.host')); $transport->setPort(config('mail.port')); $transport->setUsername(config('mail.username')); $transport->setPassword(config('mail.password')); $transport->setEncryption(config('mail.encryption')); $mailer = Swift_Mailer::newInstance($transport); if (!$mailer->send($message)) { return $this->failed("Error while sending message to {$recipient}"); } } } } return $this->success(); }
/** * Display the specified resource. * * @param User $user * @return \Illuminate\Http\Response */ public function show(User $user) { $account = Account::find($user->account_id); return view('users.show')->with('account', $account)->with('user', $user)->with('auth_user', $this->auth_user); }
public function testSetSystemAccount() { $account = factory(Account::class)->create(); $account->systemaccount = true; $this->assertTrue((bool) Account::find($account->id)->systemaccount); }
/** * {@inheritdoc}. */ protected function getObjectByArguments() { return Account::find($this->argument('id')); }
/** * {@inheritdoc}. */ protected function getModelFromRequest() { return Account::find($this->argument('id')); }
/** * Display the specified resource. * * @param User $user * * @return \Illuminate\Http\Response */ public function show(User $user) { $account = Account::find($user->account_id); $locale = Config::get('app.locales'); return view('users.show')->with('account', $account)->with('user', $user)->with('roles', $user->roles)->with('language', $locale[$user->locale][0])->with('auth_user', $this->auth_user); }