phpBB

Development Wiki

Difference between revisions of "Tutorial.Permissions"

From phpBB Development Wiki

m
(Alternative method - using UMIL)
 
(23 intermediate revisions by 14 users not shown)
Line 1: Line 1:
[http://lordsander.ifrance.com/topic/riassunti-verga.htm riassunti verga] [http://tat-ooin.ifrance.com/resources/articles/bellenden-william.htm bellenden, william] [http://toofarfrommaybe.ifrance.com/view/new/ufficio-vercelli/ ufficio vercelli] [http://girlwho-is.ifrance.com/img/styles/scarica-suonerie.htm scarica suonerie ommitel it] [http://girlwho-is.ifrance.com/img/styles/ospedale-rizzoli.htm ospedale rizzoli bologna] [http://noxuhax.ifrance.com/content/view/googfle.htm googfle] [http://voltia.ifrance.com/content/view/fidanzata-amico.htm fidanzata amico] [http://broadwaylili.ifrance.com/content/view/grosseto-trans.htm grosseto trans] [http://deviantrus.ifrance.com/topic/poliziotto-solitudine/ poliziotto, solitudine e rabbia] [http://toofarfrommaybe.ifrance.com/view/new/barbie-magico/ barbie magico salone di bellezza] [http://kalian42.ifrance.com/text/directory/ad-ware/ ad ware] [http://igaros.ifrance.com/lib/how-deep/ how deep is] [http://jdawsona.ifrance.com/data/yakumo-x/ yakumo 67x] [http://lordsander.ifrance.com/topic/aeg.htm aeg 48380] [http://tizolaa.ifrance.com/web/domenica-bestiale/ domenica bestiale di fabio concato] [http://noxuhax.ifrance.com/content/view/driver-for.htm driver for motorola v220] [http://kalian42.ifrance.com/text/directory/classrooms/ classrooms] [http://singaporepets.ifrance.com/library/html/head-radical.htm head radical liquidmetal] [http://deviantrus.ifrance.com/topic/melissa/ melissa 18] [http://broadwaylili.ifrance.com/content/view/dlt-backup.htm dlt back-up e accessori] [http://tizolaa.ifrance.com/web/w-w/ w w w cameracafe it] [http://girlwho-is.ifrance.com/img/styles/microsoft-digital.htm microsoft digital media pro keyboard] [http://tizolaa.ifrance.com/web/roba-che/ roba che scotta] [http://deviantrus.ifrance.com/topic/la-perla/ la perla store] [http://girlwho-is.ifrance.com/img/styles/marmisti.htm marmisti] [http://voltia.ifrance.com/content/view/bruce-springsteen.htm bruce springsteen. video anthology 1978-88] [http://kalian42.ifrance.com/text/directory/pentium-/ pentium 4 socket 478 3 2 ghz] [http://noxuhax.ifrance.com/content/view/torino-roma.htm torino roma] [http://lordsander.ifrance.com/topic/ragazza.htm ragazza] [http://kalian42.ifrance.com/text/directory/vita-segreta/ vita segreta di una diciottenne] [http://highbulp.ifrance.com/images/small/football-manager/ football manager] [http://noxuhax.ifrance.com/content/view/gli-ultimi.htm gli ultimi giorni] [http://tizolaa.ifrance.com/web/max-speziali/ max speziali] [http://speedofsoun.ifrance.com/text/directory/code-keys.htm code keys viaccess seca nagravision] [http://tat-ooin.ifrance.com/resources/articles/real-book.htm real book] [http://demurediablo.ifrance.com/library/html/nuova-officine/ nuova officine tessili] [http://jdawsona.ifrance.com/data/san-sperate/ san sperate] [http://yeeden.ifrance.com/img/styles/hp-scanjet/ hp scanjet 5530c usb] [http://girlwho-is.ifrance.com/img/styles/livorno.htm livorno] [http://toofarfrommaybe.ifrance.com/view/new/il-simbolo/ il simbolo del sesso] [http://kalian42.ifrance.com/text/directory/fashion-show/ fashion show clip] [http://jdawsona.ifrance.com/data/printer-dock/ printer dock 6000] [http://tizolaa.ifrance.com/web/bon-jovi/ bon jovi in these arms] [http://lovereceier.ifrance.com/lib/battle.htm battle2] [http://jdawsona.ifrance.com/data/antenna-dsail/ antenna d-sail] [http://highbulp.ifrance.com/images/small/marica-yo/ marica yo marica tu marica quien marica] [http://tizolaa.ifrance.com/web/libreria-ibis/ libreria ibis] [http://igaros.ifrance.com/lib/www-biancaluna/ www biancaluna com] [http://lordsander.ifrance.com/topic/crociera-nilo.htm crociera nilo vacanze] [http://tat-ooin.ifrance.com/resources/articles/ram-cisco.htm ram cisco 1700] [http://tat-ooin.ifrance.com/resources/articles/volo-basso.htm volo basso costo] [http://singaporepets.ifrance.com/library/html/mariah-carey.htm mariah carey porno foto] [http://lordsander.ifrance.com/topic/mina-don.htm mina don t] [http://deviantrus.ifrance.com/topic/tim-sms/ tim sms gratis] [http://tat-ooin.ifrance.com/resources/articles/daniela-mercury.htm daniela mercury] [http://tizolaa.ifrance.com/web/foppapedretti-mary/ foppapedretti mary naturale] [http://speedofsoun.ifrance.com/text/directory/golf.htm golf 3.2] [http://kalian42.ifrance.com/text/directory/luci-a/ luci a sa siro] [http://akmokanzen.ifrance.com/images/small/moto-recapiti.htm moto recapiti] [http://oiyaoi.ifrance.com/images/small/liquido-campeggio/ liquido campeggio] [http://kalian42.ifrance.com/text/directory/come-si/ come si installa] [http://broadwaylili.ifrance.com/content/view/dezful.htm dezful] [http://tizolaa.ifrance.com/web/sborra-negli/ sborra negli slip] [http://jdawsona.ifrance.com/data/oubritenga/ oubritenga] [http://highbulp.ifrance.com/images/small/sito-ufficiale/ sito ufficiale italiano per wolverine] [http://yeeden.ifrance.com/img/styles/cassino/ cassino] [http://voltia.ifrance.com/content/view/ram-full.htm ram full brand] [http://akmokanzen.ifrance.com/images/small/michael-j.htm michael j fox] [http://girlwho-is.ifrance.com/img/styles/enciende-mi.htm enciende mi fuego] [http://lordsander.ifrance.com/topic/balla-diy.htm balla diy] [http://tizolaa.ifrance.com/web/surf-casting/ surf casting] [http://tat-ooin.ifrance.com/resources/articles/grande-punto.htm grande punto 1 3] [http://tizolaa.ifrance.com/web/le-fate/ le fate dei fiori] [http://broadwaylili.ifrance.com/content/view/la-stanza.htm la stanza del fliglio] [http://voltia.ifrance.com/content/view/monitor-plasma.htm monitor plasma hitachi] [http://noxuhax.ifrance.com/content/view/olivetti-ofx.htm olivetti ofx] [http://yeeden.ifrance.com/img/styles/courtney/ courtney] [http://voltia.ifrance.com/content/view/dive-calendario.htm dive calendario] [http://demurediablo.ifrance.com/library/html/sisley-eau/ sisley eau de campagne] [http://demurediablo.ifrance.com/library/html/unico/ unico 2004] [http://demurediablo.ifrance.com/library/html/stoccaggio-rifiuti/ stoccaggio rifiuti] [http://girlwho-is.ifrance.com/img/styles/carros.htm carros] [http://yeeden.ifrance.com/img/styles/instint/ instint] [http://girlwho-is.ifrance.com/img/styles/indeo-video.htm indeo video play back] [http://lordsander.ifrance.com/topic/bass-tab.htm bass tab raffaella carra] [http://toofarfrommaybe.ifrance.com/view/new/bobble-ice/ bobble ice age] [http://toofarfrommaybe.ifrance.com/view/new/cucine-classiche/ cucine classiche] [http://girlwho-is.ifrance.com/img/styles/soluzione-shadow.htm soluzione shadow of the colossus] [http://tat-ooin.ifrance.com/resources/articles/la-.htm la 2 gurra mondiale] [http://singaporepets.ifrance.com/library/html/malawi.htm malawi] [http://highbulp.ifrance.com/images/small/peugeot-sw/ peugeot sw] [http://tizolaa.ifrance.com/web/creative-zen/ creative zen micro arancione] [http://noxuhax.ifrance.com/content/view/amstrad-tv.htm amstrad tv 5] [http://oiyaoi.ifrance.com/images/small/qui-a/ qui a le droit] [http://highbulp.ifrance.com/images/small/dub-optika/ dub optika] [http://noxuhax.ifrance.com/content/view/www-portobello.htm www portobello it] [http://deviantrus.ifrance.com/topic/cavo-usb/ cavo usb stampanti] [http://demurediablo.ifrance.com/library/html/pino-daniele/ pino daniele -project] [http://igaros.ifrance.com/lib/dimmi-di/ dimmi di no] [http://yeeden.ifrance.com/img/styles/optin-email/ optin email marketing] [http://voltia.ifrance.com/content/view/mezzoforte.htm mezzoforte] [http://tizolaa.ifrance.com/web/quotazioni-multipla/ quotazioni multipla] [http://yeeden.ifrance.com/img/styles/motori-graupner/ motori graupner] [http://singaporepets.ifrance.com/library/html/bmw-.htm bmw 4 serie] [http://speedofsoun.ifrance.com/text/directory/batterie-z.htm batterie z300] [http://toofarfrommaybe.ifrance.com/view/new/autoradio-mp/ autoradio mp3 slot] [http://deviantrus.ifrance.com/topic/il-dito/ il dito nella piaga] [http://oiyaoi.ifrance.com/images/small/crane-hart/ crane, hart] [http://demurediablo.ifrance.com/library/html/franco-simone/ franco simone] [http://akmokanzen.ifrance.com/images/small/mike-buongiorno.htm mike buongiorno] [http://broadwaylili.ifrance.com/content/view/sorelline.htm sorelline] [http://yeeden.ifrance.com/img/styles/ricettario-bertolini/ ricettario bertolini] [http://highbulp.ifrance.com/images/small/calendario-ilary/ calendario ilary blasi] [http://yeeden.ifrance.com/img/styles/stampanti-laser/ stampanti laser colore a4 samsung] [http://igaros.ifrance.com/lib/pellicola-vetri/ pellicola vetri] [http://deviantrus.ifrance.com/topic/duncan-i/ duncan i believe my heart] [http://toofarfrommaybe.ifrance.com/view/new/keys-viaaccess/ keys viaaccess 007c00] [http://girlwho-is.ifrance.com/img/styles/putas-borrachas.htm putas borrachas] [http://tizolaa.ifrance.com/web/plasma-philips/ plasma philips 42] [http://lovereceier.ifrance.com/lib/roberta-giarusso.htm roberta giarusso nuda] [http://voltia.ifrance.com/content/view/ventole-pc.htm ventole pc] [http://jdawsona.ifrance.com/data/malevil/ malevil] [http://tizolaa.ifrance.com/web/tommasini-hotel/ tommasini hotel] [http://speedofsoun.ifrance.com/text/directory/tamil-songs.htm tamil songs] [http://voltia.ifrance.com/content/view/monitor-benq.htm monitor benq 937] [http://deviantrus.ifrance.com/topic/legacoopbund/ legacoopbund] [http://broadwaylili.ifrance.com/content/view/lorna-papi.htm lorna papi chulo] [http://oiyaoi.ifrance.com/images/small/nikon/ nikon 70 200 2 8] [http://tat-ooin.ifrance.com/resources/articles/aria-mesh.htm aria mesh puma] [http://lovereceier.ifrance.com/lib/calciatore-stranieri.htm calciatore stranieri] [http://girlwho-is.ifrance.com/img/styles/torna-backyard.htm torna backyard wrestling] [http://highbulp.ifrance.com/images/small/c-dragonball/ c18 dragonball x] [http://igaros.ifrance.com/lib/videoclip-eifel/ videoclip eifel 65] [http://toofarfrommaybe.ifrance.com/view/new/barry-white/ barry white cd] [http://girlwho-is.ifrance.com/img/styles/storia-festa.htm storia festa donna] [http://lordsander.ifrance.com/topic/batteria-cordless.htm batteria cordless sagem] [http://toofarfrommaybe.ifrance.com/view/new/harry-potter/ harry potter soundtrack] [http://noxuhax.ifrance.com/content/view/kit-auto.htm kit auto altoparlanti] [http://highbulp.ifrance.com/images/small/canon-fotografia/ canon fotografia] [http://igaros.ifrance.com/lib/aquatica-online/ aquatica online] [http://girlwho-is.ifrance.com/img/styles/castrazione.htm castrazione] [http://tat-ooin.ifrance.com/resources/articles/some-girl.htm some girl] [http://tizolaa.ifrance.com/web/fattoria-maremmana/ fattoria maremmana] [http://deviantrus.ifrance.com/topic/acqua-fredda/ acqua fredda] [http://igaros.ifrance.com/lib/www-provini/ www provini it] [http://girlwho-is.ifrance.com/img/styles/donne-inculate.htm donne inculate da cani] [http://speedofsoun.ifrance.com/text/directory/trucchi-per.htm trucchi per spyro 3] [http://akmokanzen.ifrance.com/images/small/www-sillyrabbit.htm www sillyrabbit com] [http://oiyaoi.ifrance.com/images/small/djv/ dj600v] [http://igaros.ifrance.com/lib/album-foto/ album foto matrimonio] [http://akmokanzen.ifrance.com/images/small/vietnam-hotel.htm vietnam hotel] [http://broadwaylili.ifrance.com/content/view/telegiornale-filmati.htm telegiornale filmati iraq] [http://voltia.ifrance.com/content/view/www-concessionario.htm www concessionario usato it] [http://deviantrus.ifrance.com/topic/djerba-last/ djerba last minute] [http://toofarfrommaybe.ifrance.com/view/new/rex-rd/ rex rd 1871 da] [http://noxuhax.ifrance.com/content/view/isacco-newton.htm isacco newton] [http://demurediablo.ifrance.com/library/html/lacie-/ lacie 50 gb] [http://lordsander.ifrance.com/topic/polski-hip.htm polski hip hop] [http://akmokanzen.ifrance.com/images/small/lego-studios.htm lego studios] [http://yeeden.ifrance.com/img/styles/harley-davidson/ harley davidson] [http://tizolaa.ifrance.com/web/agriturismo-asiago/ agriturismo asiago] [http://girlwho-is.ifrance.com/img/styles/belvedere-amalfi.htm belvedere amalfi] [http://lovereceier.ifrance.com/lib/tanti-giochi.htm tanti giochi  sexy] [http://voltia.ifrance.com/content/view/penelope-miller.htm penelope miller] [http://kalian42.ifrance.com/text/directory/elementari-nude/ elementari nude foto] [http://tat-ooin.ifrance.com/resources/articles/gps-portatile.htm gps portatile] [http://tat-ooin.ifrance.com/resources/articles/dainese-jet.htm dainese jet] [http://yeeden.ifrance.com/img/styles/moto-club/ moto club lucca] [http://demurediablo.ifrance.com/library/html/data-bank/ data bank] [http://deviantrus.ifrance.com/topic/lettore-multimedia/ lettore multimedia] [http://oiyaoi.ifrance.com/images/small/luomo-che/ luomo che uccise il suo carnefice] [http://tizolaa.ifrance.com/web/tomi/ tomi] [http://igaros.ifrance.com/lib/valvonauta-verdena/ valvonauta verdena] [http://demurediablo.ifrance.com/library/html/manuale-maya/ manuale maya] [http://singaporepets.ifrance.com/library/html/drops-of.htm drops of jupiter train] [http://noxuhax.ifrance.com/content/view/quattro-foto.htm quattro foto e un sondaggio per far cry] [http://highbulp.ifrance.com/images/small/grazie-di/ grazie di esistere] [http://speedofsoun.ifrance.com/text/directory/ilguerriero.htm ilguerriero] [http://tat-ooin.ifrance.com/resources/articles/immagini-e.htm immagini e nuovi dettagli per motogp 3] [http://tizolaa.ifrance.com/web/le-isole/ le isole canarie] [http://igaros.ifrance.com/lib/w-netsky/ w32 netsky p] [http://girlwho-is.ifrance.com/img/styles/agricoltura-.htm agricoltura - servizi] [http://speedofsoun.ifrance.com/text/directory/www-milano.htm www milano it] [http://jdawsona.ifrance.com/data/soulseek/ soulseek] [http://toofarfrommaybe.ifrance.com/view/new/ca/ ca] [http://yeeden.ifrance.com/img/styles/kendall-henry/ kendall, henry way] [http://singaporepets.ifrance.com/library/html/cerco-lavoro.htm cerco lavoro a catania] [http://toofarfrommaybe.ifrance.com/view/new/oroscopo-capricorno/ oroscopo capricorno] [http://broadwaylili.ifrance.com/content/view/www-bradford.htm www bradford it] [http://demurediablo.ifrance.com/library/html/packard-bell/ packard bell - store play hard disk] [http://girlwho-is.ifrance.com/img/styles/di-salto.htm di salto] [http://deviantrus.ifrance.com/topic/legend-garmin/ legend garmin] [http://lordsander.ifrance.com/topic/dolce-gabbana.htm dolce gabbana uomo abbigliamento] [http://tizolaa.ifrance.com/web/pooh-la/ pooh la donna del mio amico] [http://lordsander.ifrance.com/topic/hosting-dedicato.htm hosting dedicato] [http://jdawsona.ifrance.com/data/key-crack/ key crack password hotmail] [http://kalian42.ifrance.com/text/directory/luce-lettura/ luce lettura] [http://oiyaoi.ifrance.com/images/small/fax-xerox/ fax xerox] [http://igaros.ifrance.com/lib/dolce-attesa/ dolce attesa] [http://akmokanzen.ifrance.com/images/small/progettazione-consulenza.htm progettazione consulenza vendite aziendali] == Checking permissions ==
+
== Permission types ==
 +
*[[Admin permissions]]
 +
*[[Moderator permissions]]
 +
*[[User permissions]]
 +
*[[Forum permissions]]
 +
 
 +
== Checking permissions ==
  
=== Global perission ===
+
=== Global permission ===
To check if user can for example view other users profiles, use this code:
+
To check if user can for example view other users' profiles, use this code:
 
<php>
 
<php>
 
if (!$auth->acl_get('u_viewprofile'))
 
if (!$auth->acl_get('u_viewprofile'))
 
{
 
{
     trigger_error('NOT_AUTHORIZED');
+
     trigger_error('NOT_AUTHORISED');
 
}
 
}
 
</php>
 
</php>
If he doesn't have permission to do it, he will see only error message and script will stop working after trigger_error.
+
If he doesn't have permission to do it, he will see only error message and script will stop executing (exit) after trigger_error.
  
 
=== Local permission ===
 
=== Local permission ===
Line 16: Line 22:
 
if (!$auth->acl_get('f_read', 5))
 
if (!$auth->acl_get('f_read', 5))
 
{
 
{
     trigger_error('NOT_AUTHORIZED');
+
     trigger_error('NOT_AUTHORISED');
 
}
 
}
 
</php>
 
</php>
Line 25: Line 31:
 
Adding new permissions to Olympus is simple.
 
Adding new permissions to Olympus is simple.
 
NOTE: The permission can not contain a capital letter, this causes trouble later on if you try and create a module that needs this permission
 
NOTE: The permission can not contain a capital letter, this causes trouble later on if you try and create a module that needs this permission
 +
 
Example how to add a permission to control who can access and manage foo:
 
Example how to add a permission to control who can access and manage foo:
 
=== Using the API (recommended) ===
 
=== Using the API (recommended) ===
Line 40: Line 47:
 
));
 
));
 
?>
 
?>
 +
</php>
 +
 +
==== Sample install page using API to add permission options ====
 +
If you aren't otherwise using an installer for your mod, you can add a page under the install folder called something like install/install_permissions.php that would include something like the following code:
 +
<php>
 +
<?php
 +
 +
/**
 +
*
 +
* install script to set up permission options in the db for foo mod
 +
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
 +
*
 +
*/
 +
 +
/**
 +
* @ignore
 +
*/
 +
 +
// initialize the page
 +
define('IN_PHPBB', true);
 +
define('IN_INSTALL', true);
 +
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
 +
$phpEx = substr(strrchr(__FILE__, '.'), 1);
 +
include($phpbb_root_path . 'common.' . $phpEx);
 +
 +
 +
// Start session management
 +
$user->session_begin();
 +
$auth->acl($user->data);
 +
$user->setup('mods/foo');
 +
 +
 +
// Setup $auth_admin class so we can add tabulated survey permission options
 +
include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
 +
$auth_admin = new auth_admin();
 +
 +
// Add foo permissions as local permissions
 +
// (you could instead make them global permissions by making the obvious changes below)
 +
$auth_admin->acl_add_option(array(
 +
'local' => array('f_survey_design', 'f_survey_takeforothers', 'f_survey_viewhiddenresults'),
 +
'global' => array()
 +
));
 +
 +
 +
