Create custom Permission Role Type (x_)

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
walter81
Registered User
Posts: 43
Joined: Sun Jun 26, 2011 9:29 am
Contact:

Create custom Permission Role Type (x_)

Post by walter81 » Fri Jul 01, 2011 7:30 am

Hi,

I'm trying to create a new "Permission roles" type (currently there are adim roles, user roles, moderator roles, forum roles and I want to add "my custom roles").

I've been looking into the code and I managed to get some result but it's more complex as I thought to master, so If anyone could give me some hints that would be a huge help.

So far I got the following:
  • in the MODULES_TABLE I duplicated the "user_roles" record annd changed the values for module_langname, module_mode ("my_custom_role") and left & right values (forum_roles ends with right=200 so I've made left= 201 and right= 202)
  • In function functions_modules\assign_tpl_vars() my custom role is skipped since $item_ary[depth] = 1 while it should be 2, but when the array is build in index.php => $module->list_modules('acp'); the depth for my module is 2 (which it should be). But I didn't manage to find where or why it's changed 1
  • I've added new acl_options ("x_", "x_option1, "x_option2", ..). These are all added to the "Misc" tab, I didn't find how to create other tab-options yet (although I must admit: I didn't look very well yet)
thanks in advance for any advice

-Walter-
Last edited by walter81 on Fri Jul 01, 2011 8:39 am, edited 1 time in total.

carloclaessen
Registered User
Posts: 494
Joined: Sun Mar 23, 2003 11:55 pm

Re: add a permissions role

Post by carloclaessen » Fri Jul 01, 2011 7:34 am


User avatar
walter81
Registered User
Posts: 43
Joined: Sun Jun 26, 2011 9:29 am
Contact:

Re: add a permissions role

Post by walter81 » Fri Jul 01, 2011 8:38 am

thanks for the reply, but that topic describes how to add new options to the existing role-type (a_, f_, m_ and u_) while I want to create an entire new role-type (xx_) .

User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: Create custom Permission Role Type (x_)

Post by A_Jelly_Doughnut » Sat Jul 02, 2011 4:17 am

Maybe this one is closer to what you need? http://www.phpbb.com/community/viewtopi ... 1&t=821035&
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: Create custom Permission Role Type (x_)

Post by 4_seven » Sat Jul 02, 2011 4:06 pm

Current Mods | Mod Base | php(BB) programming | No help via PM

User avatar
walter81
Registered User
Posts: 43
Joined: Sun Jun 26, 2011 9:29 am
Contact:

Re: Create custom Permission Role Type (x_)

Post by walter81 » Mon Jul 04, 2011 6:16 am

@A_Jelly_Doughnut: thanks, that's closer indeed, but still not exactly what I need, that post only handles how to add persmissions, it doesn't handle about setting those persmissions to roles.

@4_seven: also thanks, but I did my homework before I started this topic: I know how to add my custom permissions (but I did overlook the "Language file (Adding tabs) " topic, kudos for that!)

The Permissions tuturial still only handles about the 4 defined persmission types (user, moderator, admin and forum). I want to add my own "custom" permission type. In the ACP in the left menu I want another menu item "custom privileges" where I can create my own "custom" roles to link my "c_"-acl-options to my roles. And that's where i'm stuck at the moment. In assign_tpl_vars() my custom role is skipped since $item_ary[depth] = 1 while it should be 2.

User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: Create custom Permission Role Type (x_)

Post by 4_seven » Mon Jul 04, 2011 8:15 am

Hm, seems to be tricky than. May phpbb3 have not provided to do that, so we need a phpbb3 developer here.
Current Mods | Mod Base | php(BB) programming | No help via PM

User avatar
walter81
Registered User
Posts: 43
Joined: Sun Jun 26, 2011 9:29 am
Contact:

Re: Create custom Permission Role Type (x_)

Post by walter81 » Mon Jul 04, 2011 9:23 am

I found it!

i've been "debugging" the p_master class to find out how the permissons and menu items are build up and I finally discovered it:


in table phpbb_acl_options I've added 2 new rows: "c_" and "c_test_option"
in table phpbb_modules I duplicated row "ACP_USER_ROLES" (module_id 80) and changed the following fields
* langname => "C_CUSTOM_ROLES"
* module_mode => "custom_roles"
* left_id => 201
* right_id => 202
(left- and right_id are the next indexes next to "ACP_FORUM_ROLES". That way it's the next menu-element)

now the tricky part is the left_id and right_id, it took me a while to figure that out correctly. The menu-items in the ACP are grouped by pages and categories.

so to add my role type to the menu I had to do the following:
the page is ACP_CAT_PERMISSIONS (which consists of all modules who's left- and right_id is between 167 and 216)
and category is ACP_PERMISSION_ROLES (which consists of all modules who's left- and right_id is between 192 and 202).

so, for my custom role type to actuall show up in the acp "permissions" page I had to update all higher left_ and right_ids:
UPDATE phpbb_modules SET left_id = left_id + 1 WHERE left_id >= 200 AND module_id <> 199;
UPDATE phpbb_modules SET right_id = right_id + 1 WHERE right_id >= 201 AND module_id <> 199;

this updated the ACP_PERMISSIONS_ROLES to include my new module and thus adding it correctly to the modules-list in p_master().

So now It's listed and I can create my custom roles with my custom permissions. Next challange is to be able to add my custom roles to a group (if I figure that out I'll post it back here too. Maybe someone can put it in a real tutorial or copy it to the wiki with more and better explanation?)


A thought for the PHPBB Development team: I assume there are many more sites like me who'd want to use the PHPBB Forum as the framework for their site (since it's simply a great framework: it has very good and secure session management, user registration & control options, captcha's, logging, db-classes, template & caching functions, ... oh and a superb forum too ;o). It would be great if you'd make it easier to add custom role-types. That should be part of the system options in the ACP too. Would have save me a few hours :D

User avatar
walter81
Registered User
Posts: 43
Joined: Sun Jun 26, 2011 9:29 am
Contact:

Re: Create custom Permission Role Type (x_)

Post by walter81 » Mon Jul 04, 2011 9:24 am

I found it!

i've been "debugging" the p_master class to find out how the permissons and menu items are build up and I finally discovered it:


in table phpbb_acl_options I've added 2 new rows: "c_" and "c_test_option"
in table phpbb_modules I duplicated row "ACP_USER_ROLES" (module_id 80) and changed the following fields
* langname => "C_CUSTOM_ROLES"
* module_mode => "custom_roles"
* left_id => 201
* right_id => 202
(left- and right_id are the next indexes next to "ACP_FORUM_ROLES". That way it's the next menu-element)

now the tricky part is the left_id and right_id, it took me a while to figure that out correctly. The menu-items in the ACP are grouped by pages and categories.

so to add my role type to the menu I had to do the following:
the page is ACP_CAT_PERMISSIONS (which consists of all modules who's left- and right_id is between 167 and 216)
and category is ACP_PERMISSION_ROLES (which consists of all modules who's left- and right_id is between 192 and 202).

so, for my custom role type to actuall show up in the acp "permissions" page I had to update all higher left_ and right_ids:
UPDATE phpbb_modules SET left_id = left_id + 1 WHERE left_id >= 200 AND module_id <> 199;
UPDATE phpbb_modules SET right_id = right_id + 1 WHERE right_id >= 201 AND module_id <> 199;

this updated the ACP_PERMISSIONS_ROLES to include my new module and thus adding it correctly to the modules-list in p_master().

So now It's listed and I can create my custom roles with my custom permissions. Next challange is to be able to add my custom roles to a group (if I figure that out I'll post it back here too. Maybe someone can put it in a real tutorial or copy it to the wiki with more and better explanation?)


A thought for the PHPBB Development team: I assume there are many more sites like me who'd want to use the PHPBB Forum as the framework for their site (since it's simply a great framework: it has very good and secure session management, user registration & control options, captcha's, logging, db-classes, template & caching functions, ... oh and a superb forum too ;o). It would be great if you'd make it easier to add custom role-types. That should be part of the system options in the ACP too. Would have save me a few hours :D

User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: Create custom Permission Role Type (x_)

Post by 4_seven » Mon Jul 04, 2011 10:14 am

nice addition 2 the core. perfect, man :D
Current Mods | Mod Base | php(BB) programming | No help via PM

User avatar
walter81
Registered User
Posts: 43
Joined: Sun Jun 26, 2011 9:29 am
Contact:

Re: Create custom Permission Role Type (x_)

Post by walter81 » Mon Jul 04, 2011 10:19 am

and got that too: in order to be able to assign my "custom role type role" to a group I also had to do the following:
  • add a new global acl_options row with auth_option value = "a_cauth" (a_ + c + auth)
  • delete the cache (to force the auth_options array to be refreshed)
  • assign the a_cauth option to the admins-role (to give me permission to be able to assign those roles to a group)
  • add the label to lang\[lang]\acp\permissions_phpbb.php (look for 'permission_type').
that was it!

If I find time (and interest) in making a decent tutorial to "create your own custom permission type" I'll be posting that here as well.

2nd note for the developers: I'd rather not add my custom language labels to the existing phpbb-language-files. I'd rather keep them seperated. So in acp_permissions.php, function build_permission_dropdown() there should be a check to see if the label exists in the lang-array and replace it with $setting if not. (in stead of $user->lang['permission_type'][$setting].

Locked

Return to “[3.0.x] MOD Writers Discussion”