XF 2.0 How to add default permission for an addon

Fethi.dz

Active member
#1
Hello,

In the Setep.php file for an addon how to add a defaulf permission that apply on the installation.

I have the following permission postRepliesOthers and I want it to be Yes on the addon installation, How to do that?

Thnaks.
 

Fethi.dz

Active member
#4
Using a default setup file from creating a addon, how would you add this into the setup file?
I cant locate any reference on this.
By reffering to XF\AddOn\AbstractSetup line 93

This is how to applyGlobalPermission:
$this->applyGlobalPermission($applyGroupId, $applyPermissionId, $dependGroupId = null, $dependPermissionId = null)
 

[xFv]

Previously Cylent1
#5
By reffering to XF\AddOn\AbstractSetup line 93

This is how to applyGlobalPermission:
$this->applyGlobalPermission($applyGroupId, $applyPermissionId, $dependGroupId = null, $dependPermissionId = null)
Thanks for the reply!
So this has to go into a php file or setup file?
I am really not following.
 

Fethi.dz

Active member
#6
For example:

2017-12-26_20-04-43.png

Let’s say, you have a new permission where $applyGroupId = forum, and $applyPermissionId = postThread

So, we add in the setup file the following:

PHP:
public function installStep1()
{
   $this->applyGlobalPermission(forum, postThread, $dependGroupId = null, $dependPermissionId = null);
}
Note: The above install step will apply a YES value as default while installing the Add-on.

Enjoy ;)
 
Last edited:

DragonByte Tech

Well-known member
#7
For example:

View attachment 165089

Let’s say, you have a new permission where $applyGroupId = forum, and $applyPermissionId = postThread

So, we add in the seteup file the following:

PHP:
public function installStep1()
{
   $this->applyGlobalPermission(forum, postThread, $dependGroupId = null, $dependPermissionId = null);
}
Note: The above install step will apply a YES value as default while installing the Add-on.

Enjoy ;)
PHP:
public function installStep1()
{
   $this->applyGlobalPermission('forum', 'postThread');
}
This is the correct code :)

The remainder of the two parameters are used if you want to only grant the permission to user groups who already have another permission.

For instance, if you want to grant customPermissionGroup - customPermissionId permission if someone already has post thread permissions, you'd do $this->applyGlobalPermission('customPermissionGroup', 'customPermissionId', 'forum', 'postThread');


Fillip
 

[xFv]

Previously Cylent1
#8
Thank you both for the help.
I managed to finally figure it out, but have 1 more question about this.
Is it possible to just set the default permission for the admin group and not the rest using this method?
 
Last edited:

Brad Padgett

Well-known member
#9
Does anyone know if there's a way to do this without a setup file entry? My add-on I'm fixing to release does not need a setup file and I want to set my permissions to default 'yes' when they install it.

Any ideas? @Chris D ? I'm working on a most users ever online add-on and I'm almost done with it. It's a really great add-on and even implements a widget and options for putting the counts under members online. It's got counts for all users, members, and even guests. I'm almost done with it but I don't know how to setup default permissions set to 'yes'.
 

Brad Padgett

Well-known member
#11
It can only be done in the add-on Setup file.
EDIT: Nevermind, the issue I just posted about was because for some reason the setup file made permissions on the actual user (staff members) and not just the usergroup. Anyways I'd rather not take that route Chris but I appreciate the info.

EDIT: I actually think I may give this a try. Shouldn't be a big deal to setup.

Regards,

Brad
 
Last edited:

Brad Padgett

Well-known member
#12
@Chris D does this only work when when you build your add-on and install it the normal way? I ran the installStep1() with the code in it, replacing my permission group ID and permission ID and it switched them all to 'yes' but it doesn't work until I click save. Any idea?
 
Top