Adding Permission Types

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Adding Permission Types

Post by christhatsme »

Hi,

I am returning to phpBB after quite a while and I'm a little rusty!

How do I add a new permission type? And have it show in the ACP? I think I am adding it correctly but it doesn't show in the ACP.

lang file: (mods/permissions_cms.php)

Code: Select all

<?php
/**
* acp_permissions_phpbb (phpBB Permission Set) [English]
*
* @package language
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

/**
* DO NOT CHANGE
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

if (empty($lang) || !is_array($lang))
{
	$lang = array();
}

// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine

/**
*	MODDERS PLEASE NOTE
*
*	You are able to put your permission sets into a separate file too by
*	prefixing the new file with permissions_ and putting it into the acp
*	language folder.
*
*	An example of how the file could look like:
*
*	<code>
*
*	if (empty($lang) || !is_array($lang))
*	{
*		$lang = array();
*	}
*
*	// Adding new category
*	$lang['permission_cat']['bugs'] = 'Bugs';
*
*	// Adding new permission set
*	$lang['permission_type']['bug_'] = 'Bug Permissions';
*
*	// Adding the permissions
*	$lang = array_merge($lang, array(
*		'acl_bug_view'		=> array('lang' => 'Can view bug reports', 'cat' => 'bugs'),
*		'acl_bug_post'		=> array('lang' => 'Can post bugs', 'cat' => 'post'), // Using a phpBB category here
*	));
*
*	</code>
*/

	$lang['permission_cat']['pages'] = 'Pages';

	// Adding new permission set
	$lang['permission_type']['cms_'] = 'CMS Permissions';

	// Adding the permissions
	$lang = array_merge($lang, array(
		'acl_cms_view'		=> array('lang' => 'Can view CMS pages', 'cat' => 'pages'),
'acl_cms_edit'		=> array('lang' => 'Can edit CMS pages', 'cat' => 'pages'),
	));
	
	
?>
how I am adding them:

Code: Select all

      <?php
        define('IN_PHPBB', true);
        $phpbb_root_path = './';
        $phpEx = substr(strrchr(__FILE__, '.'), 1);
        include($phpbb_root_path . 'common.' . $phpEx);
        $user->session_begin();
        $auth->acl($user->data);
        $user->setup();
        include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
        $auth_admin = new auth_admin();

		$cache->destroy('acl_options');

		        $auth_admin->acl_add_option(array(
            'local'      => array(),
            'global'   => array('cms_view', 'cms_edit')
        ));
        ?>
What am I missing?

Thanks

Chris
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.
User avatar
Steve
Registered User
Posts: 1092
Joined: Tue Apr 07, 2009 7:48 pm
Location: UK ,up north!!
Name: Steven Clark
Contact:

Re: Adding Permission Types

Post by Steve »

your missing adding the permissions to the database ;)

using The umil installer is the easy way.

Example:

Code: Select all

    // permissions
        'permission_add' => array(
            array('u_cms_view'),
        ),
 
User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: Adding Permission Types

Post by christhatsme »

Code: Select all

$auth_admin->acl_add_option(array(
            'local'      => array(),
            'global'   => array('cms_view', 'cms_edit')
        ));
seems to do this? Which I have.

