Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
HowTo Create Custom Usergroup Permissions
Andreas's Avatar
Andreas
Join Date: Jan 2004
Posts: 6,863

 

Germany
Show Printable Version Email this Page Subscription
Andreas Andreas is offline 06-09-2005, 10:00 PM

Usergoup Permissions are being controlled through XML files, you don't have to edit usergroup.php anymore

To create your own usergroup permissions, the first thing to do is to modify table usergroup (keep table prefixes in mind!):

[sql]ALTER TABLE usergroup ADD myhackpermissions INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ;[/sql]

If your hack does need some integer settings as well (and not just On/Off-Options):

[sql]ALTER TABLE usergroup ADD myhackintset INT( 10 ) DEFAULT '100' NOT NULL ;[/sql]

Then you must create a an XML-File bitfield_myhack.xml and place it in includes/xml:

HTML Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bitfields product="vbulletin">
	<bitfielddefs>
		<group name="ugp">
			<group name="myhackpermissions">
				<bitfield name="canfoo" group="my_hack_permissions"  phrase="can_foo_forum" install="1,2,3,4,5,6,7">1</bitfield>
				<bitfield name="canbaa" group="my_hack_permissions"  phrase="can_baa_forum" install="">2</bitfield>
				<bitfield intperm="true" name="myhackintset" group="my_hack_permissions"  phrase="myhack_int_desc"></bitfield>
			</group>
		</group>
	</bitfielddefs>
</bitfields>
As you can see, you must create a new permission group below group ugp (short for usergroup permissions).

Parameter product of Tag bitfields should be the identifier of your Product

Paramater name of Tag group must match the column name in table usergroup.

The Parameters for Tag bitfield are:
  • name is the identifier you can use in your hack code (eg. $permissions['myhackpermissions'] & $vbulletin->bf_ugp['myhackpermissions']['canfoo'])
    In case of integer options this name must match the column name in table usergroup.
  • intperm indicates that this Option is a integer value
  • group is the varname for the Phrase that should be displayed as Permission Group Title.
    This is also being used to set up different Groups for your permissions.
  • phrase is the varname of the Phrase that should be displayed for this option in Usergroup Manager
  • install is a comma-separated list of the usergroups where this permission should be visible
    If this parameter is empty or omitted, this Option will be used for all Usergroups

The value of <bitfield> is the decimal value of the bit (eg. 1 for the first, 2 for the second, 4 for the third, and so on).
In case of an Integer Option this is the default value.

If you want to hide certain permission groups for some usergroups, for example from Guests as they don't make sense for them:

HTML Code:
<ignoregroups>
        <group name="myhackpermissions" ignoregroups="1" />
</ignoregroups>
Parameter name is the name of the permission group you want to hide, ignoregroups is a comma seperated list of usergoup IDs where this permission group should not show up.
Place this section below the <bitfielddefs>-Section.

Now create the necessary phrases (in Phrasegroup Permissions) at this point.

As vBulletin caches Bitfields in Datastore, you must rebuild this cache before the new usergroup permissions can be actually used (They will already show up in Usergroup Manager, but cannot be saved - you will get an error).
To do so, point your browser to admincp/index.php?do=buildbitfields.