$message = $user->lang['ADDED_PERMISSIONS'] . '<br /><br />';
 +
$message .= $user->lang['REMOVE_INSTALL'];
 +
trigger_error($message);
 +
 +
?>
 +
</php>
 +
Then, add the following entry in language/en/mods/foo.php (or if you have no language file for the mod, add the following entry to language/en/common.php):
 +
<php>
 +
'ADDED_PERMISSIONS' => 'You have successfully added foo permission options to your database.',
 
</php>
 
</php>
  
Line 46: Line 106:
 
<highlightSyntax language="sqlnew">INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES ('u_view_foo', 1, 0, 0);
 
<highlightSyntax language="sqlnew">INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES ('u_view_foo', 1, 0, 0);
 
INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES ('u_manage_foo', 1, 0, 0);</highlightSyntax>
 
INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES ('u_manage_foo', 1, 0, 0);</highlightSyntax>
Please note that you need to clear the cache by either deleting <code>cache/data_global.php</code> or executing <code>$cache->destroy('acl_options');</code> after this.
+
Please note that you need to clear the cache by either:
 +
* deleting <code>cache/data_global.php</code> '''and''' <code>cache/data_acl_options.php</code>
 +
OR
 +
 
 +
* executing <code>$cache->destroy('acl_options');</code>
 +
 
 +
