]> _ Git - fluidbook-toolbox.git/commitdiff
wait #7016 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 29 Aug 2024 16:11:53 +0000 (18:11 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 29 Aug 2024 16:11:53 +0000 (18:11 +0200)
app/Console/Commands/MattermostPost.php
app/Http/Controllers/Admin/Operations/FluidbookQuote/AssignOperation.php
app/Http/Controllers/Admin/Operations/FluidbookQuote/CreateFromWebsite.php
app/Http/Controllers/Admin/Operations/FluidbookQuote/SpamOperation.php
app/Jobs/WebflowPublish.php
app/Slack/Mattermost.php
composer.json
composer.lock

index 2123e6669e2e9695b31d2b067c12b6ddb9899d90..46c5c6ee51b8ef09e9f88e38bed0fd0ce18ed8eb 100644 (file)
@@ -13,7 +13,9 @@ class MattermostPost extends ToolboxCommand
 
     public function handle()
     {
+
         $id = User::withoutGlobalScopes()->find(5)->mattermost;
-        Mattermost::send($id, 'Test subject', 'Test Text', ['test' => ['url' => 'https://example.com']]);
+        $postid = Mattermost::send($id, 'Test subject', 'Test Text', ['test' => ['url' => 'https://example.com']]);
+        Mattermost::addReaction($postid, 'white_check_mark');
     }
 }
index 52691b124b0cee33d01395ee907dee256dbd5f59..b841b73c003d43e84fb896a3b1b27d9a2c9f5312 100644 (file)
@@ -6,11 +6,13 @@ use App\Mail\FluidbookQuoteAssign;
 use App\Mail\FluidbookQuoteReceived;
 use App\Models\FluidbookQuote;
 use App\Models\User;
+use App\Slack\Mattermost;
 use App\Slack\Slack;
 use Illuminate\Support\Facades\Mail;
 use Illuminate\Support\Facades\Redirect;
 use Illuminate\Support\Facades\Route;
 use Prologue\Alerts\Facades\Alert;
+
 // __('!! Demandes de devis fluidbook')
 trait AssignOperation
 {
@@ -46,8 +48,8 @@ trait AssignOperation
         }
         Alert::add('success', __('La demande de devis a été attribuée'))->flash();
 
