Skip to content

Commit 9c3c118

Browse files
committed
Update and move forum set up code
1 parent b008a4e commit 9c3c118

4 files changed

Lines changed: 144 additions & 24 deletions

File tree

controller/admin_controller.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -169,31 +169,10 @@ public function set_ideas_forum_options()
169169
trigger_error($this->language->lang('ACP_IDEAS_NO_FORUM') . adm_back_link($this->u_action), E_USER_WARNING);
170170
}
171171

172-
if (!class_exists('auth_admin'))
173-
{
174-
include $this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext;
175-
}
176-
$auth_admin = new \auth_admin();
177-
178172
$forum_id = (int) $this->config['ideas_forum_id'];
179173

180-
// Get the REGISTERED usergroup ID
181-
$sql = 'SELECT group_id
182-
FROM ' . GROUPS_TABLE . "
183-
WHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'";
184-
$this->db->sql_query($sql);
185-
$group_id = (int) $this->db->sql_fetchfield('group_id');
186-
187-
// Get 'f_' local REGISTERED users group permissions array for the ideas forum
188-
// Default undefined permissions to ACL_NO
189-
$hold_ary = $auth_admin->get_mask('set', false, $group_id, $forum_id, 'f_', 'local', ACL_NO);
190-
$auth_settings = $hold_ary[$group_id][$forum_id];
191-
192-
// Set 'Can start new topics' permissions to 'Never' for the ideas forum
193-
$auth_settings['f_post'] = ACL_NEVER;
194-
195-
// Update the registered usergroup permissions for selected Ideas forum...
196-
$auth_admin->acl_set('group', $forum_id, $group_id, $auth_settings);
174+
$permission_helper = new \phpbb\ideas\factory\permission_helper($this->config, $this->db, $this->phpbb_root_path, $this->php_ext);
175+
$permission_helper->set_ideas_forum_permissions($forum_id);
197176

198177
// Disable auto-pruning for ideas forum
199178
$sql = 'UPDATE ' . FORUMS_TABLE . '

factory/permission_helper.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
*
4+
* Ideas extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\ideas\factory;
12+
13+
class permission_helper
14+
{
15+
/**
16+
* @var \phpbb\config\config
17+
*/
18+
protected $config;
19+
20+
/**
21+
* @var \phpbb\db\driver\driver_interface
22+
*/
23+
protected $db;
24+
25+
/**
26+
* @var string
27+
*/
28+
protected $phpbb_root_path;
29+
30+
/**
31+
* @var string
32+
*/
33+
protected $php_ext;
34+
35+
/**
36+
* Constructor
37+
*
38+
* @param \phpbb\config\config $config Config object
39+
* @param \phpbb\db\driver\driver_interface $db Database object
40+
* @param string $phpbb_root_path phpBB root path
41+
* @param string $php_ext php_ext
42+
* @access public
43+
*/
44+
public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext)
45+
{
46+
$this->config = $config;
47+
$this->db = $db;
48+
$this->phpbb_root_path = $phpbb_root_path;
49+
$this->php_ext = $php_ext;
50+
}
51+
52+
/**
53+
* Set the the best permissions for an Ideas forum.
54+
*
55+
* @param int $forum_id A forum id
56+
*/
57+
public function set_ideas_forum_permissions($forum_id)
58+
{
59+
if (!class_exists('auth_admin'))
60+
{
61+
include $this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext;
62+
}
63+
$auth_admin = new \auth_admin();
64+
65+
// Get the REGISTERED usergroup ID
66+
$sql = 'SELECT group_id
67+
FROM ' . GROUPS_TABLE . "
68+
WHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'";
69+
$this->db->sql_query($sql);
70+
$group_id = (int) $this->db->sql_fetchfield('group_id');
71+
72+
// Get 'f_' local REGISTERED users group permissions array for the ideas forum
73+
// Default undefined permissions to ACL_NO
74+
$hold_ary = $auth_admin->get_mask('set', false, $group_id, $forum_id, 'f_', 'local', ACL_NO);
75+
$auth_settings = $hold_ary[$group_id][$forum_id];
76+
77+
// Set 'Can start new topics' permissions to 'Yes' for the ideas forum
78+
$auth_settings['f_post'] = ACL_YES;
79+
80+
// Can not post announcement or stickies, polls, use topic icons or lock own topic
81+
$auth_settings['f_announce'] = ACL_NEVER;
82+
$auth_settings['f_announce_global'] = ACL_NEVER;
83+
$auth_settings['f_sticky'] = ACL_NEVER;
84+
$auth_settings['f_poll'] = ACL_NEVER;
85+
$auth_settings['f_icons'] = ACL_NEVER;
86+
$auth_settings['f_user_lock'] = ACL_NEVER;
87+
88+
// Update the registered usergroup permissions for selected Ideas forum...
89+
$auth_admin->acl_set('group', $forum_id, $group_id, $auth_settings);
90+
}
91+
}

language/en/phpbb_ideas_acp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'ACP_IDEAS_FORUM_ID_EXPLAIN' => 'Select the forum that Ideas topics will be posted to. Once done, apply Ideas forum setup clicking the appropriate button below.',
2525
'ACP_IDEAS_FORUM_SETUP' => 'Set up the Ideas forum',
2626
'ACP_IDEAS_FORUM_SETUP_CONFIRM' => 'Are you sure you wish to set up the Ideas forum?',
27-
'ACP_IDEAS_FORUM_SETUP_EXPLAIN' => 'Sets up the Ideas forum. Users will not be able to start new topics. Additionally, auto-pruning will be disabled. Note: you have to set the Ideas forum first.',
27+
'ACP_IDEAS_FORUM_SETUP_EXPLAIN' => 'Sets up the Ideas forum. Many permissions will be pre-configured. Additionally, auto-pruning will be disabled. Note: you have to set the Ideas forum first.',
2828
'ACP_IDEAS_FORUM_SETUP_UPDATED' => 'phpBB Ideas forum settings successfully updated.',
2929
'ACP_IDEAS_NO_FORUM' => 'No forum selected',
3030
'ACP_IDEAS_SETTINGS_UPDATED' => 'phpBB Ideas settings updated.',

migrations/m12_set_permissions.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
*
4+
* Ideas extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\ideas\migrations;
12+
13+
class m12_set_permissions extends \phpbb\db\migration\migration
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public static function depends_on()
19+
{
20+
return [
21+
'\phpbb\ideas\migrations\m1_initial_schema',
22+
'\phpbb\ideas\migrations\m3_acp_data',
23+
'\phpbb\ideas\migrations\m11_reparse_old_ideas',
24+
];
25+
}
26+
27+
/**
28+
* {@inheritDoc}
29+
*/
30+
public function effectively_installed()
31+
{
32+
return $this->config['ideas_forum_id'] === 0;
33+
}
34+
35+
/**
36+
* @inheritDoc
37+
*/
38+
public function update_data()
39+
{
40+
return [
41+
['custom', [[$this, 'update_permissions']]],
42+
];
43+
}
44+
45+
public function update_permissions()
46+
{
47+
$permission_helper = new \phpbb\ideas\factory\permission_helper($this->config, $this->db, $this->phpbb_root_path, $this->php_ext);
48+
$permission_helper->set_ideas_forum_permissions($this->config['ideas_forum_id']);
49+
}
50+
}

0 commit comments

Comments
 (0)