diff --git a/acp/main_info.php b/acp/main_info.php index 63db3058..0d302c1b 100644 --- a/acp/main_info.php +++ b/acp/main_info.php @@ -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') ), ), diff --git a/event/main_listener.php b/event/main_listener.php index aab5314b..0ac300e8 100644 --- a/event/main_listener.php +++ b/event/main_listener.php @@ -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']); } /** diff --git a/language/en/permissions_ads.php b/language/en/permissions_ads.php index 4b6c0730..ddf86f27 100644 --- a/language/en/permissions_ads.php +++ b/language/en/permissions_ads.php @@ -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', )); diff --git a/migrations/v20x/m4_admin_permission.php b/migrations/v20x/m4_admin_permission.php new file mode 100644 index 00000000..60ae41e0 --- /dev/null +++ b/migrations/v20x/m4_admin_permission.php @@ -0,0 +1,92 @@ + + * @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); + } +}