1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Setting new permission values during add-on install

Discussion in 'XenForo Development Discussions' started by lazy llama, Feb 26, 2014.

  1. lazy llama

    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.
  2. Brogan

    Brogan XenForo Moderator Staff Member

    I believe there is a way of doing it but I haven't tried myself.

    @Chris D knows how to (I think).
    lazy llama likes this.
  3. Chris D

    Chris D XenForo Developer Staff Member

    The XenForo Resource Manager does (or used to, at least) something like this:

                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.
    Brogan and lazy llama like this.
  4. Chris D

    Chris D XenForo Developer Staff Member

    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.
  5. lazy llama

    lazy llama Well-Known Member

    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.
  6. Chris D

    Chris D XenForo Developer Staff Member

    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.
  7. Liam W

    Liam W Well-Known Member

    They do however, forget to set admin permissions... Then again, not many addons use them I've noticed.

Share This Page