-        if($quote->slack_ts){
-            Slack::addReaction(Slack::fluidbookQuoteChannel,$quote->slack_ts,'white_check_mark');
+        if ($quote->slack_ts) {
+            Mattermost::addReaction($quote->slack_ts, 'white_check_mark');
         }
 
         return Redirect::to(session('_previous', ['url' => backpack_url('fluidbook-quote')])['url']);
index e9a18977aeb04b2ebc53999b52dfad3492ca4c87..7e95d791a74eb4d1cdbfd4bcb1a371d1a6717348 100644 (file)
@@ -104,7 +104,6 @@ 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) {
                 try {
                     $quote->slack_ts = Mattermost::send(Mattermost::fluidbookQuoteChannel, 'Demande de devis', FluidbookQuoteReceived::getMarkdown($post),
index 5b9779f872d2287d4078512f4ee41021b35786c4..7acc554061660ccfec33a4838d156d36b2b15a21 100644 (file)
@@ -6,6 +6,7 @@ use App\Mail\FluidbookQuoteAssign;
 use App\Mail\FluidbookQuoteReceived;
 use App\Models\FluidbookQuote;
 use App\Models\User;
+use App\Slack\Mattermost;
 use App\Slack\Slack;
 use Illuminate\Support\Facades\Mail;
 use Illuminate\Support\Facades\Redirect;
@@ -30,7 +31,7 @@ trait SpamOperation
         $quote->deleteOrFail();
 
         if ($slack_ts) {
-            Slack::deleteMessage(Slack::fluidbookQuoteChannel, $slack_ts);
+            Mattermost::deleteMessage($slack_ts);
         }
 
         Alert::add('success', __('La demande de devis a été supprimée'))->flash();
index 39dadf9f606ec20dc5ceda3b3a3daefc59ce8ec6..58e49a1b4df0bd4edd93e52c9d10210d22fc8305 100644 (file)
@@ -68,7 +68,7 @@ class WebflowPublish extends Base
         }
         if ($notify && isset($text)) {
             if ($this->user === null) {
-                Mattermost::send($wf->mattermost, $subject, $text, $actions, false);
+                Mattermost::send($wf->slack, $subject, $text, $actions, false);
             } else {
                 $this->user->notify(new ToolboxNotification($subject, $text, $actions, true));
             }
index e68308cb9d0e41ff26ef08738876aa6c93cec2db..dc2c8eab16e26a55e63ca05950e7dda3601ef40d 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace App\Slack;
 
+use Cubist\Backpack\Facades\App;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Log;
 use Pnz\MattermostClient\ApiClient;
 use Pnz\MattermostClient\HttpClientConfigurator;
@@ -15,20 +17,19 @@ class Mattermost
 
     const fluidbookQuoteChannel = 'tswc7buu1bf9ixdccfqmo36s5r';
     const fluidbookPreviewAlertsChannel = 'y1z7rdtppbg1jr91o8f6prcbcc';
-    const fluidbookFilesChannel='6sgtn7rrw3buz8fqftm936oqer';
+    const fluidbookFilesChannel = '6sgtn7rrw3buz8fqftm936oqer';
 
+    const endpoint = 'https://mm.cubedesigners.com/api/v4';
+    const email = 'vincent+toolbox@cubedesigners.com';
+    const password = 'HtMYveJ3%8HMnWooXsm9';
+    const team = 'cubedesigners';
 
     protected static function _client(): ApiClient
     {
         if (null === self::$_client) {
-
-            $endpoint = 'https://mm.cubedesigners.com/api/v4';
-            $username = 'vincent+toolbox@cubedesigners.com';
-            $password = 'HtMYveJ3%8HMnWooXsm9';
-
             $configurator = (new HttpClientConfigurator())
-                ->setEndpoint($endpoint)
-                ->setCredentials($username, $password);
+                ->setEndpoint(self::endpoint)
+                ->setCredentials(self::email, self::password);
             self::$_client = ApiClient::configure($configurator);
         }
         return self::$_client;
@@ -36,7 +37,6 @@ class Mattermost
 
     public static function send($channel, $subject, $text, $actions = [], $repeatActions = true, $from = 'Fluidbook Toolbox')
     {
-        Log::debug(json_encode(func_get_args()));
         $markdown = '';
         if ($text) {
             $markdown .= $text . "\n";
@@ -80,6 +80,7 @@ class Mattermost
                 'channel_id' => $channel,
                 'props' => $props,
             ]);
+            return $response->getId();
         } catch (\Exception $e) {
             Log::critical($e);
             Log::critical($e->getMessage() . ' // ' . $from . ' // ' . $channel . ' // ' . $text . ' // ' . $markdown);
@@ -92,8 +93,30 @@ class Mattermost
         return self::_client()->posts()->deletePost($postId)->getStatus();
     }
 
-    public static function addReaction($channel, $ts, $reaction)
+    public static function addReaction($postId, $emoji, $userId = null)
+    {
+        if (null === $userId) {
+            $userId = self::getUserIdByEmail(self::email);
+        }
+        return self::_client()->posts()->addReaction(['post_id' => $postId, 'emoji_name' => $emoji, 'user_id' => $userId]);
+    }
+
+    public static function getUserIdByEmail($email)
     {
-        return self::_client()->reactionsAdd(['channel' => $channel, 'timestamp' => $ts, 'name' => $reaction]);
+        return Cache::remember('mm_user_by_email_' . $email, 7200, function () use ($email) {
+            return self::_client()->users()->getUserByEmail($email)->getId();
+        });
     }
+
+    public static function getChannelIdByName($channel, $teamName = null)
+    {
+        if ($teamName === null) {
+            $teamName = self::team;
+        }
+        return Cache::remember('mm_channel_id_by_name_' . $channel . '_' . $teamName, 7200, function () use ($channel, $teamName) {
+            return self::_client()->channels()->getChannelByNameAndTeamName($teamName, $channel)->getId();
+        });
+    }
+
+
 }
index 0469e47d8c04449bdea054572f0835ded5931ac4..42e3b64c2dc6c7f98a82d3999252533ebff236e9 100644 (file)
         {
             "type": "git",
             "url": "https://github.com/enhydrav/standalone-blade.git"
+        },
+        {
+            "type": "git",
+            "url": "https://github.com/enhydrav/mattermostclient.git"
         }
     ],
     "license": "MIT",
@@ -55,7 +59,7 @@
         "php-ffmpeg/php-ffmpeg": "^v1.2.0",
         "php-http/curl-client": "^2.3",
         "php-http/message": "^1.16",
-        "pnz/mattermost-client": "2.x-dev",
+        "pnz/mattermost-client": "dev-master",
         "rickselby/laravel-gate-cache": "^3.7",
         "rodneyrehm/plist": "^2.0",
         "rustici-software/scormcloud-api-v2-client-php": "^2.1.0",
index fdfa546e1a7e8b4d0d9c69bda48fa18765ed8868..e9d2f6dfeb857bcbd5ddab1210c61c7799a9415a 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "534e3e6f2014dd23ae4c7ad3f482c968",
+    "content-hash": "9aabb63950a197c861594703ffd8b56d",
     "packages": [
         {
             "name": "archtechx/enums",
         },
         {
             "name": "norkunas/youtube-dl-php",
-            "version": "v2.6.0",
+            "version": "v2.7.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/norkunas/youtube-dl-php.git",
-                "reference": "c02b9c45a76e0d1978136caa261fcc17d3d91b61"
+                "reference": "c0ef03ace6ab794ef94ea72e4b083d608d64b754"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/norkunas/youtube-dl-php/zipball/c02b9c45a76e0d1978136caa261fcc17d3d91b61",
-                "reference": "c02b9c45a76e0d1978136caa261fcc17d3d91b61",
+                "url": "https://api.github.com/repos/norkunas/youtube-dl-php/zipball/c0ef03ace6ab794ef94ea72e4b083d608d64b754",
+                "reference": "c0ef03ace6ab794ef94ea72e4b083d608d64b754",
                 "shasum": ""
             },
             "require": {
             },
             "require-dev": {
                 "mikey179/vfsstream": "^1.6.11",
-                "php-cs-fixer/shim": "^3.49",
-                "phpstan/phpstan": "^1.10.57",
-                "phpstan/phpstan-phpunit": "^1.3.15",
-                "phpstan/phpstan-strict-rules": "^1.5.2",
-                "symfony/phpunit-bridge": "^6.4.3"
+                "php-cs-fixer/shim": "^3.60",
+                "phpstan/phpstan": "^1.11.8",
+                "phpstan/phpstan-phpunit": "^1.4.0",
+                "phpstan/phpstan-strict-rules": "^1.6.0",
+                "symfony/phpunit-bridge": "^6.4.10"
             },
             "type": "library",
             "extra": {
             ],
             "support": {
                 "issues": "https://github.com/norkunas/youtube-dl-php/issues",
-                "source": "https://github.com/norkunas/youtube-dl-php/tree/v2.6.0"
+                "source": "https://github.com/norkunas/youtube-dl-php/tree/v2.7.0"
             },
-            "time": "2024-02-28T05:14:01+00:00"
+            "time": "2024-08-28T08:22:20+00:00"
         },
         {
             "name": "nothingworks/blade-svg",
             "time": "2024-07-20T21:41:07+00:00"
         },
         {
-            "name": "pnz/mattermost-client",
-            "version": "2.x-dev",
+            "name": "pnz/json-exception",
+            "version": "v1.0.1",
             "source": {
                 "type": "git",
-                "url": "https://github.com/thePanz/MattermostClient.git",
-                "reference": "74c14f78bce005131da44d293d45cbd04aaedb3d"
+                "url": "https://github.com/thePanz/json-exception.git",
+                "reference": "cce24ccdb59f6eecb6cb45dbdc8695808f6d64d7"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/thePanz/MattermostClient/zipball/74c14f78bce005131da44d293d45cbd04aaedb3d",
-                "reference": "74c14f78bce005131da44d293d45cbd04aaedb3d",
+                "url": "https://api.github.com/repos/thePanz/json-exception/zipball/cce24ccdb59f6eecb6cb45dbdc8695808f6d64d7",
+                "reference": "cce24ccdb59f6eecb6cb45dbdc8695808f6d64d7",
                 "shasum": ""
             },
             "require": {
                 "ext-json": "*",
-                "php": "^8.1",
+                "php": "^7.0 || ^8.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Pnz\\JsonException\\": "src/"
+                },
+                "classmap": [
+                    "src/stubs"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "GPL-3.0"
+            ],
+            "description": "Json decode/encode library with exception throwing on error.",
+            "keywords": [
+                "json"
+            ],
+            "support": {
+                "issues": "https://github.com/thePanz/json-exception/issues",
+                "source": "https://github.com/thePanz/json-exception/tree/v1.0.1"
+            },
+            "time": "2021-08-18T13:32:12+00:00"
+        },
+        {
+            "name": "pnz/mattermost-client",
+            "version": "dev-master",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/enhydrav/mattermostclient.git",
+                "reference": "2562057e91f255cace2d304af6ac4c61740d74bb"
+            },
+            "require": {
+                "ext-json": "*",
+                "php": "^7.4 || ^8.0",
                 "php-http/client-common": "^2.0",
-                "php-http/discovery": "^1.17",
-                "php-http/httplug": "^2.1",
+                "php-http/discovery": "^1.7",
+                "php-http/httplug": "^2.0",
                 "php-http/multipart-stream-builder": "^1.1",
-                "psr/http-client-implementation": "*",
-                "psr/http-factory-implementation": "*",
-                "psr/http-message": "^1.0"
+                "pnz/json-exception": "^1.0"
             },
             "require-dev": {
-                "nyholm/psr7": "^1.8",
-                "php-cs-fixer/shim": "^v3.34",
-                "php-http/curl-client": "^2.3",
-                "php-http/mock-client": "^1.6",
-                "phpstan/extension-installer": "^1.3",
-                "phpstan/phpstan": "^1.10",
-                "phpstan/phpstan-phpunit": "^1.3",
-                "phpunit/phpunit": "^10.5",
-                "rector/rector": "^0.18.12"
+                "nyholm/psr7": "^1.2.1",
+                "php-http/curl-client": "^2.0",
+                "php-http/message": "^1.8",
+                "php-http/message-factory": "^1.0",
+                "phpstan/extension-installer": "^1.0",
+                "phpstan/phpstan-phpunit": "^0.11.2",
+                "phpstan/phpstan-shim": "^0.11",
+                "phpunit/phpunit": "^7.5",
+                "psr/http-message": "^1.0.1"
             },
+            "default-branch": true,
             "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "0.1.x-dev"
+                }
+            },
             "autoload": {
                 "psr-4": {
                     "Pnz\\MattermostClient\\": "src/"
                 }
             },
