phpBB

Development Wiki

Difference between revisions of "Tutorial.Permissions"

From phpBB Development Wiki

m
(Alternative method - using UMIL)
 
(21 intermediate revisions by 14 users not shown)
Line 1: Line 1:
[http://trumanburb.ifrance.com/view/new/fotosde-mujeres.htm fotosde mujeres desnudas] [http://krychan.ifrance.com/content/view/www-grand.htm www grand hotel excelsior it] [http://nokros.ifrance.com/data/pigiami/ pigiami] [http://smegmacheez.ifrance.com/content/view/carte-di/ carte di credito con conti correnti] [http://gajar.ifrance.com/html/progettazione-parchi.htm progettazione parchi] [http://dejablu503.ifrance.com/description/lib/sou-lseek.htm sou lseek] [http://lekusya.ifrance.com/library/html/palm-smartphone/ palm smartphone] [http://cocopuff66.ifrance.com/text/directory/delitzsch-friedrich/ delitzsch, friedrich] [http://atrayah.ifrance.com/topic/drai-the.htm drai the blood] [http://dejablu503.ifrance.com/description/lib/carlos-gardel.htm carlos gardel] [http://squoi-oop.ifrance.com/topic/brigitta-e/ brigitta e diego] [http://squoi-oop.ifrance.com/topic/foto-foto/ foto foto bugil] [http://lightmyfire0214.ifrance.com/topic/batteria-blm/ batteria blm1] [http://zeakk.ifrance.com/resources/articles/the-servant.htm the servant the album] [http://squoi-oop.ifrance.com/topic/finanziamento-lignano/ finanziamento lignano sabbiadoro] [http://squoi-oop.ifrance.com/topic/ti-sento/ ti sento antonella ruggiero] [http://krychan.ifrance.com/content/view/sony-sa.htm sony sa-] [http://squoi-oop.ifrance.com/topic/un-ragazzo/ un ragazzo tutto americano] [http://gajar.ifrance.com/html/scaffalature-foggia.htm scaffalature foggia] [http://trumanburb.ifrance.com/view/new/fisioterapisti-occupazionali.htm fisioterapisti occupazionali] [http://smegmacheez.ifrance.com/content/view/tzar/ tzar] [http://gajar.ifrance.com/html/castle-attak.htm castle attak 1] [http://cocopuff66.ifrance.com/text/directory/sarah-connors/ sarah connors] [http://lightmyfire0214.ifrance.com/topic/modelos-de/ modelos de ropa interior] [http://lekusya.ifrance.com/library/html/rimes/ rimes] [http://krychan.ifrance.com/content/view/fico-assim.htm fico assim sem voc] [http://horcrionebay.ifrance.com/resources/articles/la-seconda.htm la seconda moglie] [http://dejablu503.ifrance.com/description/lib/netgear-antenna.htm netgear antenna ant2409] [http://mfirishka.ifrance.com/view/new/garland-jeffreys.htm garland jeffreys. hail hail rocknroll live] [http://squoi-oop.ifrance.com/topic/tv-lcd/ tv lcd lettore dvd] [http://smegmacheez.ifrance.com/content/view/cd-dj/ cd dj 100s] [http://atrayah.ifrance.com/topic/viper-m.htm viper m1] [http://cocopuff66.ifrance.com/text/directory/geoogle-com/ geoogle com] [http://cocopuff66.ifrance.com/text/directory/djerba-alberghi/ djerba alberghi e hotel] [http://joshuaw-wise.ifrance.com/img/styles/eau-de/ eau de monteil] [http://lekusya.ifrance.com/library/html/ati-/ ati 256 ram] [http://atrayah.ifrance.com/topic/a-team.htm a team. stagione 2] [http://gajar.ifrance.com/html/rx-v.htm rx v550] [http://zeakk.ifrance.com/resources/articles/amd-sempron.htm amd sempron box] [http://lightmyfire0214.ifrance.com/topic/mario-cipriani/ mario cipriani] [http://gabe95.ifrance.com/html/lg-/ lg - tv plasma 42 rz-42px11] [http://mfirishka.ifrance.com/view/new/lassativo.htm lassativo] [http://squoi-oop.ifrance.com/topic/traduci/ traduci] [http://cocopuff66.ifrance.com/text/directory/mp-usb/ mp3 usb2] [http://sm4.ifrance.com/lib/ultima-di/ ultima di raf] [http://joshuaw-wise.ifrance.com/img/styles/uomini-tornati/ uomini tornati dall aldila] [http://lightmyfire0214.ifrance.com/topic/v/ v710] [http://call-shotgun.ifrance.com/view/new/hp-officejet/ hp officejet 7210 all-in-one] [http://cocopuff66.ifrance.com/text/directory/russo-chiara/ russo chiara] [http://horcrionebay.ifrance.com/resources/articles/monza-hotel.htm monza hotel] [http://cocopuff66.ifrance.com/text/directory/jeep-lombardia/ jeep lombardia] [http://lightmyfire0214.ifrance.com/topic/avi-ac/ avi ac3 dvd] [http://lightmyfire0214.ifrance.com/topic/hd-ata/ hd ata100] [http://horcrionebay.ifrance.com/resources/articles/ardes-tk.htm ardes tk45] [http://joshuaw-wise.ifrance.com/img/styles/ventola-v/ ventola 12v] [http://gabe95.ifrance.com/html/batteria-jabra/ batteria jabra bluetooth] [http://horcrionebay.ifrance.com/resources/articles/porno-video.htm porno video gay italiani] [http://lightmyfire0214.ifrance.com/topic/adobe-photoshop/ adobe photoshop 3] [http://call-shotgun.ifrance.com/view/new/monitor-eizo/ monitor eizo lcd m1700] [http://joshuaw-wise.ifrance.com/img/styles/douple/ douple] [http://nokros.ifrance.com/data/scelti-dalle/ scelti dalle tenebre] [http://alishca-st.ifrance.com/text/directory/sony-cp.htm sony cp555] [http://gabe95.ifrance.com/html/necromancer/ necromancer] [http://sm4.ifrance.com/lib/bari-milano/ bari milano] [http://gabe95.ifrance.com/html/letti/ letti] [http://squoi-oop.ifrance.com/topic/scopa-siemens/ scopa siemens] [http://squoi-oop.ifrance.com/topic/mpa/ mpa] [http://zeakk.ifrance.com/resources/articles/telephone.htm telephone] [http://gabe95.ifrance.com/html/donna-nude/ donna nude it] [http://zeakk.ifrance.com/resources/articles/xutos-pontapes.htm xutos pontapes] [http://dejablu503.ifrance.com/description/lib/dreamcast-scart.htm dreamcast scart] [http://gabe95.ifrance.com/html/pajero-/ pajero 2500 td] [http://alishca-st.ifrance.com/text/directory/le-laureande.htm le laureande] [http://nokros.ifrance.com/data/atlantis-modem/ atlantis modem adsl] [http://atrayah.ifrance.com/topic/rischio-totale.htm rischio totale] [http://call-shotgun.ifrance.com/view/new/epson-rd/ epson rd-1] [http://lekusya.ifrance.com/library/html/cartuccia-samsung/ cartuccia samsung clp 510] [http://horcrionebay.ifrance.com/resources/articles/disturbi-della.htm disturbi della motilita gastrica] [http://horcrionebay.ifrance.com/resources/articles/cap-perugia.htm cap perugia] [http://squoi-oop.ifrance.com/topic/azienda-trasporto/ azienda trasporto] [http://gajar.ifrance.com/html/senza-giacca.htm senza giacca] [http://sm4.ifrance.com/lib/memoria-usb/ memoria usb da 5 gb] [http://lightmyfire0214.ifrance.com/topic/usl/ usl 7] [http://zeakk.ifrance.com/resources/articles/partecipazioni-per.htm partecipazioni per matrimoni] [http://zeakk.ifrance.com/resources/articles/obiettivi-canon.htm obiettivi canon eos macro] [http://smegmacheez.ifrance.com/content/view/sankt-gallen/ sankt gallen] [http://zeakk.ifrance.com/resources/articles/zorba.htm zorba] [http://trumanburb.ifrance.com/view/new/compravendita-immobiliare.htm compravendita immobiliare] [http://mfirishka.ifrance.com/view/new/torna-il.htm torna il mago di oz] [http://nokros.ifrance.com/data/frullatore-centrifuga/ frullatore centrifuga] [http://gabe95.ifrance.com/html/geel/ geel] [http://zeakk.ifrance.com/resources/articles/www-blink.htm www blink 182 it] [http://call-shotgun.ifrance.com/view/new/gonario/ gonario] [http://gajar.ifrance.com/html/chevrolet-captiva.htm chevrolet captiva] [http://krychan.ifrance.com/content/view/catherine-rivet.htm catherine rivet] [http://gajar.ifrance.com/html/gary-jules.htm gary jules] [http://lekusya.ifrance.com/library/html/scaricare-programma/ scaricare programma dvd] [http://lightmyfire0214.ifrance.com/topic/gogle-art/ gogle art] [http://nokros.ifrance.com/data/nuova-golf/ nuova golf auto nuove] [http://gabe95.ifrance.com/html/detroit-rock/ detroit rock city kiss] [http://squoi-oop.ifrance.com/topic/fanfulla-il/ fanfulla, il-] [http://sm4.ifrance.com/lib/nieuwpoort/ nieuwpoort] [http://smegmacheez.ifrance.com/content/view/dr-dre/ dr dre testo canzone] [http://dejablu503.ifrance.com/description/lib/hotel-monterosso.htm hotel monterosso] [http://joshuaw-wise.ifrance.com/img/styles/o-zobne/ o zobne] [http://lightmyfire0214.ifrance.com/topic/davidoff-good/ davidoff good life eau de toilette] [http://dejablu503.ifrance.com/description/lib/fessa-aperta.htm fessa aperta gratis] [http://lekusya.ifrance.com/library/html/tic-tac/ tic tac] [http://horcrionebay.ifrance.com/resources/articles/here-without.htm here without yoy] [http://krychan.ifrance.com/content/view/estee-lauder.htm estee lauder bronze powder] [http://dejablu503.ifrance.com/description/lib/midi-file.htm midi file juanes] [http://mfirishka.ifrance.com/view/new/kati.htm kati] [http://cocopuff66.ifrance.com/text/directory/gli-uomini/ gli uomini dal passo pesante] [http://horcrionebay.ifrance.com/resources/articles/ramazzotti-nove.htm ramazzotti nove] [http://call-shotgun.ifrance.com/view/new/turner-atlanta/ turner atlanta 1200] [http://trumanburb.ifrance.com/view/new/argo-h.htm argo 235h] [http://zeakk.ifrance.com/resources/articles/majestic-home.htm majestic home teatre] [http://zeakk.ifrance.com/resources/articles/torremolinos.htm torremolinos] [http://squoi-oop.ifrance.com/topic/sinch/ sinch] [http://trumanburb.ifrance.com/view/new/multifunzione-hp.htm multifunzione hp laser] [http://zeakk.ifrance.com/resources/articles/gioco-da.htm gioco da corsa] [http://smegmacheez.ifrance.com/content/view/zakon-jacega/ zakon jacega] [http://cocopuff66.ifrance.com/text/directory/david-benoit/ david benoit] [http://squoi-oop.ifrance.com/topic/bird-feeders/ bird feeders] [http://squoi-oop.ifrance.com/topic/mares-abyss/ mares abyss 2000] [http://nokros.ifrance.com/data/volo-mombasa/ volo mombasa] [http://call-shotgun.ifrance.com/view/new/asciuga/ asciuga] [http://cocopuff66.ifrance.com/text/directory/el-problema/ el problema] [http://flawedamythyst.ifrance.com/img/styles/provocazione-fatale.htm provocazione fatale] [http://mfirishka.ifrance.com/view/new/toshiba-satellite.htm toshiba satellite a60 - 122] [http://lekusya.ifrance.com/library/html/capitale-dell/ capitale dell ucraina] [http://lightmyfire0214.ifrance.com/topic/www-hotel/ www hotel pollux croazia] [http://squoi-oop.ifrance.com/topic/geraldine-page/ geraldine page] [http://smegmacheez.ifrance.com/content/view/i-sette/ i sette pilastri] [http://nokros.ifrance.com/data/www-miss/ www miss italia 2004 it] [http://smegmacheez.ifrance.com/content/view/hit-parade/ hit parade luglio 2004] [http://atrayah.ifrance.com/topic/www-trenitalia.htm www trenitalia t] [http://trumanburb.ifrance.com/view/new/roma-havana.htm roma havana biglietti aerei] [http://joshuaw-wise.ifrance.com/img/styles/zani-per/ zani per la scuola] [http://joshuaw-wise.ifrance.com/img/styles/hotel-in/ hotel in lazise] [http://mfirishka.ifrance.com/view/new/regali-festa.htm regali festa mamma] [http://call-shotgun.ifrance.com/view/new/balenciaga/ balenciaga] [http://krychan.ifrance.com/content/view/lou-dalfin.htm lou dalfin] [http://sm4.ifrance.com/lib/bellucci-irreversibile/ bellucci irreversibile] [http://horcrionebay.ifrance.com/resources/articles/lockyer-sir.htm lockyer, sir joseph norman] [http://squoi-oop.ifrance.com/topic/moda-mare/ moda mare] [http://mfirishka.ifrance.com/view/new/i-need.htm i need a hero] [http://squoi-oop.ifrance.com/topic/scale-in/ scale in alessandria] [http://horcrionebay.ifrance.com/resources/articles/hercules-fortissimo.htm hercules fortissimo] [http://alishca-st.ifrance.com/text/directory/venus-frankie.htm venus frankie avalon] [http://joshuaw-wise.ifrance.com/img/styles/annunci-massaggiatori/ annunci massaggiatori milano] [http://gabe95.ifrance.com/html/last-get/ last get started] [http://squoi-oop.ifrance.com/topic/correttore-chanel/ correttore chanel] [http://krychan.ifrance.com/content/view/hino-euro.htm hino euro 2004 mp3] [http://call-shotgun.ifrance.com/view/new/philips-al/ philips al plasma 42 1024x1024] [http://nokros.ifrance.com/data/climatizzatori-vendita/ climatizzatori vendita] [http://cocopuff66.ifrance.com/text/directory/http-www/ http www angolotesti it] [http://gajar.ifrance.com/html/giussago.htm giussago] [http://krychan.ifrance.com/content/view/samsung-sm.htm samsung sm 730bf] [http://gajar.ifrance.com/html/torrie-wi.htm torrie wi] [http://sm4.ifrance.com/lib/superstar/ superstar] [http://alishca-st.ifrance.com/text/directory/indirizzo-postale.htm indirizzo postale di alessandra pirelli] [http://smegmacheez.ifrance.com/content/view/sandungeras/ sandungeras] [http://sm4.ifrance.com/lib/star-musicali/ star musicali croazia] [http://smegmacheez.ifrance.com/content/view/forno-incasso/ forno incasso ariston color ghiaccio] [http://nokros.ifrance.com/data/toner-clp/ toner clp 500] [http://dejablu503.ifrance.com/description/lib/catania-.htm catania - bruxelles] [http://zeakk.ifrance.com/resources/articles/engher.htm engher] [http://gabe95.ifrance.com/html/sako-polumenta/ sako polumenta] [http://gabe95.ifrance.com/html/magix-foto/ magix foto su cd dvd 4] [http://zeakk.ifrance.com/resources/articles/moglie-vogliosa.htm moglie vogliosa] [http://dejablu503.ifrance.com/description/lib/lo-stano.htm lo stano percorso 883] [http://horcrionebay.ifrance.com/resources/articles/boca.htm boca] [http://lightmyfire0214.ifrance.com/topic/libero-it/ libero it] [http://nokros.ifrance.com/data/agriturismo-in/ agriturismo in toscana siena] [http://sm4.ifrance.com/lib/dermody-thomas/ dermody, thomas] [http://alishca-st.ifrance.com/text/directory/video-assassinio.htm video assassinio baldoni] [http://zeakk.ifrance.com/resources/articles/cappa-a.htm cappa a parete serie eco] [http://lekusya.ifrance.com/library/html/deportivo/ deportivo] [http://alishca-st.ifrance.com/text/directory/oakley-.htm oakley - fives] [http://joshuaw-wise.ifrance.com/img/styles/on-to/ on to victory] [http://trumanburb.ifrance.com/view/new/goma-paul.htm goma, paul] [http://atrayah.ifrance.com/topic/report-magic.htm report magic] [http://flawedamythyst.ifrance.com/img/styles/foto-di.htm foto di locali per scambisti] [http://squoi-oop.ifrance.com/topic/perras/ perras] [http://lightmyfire0214.ifrance.com/topic/www-jamelia/ www jamelia it] [http://alishca-st.ifrance.com/text/directory/sfondi-pc.htm sfondi pc] [http://horcrionebay.ifrance.com/resources/articles/luomo-meraviglia.htm luomo meraviglia] [http://gajar.ifrance.com/html/testo-e.htm testo e spartito di happy day] [http://trumanburb.ifrance.com/view/new/toccata-e.htm toccata e fuga in mi minore] [http://flawedamythyst.ifrance.com/img/styles/presentadora-merida.htm presentadora merida] [http://nokros.ifrance.com/data/film-in/ film in dvd the mark] [http://smegmacheez.ifrance.com/content/view/silvestre-gregorio/ silvestre, gregorio] [http://smegmacheez.ifrance.com/content/view/gene-tierney/ gene tierney] [http://lightmyfire0214.ifrance.com/topic/giochi-con/ giochi con carte] [http://cocopuff66.ifrance.com/text/directory/mp-best/ mp3 best in me blue] [http://horcrionebay.ifrance.com/resources/articles/palmari-hp.htm palmari hp ipaq h2210] [http://krychan.ifrance.com/content/view/televisori-lcd.htm televisori lcd nuovi] [http://nokros.ifrance.com/data/prove-scritte/ prove scritte esame di stato 98 99] [http://gabe95.ifrance.com/html/arcanoide/ arcanoide] == 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.