News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Adding and checking permissions

Started by Compuart, December 05, 2005, 11:33:58 AM

Previous topic - Next topic

Jim R

How would I go about getting it to print it coinciding with or instead of the error message, just as it would print a login prompt for a Guest?


Jim R

I got everything all figured out.  Thanks.

Shawn Sorrell

eldacar, I am hoping that you can help me sort something out. I am using Niko's Related Topics modification with SMF 1.1 RC2 and by following the support topic on it have been able to get it installed and running.  I am trying to add in checking for permissions on viewing a board to the modification and I ask here since it seems as if maybe Niko is no longer developing this modification.

I have examined existing SMF code in an attempt to do this in such areas of the code like Search but have not been able to find an acceptable solution. I believe that I can add the check into to the db_query but I seem to be missing something. There are three queries used.  The first simply returns all the related topics by using MATCH but I don't think I can add a check there (my msql knowledge is a bit weak).
$related = db_query("SELECT *, MATCH (ms.subject,ms.body) AGAINST ('{$mssub}') As Score  FROM {$db_prefix}messages As ms WHERE MATCH (ms.subject,ms.body) AGAINST ('{$mssub}') ORDER BY Score DESC LIMIT 0,10",__FILE__,__LINE__);

Once the initial query is made then  a while is used:
while($relTopic = mysql_fetch_array($related))
and the following queries are run:
$tox = db_query("SELECT * FROM {$db_prefix}topics As t,{$db_prefix}messages As ml WHERE t.ID_TOPIC='{$relTopic['ID_TOPIC']}' AND ml.ID_MSG = t.ID_LAST_MSG LIMIT 0,1",__FILE__,__LINE__);
$tox2 = db_query("SELECT * FROM {$db_prefix}topics As t,{$db_prefix}messages As ml WHERE t.ID_TOPIC='{$relTopic['ID_TOPIC']}' AND ml.ID_MSG = t.ID_FIRST_MSG LIMIT 0,1",__FILE__,__LINE__);

I tried using $user_info[query_see_board]
but I believe that is reliant on querying the board table AS b or reliant on the board number sent $_REQUEST.

Any insight you or others would have in this matter would be greatly appreciated.
Shawn

ttuu

I tried to solve the problem I wrote mine here:
http://www.simplemachines.org/community/index.php?topic=291427
With this guide, but I could not. Someone willing to help me in this?

uberjon

is this still relevant to SMF 2.0 Rc1?

i wish to make some custom permissions.. i use SSI.php for quite a few pages. i currently use an php array of groups that "are allowed" to view these pages. however. when i copy the permissions of say "group xyza" to a new group.. "thinking it will work" i forget to add them to the php file.. :x

example:

$allowed_groups = array(1,2,3,11,10,12,13,14,15,16,17,18);

      $can_see = FALSE;
      foreach ($allowed_groups as $allowed)
         if (in_array($allowed, $user_info['groups']))
         {
            $can_see = TRUE;
            break;
         }
         
      if (!$can_see)
      { // die, user access denied! //
      if ($context['user']['is_guest'])
        {
            redirectexit('http://domain.org/index.php?action=login');
            }
            else
                {
                redirectexit('http://domain.org/');
                }
                } else { // show the page access granted! :o //
// the content
}


found it somewhere on the SMF site. but rather inconveinent..

gift_ka


Dragooon

Quote from: uberjon on February 15, 2009, 04:24:10 AM
is this still relevant to SMF 2.0 Rc1?

i wish to make some custom permissions.. i use SSI.php for quite a few pages. i currently use an php array of groups that "are allowed" to view these pages. however. when i copy the permissions of say "group xyza" to a new group.. "thinking it will work" i forget to add them to the php file.. :x

example:

$allowed_groups = array(1,2,3,11,10,12,13,14,15,16,17,18);

      $can_see = FALSE;
      foreach ($allowed_groups as $allowed)
         if (in_array($allowed, $user_info['groups']))
         {
            $can_see = TRUE;
            break;
         }
        
      if (!$can_see)
      { // die, user access denied! //
      if ($context['user']['is_guest'])
        {
            redirectexit('http://domain.org/index.php?action=login');
            }
            else
                {
                redirectexit('http://domain.org/');
                }
                } else { // show the page access granted! :o //
// the content
}


found it somewhere on the SMF site. but rather inconveinent..
Hello uberjon, I was going through some old topics, did you ever get this solved? If no, then you can look into ManagePermissions.php under loadAllPermissions for adding a permission. As far as its language string goes, it would be $txt['permissionname_<your permission name>']. Then you can perform a check using allowedTo('<permission name>'). It is sort of still applicable for SMF 2.0 RC 1, although things have moved a bit and some new things have been added.

X3mE

Do I still have to modify the database to turn some permissions on by default, or is there an easier way in SMF 2?

This is for SMF 1, from the first post:

<?php
   
// Initialize the groups array with 'ungrouped members' (ID: 0).
   
$groups = array(0);

   
// Get all the non-postcount based groups.
   
$request db_query("
      SELECT ID_GROUP
      FROM 
{$db_prefix}membergroups
      WHERE minPosts = -1"
__FILE____LINE__);
   while (
$row mysql_fetch_assoc($request))
      
$groups[] = $row['ID_GROUP'];

   
// Give them all their new permission.
   
$request db_query("
      INSERT IGNORE INTO 
{$db_prefix}permissions
         (permission, ID_GROUP, addDeny)
      VALUES
         ('my_permission', " 
implode(", 1),
         ('my_permission', "
$groups) . ", 1)"__FILE____LINE__);
?>


If so, could someone rewrite this to make it work with SMF 2?

Thanks.
Kids, you tried your best and you failed miserably. The lesson is - never try.

My mods:
OS & Browser Detection (1.5 is out!) | Skype Profile Field | GTalk Profile Field | AllCaps Blocker | SMF Syntax Highlighter (Beta) + 2 in development!

Personal websites:
Mobilize.rs (and forum) | Lolmao.info



Dragooon

It'll be same for SMF 2 as well, there is no other way in SMF 2. You just have to use $smcFunc DB functions and correct the column/table names. Rest is same.

X3mE

Kids, you tried your best and you failed miserably. The lesson is - never try.

My mods:
OS & Browser Detection (1.5 is out!) | Skype Profile Field | GTalk Profile Field | AllCaps Blocker | SMF Syntax Highlighter (Beta) + 2 in development!

Personal websites:
Mobilize.rs (and forum) | Lolmao.info



Advertisement: