Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-21-2009, 08:29 PM
tms1791 tms1791 is offline
 
Join Date: Mar 2007
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Creating a user and forum; setting permissions

I'm working on a script that hooks into the vB framework and from submitting one form, it creates a new user, a new forum, and gives permission to only that user to view/post in the new forum. Basically, we want our customers to have "private" forums that only them and staff can see & use.

I can create/set these things (user, forum, permissions, access mask) manually and it works just like I want it to, but when trying to do it all in one shot using my script, something's not getting done.

First, I'm creating a user - no problem. Looking at the user in the admin cp, everything's perfect.

Next, I'm creating a forum named after a custom field from the new user's profile (company name). Looking at the forum in the admin cp, everything's perfect.

Then I set the group permissions on the forum. I looked at forumpermission.php and basically copied the routine for setting all the groups to 'deny', but I'm excluding the admins, mods and superusers. Looking at the permissions in the admin cp, everything's perfect.

Finally, I set the access mask. For this I'm just inserting a row into the 'access' table, setting the fields as userid=$newuserid, forumid=$newforumid and accessmask=1. Looking at the mask in the admin cp, everything's perfect.

Now... when I load the vB home page in a different browser (I use Firefox normally, I use IE for testing so there are no cookie issues), I can see the forum I just created. I'm viewing the site as a guest - not logged in at all - and I also can't see the customer forums I set up manually (as it should be).

So something's not being done. Every setting is correct, according to what can be viewed in the admin cp, yet guests and other customers are still able to see the forum that they shouldn't be able to view.

I'm pretty sure the problem is in the section that's setting up the group permissions. Here's the code I'm using for that, plus the code for setting the access mask:
PHP Code:
// deny all user groups except mods/admins
$groups $db->query_read("SELECT usergroupid FROM " TABLE_PREFIX "usergroup");
while(
$group $db->fetch_array($groups)) {
    
$mpssql "REPLACE INTO ".TABLE_PREFIX."forumpermission (forumid,usergroupid,forumpermissions) VALUES ($forumid,".$group['usergroupid'].",0)";
    if((
$group['usergroupid'] != 5) && ($group['usergroupid'] != 6) && ($group['usergroupid'] != 7)) { // do not deny mods and admins
        
if(!$mpstesting) { $db->query_write($mpssql); }
    }
}
// apply access mask for new user
$mpssql "INSERT INTO ".TABLE_PREFIX."access (userid,forumid,accessmask) VALUES ($userid,$forumid,1)";
if(!
$mpstesting) { $db->query_write($mpssql); } 
(The $mpstesting variable is just a flag I'm turning on or off that, when on, keeps the script from actually "doing" anything)

Any suggestions? Before I go digging through a lot of vB code that I'm not too likely to understand very well (I have very little OOP experience), I'm hoping that someone can say "I see the problem, you're not doing <insert simple thing here>!".

If anyone wants to see more of the script, or even the whole thing, just let me know.
Reply With Quote
  #2  
Old 02-24-2009, 05:01 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you rebuild the forum counters, etc.?
Reply With Quote
  #3  
Old 02-24-2009, 07:26 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why do you need all this? Why not have 1 forum for all your users and set the permissions so they can only see their own threads?

Creating a large amount of forums (> 1.500) might lead to server problems.
Reply With Quote
  #4  
Old 02-24-2009, 01:43 PM
tms1791 tms1791 is offline
 
Join Date: Mar 2007
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Marco van Herwaarden View Post
Why do you need all this? Why not have 1 forum for all your users and set the permissions so they can only see their own threads?

Creating a large amount of forums (> 1.500) might lead to server problems.
That make entirely too much sense. Why would I want to make it so easy on myself?!

Hadn't thought of that - I'll play around with the idea and see how it works out. Thanks for the tip!
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 07: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.03991 seconds
  • Memory Usage 2,204KB
  • Queries Executed 13 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)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_postinfo_query
  • fetch_postinfo
  • 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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete