Migration: set group forum permission to Yes by default

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Senky
Extension Customisations
Extension Customisations
Posts: 2106
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Migration: set group forum permission to Yes by default

Post by Senky » Tue Feb 16, 2016 2:50 pm

Hi,
I add a new forum permission with my migration and I want to set it to Yes by default for Admins and Global mods groups for all forums that already exist. I tried this:

Code: Select all

array('permission.permission_set', array('ROLE_ADMIN_STANDARD', 'f_ext_perm', 'role', true)),
array('permission.permission_set', array('ROLE_ADMIN_FULL', 'f_ext_perm', 'role', true)),
array('permission.permission_set', array('ROLE_ADMIN_FORUM', 'f_ext_perm', 'role', true)),
array('permission.permission_set', array('ROLE_ADMIN_USERGROUP', 'f_ext_perm', 'role', true)),
array('permission.permission_set', array('ROLE_MOD_STANDARD', 'f_ext_perm', 'role', true)),
array('permission.permission_set', array('ROLE_MOD_SIMPLE', 'f_ext_perm', 'role', true)),
array('permission.permission_set', array('ROLE_MOD_FULL', 'f_ext_perm', 'role', true)),
array('permission.permission_set', array('ROLE_MOD_QUEUE', 'f_ext_perm', 'role', true)),
 
But this sets Admins to Yes, however keeps Global mods to No. Anyway, I do not consider this being good solution. Can you advise me on how to do it the right way?

Thanks in advance for your replies!

User avatar
3Di
Former Team Member
Posts: 13766
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Migration: set group forum permission to Yes by default

Post by 3Di » Tue Feb 16, 2016 9:05 pm

Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

Senky
Extension Customisations
Extension Customisations
Posts: 2106
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Re: Migration: set group forum permission to Yes by default

Post by Senky » Fri Feb 19, 2016 5:59 pm

Yes, and as I stated above, I consider permission.permission_set being the only appropriate tool to set this. However, I was unable to find group names, so that I could set permission for it. Can you provide me with the group names?

User avatar
david63
Registered User
Posts: 16162
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Migration: set group forum permission to Yes by default

Post by david63 » Fri Feb 19, 2016 6:49 pm

The problem with group names is that they can be changed and ids are not much use either. Thinking about it I doubt that it is possible apart from setting it for all groups which would be totally poitless.

I suspect that if you have a group permission then it will need to be set manually.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
gn#36
Translator
Posts: 185
Joined: Fri Oct 13, 2006 1:16 pm
Contact:

Re: Migration: set group forum permission to Yes by default

Post by gn#36 » Fri Feb 19, 2016 9:16 pm

All default role names are in language/en/acp/permissions.php. I don't think it makes sense to set a forum permission for an admin role, nor does it make sense to set a forum permission for a moderator role, but that is precisely what you are doing with your commands.

If your permission is supposed to be for moderators, you should make it a moderator permission starting with m_. Then, you should only set it for moderator roles and assume that a board that wants admins to act as moderators will also give the admins moderator permissions. That means you cannot give this permission to regular users, though. If you want regular users to have this permission as well, then your choice of f_ is correct, if the permission could change on a forum-by-forum basis. If it is global, it should be a u_ permission. However, in both cases, there will be no way of ensuring that admins and moderators have this permission. If you want to make sure all moderators have permission to do something, you should change your code logic accordingly and do something like if ($auth->acl_get('f_yourpermission') || $auth->acl_get('m_') || $auth->acl_get('a_')) instead of changing their permissions, or even create a separate moderator or administrator permission for your specific case.

You can decide what local permission roles should by default receive your permissions:

Code: Select all

 162      'ROLE_ADMIN_FORUM'            => 'Forum Admin',
 163      'ROLE_ADMIN_FULL'            => 'Full Admin',
 164      'ROLE_ADMIN_STANDARD'        => 'Standard Admin',
 165      'ROLE_ADMIN_USERGROUP'        => 'User and Groups Admin',
 166      'ROLE_FORUM_BOT'            => 'Bot Access',
 167      'ROLE_FORUM_FULL'            => 'Full Access',
 168      'ROLE_FORUM_LIMITED'        => 'Limited Access',
 169      'ROLE_FORUM_LIMITED_POLLS'    => 'Limited Access + Polls',
 170      'ROLE_FORUM_NOACCESS'        => 'No Access',
 171      'ROLE_FORUM_ONQUEUE'        => 'On Moderation Queue',
 172      'ROLE_FORUM_POLLS'            => 'Standard Access + Polls',
 173      'ROLE_FORUM_READONLY'        => 'Read Only Access',
 174      'ROLE_FORUM_STANDARD'        => 'Standard Access',
 175      'ROLE_FORUM_NEW_MEMBER'        => 'Newly Registered User Access',
 176      'ROLE_MOD_FULL'                => 'Full Moderator',
 177      'ROLE_MOD_QUEUE'            => 'Queue Moderator',
 178      'ROLE_MOD_SIMPLE'            => 'Simple Moderator',
 179      'ROLE_MOD_STANDARD'            => 'Standard Moderator',
 180      'ROLE_USER_FULL'            => 'All Features',
 181      'ROLE_USER_LIMITED'            => 'Limited Features',
 182      'ROLE_USER_NOAVATAR'        => 'No Avatar',
 183      'ROLE_USER_NOPM'            => 'No Private Messages',
 184      'ROLE_USER_STANDARD'        => 'Standard Features',
 185      'ROLE_USER_NEW_MEMBER'        => 'Newly Registered User Features',