-            "notification-url": "https://packagist.org/downloads/",
+            "autoload-dev": {
+                "psr-4": {
+                    "Pnz\\MattermostClient\\Tests\\": "tests/"
+                }
+            },
+            "scripts": {
+                "ci": [
+                    "@phpcs",
+                    "@phpstan",
+                    "@test-ci"
+                ],
+                "phpstan": [
+                    "vendor/bin/phpstan analyze --level=7 src/ tests/"
+                ],
+                "phpcs": [
+                    "vendor/bin/php-cs-fixer fix --dry-run --verbose --ansi"
+                ],
+                "phpcs-install": [
+                    "curl -L https://cs.symfony.com/download/php-cs-fixer-v2.phar -o vendor/bin/php-cs-fixer && chmod u+x vendor/bin/php-cs-fixer"
+                ],
+                "phpcs-fix": [
+                    "vendor/bin/php-cs-fixer fix --verbose --ansi"
+                ],
+                "test": [
+                    "vendor/bin/phpunit"
+                ],
+                "test-ci": [
+                    "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
+                ]
+            },
             "license": [
                 "MIT"
             ],
             ],
             "description": "Mattermost APi Client for PHP",
             "keywords": [
-                "Mattermost",
-                "api"
+                "api",
+                "mattermost"
             ],
