News:

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

Main Menu

Custom Permissions

Started by Kays, April 06, 2011, 06:57:06 PM

Previous topic - Next topic

Kays

Link to Mod

This mod will allow you to create custom permissions. Custom permissions can be used when one is scripting to include or exclude member groups from doing certain actions or viewing certain pages.

Usage:

Permissions are used in conjunction with the allowedTo() function. Which will return either true or false depending on whether the permission is set for that member group or not. As an example, if you create a permission named view_this then it can be used as such:


if (allowedTo('view_this'))
echo 'Yes, you can see this.';
else
echo 'Nope, say goodbye';

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Joker™

Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

mgrmgr

Great mod. It wouldn't be me if I hadn't a request though: I desperately search for something like that for SMF 1.1.13 (our production forum) - would you possibly be able to implement something like this mod also for the V1 version ???

Kays

Thanks Joker. :)

mgrmgr, it will install for both versions.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

mgrmgr

#4
Quote from: Kays on April 07, 2011, 07:24:11 PM
...
mgrmgr, it will install for both versions.

Thanks for the answer. Just a tip: mentioning that in the modification description could be a good way to promote this fabulous mod even more :)

Just saw - you already did so :)

Chas Large

Great mod Kays,

Now all I need to do is work out how to add a permission to just one board.
My Modifications :)  My Forum

Please DO NOT PM me with support requests. Post the problem in the appropriate Support Board so everyone can benefit from the advice given.

live627

Create a new permission profile and assign it to a board as a first step

Kays

Thanks. This mod is only for user permissions and not board permissions.

Plus, if you do create a permission, It does nothing unless you code it in.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

live627

If allowedTo() is called on a board, it first attempts to check the related permission in the board.

Kays

Yes, but this mod doesn't add to the board permission list. So the board id would need to be checked as well.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

CapadY

#10
Great MOD but I have a little problem.

I've installed it in SMF 2.0 but the permissions are only shown in an own group (custom_permissions) in the classic mode, in simple mode they are not shown in an own group (custom_permissions) but they are added to the basic functionality group.

edit:

Another problem.
When I try to edit the permission description I get an errormessage the permission name can't be the same as an existing permission.
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

DanCarroll

I  hope this thread isn't dead. Kays: great mod. Very useful.

But I have the same problem as CapadY, the [Edit] function won't allow an edit to be saved. Unless you modify the permission name, which in effect creates a new permission. Also, I would expect an edit function to allow editing the description. The description field value isn't included in the "edit".

Thank you again for a great mod.

Kays

Not dead, just kinda forgotten about. And thanks. :)

Quote from: CapadY on June 25, 2011, 07:25:27 AM
Great MOD but I have a little problem.

I've installed it in SMF 2.0 but the permissions are only shown in an own group (custom_permissions) in the classic mode, in simple mode they are not shown in an own group (custom_permissions) but they are added to the basic functionality group.

This has something to do with how SMF handles permissions added by a mod and from what I've can tell there's no way around it.

Quote from: DanCarroll on March 16, 2012, 06:39:23 AM
Also, I would expect an edit function to allow editing the description. The description field value isn't included in the "edit".

This might be difficult to do since the focus can only be on one field. (I think). Plus if one is to edit a current description I figured it's best to start with an empty field. :)

I did fix the bug when trying to edit a permission and uploaded an updated version.


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

Hi! again Kays, I wanted to let you know that I just installed your custom permissions mod on my test pc that I have SMF 2.0.2 installed. And I been getting some errors from your mod. and one of the errors I can't remove from the logs. It says.

http://www.toppersbbs.info/smf/index.php?action=admin;area=logs;sa=errorlog;desc=
8: Undefined index: custom_permissions
File: C:/www/vhosts/_static/toppers/smf/Sources/Admin.php
Line: 327

So far this is the only error I'm getting and the one I can't remove

SMF Forums http://www.df-barracks.com Where gamers go.

Kays

Thanks for that, but I can't reproduce it. And I can't see why it's happening. ???

The problem appears to be a missing $txt string.


'custom' => array($txt['custom_permissions'], 'admin_forum'),


So check Modifications.english.php to see if it is there. But it should be as the other $txt strings added appear to be there

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

Well I check the installer for your mod, and I guess you do have some thing wrong. That part to show me goes into the Admin.php file. Below is from your installer.


<id>Kays:CustomPermissions</id> <version>1.1.0</version> -<file name="$sourcedir/Admin.php"> -<operation> -<search position="before">
<![CDATA['profiles' => array($txt['permissions_profiles'], 'manage_permissions'), 'postmod' => array($txt['permissions_post_moderation'], 'manage_permissions', 'enabled' => $modSettings['postmod_active']),]]>
</search> -<add>
<![CDATA[ 'custom' => array($txt['custom_permissions'], 'admin_forum'),]]>
</add> </operation> </file>

SMF Forums http://www.df-barracks.com Where gamers go.

bigjoe11a

Could the reason why I'm getting this error is because I'm using it my mod. ?
SMF Forums http://www.df-barracks.com Where gamers go.

Kays

It could have something to do with your mod. ???

What to do is to add the following to your Admin language file.


$txt['custom_permissions'] = 'Custom Permissions';

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

bigjoe11a

Ok, well This got rid of the error. So I don't know. Thanks
SMF Forums http://www.df-barracks.com Where gamers go.

Eclipse16V

Hello,
first of all thanks for the great mod
I now have but one question:
In my SMF version 2.0.4 I've created a few new profile fields manually. These work quite well. Now I wanted to with this mod make it so that only certain groups can fill out these fields and can see.
How do I connect this mod for example in the Profiles-Modify.php with this one:
function tmMap($memID)
{
global $context, $user_profile, $user_info, $txt, $modSettings;

loadThemeOptions($memID);
if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
loadCustomFields($memID, 'tmmap');

$context['sub_template'] = 'edit_options';
$context['page_desc'] = $txt['tmMap_info'];

setupProfileContext(
array(
'pf_design_der_map', ... 'pf_css_a_link_color',
)
);
}


It just does not work as I would like.
I worked with:
SMF 2 in German

Shop:
SID Giessen

Advertisement: