Setting new permission values during add-on install

lazy llama

Well-known member
Is there any way of setting usergroup permission values for a new permission during the installation of an add-on? Preferably a way that won't make my tiny brain melt into a puddle of goo.

I've got a new permission that I'd like to be set to match an existing permission when the add-on is installed.
I've seen posts in here saying it might be possible using a query, and another saying you shouldn't do it, it should always be done manually using the ACP.

Looking at the db, it looks like permission combos are all stored in serialized (?) blobs so can't really be easily queried.

Also, did permissions used to have a default value which would be set for new usergroups? That doesn't seem to exist any more.
 
The XenForo Resource Manager does (or used to, at least) something like this:

Code:
            INSERT IGNORE INTO xf_permission_entry
                (user_group_id, user_id, permission_group_id, permission_id, permission_value, permission_value_int)
            SELECT user_group_id, user_id, 'resource', 'view', permission_value, 0
            FROM xf_permission_entry
            WHERE permission_group_id = 'general' AND permission_id = 'viewNode'

It's basically setting a usergroup permission based on an existing value for all user groups.

So this is setting the view resource permission to allow for all users who currently have the view node permission, I believe.
 
I suppose it's worth adding: I actually don't use this permission myself. I could do easily. But I prefer to get people to set the perms up themselves. That way they get familiar with all of the permissions available to them and I don't have to make any assumptions on what is correct for them.
 
Thanks, @Chris D - I'll have a look at that and give it a try.

I'd agree about getting people to set permissions themselves, but in this case it alters the default behaviour of XF if the permissions isn't set.
I know that if I released it as is, people would complain even if I put a big "OMG Don't Forget To Set The Permission!!!" message on the release note.
 
None of my add-ons even work unless permissions are set. It's not very often someone forgets to set them. But either way that query should help you.
 
They do however, forget to set admin permissions... Then again, not many addons use them I've noticed.
 
Back
Top Bottom