News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Apply permissions to custom actions

Started by Elijah Bliss, October 31, 2004, 05:32:54 PM

Previous topic - Next topic

Elijah Bliss

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?

[Unknown]

#1
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:
// Standard - ie. members.  They can do anything Restrictive can.
$groupLevels['global']['standard'] = array_merge($groupLevels['global']['restrict'], array(


Add after:

'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:
$permissionList = array(
'membergroup' => array(
'general' => array(


Add after:
'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' ;).)

isAllowedTo('arcade_play');

You could also do something like:

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:

$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:

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]

Elijah Bliss

Quote from: [Unknown] on November 02, 2004, 12:31:30 AM
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.

Elijah Bliss

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']?

[Unknown]

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]

Elijah Bliss

Quote from: [Unknown] 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]

That worked, thanks!

Søren Bjerg

Quote from: [Unknown] on November 02, 2004, 12:31:30 AM[...]

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).

anunlike

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?:

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.

Thantos

That would go into your add_settings.php file in the package

anunlike

Thanks.

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

Thantos

Its part of the package.  If you aren't making a package out of it just manually query the database to insert those values

anunlike

#11
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.

rkarnes

#12
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

anunlike

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.

[Unknown]

I'm afraid I haven't the slightest idea what exactly you're asking...?

-[Unknown]

anunlike

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.

anunlike

Was that a clear enough explanation? Enough to get some help with it?

anunlike

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

Herman's Mixen

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 ;)

anunlike

#19
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

Advertisement: