Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
[Writing Extensions] Setting up Permissions
I'm branching off from the Who's Online discussion, only because I want to expand the idea over a few different extensions that I plan on building/mod'ing.
However, at the current moment, I am mod'ing the Who's Online extension so that it only shows for those who have their permissions set up to do so. Mainly, the administrators. Currently, this is what Who's Online looks like, with my modifications:
Basically, the goal is to add a permission to an existing extension. I'd like to do the same thing with the Discussion Filters Extension as well as the Side Panel Extension, which I am hoping to combine with a ajax-shoutcast-like chat with.
BUT -- Getting this permissions thing underwraps is the only thing stopping me from doing what I need. The above code does not effect the extension. I can see it no matter if I have I have the permission set or not.
What am I doing wrong?
However, at the current moment, I am mod'ing the Who's Online extension so that it only shows for those who have their permissions set up to do so. Mainly, the administrators. Currently, this is what Who's Online looks like, with my modifications:
$Context->Dictionary["MenuOptions"] = "Menu Options";
$Context->Dictionary["HideWhosOnline"] = "Hide the \"Who's Online\" panel";
$Context->Dictionary["Phantom"] = "Hide my username from the \"Who's Online\" panel";
$Context->Dictionary['PERMISSION_SEE_WHOS_ONLINE'] = "See \"Who's Online\" panel";
// Default permissions
$Context->Configuration['PERMISSION_SEE_WHOS_ONLINE'] = '0';
if ( $Context->Session->UserID > 0 && $Context->Session->User->Permission('PERMISSION_SEE_WHOS_ONLINE') ) {
// extension code that adds list to the panel goes here
}
class WhosOnline {
var $Name;
var $Context;
Basically, the goal is to add a permission to an existing extension. I'd like to do the same thing with the Discussion Filters Extension as well as the Side Panel Extension, which I am hoping to combine with a ajax-shoutcast-like chat with.
BUT -- Getting this permissions thing underwraps is the only thing stopping me from doing what I need. The above code does not effect the extension. I can see it no matter if I have I have the permission set or not.
What am I doing wrong?
0
This discussion has been closed.
Comments
::Ponders another meta-extension that could easily add permissions to any extension::
Here is what you need to do:
Cut this line out of the top of the extension and into your clipboard:
and delete the two lines below it. (the comment and the closing curly brace)
Scroll down until you see this line
(it should be around line 145)
Paste from the clipboard before that line.
Remove the close curly brace from line 11
and finally, scroll all the way to the bottom, and type a close curly brace on the line before the
That worked perfectly. Thank you so much WallPhone. Now I can start building the other extensions that I need. Eventually... when I can find time. Now that I know how to do it, I'm swamped with other crap : )
Is there a way to "clear" these when you're plugin is deactivated? Perhaps the permissions page should hide options from view if it can't find a translation string (thus leaving the value at default with a hidden input or something.)
At least its in the role table, with 3-6 rows instead of the user table...
For example:
if( empty(Permissions[$perm]) ) { // don't display, but keep the variable set as a hidden element } else { //normal display }
That way, if an extension is disabled or changes, the old settings still stick around (in case it is only a temporary enabling) but you don't have the uglies shoved in your face. Can you see any problem with that?
// Function to remove a permission key from a role in the database. function RemovePermissionKeyFromRole($Role, $Permission = ""){ if (array_key_exists($Permission,$Role->Permissions)){ unset($Role->Permissions[$Permission]); } } // Function to save just the permissions of a role to the database. function SaveRolePermissions($Context,$Role){ $Role->FormatPropertiesForDatabaseInput(); // Build a custom query to replace the role permissions. $Query = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder'); $Query->SetMainTable('Role','r'); $Query->AddFieldNameValue('Permissions',$Role->Permissions); $Query->AddWhere('r','RoleID','',$Role->RoleID,'='); // Update the database and report errors if necessary. $RowCount = $Context->Database->Update($Query,'XX','RemovePermissionKey', $Context->GetDefinition('XX_ErrorRemovingPermissions')); if ($RowCount != 1){ $Context->WarningCollector->Add( $Context->GetDefinition('XX_ErrorRemovingPermissions')); } } // This function removes a particular permission key and value from // all roles that contain it, and saves the modified roles back to the // database. function RemovePermissionFromAllRoles($Context, $Permission) { $RoleManager = $Context->ObjectFactory->NewContextObject($Context, 'RoleManager'); $RoleData = $RoleManager->GetRoles(); while ($Row = $Context->Database->GetRow($RoleData)){ $Role = $Context->ObjectFactory->NewContextObject($Context, 'Role'); $Role->Clear(); $Role->GetPropertiesFromDataSet($Row); // Modify the role only if it contains the permission key. if (array_key_exists($Permission,$Role->Permissions)){ RemovePermissionKeyFromRole($Role, $Permission); SaveRolePermissions($Context,$Role); } } }