diff --git a/Listener.php b/Listener.php index 077ff59..ba68034 100644 --- a/Listener.php +++ b/Listener.php @@ -16,6 +16,8 @@ class Listener { public static function forumEntityStructure(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure) { - $structure->columns['wfp_password'] = ['type' => Entity::STR, 'maxLength' => 64, 'nullable' => true, 'default' => null]; + $structure->columns['wfp_password'] = [ + 'type' => Entity::STR, 'maxLength' => 64, 'nullable' => true, 'default' => null + ]; } } \ No newline at end of file diff --git a/XF/Entity/Forum.php b/XF/Entity/Forum.php index 5dfd90b..6e78089 100644 --- a/XF/Entity/Forum.php +++ b/XF/Entity/Forum.php @@ -16,14 +16,17 @@ public function isPasswordAccessGranted() $nodeId = $this->node_id; if (\XF::visitor()->hasNodePermission($nodeId, 'wfpBypass')) + { return true; + } $data = \XF::session()->get('wfp_data'); - if ($data && isset($data[$nodeId])) { if ($this->wfp_password == $data[$nodeId]) + { return true; + } } return false; } diff --git a/XF/Pub/Controller/Forum.php b/XF/Pub/Controller/Forum.php index 442a073..d99557b 100644 --- a/XF/Pub/Controller/Forum.php +++ b/XF/Pub/Controller/Forum.php @@ -6,6 +6,8 @@ class Forum extends XFCP_Forum { + use ForumPasswordTrait; + /** * @param ParameterBag $params * @return \XF\Mvc\Reply\Redirect|\XF\Mvc\Reply\View @@ -51,19 +53,7 @@ protected function assertViewableForum($nodeIdOrName, array $extraWith = []) /** @var \West\ForumPassword\XF\Entity\Forum $parent */ $parent = parent::assertViewableForum($nodeIdOrName, $extraWith); - if ($parent->wfp_password) - { - if (!$parent->isPasswordAccessGranted()) - { - throw $this->exception( - $this->rerouteController( - 'XF:Forum', - 'Password', - $parent->toArray() - ) - ); - } - } + $this->checkForumPasswordAccess($parent); return $parent; } diff --git a/XF/Pub/Controller/ForumPasswordTrait.php b/XF/Pub/Controller/ForumPasswordTrait.php new file mode 100644 index 0000000..b6f8b53 --- /dev/null +++ b/XF/Pub/Controller/ForumPasswordTrait.php @@ -0,0 +1,38 @@ +wfp_password) + { + if (\XF::visitor()->hasPermission('general', 'wfpAccessProtectedNodes')) + { + if (!$forum->isPasswordAccessGranted()) + { + throw $this->exception( + $this->rerouteController( + 'XF:Forum', + 'Password', + $forum->toArray() + ) + ); + } + } + else + { + throw $this->exception($this->noPermission()); + } + } + } +} \ No newline at end of file diff --git a/XF/Pub/Controller/Thread.php b/XF/Pub/Controller/Thread.php index 4568bdc..a92b5d9 100644 --- a/XF/Pub/Controller/Thread.php +++ b/XF/Pub/Controller/Thread.php @@ -4,24 +4,15 @@ class Thread extends XFCP_Thread { + use ForumPasswordTrait; + protected function assertViewableThread($threadId, array $extraWith = []) { $parent = parent::assertViewableThread($threadId, $extraWith); + /** @var \West\ForumPassword\XF\Entity\Forum $forum */ $forum = $parent->Forum; - if ($forum->wfp_password) - { - if (!$forum->isPasswordAccessGranted()) - { - throw $this->exception( - $this->rerouteController( - 'XF:Forum', - 'Password', - $forum->toArray() - ) - ); - } - } + $this->checkForumPasswordAccess($forum); return $parent; } diff --git a/_output/permissions/_metadata.json b/_output/permissions/_metadata.json index 3aec720..f62c8a8 100644 --- a/_output/permissions/_metadata.json +++ b/_output/permissions/_metadata.json @@ -1,5 +1,8 @@ { "forum-wfpBypass.json": { "hash": "a9accb917b5ccdee70cd3edca0a0499e" + }, + "general-wfpAccessProtectedNodes.json": { + "hash": "1732141476333360460c0d3c87d0711f" } } \ No newline at end of file diff --git a/_output/permissions/general-wfpAccessProtectedNodes.json b/_output/permissions/general-wfpAccessProtectedNodes.json new file mode 100644 index 0000000..6f3e32c --- /dev/null +++ b/_output/permissions/general-wfpAccessProtectedNodes.json @@ -0,0 +1,6 @@ +{ + "permission_type": "flag", + "interface_group_id": "generalPermissions", + "display_order": 100600, + "depend_permission_id": "" +} \ No newline at end of file diff --git a/_output/phrases/_metadata.json b/_output/phrases/_metadata.json index 29074b8..bd0ad2c 100644 --- a/_output/phrases/_metadata.json +++ b/_output/phrases/_metadata.json @@ -5,6 +5,12 @@ "version_string": "1.0.0", "hash": "da0146061bd27a8ec89d2ff32ef92654" }, + "permission.general_wfpAccessProtectedNodes.txt": { + "global_cache": false, + "version_id": 1000070, + "version_string": "1.0.0", + "hash": "37643a4b9b1cbd4127570885db0b7ca0" + }, "wfp_password_required.txt": { "global_cache": true, "version_id": 1000010, diff --git a/_output/phrases/permission.general_wfpAccessProtectedNodes.txt b/_output/phrases/permission.general_wfpAccessProtectedNodes.txt new file mode 100644 index 0000000..e14a101 --- /dev/null +++ b/_output/phrases/permission.general_wfpAccessProtectedNodes.txt @@ -0,0 +1 @@ +[West: Forum Password] Access password protected nodes \ No newline at end of file diff --git a/addon.json b/addon.json index c5ed91d..b3273d0 100644 --- a/addon.json +++ b/addon.json @@ -2,8 +2,8 @@ "legacy_addon_id": "", "title": "[West] Forum Password", "description": "Adds functionality which allows to protect the forum with a password.", - "version_id": 1000070, - "version_string": "1.0.0", + "version_id": 1000170, + "version_string": "1.0.1", "dev": "West", "dev_url": "https://t.me/West99", "faq_url": "",