ROLE_ADMIN means only a_ permissions, ROLE_FORUM means only f_ permissions, ROLE_MOD means only m_ permissions, and ROLE_USER means only u_ permissions.

So your f_ permissions should only be added to new roles you create or the 10 ROLE_FORUM roles.
German Support Team Member • http://www.phpbb.deMy Extensions in the CDBMy Extensions on Github • Contact with caos is inavoidable but no catastrophy if you keep an overview.

User avatar
3Di
Former Team Member
Posts: 13766
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Migration: set group forum permission to Yes by default

Post by 3Di » Fri Feb 19, 2016 9:20 pm

Senky wrote:Yes, and as I stated above, I consider permission.permission_set being the only appropriate tool to set this. However, I was unable to find group names, so that I could set permission for it. Can you provide me with the group names?
I would go with this, instead.
https://area51.phpbb.com/docs/dev/31x/m ... l#add-role

On a side note, I haven't found any example done by phpBB itself into the repository.
This is the first time for me I am playing with this stuff.
A link to your repository makes the life easier to us to help you.
I would consider also to use the auth() class, but if we can't watch...
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
3Di
Former Team Member
Posts: 13766
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Migration: set group forum permission to Yes by default

Post by 3Di » Fri Feb 19, 2016 9:21 pm

@gn#36
Very usefull tutorial I can say. ;) I was posting while you created it.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4863
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Migration: set group forum permission to Yes by default

Post by VSE » Sat Feb 20, 2016 1:48 am

https://area51.phpbb.com/docs/dev/31x/m ... ission-set

Code: Select all

array('permission.permission_set', array('ADMINISTRATORS', 'f_ext_perm', 'group')),
array('permission.permission_set', array('GLOBAL_MODERATORS', 'f_ext_perm', 'group')), 
By the way, I hope that's not really your permission name. Please use unique and descriptive permission names.
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

User avatar
P_I
Registered User
Posts: 923
Joined: Tue Mar 01, 2011 8:35 pm
Location: Calgary
Contact:

Re: Migration: set group forum permission to Yes by default

Post by P_I » Tue Feb 21, 2017 1:11 am

As discussed here is there a "best practices" model for an extension developer to follow when deciding the default permission settings?
Normal people… believe that if it ain’t broke, don’t fix it. Engineers believe that if it ain’t broke, it doesn’t have enough features yet. – Scott Adams

User avatar
gn#36
Translator
Posts: 185
Joined: Fri Oct 13, 2006 1:16 pm
Contact:

Re: Migration: set group forum permission to Yes by default

Post by gn#36 » Tue Feb 21, 2017 11:21 pm

I don't know of any "best practices". Usually, I would try to find an existing permission that covers a roughly similar behavior and just copy that. In most cases, I would think that this will lead to a roughly expected behavior, if the reference permission is similar enough.

For example, if your extension adds f_read_all, which allows reading in the respective forum in the same way as usually f_read, which is adjusted by your extension to only permit reading for a certain time, I would copy f_read_all permissions from f_read, so the behavior of the forum doesn't change abruptly on installation of the extension. Conversely, if the new permission was used for the limited view instead of an all view, taking only effect if f_read is "no", it will not change behavior if it is either initialized with f_read or simply "no" in all cases.

If your extension adds new functionality and the permission controls who should be permitted to use it it is essentially depending on the functionality who should be able to use it. Nevertheless it could make sense to couple it to some existing permissions. For example, if your extension allows adding a questionaire to each topic, this is a similar addon feature as polls. So it could make sense to copy the permission from f_poll in this case.

I would assume that in most cases one should be able to find a reasonable permission to copy, even if the functionality is unrelated. The nice thing about that is that it will apply the same behavior to standard roles and user created roles. This is also why I would prefer copying from other permissions over explicitly setting values in the default roles. While setting default roles will give you a slightly more deterministic behavior of the extension, it will give administrators more work to do compared to a carefully selected copied permission.
German Support Team Member • http://www.phpbb.deMy Extensions in the CDBMy Extensions on Github • Contact with caos is inavoidable but no catastrophy if you keep an overview.

User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Migration: set group forum permission to Yes by default

Post by javiexin » Wed Feb 22, 2017 12:19 am

I echo the recommendation to copy a permission. Here is an example:
https://github.com/javiexin/chgposttime ... ssions.php

User avatar
pierredu
Registered User
Posts: 923
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: Migration: set group forum permission to Yes by default

Post by pierredu » Thu Feb 23, 2017 4:24 pm

Thanks for your comments.

Post Reply

Return to “Extension Writers Discussion”