Skip to content

Commit

Permalink
Merge pull request #36 from Crizz0/issue/35
Browse files Browse the repository at this point in the history
Add permission to a few standard roles
  • Loading branch information
Crizz0 authored Sep 1, 2020
2 parents 70dd09f + e05b573 commit 8aad3b8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
4 changes: 2 additions & 2 deletions migrations/pastebin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function update_schema()
{
return array(
'add_tables' => array(
$this->table_prefix . 'pb' => array(
$this->table_prefix . 'pastebin' => array(
'COLUMNS' => array(
'snippet_id' => array('UINT:8', null, 'auto_increment'),
'snippet_author' => array('UINT:8', 0),
Expand All @@ -50,7 +50,7 @@ public function update_schema()
public function revert_schema()
{
return array(
'drop_tables' => array($this->table_prefix . 'pb'),
'drop_tables' => array($this->table_prefix . 'pastebin'),
);
}

Expand Down
71 changes: 71 additions & 0 deletions migrations/v204.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
*
* Pastebin extension for the phpBB Forum Software package.
*
* @copyright (c) 2020 Crizzo <https://www.phpBB.de>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

namespace phpbbde\pastebin\migrations;

class v204 extends \phpbb\db\migration\migration
{
static public function depends_on()
{
return array(
'\phpbbde\pastebin\migrations\v_0_0_1',
);
}

public function update_data()
{
$data = array(
array('config.update', array('pastebin_version', '2.0.4')),
);

// Check if user role exists and assign permission to user standard role
if ($this->role_exists('ROLE_USER_STANDARD'))
{
$data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_post', 'role', true));
$data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_edit', 'role', true));
$data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_delete', 'role', true));
$data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_post_novc', 'role', true));
$data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_view', 'role', true));
}
// Check if moderator role exists and assign permission to moderator standard role
if ($this->role_exists('ROLE_MOD_STANDARD'))
{
$data[] = array('permission.permission_set', array('ROLE_MOD_STANDARD', 'm_pastebin_delete', 'role', true));
$data[] = array('permission.permission_set', array('ROLE_MOD_STANDARD', 'm_pastebin_edit', 'role', true));
$data[] = array('permission.permission_set', array('ROLE_MOD_STANDARD', 'm_pastebin_post_notlim', 'role', true));
}
// Check if moderator role exists and assign permission to moderator full role
if ($this->role_exists('ROLE_MOD_FULL'))
{
$data[] = array('permission.permission_set', array('ROLE_MOD_FULL', 'm_pastebin_delete', 'role', true));
$data[] = array('permission.permission_set', array('ROLE_MOD_FULL', 'm_pastebin_edit', 'role', true));
$data[] = array('permission.permission_set', array('ROLE_MOD_FULL', 'm_pastebin_post_notlim', 'role', true));
}

return $data;
}
/**
* Checks whether the given role does exist or not.
*
* @param String $role the name of the role
* @return true if the role exists, false otherwise
* Source: https://github.com/paul999/mention/
*/
private function role_exists($role)
{
$sql = 'SELECT role_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = '" . $this->db->sql_escape($role) . "'";
$result = $this->db->sql_query_limit($sql, 1);
$role_id = $this->db->sql_fetchfield('role_id');
$this->db->sql_freeresult($result);
return $role_id;
}
}

0 comments on commit 8aad3b8

Please sign in to comment.