Loading...
 
Skip to main content

Custom Share Module 0.1dev

History: CategoryPermissions

Preview of version: 2

HOWTO: Assign permissions to all objects of a specified category

After a time looking at so nice program like TikiWiki is I started looking how could I 'group' objects permissions.

I explain, my intention has been to be able to assign the same permissions to a couple of objects with minimun effort, the nearest thing to that target are Categories, that's the easiest way to group objects inside TikiWiki but there's no way to apply permissions to Categories so... Here comes the nice things.

The only way you can assign the same permissions to a couple of objects is from direct SQL queries.

Assume we have a Category defined in our TikiWiki called 'PrivateElements' with a couple of wiki pages on it.
Then we want to easilly assign 'wiki_p_view' permission only to our 'Registered' group on all those pages.

Well, it's possible, after a few looks onto tiki's sources and the database I wrote that query:

Copy to clipboard
INSERT IGNORE INTO `users_objectpermissions` (groupName, permName, objectType, objectId) SELECT 'Registered', 'tiki_p_view', 'wiki page', MD5(CONCAT(tiki_categorized_objects.type,tiki_categorized_objects.ObjId)) FROM tiki_categorized_objects, tiki_category_objects, tiki_categories WHERE tiki_categories.name = 'PrivateElements' AND tiki_category_objects.categId = tiki_categories.categId AND tiki_category_objects.catObjectId = tiki_categorized_objects.catObjectId AND tiki_categorized_objects.type = 'wiki page';

What does this do?

This simply searches for all 'wiki page' objects that are into category 'PrivateElements' and inserts a new registry into users_objectpermissions table for group 'Registered', permission 'tiki_p_view' for every object found.

You can easylly adapt that query to your own needs, only change the following:

'Registered' by the group you wish to apply permissions
'tiki_p_view' by the permission you want to give
'wiki_page' (both entries) by the object type you want to search and apply.
'PrivateElements' by the Category you want to search objects for.

Just hope that this helps somebody!

Marc Fargas.

History

Advanced
Information Version
Terence? 4
View
Marc Fargas First writting about that 2
View