Skip to content

Commit 8aad3b8

Browse files
authored
Merge pull request #36 from Crizz0/issue/35
Add permission to a few standard roles
2 parents 70dd09f + e05b573 commit 8aad3b8

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

migrations/pastebin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function update_schema()
2626
{
2727
return array(
2828
'add_tables' => array(
29-
$this->table_prefix . 'pb' => array(
29+
$this->table_prefix . 'pastebin' => array(
3030
'COLUMNS' => array(
3131
'snippet_id' => array('UINT:8', null, 'auto_increment'),
3232
'snippet_author' => array('UINT:8', 0),
@@ -50,7 +50,7 @@ public function update_schema()
5050
public function revert_schema()
5151
{
5252
return array(
53-
'drop_tables' => array($this->table_prefix . 'pb'),
53+
'drop_tables' => array($this->table_prefix . 'pastebin'),
5454
);
5555
}
5656

migrations/v204.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
*
4+
* Pastebin 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+
namespace phpbbde\pastebin\migrations;
12+
13+
class v204 extends \phpbb\db\migration\migration
14+
{
15+
static public function depends_on()
16+
{
17+
return array(
18+
'\phpbbde\pastebin\migrations\v_0_0_1',
19+
);
20+
}
21+
22+
public function update_data()
23+
{
24+
$data = array(
25+
array('config.update', array('pastebin_version', '2.0.4')),
26+
);
27+
28+
// Check if user role exists and assign permission to user standard role
29+
if ($this->role_exists('ROLE_USER_STANDARD'))
30+
{
31+
$data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_post', 'role', true));
32+
$data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_edit', 'role', true));
33+
$data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_delete', 'role', true));
34+
$data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_post_novc', 'role', true));
35+
$data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_view', 'role', true));
36+
}
37+
// Check if moderator role exists and assign permission to moderator standard role
38+
if ($this->role_exists('ROLE_MOD_STANDARD'))
39+
{
40+
$data[] = array('permission.permission_set', array('ROLE_MOD_STANDARD', 'm_pastebin_delete', 'role', true));
41+
$data[] = array('permission.permission_set', array('ROLE_MOD_STANDARD', 'm_pastebin_edit', 'role', true));
42+
$data[] = array('permission.permission_set', array('ROLE_MOD_STANDARD', 'm_pastebin_post_notlim', 'role', true));
43+
}
44+
// Check if moderator role exists and assign permission to moderator full role
45+
if ($this->role_exists('ROLE_MOD_FULL'))
46+
{
47+
$data[] = array('permission.permission_set', array('ROLE_MOD_FULL', 'm_pastebin_delete', 'role', true));
48+
$data[] = array('permission.permission_set', array('ROLE_MOD_FULL', 'm_pastebin_edit', 'role', true));
49+
$data[] = array('permission.permission_set', array('ROLE_MOD_FULL', 'm_pastebin_post_notlim', 'role', true));
50+
}
51+
52+
return $data;
53+
}
54+
/**
55+
* Checks whether the given role does exist or not.
56+
*
57+
* @param String $role the name of the role
58+
* @return true if the role exists, false otherwise
59+
* Source: https://github.com/paul999/mention/
60+
*/
61+
private function role_exists($role)
62+
{
63+
$sql = 'SELECT role_id
64+
FROM ' . ACL_ROLES_TABLE . "
65+
WHERE role_name = '" . $this->db->sql_escape($role) . "'";
66+
$result = $this->db->sql_query_limit($sql, 1);
67+
$role_id = $this->db->sql_fetchfield('role_id');
68+
$this->db->sql_freeresult($result);
69+
return $role_id;
70+
}
71+
}

0 commit comments

Comments
 (0)