How to set Permission for own Applications
Hi ...
today i try a deeper look into the Permissionmodel of Garden and i´m not sure if it´s possible to set Permissions for my own Application, because there are "hardcoded" columnnames of the permission table. Is it possible to add a permission
e.g.:
MyApplication.myController.Add
MyApplication.myController.Edit
MyApplication.myController.Delete
...
My thar is a good way to to this ... than let my now;)
LG
René
today i try a deeper look into the Permissionmodel of Garden and i´m not sure if it´s possible to set Permissions for my own Application, because there are "hardcoded" columnnames of the permission table. Is it possible to add a permission
e.g.:
MyApplication.myController.Add
MyApplication.myController.Edit
MyApplication.myController.Delete
...
My thar is a good way to to this ... than let my now;)
LG
René
0

Comments
$PermissionModel = Gdn::PermissionModel();
$PermissionModel->Database = $Database;
$PermissionModel->SQL = $SQL;
$PermissionModel->Define(array(
'CichlidWiki.Settings.Manage',
'CichlidWiki.Genus.Add',
'CichlidWiki.Genus.Edit',
'CichlidWiki.Genus.Delete'
));
And it run!!
realy realy cool permissionmodel! You have to wirte a Documentation
<?php if (!defined('APPLICATION')) exit();
Oh and you might also note that $SQL is missing from the default structure.php in skeleton, as is $construct.if (!isset($Drop))
$Drop = FALSE;
if (!isset($Explicit))
$Explicit = TRUE;
$SQL = $Database->SQL();
$PermissionModel = Gdn::PermissionModel();
$PermissionModel->Database = $Database;
$PermissionModel->SQL = $SQL;
// Define some global vanilla permissions.
$PermissionModel->Define('DigitalMedia.Lab.Time');
// Make sure that User.Permissions is blank so new permissions for users get applied.
// $SQL->Update('User', array('Permissions' => ''))->Put();
I'm also confused--do I have to add the permission to RegisterPermissions in about.php for my app? I haven't tried that yet, but if so, why doesn't Vanilla?
Anyway, the above code gives the following error:
Fatal Error in Gdn_DatabaseDebug.Query();
Unknown column 'DigitalMedia.Lab.Time' in 'field list'
update GDN_Permission Permission set
`DigitalMedia.Lab.Time` = :DigitalMediaLabTime
where RoleID = :RoleID and JunctionTable is null and JunctionColumn is null
where the key backtrace lines are:
[/home/simplerca/dm.lsta.me/applications/garden/models/class.permissionmodel.php:43] Gdn_SQLDriver->Replace();
[/home/simplerca/dm.lsta.me/applications/digitalmedia/settings/structure.php:27] Gdn_PermissionModel->Define();
Line 43 of PermissionModel says: $this->SQL->Replace('Permission', $this->_Backtick($DefaultPermissions), array('RoleID' => 0, 'JunctionTable' => $JunctionTable, 'JunctionColumn' => $JunctionColumn));
This doesn't change how PermissionModel was failing me (above), but at least I have an easy option that works. For each permission in the array, the Roles edit screen will create an HTML table based on the dot-separated hierarchy:
'RegisterPermissions' => array('AppName.Row.Column1','AppName.Row.Column2')My only question now, is can we use spaces? Or are underscores converted to spaces? I guess I'll have to try it and find out...I would suggest that underscores be converted to spaces when presenting the application name or permission name, etc. Alternatively, if these app/column names are passed through translation, I could imagine the conversion being performed there instead.