Skip to content

Commit 37ad317

Browse files
authored
Merge pull request #269 from iMattPro/permissions
Rework the permissions systems documentation in extensions
2 parents 73d9bbb + 2e438cd commit 37ad317

File tree

3 files changed

+88
-135
lines changed

3 files changed

+88
-135
lines changed

development/extensions/index.rst

-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ Welcome to phpBB's extension development tutorial and documentation.
2727
skeleton_extension
2828
events_list
2929
database_types_list
30-
permission_system

development/extensions/permission_system.rst

-124
This file was deleted.

development/extensions/tutorial_permissions.rst

+88-10
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ Tutorial: Permissions
55
Introduction
66
============
77

8-
Adding new permissions in an extension is an easy three-step process:
8+
The permission system in phpBB is used to control access to different parts of the software. It works by allowing administrators to assign certain permissions to user groups or individual users, which determine what actions they are able to perform.
99

1010
1. `Create permissions`_ with a migration.
1111
2. `Define permissions`_ with language keys.
1212
3. `Wire up permissions`_ with events.
13+
4. `Checking permissions`_ with PHP.
14+
5. `Understanding Permissions`_ in phpBB.
1315

1416
Create permissions
1517
==================
@@ -28,7 +30,7 @@ assign your permissions to if desired.
2830
Permissions must first be created in a migration using the :doc:`../migrations/tools/permission`.
2931
It helps with adding, removing, setting, and unsetting permissions and adding
3032
or removing permission roles. For example, to create a new User permission
31-
``u_foo_bar`` and set it to "yes" for the Registered Users group and
33+
``u_foo_bar`` and set it to ``YES`` for the Registered Users group and
3234
the Standard User Role:
3335

3436
.. code-block:: php
@@ -66,17 +68,93 @@ add your new permissions to phpBB's permission data array:
6668

6769
.. code-block:: php
6870
69-
$permissions = $event['permissions'];
70-
$permissions['u_foo_bar'] = ['lang' => 'ACL_U_FOOBAR', 'cat' => 'post'];
71-
$event['permissions'] = $permissions;
71+
$event->update_subarray('permissions', 'u_foo_bar', ['lang' => 'ACL_U_FOOBAR', 'cat' => 'post']);
7272
73-
.. note::
73+
.. warning::
7474

75-
Note how the ``permissions`` event variable is first copied by assigning
76-
it to a local variable, then modified, and then copied back. This is because the event
77-
variables are overloaded, which is a limitation in PHP. For example, this shortcut
78-
will not work:
75+
In order to support phpBB 3.2.1 or earlier versions, you can not use the ``update_subarray()`` method, and must instead use the following older style of code:
7976

8077
.. code-block:: php
8178
79+
# Wiring permissions the correct way for phpBB 3.1.0 - 3.2.1
80+
$permissions = $event['permissions'];
81+
$permissions['u_foo_bar'] = ['lang' => 'ACL_U_FOOBAR', 'cat' => 'post'];
82+
$event['permissions'] = $permissions;
83+
84+
# Notice that the above permissions $event variable must first be copied by assigning it to a
85+
# local variable, then modified, and then copied back. This is because the event variables are
86+
# overloaded, which is a limitation in PHP. For example, this shortcut will not work:
8287
$event['permissions']['u_foo_bar'] = ['lang' => 'ACL_U_FOOBAR', 'cat' => 'post'];
88+
89+
Checking permissions
90+
====================
91+
92+
A user's permission can be checked by calling ``$auth->acl_get()``:
93+
94+
.. code-block:: php
95+
96+
// Check a user's permissions
97+
$auth->acl_get('u_foo_bar');
98+
99+
If it is specific to a forum (i.e local) then pass it the forum ID as a second argument:
100+
101+
.. code-block:: php
102+
103+
// Check a user's permission in the forum with ID 3
104+
$auth->acl_get('u_foo_bar', 3);
105+
106+
For forums one can use the forum specific call ``$auth->acl_getf()``:
107+
108+
.. code-block:: php
109+
110+
// Check a forum's permissions
111+
$auth->acl_getf('f_your_permission');
112+
113+
It is also possible to check for more than one option with ``acl_gets()``:
114+
115+
.. code-block:: php
116+
117+
$auth->acl_gets('permission1'[, 'permission2', ..., 'permissionNth'], $forumId);
118+
119+
.. note::
120+
121+
When checking permissions, it's also important to keep in mind whether the global or local permissions should be checked.
122+
If ``acl_get`` is called without a forum id, the global permissions will be used. Instead, passing a forum id will also
123+
check the local permissions which can then potentially override a ``NO`` with a ``YES``.
124+
After checking all user, group, forum, and global permissions, the return permission is always either ``YES`` or ``NO``,
125+
``NEVER`` is only used to enforce a ``NO``.
126+
127+
Understanding Permissions
128+
=========================
129+
130+
Permissions in phpBB control what actions users are allowed to perform on the forum, such as creating a new topic, replying to a post, or editing a user’s profile. Each permission is assigned a value of ``YES``, ``NO``, or ``NEVER``.
131+
132+
- ``YES`` means that the user or group is allowed to perform the action.
133+
- ``NO`` means that the user or group is not allowed to perform the action, but it can be overruled by a ``YES`` from a group or role they are assigned to.
134+
- ``NEVER`` means that the user or group is not allowed to perform the action and cannot be overruled by a ``YES`` from a group or role they are assigned to.
135+
136+
When a user requests to perform an action, phpBB combines all the permissions assigned to the user through their groups, roles, and direct permission assignments. If any permission is set to ``NEVER``, it overrides all other permissions and denies the user access to that action. If a permission is set to ``NO``, it can be overridden by a ``YES`` permission from another group or role.
137+
138+
Permission Types
139+
----------------
140+
141+
There are four types of permissions in phpBB:
142+
143+
- ``a_*`` Administrator: These permissions are applied to users who are assigned administrator roles.
144+
- ``f_*`` Forum: These permissions are applied to individual forums and can be set for each user group or individual user.
145+
- ``m_*`` Moderator: These permissions are applied to users who are assigned moderator roles for specific forums.
146+
- ``u_*`` User: These permissions are applied to individual users and override the permissions set for their user group.
147+
148+
Local and Global Permissions
149+
----------------------------
150+
151+
Permissions can be set to apply locally or globally. Local permissions are specific to a single forum, while global permissions apply to the entire board. By default, forum permissions are set to local. Administrator and User permissions are typically set to global.
152+
153+
Permission options can also be set to apply both locally and globally, which is typical for Moderator permissions. This allows some users to be granted the permission on a single forum, while others might be granted the permission board-wide.
154+
155+
Roles
156+
-----
157+
158+
Roles are a predefined set of permission options that can be applied to users or groups. When the permission options of a role are changed, the users or groups assigned that role are automatically updated.
159+
160+
The effective permission for any option is determined by a combination of the user's group membership, assigned roles, and direct permission assignments. In some cases, opposing permissions may exist, which can lead to unexpected results. It's important to carefully consider the permission settings to ensure that users are granted the appropriate level of access on the forum.

0 commit comments

Comments
 (0)