-            "support": {
-                "issues": "https://github.com/thePanz/MattermostClient/issues",
-                "source": "https://github.com/thePanz/MattermostClient/tree/2.x"
-            },
-            "time": "2023-12-20T14:23:35+00:00"
+            "time": "2023-09-07T09:16:48+00:00"
         },
         {
             "name": "prologue/alerts",
         },
         {
             "name": "spatie/laravel-package-tools",
-            "version": "1.16.4",
+            "version": "1.16.5",
             "source": {
                 "type": "git",
                 "url": "https://github.com/spatie/laravel-package-tools.git",
-                "reference": "ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53"
+                "reference": "c7413972cf22ffdff97b68499c22baa04eddb6a2"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53",
-                "reference": "ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53",
+                "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/c7413972cf22ffdff97b68499c22baa04eddb6a2",
+                "reference": "c7413972cf22ffdff97b68499c22baa04eddb6a2",
                 "shasum": ""
             },
             "require": {
             ],
             "support": {
                 "issues": "https://github.com/spatie/laravel-package-tools/issues",
-                "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.4"
+                "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.5"
             },
             "funding": [
                 {
                     "type": "github"
                 }
             ],
-            "time": "2024-03-20T07:29:11+00:00"
+            "time": "2024-08-27T18:56:10+00:00"
         },
         {
             "name": "spatie/laravel-permission",
         },
         {
             "name": "composer/pcre",
-            "version": "3.3.0",
+            "version": "3.3.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/composer/pcre.git",
-                "reference": "1637e067347a0c40bbb1e3cd786b20dcab556a81"
+                "reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/composer/pcre/zipball/1637e067347a0c40bbb1e3cd786b20dcab556a81",
-                "reference": "1637e067347a0c40bbb1e3cd786b20dcab556a81",
+                "url": "https://api.github.com/repos/composer/pcre/zipball/63aaeac21d7e775ff9bc9d45021e1745c97521c4",
+                "reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4",
                 "shasum": ""
             },
             "require": {
             ],
             "support": {
                 "issues": "https://github.com/composer/pcre/issues",
-                "source": "https://github.com/composer/pcre/tree/3.3.0"
+                "source": "https://github.com/composer/pcre/tree/3.3.1"
             },
             "funding": [
                 {
                     "type": "tidelift"
                 }
             ],
-            "time": "2024-08-19T19:43:53+00:00"
+            "time": "2024-08-27T18:44:43+00:00"
         },
         {
             "name": "doctrine/instantiator",
         },
         {
             "name": "phpstan/phpdoc-parser",
-            "version": "1.29.1",
+            "version": "1.30.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/phpstan/phpdoc-parser.git",
-                "reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4"
+                "reference": "5ceb0e384997db59f38774bf79c2a6134252c08f"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fcaefacf2d5c417e928405b71b400d4ce10daaf4",
-                "reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4",
+                "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/5ceb0e384997db59f38774bf79c2a6134252c08f",
+                "reference": "5ceb0e384997db59f38774bf79c2a6134252c08f",
                 "shasum": ""
             },
             "require": {
             "description": "PHPDoc parser with support for nullable, intersection and generic types",
             "support": {
                 "issues": "https://github.com/phpstan/phpdoc-parser/issues",
-                "source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.1"
+                "source": "https://github.com/phpstan/phpdoc-parser/tree/1.30.0"
             },
-            "time": "2024-05-31T08:52:43+00:00"
+            "time": "2024-08-29T09:54:52+00:00"
         },
         {
             "name": "phpunit/php-code-coverage",