Set permissions on a Forum

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
kizuzi
Registered User
Posts: 21
Joined: Sat Mar 28, 2020 7:41 am

Set permissions on a Forum

Post by kizuzi »

Dear,

I am writing an extension (for phpBB3.2) in that I want to give the users or admins the possibility to create new Groups and related Forums as simple as possible. They should have a form, in that the user or administrator write the name and the description and the group and the forum will be created. The group should get user permissions to the group related forum and the group moderators should get moderator permissions on that group related Forum.

Now my question: How I can set permission to a forum? It would be nice, if I could use a predefined permission role to set this permissons. I have found the following function, that seems to set the permissions (includes/acp/acp_permissions.php:745), but I can not find in the code, how the parameter $auth_settings have been filled.

Code: Select all

$auth_admin->acl_set($ug_type, $forum_id, $ug_id, $auth_settings, $assigned_role);
I have found that (includes/acp/acp_permissions.php:700) but I have not found the correct template file and how the request variable "setting" have been filled:

Code: Select all

$settings = $request->variable('setting', array(0 => array(0 => array('' => 0))), false, \phpbb\request\request_interface::POST);
Or can I just ignore this parameter and set the permissions with the role id in $assigned_role?

Best Regards,
Daniel
User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 4741
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Set permissions on a Forum

Post by kasimi »

You can use the migrator.tool.permission service:

Code: Select all

$role_name = 'ROLE_FORUM_STANDARD';
$auth_name = 'f_some_permission';
$this->permission_tool->permission_set($role_name, $auth_name, 'role', true);
kizuzi
Registered User
Posts: 21
Joined: Sat Mar 28, 2020 7:41 am

Re: Set permissions on a Forum

Post by kizuzi »

Dear Kasimi,

I have checked the whole class permission but I have not found any possibility to define the forum to set any permission. It seems that class can be used to create new permissions, they can be added via the acp to users, roles or groups.

But I want to apply permissions automatically without the interaction of the administrator (in the best case). My modification should create a forum, a role and apply permissions in one step (otherwise, the administrator need to open 3 different modules to do that).

Best Regards,
Daniel
User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 4741
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Set permissions on a Forum

Post by kasimi »

A role can't be applied to forums. A role can only be applied to a group/user (global permissions) or a pair of group/user and forum (local permissions). You will need to:
  • Create a group.
  • Use the permission tool to create a role:

    Code: Select all

    $role_name = 'SOME_ROLE_NAME';
    $role_type = 'f_';
    $this->permission_tool->role_add($role_name, $role_type);
    
  • Set permissions to the new role, see my previous post.
  • Set the role for the pair of group and forum by calling the $auth_admin->acl_set() function you mention in your first post. $auth_settings is an array containing all local permission names as keys and their values as defined for that role (1=yes, -1=no, 0=never). Example:

    Code: Select all

    $auth_settings = [
        'f_post'            => 1,
        'f_sticky'          => 1,
        'f_announce'        => 1,
        'f_announce_global' => 1,
        ...
    ];
    The acl_set() function doesn't query the defined role's permission values for you. I'm not sure if there's a core function you can use. You might have to do it manually.
kizuzi
Registered User
Posts: 21
Joined: Sat Mar 28, 2020 7:41 am

Re: Set permissions on a Forum

Post by kizuzi »

Dear Kasimi,

OK. I think I know, what i need to do. I can read the permissions of one role from the database with the following statement and use the result to create the $auth_settings array.

Code: Select all

SELECT  r.role_id,  r.role_name, o.auth_option, rd.auth_setting
	FROM phpbb_acl_roles r
 	JOIN phpbb_acl_roles_data rd
 	JOIN phpbb_acl_options o
 	ON r.role_id = rd.role_id
 	AND rd.auth_option_id = o.auth_option_id
 	WHERE r.role_id = 5
If I use that generated array and the id of the role together in the function

Code: Select all

$auth_admin->acl_set($ug_type, $forum_id, $ug_id, $auth_settings, $assigned_role);
Then the permissions will be set and linked with the role? If something will be changed in the role, the permissions will be updated. Is that correct?

Best Regards,
Daniel
Post Reply

Return to “Extension Writers Discussion”