Skip to content

Commit

Permalink
Add ACP permissions
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Friedman <[email protected]>
  • Loading branch information
iMattPro committed Jun 14, 2022
1 parent eefb5fc commit fe14790
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
4 changes: 2 additions & 2 deletions acp/main_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public function module()
'modes' => array(
'manage' => array(
'title' => 'ACP_MANAGE_ADS_TITLE',
'auth' => 'ext_phpbb/ads && acl_a_board',
'auth' => 'ext_phpbb/ads && acl_a_phpbb_ads_m',
'cat' => array('ACP_PHPBB_ADS_TITLE')
),
'settings' => array(
'title' => 'ACP_ADS_SETTINGS_TITLE',
'auth' => 'ext_phpbb/ads && acl_a_board',
'auth' => 'ext_phpbb/ads && acl_a_phpbb_ads_s',
'cat' => array('ACP_PHPBB_ADS_TITLE')
),
),
Expand Down
2 changes: 2 additions & 0 deletions event/main_listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public function __construct(\phpbb\template\template $template, \phpbb\template\
public function set_permissions($event)
{
$event->update_subarray('permissions', 'u_phpbb_ads', ['lang' => 'ACL_U_PHPBB_ADS', 'cat' => 'misc']);
$event->update_subarray('permissions', 'a_phpbb_ads_m', ['lang' => 'ACL_A_PHPBB_ADS_M', 'cat' => 'misc']);
$event->update_subarray('permissions', 'a_phpbb_ads_s', ['lang' => 'ACL_A_PHPBB_ADS_S', 'cat' => 'misc']);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions language/en/permissions_ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@

$lang = array_merge($lang, array(
'ACL_U_PHPBB_ADS' => 'Can view own advertisement management statistics',
'ACL_A_PHPBB_ADS_M' => 'Can manage phpBB Advertisements',
'ACL_A_PHPBB_ADS_S' => 'Can manage phpBB Advertisement settings',
));
92 changes: 92 additions & 0 deletions migrations/v20x/m4_admin_permission.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
*
* Advertisement management. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2022 phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

namespace phpbb\ads\migrations\v20x;

/**
* Migration stage 4: Add Admin Permission
*/
class m4_admin_permission extends \phpbb\db\migration\container_aware_migration
{
/**
* {@inheritdoc
*/
public function effectively_installed()
{
$sql = 'SELECT * FROM ' . $this->table_prefix . "acl_options
WHERE auth_option = 'a_phpbb_ads_m' OR auth_option = 'a_phpbb_ads_s'";
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);

return $row !== false;
}

/**
* {@inheritDoc}
*/
public static function depends_on()
{
return [
'\phpbb\ads\migrations\v10x\m1_initial_schema',
'\phpbb\ads\migrations\v10x\m2_acp_module',
'\phpbb\ads\migrations\v20x\m3_add_start_date',
];
}

/**
* {@inheritDoc}
*/
public function update_data()
{
return [
// Add permission
['permission.add', ['a_phpbb_ads_m', true]],
['permission.add', ['a_phpbb_ads_s', true]],

// Set permissions
['if', [
['permission.role_exists', ['ROLE_ADMIN_FULL']],
['permission.permission_set', ['ROLE_ADMIN_FULL', 'a_phpbb_ads_m']],
]],
['if', [
['permission.role_exists', ['ROLE_ADMIN_FULL']],
['permission.permission_set', ['ROLE_ADMIN_FULL', 'a_phpbb_ads_s']],
]],
['if', [
['permission.role_exists', ['ROLE_ADMIN_STANDARD']],
['permission.permission_set', ['ROLE_ADMIN_STANDARD', 'a_phpbb_ads_m']],
]],
['if', [
['permission.role_exists', ['ROLE_ADMIN_STANDARD']],
['permission.permission_set', ['ROLE_ADMIN_STANDARD', 'a_phpbb_ads_s']],
]],

// Update module auth
['custom', [[$this, 'update_acp_module_auth']]],
];
}

/**
* Update module auth manually, because "module.remove" tool causes problems when deleting extension.
*/
public function update_acp_module_auth()
{
$sql = 'UPDATE ' . $this->container->getParameter('tables.modules') . "
SET module_auth = 'ext_phpbb/ads && acl_a_phpbb_ads_m'
WHERE module_langname = 'ACP_MANAGE_ADS_TITLE'";
$this->db->sql_query($sql);

$sql = 'UPDATE ' . $this->container->getParameter('tables.modules') . "
SET module_auth = 'ext_phpbb/ads && acl_a_phpbb_ads_s'
WHERE module_langname = 'ACP_ADS_SETTINGS_TITLE'";
$this->db->sql_query($sql);
}
}

0 comments on commit fe14790

Please sign in to comment.