From: Vincent Vanwaelscappel Date: Mon, 10 Oct 2022 08:16:00 +0000 (+0200) Subject: wait #5517 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=9a967c66b58723f898754349340a0f6df5133d8c;p=fluidbook-toolbox.git wait #5517 @1.5 --- diff --git a/app/Http/Controllers/Admin/Operations/FluidbookQuote/AssignOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookQuote/AssignOperation.php index 2bdd266b0..9de93b77f 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookQuote/AssignOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookQuote/AssignOperation.php @@ -25,10 +25,17 @@ trait AssignOperation 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) { diff --git a/app/Http/Controllers/Admin/Operations/FluidbookQuote/CreateFromWebsite.php b/app/Http/Controllers/Admin/Operations/FluidbookQuote/CreateFromWebsite.php index 50c45860b..a3eb0e504 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookQuote/CreateFromWebsite.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookQuote/CreateFromWebsite.php @@ -10,6 +10,7 @@ use App\Mail\FluidbookQuoteReceived; 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; @@ -83,6 +84,10 @@ trait CreateFromWebsite $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); diff --git a/app/Jobs/DownloadBase.php b/app/Jobs/DownloadBase.php index 837c54693..2856fda1e 100644 --- a/app/Jobs/DownloadBase.php +++ b/app/Jobs/DownloadBase.php @@ -5,6 +5,8 @@ namespace App\Jobs; 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; @@ -56,62 +58,7 @@ class DownloadBase extends Base 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 = []) diff --git a/app/Mail/FluidbookQuoteReceived.php b/app/Mail/FluidbookQuoteReceived.php index a23d91a09..8e5d2ae47 100644 --- a/app/Mail/FluidbookQuoteReceived.php +++ b/app/Mail/FluidbookQuoteReceived.php @@ -3,14 +3,32 @@ 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', @@ -35,34 +53,23 @@ class FluidbookQuoteReceived extends Base '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 = '

Une demande de devis a été envoyée avec les informations suivantes :

"; - if (!$spam) { - $body .= 'Veuillez-vous rendre sur la Toolbox 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 .= '

'; - $this->html($body); - + return $res; } } diff --git a/app/Slack/Slack.php b/app/Slack/Slack.php new file mode 100644 index 000000000..358d30c04 --- /dev/null +++ b/app/Slack/Slack.php @@ -0,0 +1,68 @@ + '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, + ]); + } +} diff --git a/resources/views/vendor/backpack/crud/buttons/fluidbook_quote/assign.blade.php b/resources/views/vendor/backpack/crud/buttons/fluidbook_quote/assign.blade.php index 07d3d8114..c3c4e3312 100644 --- a/resources/views/vendor/backpack/crud/buttons/fluidbook_quote/assign.blade.php +++ b/resources/views/vendor/backpack/crud/buttons/fluidbook_quote/assign.blade.php @@ -1,6 +1,6 @@ @if($entry->status==0)