(and I'm not using u_ etc. because I have defined a new type cms_ in the language file )
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52298
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Adding Permission Types

Post by Brf »

christhatsme wrote:

Code: Select all

 ('cms_view', 'cms_edit')
Your permissions need to have a prefix, so it knows which page they belong.
User avatar
Steve
Registered User
Posts: 1092
Joined: Tue Apr 07, 2009 7:48 pm
Location: UK ,up north!!
Name: Steven Clark
Contact:

Re: Adding Permission Types

Post by Steve »

christhatsme wrote:

Code: Select all

$auth_admin->acl_add_option(array(
            'local'      => array(),
            'global'   => array('cms_view', 'cms_edit')
        ));
seems to do this? Which I have.

(and I'm not using u_ etc. because I have defined a new type cms_ in the language file )
^^
Looks like an old umil install file.

u_cms_view u_ == you ,but can be set by group permissions;

Code: Select all

'permission_set' => array(
            // Global Group permissions
            array('ROLE_ADMIN_USERGROUP', 'u_cms_view', 'group'),
            ),
 
a_cms_view a_ == admin permission roles.

If you can let me know exactly the permissions needed for each group i would ,be so kind to write the install file.
BRF is correct
User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: Adding Permission Types

Post by christhatsme »

Have I misunderstood what a permission type is? I want to add a new permission type with a new prefix. it will be completely separate to the u_ permission set and display on a different page. There is some documentation at the top of the permissions_phpbb.php lang file for this.

also acl_add_options does work, it does add them to the database as I have checked, it is also the way this article:

http://wiki.phpbb.com/Tutorial.Permissi ... on_options

suggests to do it. (this isn't for an install file).

the above usage of acl_add_options() also adds the cms_ prefix to the database automatically but no new option is appearing in the permission type drop down on permission pages
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52298
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Adding Permission Types

Post by Brf »

The Global permissions are User, Global Mod, and Admin. You have to choose one of those. Otherwise, which page would it show on?
User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: Adding Permission Types

Post by christhatsme »

it seemed from the lang file you could add a new permission type

* // Adding new permission set
* $lang['permission_type']['bug_'] = 'Bug Permissions';
(this is from the top of language/acp/permissions_phpbb.php)

I assumed it would happen automatically, like adding categories to languages files does.

edit:

Guessing its more complicated than it seems and I would have to make code additions to the permissions module to create an extra permissions set?
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52298
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Adding Permission Types

Post by Brf »

I would think you would have to define the ACP page it would show on and make the links to it and stuff.
User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: Adding Permission Types

Post by christhatsme »

Ah okay, just thought it would add itself as categories do.

No worries will have to look at how to add it in with code additions or perhaps simplify my permission so i can fit it into one of the other types without over cluttering it.

If anyone has any alternative solutions let me know :) .
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.
User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: Adding Permission Types

Post by christhatsme »

I managed to figure this out.

How to create a new global permission type/class for others reference:

First decide what prefix your new permission class/type is going to use. Here I will use pre_ as an example.

Second, you need to create the new permissions.

this can be done by running this in your phpBB root directory.:

Code: Select all

      <?php
        define('IN_PHPBB', true);
        $phpbb_root_path = './';
        $phpEx = substr(strrchr(__FILE__, '.'), 1);
        include($phpbb_root_path . 'common.' . $phpEx);
        $user->session_begin();
        $auth->acl($user->data);
        $user->setup();
        include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
        $auth_admin = new auth_admin();

		        $auth_admin->acl_add_option(array(
            'local'      => array(),
            'global'   => array('a_preauth', 'pre_view', 'pre_edit')
        ));
        ?>

Here I add 3 permissions, the first of which is necessary as phpBB checks for this permission automatically when trying to edit the new permission class in the ACP.

Next, add the language variables in a new file in the language/mods directory with the file name permissions_yourmod.php, don't forget to replace all instances of pre_/PRE_ with your prefix.

Code: Select all

<?php
/**
* acp_permissions_phpbb (phpBB Permission Set) [English]
*
* @package language
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

/**
* DO NOT CHANGE
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

if (empty($lang) || !is_array($lang))
{
	$lang = array();
}

// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine

/**
*	MODDERS PLEASE NOTE
*
*	You are able to put your permission sets into a separate file too by
*	prefixing the new file with permissions_ and putting it into the acp
*	language folder.
*
*	An example of how the file could look like:
*
*	<code>
*
*	if (empty($lang) || !is_array($lang))
*	{
*		$lang = array();
*	}
*
*	// Adding new category
*	$lang['permission_cat']['bugs'] = 'Bugs';
*
*	// Adding new permission set
*	$lang['permission_type']['bug_'] = 'Bug Permissions';
*
*	// Adding the permissions
*	$lang = array_merge($lang, array(
*		'acl_bug_view'		=> array('lang' => 'Can view bug reports', 'cat' => 'bugs'),
*		'acl_bug_post'		=> array('lang' => 'Can post bugs', 'cat' => 'post'), // Using a phpBB category here
*	));
*
*	</code>
*/

	$lang['permission_cat']['examplecat'] = 'Example Category';

	// Adding new permission set
	$lang['permission_type']['pre_'] = 'Pre Permissions Permissions';
	$lang['ACL_TYPE_PRE_'] = 'Pre Permissions';
	$lang['ACL_TYPE_GLOBAL_PRE_'] = 'Pre Permissions';
	
	$lang = array_merge($lang, array(
		'acl_a_preauth'		=> array('lang' => 'Can alter the pre permission class', 'cat' => 'permissions')
	));
	
	// Pages administration
	$lang = array_merge($lang, array(
		'acl_pre_view'		=> array('lang' => 'Can view Pre pages', 'cat' => 'examplecat'),
		'acl_pre_edit'		=> array('lang' => 'Can edit Pre pages', 'cat' => 'examplecat')

	));
	
	
?>
next open includes/acp/acp_permissions.php

find (circa line 176).

Code: Select all

$this->permission_dropdown = array('u_', 'm_', 'a_');
replace with

Code: Select all

$this->permission_dropdown = array('u_', 'm_', 'a_', 'pre_');
You should now be all good to go, make sure you have the permission in acp permissions to alter the class (it will appear under the permissions tab automatically once these changes are made).
Then browser to either user permissions or group permissions, choose a user / group and press enter. Your new permission class should now be in the permission type dropdown at the top (it defualts on "user permissions".

You will have to make further small changes to allow viewing of permissions and creating of roles for the new permission type. I won't detail that here but if you want help with it let me know.

I hope this is of help to others,

Chris
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.
Locked

Return to “[3.0.x] MOD Writers Discussion”