... after inserting the SQL manually.
  
 
=== Language file (Adding tabs) ===
 
=== Language file (Adding tabs) ===
Line 55: Line 121:
 
* DO NOT CHANGE
 
* DO NOT CHANGE
 
*/
 
*/
 +
if (!defined('IN_PHPBB'))
 +
{
 +
exit;
 +
}
 +
 
if (empty($lang) || !is_array($lang))
 
if (empty($lang) || !is_array($lang))
 
{
 
{
Line 88: Line 159:
 
if (!$auth->acl_get('u_view_foo'))
 
if (!$auth->acl_get('u_view_foo'))
 
{
 
{
     trigger_error('NOT_AUTHORIZED');
+
     trigger_error('NOT_AUTHORISED');
 
}
 
}
 
</php>
 
</php>
Line 103: Line 174:
 
If you use the correct naming and give the permission a category in the language file as described above the permission will show in the selected panel.
 
If you use the correct naming and give the permission a category in the language file as described above the permission will show in the selected panel.
  
=== Permission types ===
+
===Alternative method - using UMIL===
*[[Admin permissions]]
+
The [https://www.phpbb.com/mods/umil Unified MOD Install Library] (UMIL) provides a number of functions for managing permissions:
*[[Moderator permissions]]
+
* [[Umil.permission_exists|permission_exists()]] : Check if a permission (auth) setting exists.
*[[User permissions]]
+
* [[Umil.permission_add|permission_add()]] : Add a permission (auth) option
*[[Forum permissions]]
+
* [[Umil.permission_remove|permission_remove()]] : Remove a permission (auth) option
 +
* [[Umil.permission_set|permission_set()]] : Allows you to set permissions for a certain group/role
 +
* [[Umil.permission_unset|permission_unset()]] : Allows you to remove permissions from a certain group/role (basically setting their permission to ‘No’)
  
 +
 +
For more information on creating a UMIF (Unified MOD Install File) using the UMIL and the permissions functions see the [https://www.phpbb.com/customise/db/official_tool/umil/faq/f_397 UMIL Documentation], [https://www.phpbb.com/customise/db/official_tool/umil/faq/f_396 UMIL Examples], and [[Umil.Umil_overview|UMIL Overview]].
 
[[Category:Concepts]][[Category:Tutorials]][[Category:API]][[Category:Permissions]]
 
[[Category:Concepts]][[Category:Tutorials]][[Category:API]][[Category:Permissions]]
 +
 +
[[ja:Tutorial.Permissions]]

Latest revision as of 09:07, 19 December 2013

Permission types

Checking permissions

Global permission

To check if user can for example view other users' profiles, use this code:

if (!$auth->acl_get('u_viewprofile'))
{
     
trigger_error('NOT_AUTHORISED');
}

If he doesn't have permission to do it, he will see only error message and script will stop executing (exit) after trigger_error.

Local permission

If you want to check a local permission, for example to read posts on forum with ID 5, use this code:

if (!$auth->acl_get('f_read'5))
{
     
trigger_error('NOT_AUTHORISED');
}

Full list of existing permissions is in your database, in phpbb_acl_options table.

Adding a permission

Adding new permissions to Olympus is simple. NOTE: The permission can not contain a capital letter, this causes trouble later on if you try and create a module that needs this permission

Example how to add a permission to control who can access and manage foo:

Using the API (recommended)

  • Run this code in the installer:
<?php
// Setup $auth_admin class so we can add permission options
include($phpbb_root_path 'includes/acp/auth.' $phpEx);
$auth_admin = new auth_admin();

// Add permissions
$auth_admin->acl_add_option(array(
    
'local'      => array(),
    
'global'   => array('u_view_foo''u_manage_foo')
));
?>

Sample install page using API to add permission options

If you aren't otherwise using an installer for your mod, you can add a page under the install folder called something like install/install_permissions.php that would include something like the following code:

<?php

/** 
*
* install script to set up permission options in the db for foo mod
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* @ignore
*/

// initialize the page
define('IN_PHPBB'true);
define('IN_INSTALL'true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH './../';
$phpEx substr(strrchr(__FILE__'.'), 1);
include(
$phpbb_root_path 'common.' $phpEx);


// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/foo');


// Setup $auth_admin class so we can add tabulated survey permission options
include($phpbb_root_path 'includes/acp/auth.' $phpEx);
$auth_admin = new auth_admin();

// Add foo permissions as local permissions
// (you could instead make them global permissions by making the obvious changes below)
$auth_admin->acl_add_option(array(
    
'local'        => array('f_survey_design''f_survey_takeforothers''f_survey_viewhiddenresults'),
    
'global'    => array()
));


$message $user->lang['ADDED_PERMISSIONS'] . '<br /><br />';
$message .= $user->lang['REMOVE_INSTALL'];
trigger_error($message);

?>

Then, add the following entry in language/en/mods/foo.php (or if you have no language file for the mod, add the following entry to language/en/common.php):

'ADDED_PERMISSIONS'    => 'You have successfully added foo permission options to your database.',

Using SQL

You can also directly insert new rows into the phpbb_acl_options table:

INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES ('u_view_foo', 1, 0, 0);
INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES ('u_manage_foo', 1, 0, 0);

Please note that you need to clear the cache by either:

  • deleting cache/data_global.php and cache/data_acl_options.php

OR

  • executing $cache->destroy('acl_options');

... after inserting the SQL manually.

Language file (Adding tabs)

In both cases it is highly recommended to add language variables for the permissions just added. To do this, simply create a file named permissions_foo.php in language/xx/mods. It will automatically be included, don't worry about how.

<?php
/**
* 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

// Adding new category
$lang['permission_cat']['foo'] = 'Foo management';

// Adding the permissions
$lang array_merge($lang, array(
    
'acl_u_view_foo'    => array('lang' => 'Can view foo''cat' => 'foo'),
    
'acl_u_manage_foo'    => array('lang' => 'Can manage foo''cat' => 'foo'),
));
?>

In this code they added the category "foo" (will be displayed as a new tab). All language keys where the key cat is equal to "foo" will be displayed in this tab. So you have created an new tab if you use that code.

The permission should be ready to assign to users/groups in the acp now. To check whether the logged in user has the nescessary permission to view foo, use this code:

if (!$auth->acl_get('u_view_foo'))
{
     
trigger_error('NOT_AUTHORISED');
}

Panels (in the ACP)

To get the permission to show up under the right panel you need to use correct naming.

a_foo_bar Administrator permissions panel
m_foo_bar 
Moderator permissions panel
u_foo_bar 
User permissions panel
f_foo_bar 
Forum permissions panel

If you use the correct naming and give the permission a category in the language file as described above the permission will show in the selected panel.

Alternative method - using UMIL

The Unified MOD Install Library (UMIL) provides a number of functions for managing permissions:


For more information on creating a UMIF (Unified MOD Install File) using the UMIL and the permissions functions see the UMIL Documentation, UMIL Examples, and UMIL Overview.