]> git.mxchange.org Git - friendica.git/commitdiff
Replace args call with parameter from router in Module\Group
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 26 Nov 2021 14:48:05 +0000 (09:48 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Fri, 26 Nov 2021 14:48:05 +0000 (09:48 -0500)
src/Module/Group.php
static/routes.config.php

index 1750d3e04f7b2581d4517cf309af882de69358ed..30ca0805a08acaf09c64c12f1f6ab10de82a201f 100644 (file)
@@ -34,10 +34,8 @@ class Group extends BaseModule
 {
        public function post()
        {
-               $a = DI::app();
-
                if (DI::mode()->isAjax()) {
-                       self::ajaxPost();
+                       $this->ajaxPost();
                }
 
                if (!local_user()) {
@@ -80,20 +78,16 @@ class Group extends BaseModule
                }
        }
 
-       public static function ajaxPost()
+       public function ajaxPost()
        {
                try {
-                       $a = DI::app();
-
                        if (!local_user()) {
                                throw new \Exception(DI::l10n()->t('Permission denied.'), 403);
                        }
 
-                       // POST /group/123/add/123
-                       // POST /group/123/remove/123
-                       // @TODO: Replace with parameter from router
-                       if (DI::args()->getArgc() == 4) {
-                               list($group_id, $command, $contact_id) = array_slice(DI::args()->getArgv(), 1);
+                       if (isset($this->parameters['command'])) {
+                               $group_id = $this->parameters['group'];
+                               $contact_id = $this->parameters['contact'];
 
                                if (!Model\Group::exists($group_id, local_user())) {
                                        throw new \Exception(DI::l10n()->t('Unknown group.'), 404);
@@ -108,7 +102,7 @@ class Group extends BaseModule
                                        throw new \Exception(DI::l10n()->t('Contact is deleted.'), 410);
                                }
 
-                               switch($command) {
+                               switch($this->parameters['command']) {
                                        case 'add':
                                                if (!Model\Group::addMember($group_id, $contact_id)) {
                                                        throw new \Exception(DI::l10n()->t('Unable to add the contact to the group.'), 500);
@@ -123,8 +117,6 @@ class Group extends BaseModule
 
                                                $message = DI::l10n()->t('Contact successfully removed from group.');
                                                break;
-                                       default:
-                                               throw new \Exception(DI::l10n()->t('Unknown group command.'), 400);
                                }
                        } else {
                                throw new \Exception(DI::l10n()->t('Bad request.'), 400);
index 467f3cff43e93713f884424f1dc81591e44e0bbf..c06c75929e88526afb6305fceb2cccf1f93e2184 100644 (file)
@@ -389,9 +389,7 @@ return [
                '/new'                       => [Module\Group::class, [R::GET, R::POST]],
                '/drop/{group:\d+}'          => [Module\Group::class, [R::GET, R::POST]],
                '/{group:\d+}/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]],
-
-               '/{group:\d+}/add/{contact:\d+}'    => [Module\Group::class, [R::GET, R::POST]],
-               '/{group:\d+}/remove/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]],
+               '/{group:\d+}/{command:add|remove}/{contact:\d+}'    => [Module\Group::class, [R::GET, R::POST]],
        ],
        '/hashtag'                    => [Module\Hashtag::class,           [R::GET]],
        '/help[/{doc:.+}]'            => [Module\Help::class,              [R::GET]],