Visman 7 anni fa
parent
commit
c7d666fa61
4 ha cambiato i file con 125 aggiunte e 20 eliminazioni
  1. 16 20
      app/Models/Pages/Profile.php
  2. 32 0
      app/Models/Rules.php
  3. 75 0
      app/Models/Rules/Profile.php
  4. 2 0
      app/config/main.dist.php

+ 16 - 20
app/Models/Pages/Profile.php

@@ -39,14 +39,10 @@ class Profile extends Page
             return $this->c->Message->message('Bad request');
             return $this->c->Message->message('Bad request');
         }
         }
 
 
-        $myProf      = $curUser->id === $this->user->id;
-        $isAdmin     = $this->user->isAdmin && ($myProf || ! $curUser->isAdmin);
-        $isModer     = $this->user->isAdmMod && ($myProf || ! $curUser->isAdmMod);
-        $canEditProf = $myProf || $isAdmin || ($isModer && '1' == $this->user->g_mod_edit_users);
-        $canEditConf = $myProf || $isAdmin || ($isModer && '1' == $this->user->g_mod_edit_users); // ????
+        $rules = $this->c->ProfileRules->setUser($curUser);
 
 
         if ($isEdit) {
         if ($isEdit) {
-            if (! $canEditProf) {
+            if (! $rules->editProfile) {
                 return $this->c->Message->message('Bad request');
                 return $this->c->Message->message('Bad request');
             }
             }
 
 
@@ -55,6 +51,10 @@ class Profile extends Page
 
 
         $this->c->Lang->load('profile');
         $this->c->Lang->load('profile');
 
 
+        if ($isEdit && 'POST' === $method) {
+
+        }
+
         $clSuffix = $isEdit ? '-edit' : '';
         $clSuffix = $isEdit ? '-edit' : '';
 
 
         if ($isEdit) {
         if ($isEdit) {
@@ -82,7 +82,7 @@ class Profile extends Page
             'class' => 'usertitle',
             'class' => 'usertitle',
             'type'  => 'wrap',
             'type'  => 'wrap',
         ];
         ];
-        if ($isEdit && ($isAdmin || $isModer && '1' == $this->user->g_mod_rename_users)) {
+        if ($isEdit && $rules->rename) {
             $fieldset['username'] = [
             $fieldset['username'] = [
                 'id'        => 'username',
                 'id'        => 'username',
                 'type'      => 'text',
                 'type'      => 'text',
@@ -101,7 +101,7 @@ class Profile extends Page
                 'value'   => $curUser->username,
                 'value'   => $curUser->username,
             ];
             ];
         }
         }
-        if ($isEdit && ($isAdmin || $isModer || '1' == $this->user->g_set_title)) {
+        if ($isEdit && $rules->setTitle) {
             $fieldset['title'] = [
             $fieldset['title'] = [
                 'id'        => 'title',
                 'id'        => 'title',
                 'type'      => 'text',
                 'type'      => 'text',
@@ -247,7 +247,7 @@ class Profile extends Page
 
 
         // контактная информация
         // контактная информация
         $fieldset = [];
         $fieldset = [];
-        if ($myProf || $this->user->isAdmMod) {
+        if ($rules->openEmail) {
             $fieldset['open-email'] = [
             $fieldset['open-email'] = [
                 'id'      => 'open-email',
                 'id'      => 'open-email',
                 'class'   => 'pline',
                 'class'   => 'pline',
@@ -257,11 +257,7 @@ class Profile extends Page
                 'href'    => 'mailto:' . $curUser->email,
                 'href'    => 'mailto:' . $curUser->email,
             ];
             ];
         }
         }
-        if (! $myProf
-            && (($this->user->isAdmMod && 1 === $curUser->email_setting)
-                || (! $this->user->isGuest && '1' == $this->user->g_send_email)
-            )
-        ) {
+        if ($rules->email) {
             if (0 === $curUser->email_setting) {
             if (0 === $curUser->email_setting) {
                 $fieldset['email'] = [
                 $fieldset['email'] = [
                     'id'      => 'email',
                     'id'      => 'email',
@@ -371,7 +367,7 @@ class Profile extends Page
                 'title'   => 'IP',
                 'title'   => 'IP',
             ];
             ];
         }
         }
-        if ($myProf || $this->user->isAdmMod) { // ????
+        if ($rules->lastvisit) {
             $fieldset['lastvisit'] = [
             $fieldset['lastvisit'] = [
                 'id'      => 'lastvisit',
                 'id'      => 'lastvisit',
                 'class'   => 'pline',
                 'class'   => 'pline',
@@ -446,7 +442,7 @@ class Profile extends Page
             );
             );
         }
         }
 
 
-        $this->fIndex    = $myProf ? 'profile' : 'userlist';
+        $this->fIndex    = $rules->my ? 'profile' : 'userlist';
         $this->nameTpl   = 'profile';
         $this->nameTpl   = 'profile';
         $this->onlinePos = 'profile-' . $curUser->id; // ????
         $this->onlinePos = 'profile-' . $curUser->id; // ????
         $this->title     = \ForkBB\__('%s\'s profile', $curUser->username);
         $this->title     = \ForkBB\__('%s\'s profile', $curUser->username);
@@ -454,19 +450,19 @@ class Profile extends Page
         $this->curUser   = $curUser;
         $this->curUser   = $curUser;
 
 
         $btns = [];
         $btns = [];
-        if (! $myProf && ($isAdmin || ($isModer && '1' == $this->user->g_mod_ban_users))) {
+        if ($rules->banUser) {
             $btns['ban-user'] = [
             $btns['ban-user'] = [
                 $this->c->Router->link('',  ['id' => $curUser->id]),
                 $this->c->Router->link('',  ['id' => $curUser->id]),
                 \ForkBB\__('Ban user'),
                 \ForkBB\__('Ban user'),
             ];
             ];
         }
         }
-        if (! $myProf && ($isAdmin || $isModer)) { // ????
+        if ($rules->deleteUser) {
             $btns['delete-user'] = [
             $btns['delete-user'] = [
                 $this->c->Router->link('',  ['id' => $curUser->id]),
                 $this->c->Router->link('',  ['id' => $curUser->id]),
                 \ForkBB\__('Delete user'),
                 \ForkBB\__('Delete user'),
             ];
             ];
         }
         }
-        if (!$isEdit && $canEditProf) {
+        if (! $isEdit && $rules->editProfile) {
             $btns['edit-profile'] = [
             $btns['edit-profile'] = [
                 $this->c->Router->link('EditUserProfile',  ['id' => $curUser->id]),
                 $this->c->Router->link('EditUserProfile',  ['id' => $curUser->id]),
                 \ForkBB\__('Edit '),
                 \ForkBB\__('Edit '),
@@ -478,7 +474,7 @@ class Profile extends Page
                 \ForkBB\__('View '),
                 \ForkBB\__('View '),
             ];
             ];
         }
         }
-        if ($canEditConf) {
+        if ($rules->editConfig) {
             $btns['edit-settings'] = [
             $btns['edit-settings'] = [
                 $this->c->Router->link('EditBoardConfig', ['id' => $curUser->id]),
                 $this->c->Router->link('EditBoardConfig', ['id' => $curUser->id]),
                 \ForkBB\__('Configure '),
                 \ForkBB\__('Configure '),

+ 32 - 0
app/Models/Rules.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace ForkBB\Models;
+
+use ForkBB\Core\Container;
+use ForkBB\Models\Model;
+use RuntimeException;
+
+class Rules extends Model
+{
+    /**
+     * Флаг готовности
+     * @var bool
+     */
+    protected $ready = false;
+
+    /**
+     * Возвращает значение свойства
+     *
+     * @param string $name
+     *
+     * @return mixed
+     */
+    public function __get($name)
+    {
+        if (true === $this->ready) {
+            return parent::__get($name);
+        } else {
+            throw new RuntimeException('The model of rules isn\'t ready');
+        }
+    }
+}

+ 75 - 0
app/Models/Rules/Profile.php

@@ -0,0 +1,75 @@
+<?php
+
+namespace ForkBB\Models\Rules;
+
+use ForkBB\Models\Model;
+use ForkBB\Models\Rules;
+use ForkBB\Models\User\Model as User;
+use RuntimeException;
+
+class Profile extends Rules
+{
+    protected $curUser;
+
+    protected $user;
+
+    /**
+     * Задает профиль пользователя для применения правил
+     *
+     * @param User $curUser
+     *
+     * @return ProfileRules
+     */
+    public function setUser(User $curUser)
+    {
+        $this->ready = true;
+
+        $this->user        = $this->c->user;
+        $this->curUser     = $curUser;
+        $this->my          = $curUser->id === $this->user->id;
+        $this->admin       = $this->user->isAdmin && ($this->my || ! $curUser->isAdmin);
+        $this->moderator   = $this->user->isAdmMod && ($this->my || ! $curUser->isAdmMod);
+        $this->editProfile = $this->my || $this->admin || ($this->moderator && '1' == $this->user->g_mod_edit_users);
+        $this->editConfig  = $this->my || $this->admin || ($this->moderator && '1' == $this->user->g_mod_edit_users); // ????
+
+        return $this;
+    }
+
+    public function getrename()
+    {
+        return $this->admin || ($this->moderator  && '1' == $this->user->g_mod_rename_users);
+    }
+
+    public function getsetTitle()
+    {
+        return $this->admin || $this->moderator || '1' == $this->user->g_set_title;
+    }
+
+    public function getopenEmail()
+    {
+        return $this->my || $this->user->isAdmMod;
+    }
+
+    public function getemail() // ?????
+    {
+        return ! $this->my
+            && (($this->user->isAdmMod && 1 === $this->curUser->email_setting)
+                || (! $this->user->isGuest && '1' == $this->user->g_send_email)
+            );
+    }
+
+    public function getlastvisit()
+    {
+        return $this->my || $this->user->isAdmMod;
+    }
+
+    public function getbanUser()
+    {
+        return ! $this->my && ($this->admin || ($this->moderator && '1' == $this->user->g_mod_ban_users));
+    }
+
+    public function getdeleteUser()
+    {
+        return ! $this->my && ($this->admin || $this->moderator); // ????
+    }
+}

+ 2 - 0
app/config/main.dist.php

@@ -227,5 +227,7 @@ return [
         'SearchModelTruncateIndex'   => \ForkBB\Models\Search\TruncateIndex::class,
         'SearchModelTruncateIndex'   => \ForkBB\Models\Search\TruncateIndex::class,
         'SearchModelPrepare' => \ForkBB\Models\Search\Prepare::class,
         'SearchModelPrepare' => \ForkBB\Models\Search\Prepare::class,
         'SearchModelExecute' => \ForkBB\Models\Search\Execute::class,
         'SearchModelExecute' => \ForkBB\Models\Search\Execute::class,
+
+        'ProfileRules' => \ForkBB\Models\Rules\Profile::class,
     ],
     ],
 ];
 ];