Skip to content

Commit 8a07108

Browse files
authored
Merge pull request #17 from Crizz0/issue/16
Add ACP permission for ToU ACP pages
2 parents afbfe3b + 10c345c commit 8a07108

File tree

6 files changed

+145
-3
lines changed

6 files changed

+145
-3
lines changed

acp/tou_info.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ function module()
1919
'title' => 'ACP_TOU_TITLE',
2020
'modes' => array(
2121
'settings' => array(
22-
'title' => 'ACP_TOU_SETTINGS',
23-
'cat' => array('ACP_TOU_TITLE')
22+
'title' => 'ACP_TOU_SETTINGS',
23+
'auth' => 'ext_phpbbde/tou && acl_a_tou_manage',
24+
'cat' => array('ACP_TOU_TITLE')
2425
),
2526
'tousetup' => array(
2627
'title' => 'ACP_TOU_TOUSETUP',
28+
'auth' => 'ext_phpbbde/tou && acl_a_tou_manage',
2729
'cat' => array('ACP_TOU_TITLE')
2830
),
2931
'ppsetup' => array(
3032
'title' => 'ACP_TOU_PPSETUP',
33+
'auth' => 'ext_phpbbde/tou && acl_a_tou_manage',
3134
'cat' => array('ACP_TOU_TITLE')
3235
),
3336
),

config/services.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ services:
2525
- '@controller.helper'
2626
- '%core.root_path%'
2727
- '%core.php_ext%'
28+
phpbbde.tou.listener:
29+
class: phpbbde\tou\event\permission_listener
30+
arguments:
31+
- '@auth'
32+
tags:
33+
- { name: event.listener }

event/permission_listener.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
*
4+
* @package phpBB.de Terms of use
5+
* @copyright (c) 2020 https://www.phpBB.de, Crizzo
6+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7+
*
8+
*/
9+
10+
namespace phpbbde\tou\event;
11+
12+
/**
13+
* @ignore
14+
*/
15+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16+
17+
/**
18+
* Event listener
19+
*/
20+
class permission_listener implements EventSubscriberInterface
21+
{
22+
/** @var \phpbb\auth\auth */
23+
protected $auth;
24+
25+
/**
26+
* Constructor
27+
*
28+
* @param \phpbb\template\template $template Template object
29+
*/
30+
public function __construct(\phpbb\auth\auth $auth)
31+
{
32+
$this->auth = $auth;
33+
}
34+
35+
static public function getSubscribedEvents()
36+
{
37+
return array(
38+
'core.permissions' => 'permissions',
39+
);
40+
}
41+
42+
/**
43+
* Add permissions
44+
*
45+
* @param object $event The event object
46+
* @return null
47+
* @access public
48+
*/
49+
public function permissions($event)
50+
{
51+
$permissions = $event['permissions'];
52+
$permissions['a_tou_manage'] = array('lang' => 'ACL_A_TOU_MANAGE', 'cat' => 'misc');
53+
$event['permissions'] = $permissions;
54+
}
55+
}

language/de/permissions_tou.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
*
4+
* Terms of Use extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2020 Crizzo <https://www.phpBB.de>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
12+
/**
13+
* DO NOT CHANGE
14+
*/
15+
if (!defined('IN_PHPBB'))
16+
{
17+
exit;
18+
}
19+
if (empty($lang) || !is_array($lang))
20+
{
21+
$lang = array();
22+
}
23+
24+
$lang = array_merge($lang, array(
25+
'ACL_A_TOU_MANAGE' => 'Kann “Terms of Use“ verwalten',
26+
));

language/en/permissions_tou.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
*
4+
* Terms of Use extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2020 Crizzo <https://www.phpBB.de>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
12+
/**
13+
* DO NOT CHANGE
14+
*/
15+
if (!defined('IN_PHPBB'))
16+
{
17+
exit;
18+
}
19+
if (empty($lang) || !is_array($lang))
20+
{
21+
$lang = array();
22+
}
23+
24+
$lang = array_merge($lang, array(
25+
'ACL_A_TOU_MANAGE' => 'Can manage “Terms of Use“',
26+
));

migrations/v110.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,35 @@ public function update_data()
5151
array('config_text.add', array('tou_custom_pp_uid', '')),
5252
array('config_text.add', array('tou_custom_pp_bitfield', '')),
5353
array('config_text.add', array('tou_custom_pp_flags', OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS)),
54-
54+
// Add permissions
55+
array('permission.add', array('a_tou_manage', true)),
56+
// Add config version
5557
array('config.add', array('tou_ext_version', '1.1.0')),
5658
);
59+
60+
// Check if admin role exists and assign permission to admin role
61+
if ($this->role_exists('ROLE_ADMIN_FULL'))
62+
{
63+
$data[] = array('permission.permission_set', array('ROLE_ADMIN_FULL', 'a_tou_manage', 'role', true));
64+
}
5765
return $data;
5866
}
67+
68+
/**
69+
* Checks whether the given role does exist or not.
70+
*
71+
* @param String $role the name of the role
72+
* @return true if the role exists, false otherwise
73+
* Source: https://github.com/paul999/mention/
74+
*/
75+
private function role_exists($role)
76+
{
77+
$sql = 'SELECT role_id
78+
FROM ' . ACL_ROLES_TABLE . "
79+
WHERE role_name = '" . $this->db->sql_escape($role) . "'";
80+
$result = $this->db->sql_query_limit($sql, 1);
81+
$role_id = $this->db->sql_fetchfield('role_id');
82+
$this->db->sql_freeresult($result);
83+
return $role_id;
84+
}
5985
}

0 commit comments

Comments
 (0)