Advertisement:

Author Topic: Apply permissions to custom actions  (Read 54151 times)

Offline Elijah Bliss

  • Sophist Member
  • *****
  • Posts: 1,340
Apply permissions to custom actions
« on: October 31, 2004, 05:32:54 PM »
I am not sure if this is possible, but is it possible to apply permissions to custom actions?

Saying for example I only want a certain membergroup to access the chatroom, arcade, (a particular mod) etc. would that be difficult to accomplish?
« Last Edit: November 13, 2004, 02:00:06 AM by andrea »

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: A permissions tutorial?
« Reply #1 on: November 02, 2004, 12:31:30 AM »
Sources/ManagePermissions.php... look for:

function setPermissionLevel($level, $group, $board = 'null')

Inside you'll see a series of arrays.  Let's say we're adding an arcade_play permission:

Find:
Code: [Select]
// Standard - ie. members.  They can do anything Restrictive can.
$groupLevels['global']['standard'] = array_merge($groupLevels['global']['restrict'], array(

Add after:
Code: [Select]
'arcade_play',
This adds said permission to the "standard" set.  You can put it in any of the sets, just remember that they inherit downward.  It's a little more complicated for board permissions, but nearly the same.

Next, we're going to look under:

function loadAllPermissions()

Find:
Code: [Select]
$permissionList = array(
'membergroup' => array(
'general' => array(

Add after:
Code: [Select]
'arcade_play' => false,
This adds it to the "advanced" view of permissions, which makes it a lot easier to turn on/off/deny.

Now, in your arcade script, just do the following: (this will give them an error if they cannot 'arcade_view' ;).)

Code: [Select]
isAllowedTo('arcade_play');
You could also do something like:

Code: [Select]
if (allowedTo('arcade_play'))
echo 'Hi!!';

Notice the very crucial difference in function names.  Last, we want to add entries to the language file... Modifications.english.php:

Code: [Select]
$txt['cannot_arcade_play'] = 'Sorry, you\'re not allowed to play games in the arcade.';
$txt['permissionname_arcade_play'] = 'Play games in the arcade';
$txt['permissionhelp_arcade_play'] = 'This permission allows people to play games in the arcade.  Without it, they won't even be able to view games at all.';

Another good idea, when making a mod, is to insert the default permissions... for that, you might:

Code: [Select]
INSERT INTO {$db_prefix}permissions
(permission, ID_GROUP)
SELECT 'arcade_play', ID_GROUP
FROM {$db_prefix}membergroups
WHERE ID_GROUP != 3;

INSERT INTO {$db_prefix}permissions
(permission, ID_GROUP)
VALUES ('arcade_play', 0),
('arcade_play', -1);

Again, it's more complex for board permissions, but that's the general idea.

That's a sorta brief tutorial, but it's all you need to do.  I don't suppose you could tell me what you think?

-[Unknown]
« Last Edit: November 02, 2004, 12:36:02 AM by [Unknown] »

Offline Elijah Bliss

  • Sophist Member
  • *****
  • Posts: 1,340
Re: A permissions tutorial?
« Reply #2 on: November 02, 2004, 11:27:20 PM »
I don't suppose you could tell me what you think?

-[Unknown]

I think you ROCK dude.

This is this tutorial is the best one yet, followed by "smf custom actions" and "custom profile fields." Everything works perfectly. I don't plan on adding any other mods to the permissions systems, but I personally felt that the Arcade mod needed some form governing. I am continuously amazed on how easily SMF can be customized and tailored. It's a wrap for other forum software.

Offline Elijah Bliss

  • Sophist Member
  • *****
  • Posts: 1,340
Re: A permissions tutorial?
« Reply #3 on: November 02, 2004, 11:32:04 PM »
One last question, I want to place a button to the arcade on the index template, and I'd prefer that it's visible to only those who are allowed to play the games.

I know for admin only access it would be ['is_admin'] but what would the variable be for member groups, ['is_allowed']?

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: A permissions tutorial?
« Reply #4 on: November 02, 2004, 11:44:24 PM »
Well, that's specially filled in the source files to simplify things...

You probably want to just call the function there too, like:

if (allowedTo('arcade_play'))

SMF was made to be simple to tailor, that's the entire point ;)!

-[Unknown]

Offline Elijah Bliss

  • Sophist Member
  • *****
  • Posts: 1,340
Re: A permissions tutorial?
« Reply #5 on: November 02, 2004, 11:54:39 PM »
Well, that's specially filled in the source files to simplify things...

You probably want to just call the function there too, like:

if (allowedTo('arcade_play'))

SMF was made to be simple to tailor, that's the entire point ;)!

-[Unknown]

That worked, thanks!

Offline Søren Bjerg

  • Jr. Member
  • **
  • Posts: 228
  • Gender: Male
  • Dragoon!
    • RUNE HORDES dot INFO
Re: A permissions tutorial?
« Reply #6 on: November 11, 2004, 07:45:14 PM »
[...]

Wow... this is great, and will certainly help me use the permissions system in a system I'm developing on my site flexibly; no need to hardcode a membergroup's ID in the code now :D.
RUNE HORDES dot INFO - SMF 1.1.10 w/ Custom Profile Mod... and various permissions hooks and template changes (new topic form).

Offline anunlike

  • Sr. Member
  • ****
  • Posts: 746
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #7 on: April 23, 2005, 05:23:50 PM »
Hi.

I'm trying to do something like this as well. I've done everything said here, but I think I still need to make it apply specifically to the membergroup I'm setting this up for. So, where would I put the last step?:
Code: [Select]
INSERT INTO {$db_prefix}permissions
(permission, ID_GROUP)
SELECT 'arcade_play', ID_GROUP
FROM {$db_prefix}membergroups
WHERE ID_GROUP != 3;

INSERT INTO {$db_prefix}permissions
(permission, ID_GROUP)
VALUES ('arcade_play', 0),
('arcade_play', -1);
I'm not sure which file and where in the file I should put this(?).


Thanks.

Offline Thantos

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 16,163
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #8 on: April 23, 2005, 05:28:06 PM »
That would go into your add_settings.php file in the package

Offline anunlike

  • Sr. Member
  • ****
  • Posts: 746
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #9 on: April 23, 2005, 05:49:27 PM »
Thanks.

But, I can't find 'add_settings.php' anywhere?

Offline Thantos

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 16,163
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #10 on: April 23, 2005, 06:03:07 PM »
Its part of the package.  If you aren't making a package out of it just manually query the database to insert those values

Offline anunlike

  • Sr. Member
  • ****
  • Posts: 746
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #11 on: April 23, 2005, 06:14:25 PM »
Thanks, but please go easy on me. I'm still new at this.
 
Saying "query the database" doesn't help. I need more detailed instructions to get anywhere.


No, I'm not making a package. I'm just trying to make it so that anyone who signs up with a certain username, which I've set up as 'member' and have it under a specific membergroup, has very limited permissions. I'm providing a public username and password for any guest to be able to preview the site with. Right now though, I'm trying to deny them the ability to access two areas (not the boards/forums) which will house various media to download.

I've put in all the above, except the last step. So, with the way it's set up now, I'm preventing anyone from accessing them and I think that all I need to do is to set the permissions to the specific membergroup that I want to resrict.
« Last Edit: April 23, 2005, 06:16:45 PM by anunlike »

Offline rkarnes

  • Newbie
  • *
  • Posts: 3
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #12 on: April 25, 2005, 09:58:25 AM »
I've followed the above steps and now I get this error:

I get this when does almost anything, including viewing the new section, viewing who, or views the index. I don't seem to get any errors from any guests ( of course they can't access the new section) and things appear to be working otherwise. I just get the errors showing up in the log. I'm sure it's something dumb I did (or maybe didn't do).

BTW I'm using version 1.0.3


Edit; Never mind I found what I did wrong, and it was stupid. :)

TIA

Reed
« Last Edit: April 25, 2005, 10:23:50 AM by rkarnes »

Offline anunlike

  • Sr. Member
  • ****
  • Posts: 746
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #13 on: April 27, 2005, 12:01:47 PM »
I'm sorry to be pushy with this, but I'd really like to get this set up as soon as I can. I'm really wanting to get things going and to the best of my ability, I don't want anyone in this membergroup (reserved for one specific username) to have access to them. I just need the last bit (I think) of help to manually put in the values for that membergoup. If someone could just point the basics out, I should be able to figure the rest.

Thank you much again. Apologies for being impatient and demanding.

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #14 on: April 27, 2005, 02:30:26 PM »
I'm afraid I haven't the slightest idea what exactly you're asking...?

-[Unknown]

Offline anunlike

  • Sr. Member
  • ****
  • Posts: 746
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #15 on: April 27, 2005, 03:08:52 PM »
Ok. LOL Apologies.

Basically I'm just wanting to restrict one membergroup (which will only have one username) from a certain area. This area is not the board / forum area, but a modded area, a downloads area ('Simple Download', I think it's called). Since it's not in the forums and the mod didn't put an option in the admin area (and I don't know how to do that myself), I can't do it through the admin area (not that I know of, anyway).

This username will be provided as a username that anyone can use to preview the site, before actually signing up themselves. So, basically, anyone will be able to use this username. As such, I'm trying to get it so that no one with this username will have access to this modded area. So far, I've gotten it so that the restriction works, but I don't have it set to the specific membergroup or username (whichever would work the best?).

Hope that clears it up.


Actually, now that I look at this thread, it's not exactly what my question relates to, but very close. I want to make this restriction of this modded area for this membergroup (single username). I hope this this thread was the most appropriate to ask for this in.

Offline anunlike

  • Sr. Member
  • ****
  • Posts: 746
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #16 on: May 01, 2005, 01:32:10 AM »
Was that a clear enough explanation? Enough to get some help with it?

Offline anunlike

  • Sr. Member
  • ****
  • Posts: 746
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #17 on: May 03, 2005, 01:59:56 PM »
Could I possibly get some help with this? Again, I'm not trying to be pushy and I understand people are busy. I was just hoping to be able to use this by now. I'd very much appreciate any help, soon...

Offline Herman's Mixen

  • SMF Hero
  • ******
  • Posts: 7,228
    • Herman's Mixen
Re: Apply permissions to custom actions
« Reply #18 on: May 04, 2005, 02:50:06 PM »
it ain't a package jet !!
just follow the instructions in install.txt
in the main mod zip or tar.gz
Met vriendelijke groet, The Burglar!

 House Mixes | Mixcloud | Any Intelligent fool can make things bigger, more complex, and more violent.
It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Albert Einstein

Former Godfather of our dutch community ;)

Offline anunlike

  • Sr. Member
  • ****
  • Posts: 746
  • Gender: Male
Re: Apply permissions to custom actions
« Reply #19 on: May 05, 2005, 12:10:07 PM »
Ah! I figured it out!  :D

Apparently, somehow, the entries in ManagePermissions.php were not entered in correctly. So, I changed them manually and the permission options are showing up now.

Thanks. Apologies for any confusions and annoyances. :-X
« Last Edit: May 05, 2005, 12:11:42 PM by anunlike »