Split permission logic from translations

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: Split permission logic from translations

Post by nickvergessen » Tue Jul 23, 2013 2:12 pm

VSE+ wrote:OK, so I'm trying out this (now that it has been merged) in an extension.

I got it working, but I want to make sure I'm doing it right.

It claims we use the core.permissions event for the logic.

Is this example the correctly intended way of doing the logic?

Code: Select all

static public function getSubscribedEvents()
{
    return array(
        'core.permissions'    => 'foo_bar_permissions',
    );
}

public function foo_bar_permissions($event)
{
    $event['permissions'] = array_merge($event['permissions'], array(
        'u_foobar'    => array(
            'lang' => 'ACL_U_FOOBAR',
            'cat' => 'misc',
        ),
    ));
}
And of course, I have a typical lang file named permissions_foobar.php with this:

Code: Select all

$lang = array_merge($lang, array(
    'ACL_U_FOOBAR'    => 'Can view foo bar topics',
));
Yes, thats correct. Also see the testing extension for helps:
https://github.com/phpbb/phpbb3/blob/de ... ns_foo.php
and https://github.com/phpbb/phpbb3/blob/de ... stener.php
Member of the Development-TeamNo Support via PM

User avatar
VSE
Extension Customisations
Extension Customisations
Posts: 670
Joined: Mon Mar 08, 2010 9:18 am

Re: Split permission logic from translations

Post by VSE » Tue Jul 23, 2013 3:37 pm

nickvergessen wrote:Yes, thats correct. Also see the testing extension for helps:
https://github.com/phpbb/phpbb3/blob/de ... ns_foo.php
and https://github.com/phpbb/phpbb3/blob/de ... stener.php
I think I like your test code better:

Code: Select all

public function add_permissions($event)
{
    $permissions = $event['permissions'];
    $permissions['u_foo'] = array('lang' => 'ACL_U_FOOBAR', 'cat' => 'post');
    $event['permissions'] = $permissions;
} 
Better than my array merge code:

Code: Select all

public function add_permissions($event)
{
    $event['permissions'] = array_merge($event['permissions'], array(
        'u_foo'    => array(
            'lang' => 'ACL_U_FOOBAR',
            'cat' => 'post',
        ),
    ));
}
 
Any idea which version is better/optimal, or which will be documented in the coding guidelines (it'd be so nice to have guidelines ;) )
Has an irascible disposition.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: Split permission logic from translations

Post by EXreaction » Wed Jul 24, 2013 3:38 pm

Or could trim it to one line and do

Code: Select all

$event['permissions']['u_foo'] = array('lang' => 'ACL_U_FOOBAR', 'cat' => 'post');

User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: Split permission logic from translations

Post by nickvergessen » Wed Jul 24, 2013 3:39 pm

IIRC that does not work, due to some magic somewhere in Symfony's Event Stuff
Member of the Development-TeamNo Support via PM

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: Split permission logic from translations

Post by EXreaction » Wed Jul 24, 2013 4:23 pm

Well someone should try it and see what happens :)

User avatar
VSE
Extension Customisations
Extension Customisations
Posts: 670
Joined: Mon Mar 08, 2010 9:18 am

Re: Split permission logic from translations

Post by VSE » Wed Jul 24, 2013 5:16 pm

EXreaction wrote:Well someone should try it and see what happens :)

Code: Select all

$event['permissions']['u_foo'] = array('lang' => 'ACL_U_FOOBAR', 'cat' => 'post');
results in:
[phpBB Debug] PHP Notice: Indirect modification of overloaded element of phpbb_event_data has no effect
Has an irascible disposition.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: Split permission logic from translations

Post by EXreaction » Wed Jul 24, 2013 5:44 pm

Hehe, that's quite interesting :P

Post Reply