You can also use the following Code (in a Custom Installer or Install-Code of a Product) to update the Bitfield Cache:
PHP Code:
if (is_newer_version('3.5.1'$vbulletin->options['templateversion']))
{
    
// Rebuild Bitfields
    // Do this for vBulletin < 3.5.1 *ONLY*; later versions rebuild
    // automatically and calling the builder in install code causes
    // the bitfields NOT to be rebuild correctly
    
require_once(DIR '/includes/class_bitfield_builder.php');
    
vB_Bitfield_Builder::save($db);
    
build_forum_permissions();

If you install/upgrade vBulletin and custom bitfield_xxx.xml files are already in place, they will be used - you don't have to update the Bitfield Cache in this case.

This How-To is (C) 2005 by KirbyDE and you are not allowed to redistribute it in any way without my explicit consent.
Reply With Quote
  #77  
Old 01-12-2006, 12:22 PM
Delphiprogrammi Delphiprogrammi is offline
 
Join Date: Feb 2004
Location: Landen(Belgium)
Posts: 1,335
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hi,

Thanks for your explanation verry usefull.One question through.My permissions show up fine the only thing that annoys me a little is that that little help icon that refuses to shoowup nexto my permissions ? i bet it got something todo with the adminhelp manager you see in debug mode ?

buh i hate XML most of the time i doesn't work for me

HTML Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<bitfields product="myproduct">
<bitfielddefs>
<group name="ugp">
<group name="myproductpermissions">
 <bitfield name="canview" group="myproduct_permissions" phrase="can_view" install="2,5,6,7">1</bitfield>
 <bitfield name="canmanage" group="myproduct_permissions" phrase="can_manage" install="2,5,6,7">2</bitfield>
</group>
</group>
</bitfielddefs>
</bitfields>
can't even choose between yes or no i can change it and vbulletin says options saved successfully but when i goback to check .... (you can guess)the value doesn't change

Code:
"ALTER TABLE " . TABLE_PREFIX . "usergroup ADD myproductpermissions INT(10) UNSIGNED NOT NULL DEFAULT 0";
really hate XML :devious:
Attached Images
File Type: gif pr_permissions.gif (7.4 KB, 0 views)
Reply With Quote
  #78  
Old 01-17-2006, 04:52 PM
CyberRanger's Avatar
CyberRanger CyberRanger is offline
 
Join Date: Mar 2004
Posts: 1,319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

posted in wrong thread ...
Reply With Quote
  #79  
Old 02-07-2006, 01:18 AM
joefitz joefitz is offline
 
Join Date: May 2005
Location: Boston, MA
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just an FYI, for those interested in having custom forum permissions that correspond with custom usergroup permissions, you may want to check out my hack discussed in the following thread:
Custom Usergroup Forum Permissions
Reply With Quote
  #80  
Old 02-07-2006, 01:29 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There is a reason why there is no built-in support for custom forum permissions
Reply With Quote
  #81  
Old 04-06-2006, 01:43 PM
vasudeva's Avatar
vasudeva vasudeva is offline
 
Join Date: Sep 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Andreas
There is a reason why there is no built-in support for custom forum permissions
What is that reason, for those of us new to the game? I'm trying to get my head around expanding vB's permissions system and would appreciate any insights.
Reply With Quote
  #82  
Old 06-25-2006, 06:55 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I wonder why the "INSTALL" bit never works correctly. If I install such xml, all settings are initially off, regardless of install value.
Reply With Quote
  #83  
Old 07-12-2006, 07:59 PM
andrefedalto andrefedalto is offline
 
Join Date: Dec 2005
Location: Brazil
Posts: 81
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks Andreas for this nice custom usergroup permission howto...

i used to make my usergroup permissions with a plugin in the hook 'admin_usergroup_edit', but i needed 1 column in 'usergroup' table for each permission (too bad for lots of new perms)

but now this xml really rocks
Reply With Quote
  #84  
Old 07-30-2006, 06:52 AM
Mythotical Mythotical is offline
 
Join Date: Jun 2004
Location: Booneville, AR, USA
Posts: 1,428
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

EDIT: Got it fixed
Reply With Quote
  #85  
Old 07-30-2006, 12:01 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

how do you check for INT Permissions?
Reply With Quote
  #86  
Old 08-08-2006, 08:17 AM
rogersnm rogersnm is offline
 
Join Date: Apr 2006
Location: Cyberspace, UK
Posts: 729
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So can you just do:
HTML Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bitfields product="vbulletin">
	<bitfielddefs>
		<group name="ugp">
			<group name="myhackpermissions">
				<bitfield name="canfoo" group="my_hack_permissions"  phrase="can_foo_forum" install="">1</bitfield>
			</group>
		</group>
	</bitfielddefs>
</bitfields>
And then the query
PHP Code:
ALTER TABLE usergroup ADD myhackpermissions INT10 UNSIGNED DEFAULT '0' NOT NULL 
To add a Yes/No?
Reply With Quote
  #87  
Old 08-09-2006, 09:45 PM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I couldn't get it to work so I made my own function in the hook "global_start".
I kept everything else the same but removed "can_administer".

I had to use this query to add the field to the "administrator" table.
PHP Code:
$db->query_write("ALTER TABLE `" TABLE_PREFIX "administrator` ADD hostingadminperms INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ;"); 

I put this in global_start
PHP Code:
function can_admin_hosting()
{
  global 
$vbulletin$db;

  
$getuserperms $db->query_read("SELECT * FROM " TABLE_PREFIX "administrator WHERE userid='".$vbulletin->userinfo['userid']."' ");
    
$perms $db->fetch_array($getuserperms);
 
  return 
$perms['hostingadminperms'];


In your admin backend file I just used
PHP Code:
can_admin_hosting(); 
Reply With Quote
  #88  
Old 10-21-2006, 04:59 AM
MaryTheG(r)eek MaryTheG(r)eek is offline
 
Join Date: Sep 2006
Location: Greece
Posts: 1,340
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Very helpfull topic. Could you please extend it a bit saying me how I can set a default value per bitfield (for all usergroups) ?

I've the following code in bitfield_vbmates.xml
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bitfields product="vbmates">
	<bitfielddefs>
		<group name="ugp">
			<group name="vbmates">
				<bitfield name="canuse" group="vbmates_permissions" phrase="vbmates_can_use">1</bitfield>
                <bitfield name="canadd" group="vbmates_permissions" phrase="vbmates_can_add">2</bitfield>
..... and others below..........
			</group>
		</group>
	</bitfielddefs>
</bitfields>
Then I setup correctly persmissions per user group. Why with the code:

Code:
if(!$permissions['vbmates'] & $vbulletin->bf_ugp['vbmates']['canadd']){
    $vbulletin->url = "vbmates.php?" . $vbulletin->session->vars['sessionurl'] ."";
    eval(print_standard_redirect('vbmates_no_add_profile', true, true));
}
a usergroup can go on while they dont have permission for it? Please note:
1.- I changed bitfield_vbmates.xml after the first product installation
2.- I've also trying to use in this file: <group name="vbmates_permissions"> but no chance.

Ok, I found it. It needed one couple of parenthesis more. Instead of:
if(!$permissions['vbmates'] & $vbulletin->bf_ugp['vbmates']['canadd'])
should be ...
if(!($permissions['vbmates'] & $vbulletin->bf_ugp['vbmates']['canadd']))
Reply With Quote
  #89  
Old 10-22-2006, 12:46 PM
mrpaint's Avatar
mrpaint mrpaint is offline
 
Join Date: Sep 2004
Location: Hanoi Capital
Posts: 630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi, can you help me a bit in this problem?

My bitfield_get_direct_links.xml:
HTML Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<bitfields product="get_direct_links">
	<bitfielddefs>
		<group name="ugp">
 			<group name="get_direct_links_permissions">
				<bitfield intperm="true" name="get_direct_links_number" group="get_direct_links_permissions" phrase="get_direct_links_number_desc">5</bitfield>
			</group>
		</group>
	</bitfielddefs>
</bitfields>
In UserGroupt Manager, it work well but in my php code, when I call
PHP Code:
var_dump($vbulletin->bf_ugp); 
I can't find my get_direct_links_permissions. And when I call
PHP Code:
var_dump($permissions['get_direct_links_permissions']); 
It is NULL

Can you help me? Thank you very much!

PS: Sorry for my bad English
Reply With Quote
  #90  
Old 11-05-2006, 06:37 PM
Kungfu Kungfu is offline
 
Join Date: Dec 2005
Posts: 242
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have some problems with an int bitfield.

<bitfield intperm="true" name="myhackintset" group="my_hack_permissions" phrase="myhack_int_desc"></bitfield>

Its baiscally like this one, only difference is it installs to all usergroups, including custom usergroups. Well my problem is this, i want to check if a person is in two usergroups, but one of the usergroups bitfield is set to 0. Example, Registered usergroup setting is 0, but Custom usergroup setting is 1. Instead of taking the 1 as the value, i need the 0.

Anyway to do this? Hope thats clear.
Reply With Quote
  #91  
Old 11-26-2006, 07:31 PM
timetunnel timetunnel is offline
 
Join Date: Sep 2005
Posts: 86
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello.

How to change a custom bitfield_xx.xml parameter via vB Options?

For example, as I add new usergroups, I want to update the 'install' or 'ignore' param (e.g. comma-separated value) via ACP vs. editing the file.

Is that possible e.g. putting an ACP variable in the xml file?

Thanks in advance.

Update: Using a variable in the 'xml' file is not necessary but vB requires code revisions in order to update bitfield 'usergroups' via ACP vs. modifying 'bitfield_xx.xml' file. It may be better to work with the 'ignoregroups' feature in usergroups.php combined with vBulletin Options' User Profile Options instead of the 'install' parameter of the 'xml' file since 'ignoregroups' works in v.3.6.3 after installation whereas, it seems that the 'install' parameter of <bitfields> is only recognized during new installations.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:37 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06549 seconds
  • Memory Usage 2,420KB
  • Queries Executed 31 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_code
  • (5)bbcode_html
  • (7)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (16)post_thanks_box
  • (2)post_thanks_box_bit
  • (16)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (16)post_thanks_postbit_info
  • (15)postbit
  • (1)postbit_attachment
  • (16)postbit_onlinestatus
  • (16)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete