Jelajahi Sumber

Add return to the profile for ban/unban

Visman 5 tahun lalu
induk
melakukan
53b07de925

+ 5 - 5
app/Controllers/Routing.php

@@ -139,11 +139,11 @@ class Routing
             $r->add('GET',           '/admin/users/promote/{uid:[2-9]|[1-9]\d+}/{pid:[1-9]\d*}/{token}', 'AdminUsersPromote:promote', 'AdminUserPromote');
 
             if ($this->c->userRules->banUsers) {
-                $r->add(['GET', 'POST'], '/admin/bans',                                 'AdminBans:view',   'AdminBans');
-                $r->add(['GET', 'POST'], '/admin/bans/new[/{ids:\d+(?:-\d+)*}]',        'AdminBans:add',    'AdminBansNew');
-                $r->add(['GET', 'POST'], '/admin/bans/edit/{id:[1-9]\d*}',              'AdminBans:edit',   'AdminBansEdit');
-                $r->add('GET',           '/admin/bans/result/{data}[/{page:[1-9]\d*}]', 'AdminBans:result', 'AdminBansResult');
-                $r->add('GET',           '/admin/bans/delete/{id:[1-9]\d*}/{token}',    'AdminBans:delete', 'AdminBansDelete');
+                $r->add(['GET', 'POST'], '/admin/bans',                                                     'AdminBans:view',   'AdminBans');
+                $r->add(['GET', 'POST'], '/admin/bans/new[/{ids:\d+(?:-\d+)*}[/{uid:[2-9]|[1-9]\d+}]]',     'AdminBans:add',    'AdminBansNew');
+                $r->add(['GET', 'POST'], '/admin/bans/edit/{id:[1-9]\d*}',                                  'AdminBans:edit',   'AdminBansEdit');
+                $r->add('GET',           '/admin/bans/result/{data}[/{page:[1-9]\d*}]',                     'AdminBans:result', 'AdminBansResult');
+                $r->add('GET',           '/admin/bans/delete/{id:[1-9]\d*}/{token}[/{uid:[2-9]|[1-9]\d+}]', 'AdminBans:delete', 'AdminBansDelete');
             }
         }
         // только админ

+ 28 - 4
app/Models/Pages/Admin/Bans.php

@@ -6,6 +6,7 @@ use ForkBB\Core\Container;
 use ForkBB\Core\Validator;
 use ForkBB\Models\Pages\Admin;
 use ForkBB\Models\User\Model as User;
+use RuntimeException;
 
 class Bans extends Admin
 {
@@ -687,9 +688,16 @@ class Bans extends Admin
 
                 $this->c->bans->load();
 
-                return $this->c->Redirect
-                    ->page('AdminBans')
-                    ->message($isNew ? 'Ban added redirect' : 'Ban edited redirect');
+                $redirect = $this->c->Redirect;
+
+                if ($isNew && ! empty($args['uid']) && 1 === $this->banCount) {
+                    $user = \reset($userList);
+                    $redirect->url($user->link);
+                } else {
+                    $redirect->page('AdminBans');
+                }
+
+                return $redirect->message($isNew ? 'Ban added redirect' : 'Ban edited redirect');
             }
 
             $data         = $v->getData();
@@ -862,6 +870,8 @@ class Bans extends Admin
      * @param array $args
      * @param string $method
      *
+     * @throws RuntimeException
+     *
      * @return Page
      */
     public function delete(array $args, $method)
@@ -875,6 +885,20 @@ class Bans extends Admin
         ];
         $this->c->bans->delete($ids);
 
-        return $this->c->Redirect->page('AdminBans')->message('Ban removed redirect');
+        $redirect = $this->c->Redirect;
+
+        if (empty($args['uid'])) {
+            $redirect->page('AdminBans');
+        } else {
+            $user = $this->c->users->load((int) $args['uid']);
+
+            if (! $user instanceof User) {
+                throw new RuntimeException('User profile not found');
+            }
+
+            $redirect->url($user->link);
+        }
+
+        return $redirect->message('Ban removed redirect');
     }
 }

+ 9 - 2
app/Models/Pages/Profile.php

@@ -93,13 +93,20 @@ abstract class Profile extends Page
                 $btns['unban-user'] = [
                     $this->c->Router->link('AdminBansDelete', [
                         'id'    => $id,
-                        'token' => $this->c->Csrf->create('AdminBansDelete', ['id' => $id]),
+                        'uid'   => $this->curUser->id,
+                        'token' => $this->c->Csrf->create('AdminBansDelete', [
+                            'id'  => $id,
+                            'uid' => $this->curUser->id,
+                        ]),
                     ]),
                     \ForkBB\__('Unban user'),
                 ];
             } else {
                 $btns['ban-user'] = [
-                    $this->c->Router->link('AdminBansNew',  ['ids' => $this->curUser->id]),
+                    $this->c->Router->link('AdminBansNew',  [
+                        'ids' => $this->curUser->id,
+                        'uid' => $this->curUser->id,
+                    ]),
                     \ForkBB\__('Ban user'),
                 ];
             }