protected function assign($id, $reseller)
{
+ if (!can('fluidbook-quote:admin')) {
+ abort(403);
+ }
+ $me = backpack_user()->id;
+ if ($reseller === 'me') {
+ $reseller = $me;
+ }
$quote = FluidbookQuote::where('id', $id)->first();
$quote->reseller = $reseller;
$quote->status = 1;
- $quote->admin = backpack_user()->id;
+ $quote->admin = $me;
$quote->save();
if ($quote->reseller != $quote->admin) {
use App\Models\Company;
use App\Models\FluidbookQuote;
use App\Models\AuthUser;
+use App\Slack\Slack;
use Cubist\Util\ArrayUtil;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Route;
$resp['message'] = __("Votre demande de devis a bien été envoyée. Merci pour l'intérêt que vous portez à Fluidbook.", [], $post['lang']);
+ if ($post && !$spam) {
+ Slack::send('C045CH0UB47', 'Demande de devis', FluidbookQuoteReceived::getMarkdown($post), ['Je vais voir' => 'https://toolbox.fluidbook.com/fluidbook-quote?status=0', 'Je m\'en charge' => 'https://toolbox.fluidbook.com/fluidbook-quote/' . $quote->id . '/assign/me']);
+ }
+
$quoteMail = new FluidbookQuoteReceived();
$quoteMail->setData($post);
Mail::send($quoteMail);
use App\Mail\DeferredDownload;
use App\Models\User;
use App\Services\ScormCloud;
+use App\Slack\Message;
+use App\Slack\Slack;
use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
use Cubist\Util\Files\Files;
use Cubist\Util\Str;
public function sendSlack($subject, $text, $actions = [])
{
- $client = ClientFactory::create(env('SLACK_BOT_TOKEN'));
- $blocks = [
- [
- 'type' => 'section',
- 'text' => [
- 'type' => 'mrkdwn',
- 'text' => '*' . $subject . '*',
- ]
- ]
- ];
- if ($text) {
- $blocks[] = [
- 'type' => 'section',
- 'text' => [
- 'type' => 'mrkdwn',
- 'text' => $text,
- ]
- ];
- }
- if (count($actions) > 0) {
- $a = [
- 'type' => 'actions',
- 'block_id' => 'actions',
- 'elements' => [],
- ];
- $text = '';
- $i = 0;
- foreach ($actions as $label => $url) {
- $a['elements'][] = [
- 'type' => 'button',
- 'text' => [
- 'type' => 'plain_text',
- 'text' => $label
- ],
- 'url' => $url,
- ];
- $i++;
- $text .= '> ' . $label . ' : ' . $url . "\n";
- }
- $blocks[] = [
- 'type' => 'section',
- 'text' => [
- 'type' => 'mrkdwn',
- 'text' => $text,
- ]
- ];
- $blocks[] = $a;
- }
-
- $client->chatPostMessage([
- 'username' => 'Fluidbook Toolbox',
- 'channel' => $this->getUser()->slack,
- 'blocks' => json_encode($blocks),
- 'text' => $subject,
- 'unfurl_links' => false,
- ]);
+ Slack::send($this->getUser()->slack, $subject, $text, $actions);
}
public function sendEmail($subject, $text, $actions = [])
namespace App\Mail;
use Cubist\Locale\Country;
-use Illuminate\Bus\Queueable;
-use Illuminate\Mail\Mailable;
-use Illuminate\Queue\SerializesModels;
+use League\CommonMark\CommonMarkConverter;
class FluidbookQuoteReceived extends Base
{
public function setData($post)
+ {
+ $this->from($post['email'], $post['prenom'] . ' ' . $post['nom']);
+ $this->to('tech@fluidbook.com');
+ $spam = '';
+ if ($post['spam'] === 'Oui') {
+ $spam = ' *** SPAM ***';
+ }
+ $this->subject('[Fluidbook Workshop]' . $spam . ' Demande de devis');
+
+ if (!$spam) {
+ $footer = 'Veuillez-vous rendre sur la [Toolbox](https://toolbox.fluidbook.com/fluidbook-quote) pour prendre en charge la demande ou la confier à un revendeur';
+ } else {
+ $footer = 'Cette demande est un SPAM supposé. Elle n\'a pas été enregistrée dans la Toolbox.';
+ }
+ $markdown = self::getMarkdown($post, $footer);
+ $converter = new CommonMarkConverter();
+ $this->html($converter->convertToHtml($markdown));
+ }
+
+ public static function getMarkdown($post, $footer = '')
{
$fields = array(
'spam' => 'Demande SPAM',
'gclid' => 'Google Ads ID (gclid)'
);
- $this->from($post['email'], $post['prenom'] . ' ' . $post['nom']);
- $this->to('tech@fluidbook.com');
- $spam = '';
- if ($post['spam'] === 'Oui') {
- $spam = ' *** SPAM ***';
- }
- $this->subject('[Fluidbook Workshop]' . $spam . ' Demande de devis');
-
- $body = '<html><body><p>Une demande de devis a été envoyée avec les informations suivantes :</p><ul>';
+ $res = 'Une demande de devis a été envoyée avec les informations suivantes :' . "\n\n";
foreach ($fields as $f => $d) {
if ($post[$f] != '') {
+ $res .= '- ' . $d . ' : ';
if ($f == 'email') {
- $body .= '<li>' . $d . ' : <a href="mailto:' . $post[$f] . '">' . $post[$f] . '</a></li>';
+ $res .= $post[$f];
} elseif ($f == 'pays') {
- $body .= '<li>' . $d . ' : ' . Country::translate($post[$f], 'fr') . '</li>';
+ $res .= Country::translate($post[$f], 'fr');
} else {
- $body .= '<li>' . $d . ' : ' . nl2br($post[$f]) . '</li>';
+ $res .= $post[$f];
}
+ $res .= "\n";
}
}
- $body .= "</ul><p>";
- if (!$spam) {
- $body .= 'Veuillez-vous rendre sur la <a href="https://toolbox.fluidbook.com/fluidbook-quote">Toolbox</a> pour prendre en charge la demande ou la confier à un revendeur';
- } else {
- $body .= 'Cette demande est un SPAM supposé. Elle n\'a pas été enregistrée dans la Toolbox.';
+ if ($footer !== '') {
+ $res .= "\n" . $footer . "\n";
}
- $body .= '</p></body></html>';
- $this->html($body);
-
+ return $res;
}
}
--- /dev/null
+<?php
+
+namespace App\Slack;
+
+use JoliCode\Slack\ClientFactory;
+
+class Slack
+{
+ public static function send($channel, $subject, $text, $actions = [], $from = 'Fluidbook Toolbox')
+ {
+ $client = ClientFactory::create(env('SLACK_BOT_TOKEN'));
+ $blocks = [
+ [
+ 'type' => 'section',
+ 'text' => [
+ 'type' => 'mrkdwn',
+ 'text' => '*' . $subject . '*',
+ ]
+ ]
+ ];
+ if ($text) {
+ $blocks[] = [
+ 'type' => 'section',
+ 'text' => [
+ 'type' => 'mrkdwn',
+ 'text' => $text,
+ ]
+ ];
+ }
+ if (count($actions) > 0) {
+ $a = [
+ 'type' => 'actions',
+ 'block_id' => 'actions',
+ 'elements' => [],
+ ];
+ $text = '';
+ $i = 0;
+ foreach ($actions as $label => $url) {
+ $a['elements'][] = [
+ 'type' => 'button',
+ 'text' => [
+ 'type' => 'plain_text',
+ 'text' => $label
+ ],
+ 'url' => $url,
+ ];
+ $i++;
+ $text .= '> ' . $label . ' : ' . $url . "\n";
+ }
+ $blocks[] = [
+ 'type' => 'section',
+ 'text' => [
+ 'type' => 'mrkdwn',
+ 'text' => $text,
+ ]
+ ];
+ $blocks[] = $a;
+ }
+
+ $client->chatPostMessage([
+ 'username' => $from,
+ 'channel' => $channel,
+ 'blocks' => json_encode($blocks),
+ 'text' => $subject,
+ 'unfurl_links' => false,
+ ]);
+ }
+}
@if($entry->status==0)
<a class="btn btn-sm btn-link assignto" href="#" data-toggle="tooltip"
- data-context-actions="{{json_encode([backpack_user()->id=>__('Je vais traiter la demander'),'94'=>__('Confier à :reseller',['reseller'=>'Kadreo'])])}}"
+ data-context-actions="{{json_encode(['me'=>__('Je vais traiter la demander'),'94'=>__('Confier à :reseller',['reseller'=>'Kadreo'])])}}"
data-context-route="{{$crud->route}}/$id/assign/$action"
data-context-id="{{$entry->getKey()}}"
data-context-confirm="{{json_encode(