Page 1 of 1

Migration: set group forum permission to Yes by default

Posted: Tue Feb 16, 2016 2:50 pm
by Senky
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!

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

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

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

Posted: Fri Feb 19, 2016 5:59 pm
by Senky
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?

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

Posted: Fri Feb 19, 2016 6:49 pm
by david63
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.

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

Posted: Fri Feb 19, 2016 9:16 pm
by gn#36
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.

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

Posted: Fri Feb 19, 2016 9:20 pm
by 3Di
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...

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

Posted: Fri Feb 19, 2016 9:21 pm
by 3Di
@gn#36
Very usefull tutorial I can say. ;) I was posting while you created it.

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

Posted: Sat Feb 20, 2016 1:48 am
by VSE
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.

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

Posted: Tue Feb 21, 2017 1:11 am
by P_I
As discussed here is there a "best practices" model for an extension developer to follow when deciding the default permission settings?

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

Posted: Tue Feb 21, 2017 11:21 pm
by gn#36
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.

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

Posted: Wed Feb 22, 2017 12:19 am
by javiexin
I echo the recommendation to copy a permission. Here is an example:
https://github.com/javiexin/chgposttime ... ssions.php

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

Posted: Thu Feb 23, 2017 4:24 pm
by pierredu
Thanks for your comments.