Ok, let's try to explain this.
I do not want users to have their own album, so i deactivated that function. Nevertheless, i want them to be able to upload their own pictures to an already existing album. I've managed to do all this so far, but here comes the tricky part: I want users to be able to delete their own objects. No one else shall be able to do this. So is there a way to automatically set object permissions for a owned file? So that when someone uploads something he automatically gets permission to delete that item. Hope I've made myself clear. Thanks for your help
Best regards // Rasta
----
Gallery URL (optional):
Gallery version: G2 alpha 4
Webserver (with version):
Datatabase (with version):
PHP version (eg 4.2.1):
phpinfo URL (optional):
Graphics Toolkit(s):
Operating system:
Web browser/version:
Posts: 8601
this post i just wrote is somewhat similar.. you also want permissions of the images to be different than permissions of the album where the images are added. you can write a custom module to do this.
Posts: 14
Firstly, thank you for your quick reply. Now:
How can i do this?
I tried reading your post, didn't really understand what it has to do with my issue, only that it also deals with different permissions on sub-items...
Posts: 8601
if you'd like to write a custom module to do this we can help... are you proficient with PHP? if so i'll post some instructions for you to get started.
(and yes, that was the extent of the similarity...)
Posts: 14
Sounds cool, I would like to give it a try. I'm afraid I'm not very good at PHP though, but please post those instructions and I'll se if it isn't completely incomprehensible to me.
Posts: 8601
ok, start by taking a look at the following code:
modules/useralbum/classes/UserAlbumHelper.class, function createUserAlbum(). this function does some permissions stuff, so it's a good example.
here's what you'll do to build your module:
1) make a new directory under modules/ dir for your module
2) copy modules/sizelimit/module.inc into your dir (i pick this one as a starting point because it has the same module functions you'll need...)
3) edit your module.inc, set the classname, module id/name/etc
4) remove functions performFactoryRegistrations and isRecommendedDuringInstall.. you don't need those
5) change the classname in registerEventListeners to your class
6) now rewrite the handleEvent method to do what you want!
in handleEvent you'll want to detect that a GalleryDataItem has been added (not a new album, new user, or anything else..) so just modify the check you'll see that sizelimit uses to detect a new album. then you'll want to add user permissions to the item.. follow the examples from UserAlbumHelper.class (see docs for those methods in modules/core/classes/GalleryCoreApi.class). call getOwnerId() on the item from the $event for the id of the user. look in your g2_PermissionSetMap for the permissions you can add.. probably you want 'core.delete'
Posts: 14
I'm afraid i can't find such dir (modules/sizelimit). I guess I don't have it installed..where can I get it? Or can I try something else as a starting point. I have checked that it's not deactivated or something.
EDIT: I can't even find this dir: modules/useralbum/classes
Posts: 314
rastafari, I suspect you have alpha 4, which is quite outdated, and indeed doesn't include sizelimit (nor, if I am not mistaken, useralbum). Obviously, you can start with any other module, but (a) as mindless wrote it has the same functions that you will prbably need, and (b) even more important, there were significant changes in the framework that will impact your code.
So, you are better off using either nightly builds or CVS
Posts: 14
Interesting. I will try to upgrade to the latest version using CVS (which is new to me) and if I manage to do that, I will give mindless' instrucions another try. Thanks for noticing, virshu.
Posts: 14
OK guys, new problem. When i try to install the latest CVS build (fresh install) i get this error when i try to access install/index.php:
Fatal error: Using $this when not in object context in /var/www/htdocs/test/gallery2/modules/core/classes/GalleryUrlGenerator.class on line 93
Though, everything works fine when i use an older build such as gallery2-2005-01-05.tar.gz .
Any suggestions?
Posts: 32509
just did a cvs update and visited install/index.php, everything works fine.
Try again... replace your G2 files with current cvs files.
Posts: 14
well, I've tried it several times, and removed everything and tried it again. Still gives me the same error. maybe something could be wrong with my PHP configuration? But the older version of gallery works, so...hmm
Posts: 8601
oops, looks like I created that error.. what is your php version? though i clearly put in some bad code i wonder why my php doesn't get a fatal error... oh, and are you using multiple installs from one codebase? you should only hit the error in that setup.
update from cvs later today and this will be fixed, sorry!
Posts: 14
Oh, let's hope that this caused my error. I tried updating now but it didn't work, so I'll try later this evening, maybe I was a little bit too keen ;)
If you want to look at my php info, here it is:
EDIT: removed links
Posts: 17
just now,i download the latest nightly build gallery2.2005-02-08-09-34-52.tar.gz from CVS,fresh install,but i still have the problem too,same as you!
Posts: 314
supercn,
'later' usually means in 6-8 hours (depending on SF schedule) or, for sure with tomorrow's (2005-02-09) nightly build
Posts: 17
thank you very much!
Posts: 14
Got the new build to work through CVS, so far everything is fine. But I have some problems following your instructions mindless, on building my own module. I manage to copy the sizelimit module and modify classes and stuff but since I'm not very familiar to PHP I don't know what permission lines I need to add and which I don't, and where etc. I need further help on this. I end up with this error message, when i have installed and activated the module and try to upload a file:
Now, probably it just has to do with my bad knowledge of PHP. So mindless, is it way to much to ask you to construct the module for me? Otherwise I could post a link to my module and maybe from that you can tell what's wrong.
Thanks in advance, /Rasta
Posts: 8601
where's your code?
Posts: 14
Here:
EDIT: removed link
Posts: 8601
1) remove the $parentId ... foreach stuff
2) make sure you don't use variables you haven't defined... $fileId, $user
(probably $fileId = $file->getId(), $user = $gallery->getActiveUser())
3) i thought you would look at the UserAlbum code and the phpdoc in GalleryCoreApi.class to understand the permissions apis and use them as needed, but it looks like you just copy/pasted some code.. do you really want to remove all permissions from the item and add permissions like the code you put there? what permission operation(s) do you want to perform?
4) everywhere in handleEvent() where you have return $ret->wrap(__FILE__, __LINE__); you need return array($ret->wrap(__FILE__, __LINE__), null);
Posts: 14
ok..starting to get some hold of this now.. atm my module works and sets the permissions it's supposed to.. now could you please check my code again to see if there's something dramatically wrong? same link. Thanks again
EDIT: EDIT: Removed previous edit.. my bad
Posts: 8601
looks good, just remove the releaseLocks call you have in there.
Posts: 14
Like this? or do i have to completely remove the if clause (if$ret->isError())
Starting to feel really proud of almost having built my own module :D
Posts: 8601
like you've got it.. you still need the error check, but you don't have any locks to release if an error occurs.
i dub thy module complete.. nice work.
Posts: 14
cool! man, a big thanks for your guidance! I'll just post the module here in case anyone wants to use it or have a look at it:
Posts: 8601
rastafari, thanks to you for demonstrating the power of G2.. you've now customized your site to do something G2 doesn't normally do, but completely in a module which means you can continue to upgrade your G2 and keep your customization intact! After each upgrade (where core module is upgraded and you must go through the upgrader) you should check the Site Admin / modules page and make sure your module is still active. If we change the module api in some way your module will automatically get deactivated. We keep a sticky topic in the G2 dev forum that explains any api changes, so you can check there to see how to bring your module up to date and reinstall it.
Posts: 14
I'm only lucky you helped me out! Wouldn't have managed to do it else.
Interesting, thanks for noticing!
Now a (final?) question: If I want to add another automatic permission (same delete-own-thing but for comments) , do I need to create a completely new module or is it just to put in a new if (GalleryUtilities::isA(...)) in the main if-clause in the same module?
Posts: 8601
either would work, but since your module is just for your site i think you can just add to your existing module..
Posts: 14
I have created the modules.inc in /modules/jensperms
I have then pasted the copde and saved. When i press modules in my gallery site admin frame The apge has this error on top:
class JensPermsModule extends GalleryModule { function JensPermsModule() { global $gallery; $this->setId('jensperms'); /* this must match the directory name */ $this->setName('Jens Permissions'); /* this is the module name */ $this->setDescription($gallery->i18n('Automatically set permissions for uploaded file')); $this->setVersion('0.8.7'); $this->setGroup('gallery', $gallery->i18n('Gallery')); $this->setCallbacks('registerEventListeners'); $this->setRequiredCoreApi(array(3, 0)); $this->setRequiredModuleApi(array(0, 9)); } /** * @see GalleryModule::registerEventListeners() */ function registerEventListeners() { GalleryCoreApi::registerEventListener('GalleryEntity::save', new JensPermsModule(), true); /* true=disableForUnitTest */ } /** * @see GalleryModule::autoConfigure */ function autoConfigure() { /* We don't require any special configuration */ return array(GalleryStatus::success(), true); } /** * Event handler for GalleryEntity::save event * Copy dimension / filesize limits when the album is created * * @param object GalleryEvent the event * @return object GalleryStatus a status code */ function handleEvent($event) { if ($event->getEventName() == 'GalleryEntity::save') { $file = $event->getEntity(); if (GalleryUtilities::isA($file, 'GalleryDataItem') && $file->testPersistentFlag(STORAGE_FLAG_NEWLY_CREATED)) { $fileId = $file->getId(); /* Set permissions.. */ global $gallery; $user = $gallery->getActiveUser(); $ret = GalleryCoreApi::addUserPermission($fileId, $user->getId(), 'core.delete'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } } return array(GalleryStatus::success(), null); } } }
Then the design begins and the follow text is written:
Error: Error (ERROR_BAD_PLUGIN) : Class jenspermsModule does not exist
* in modules/core/classes/helpers/GalleryPluginHelper_simple.class at line 101 (gallerystatus::error)
* in modules/core/classes/GalleryCoreApi.class at line 187 (gallerypluginhelper_simple::loadplugin)
* in modules/core/AdminModules.inc at line 226 (gallerycoreapi::loadplugin)
* in modules/core/SiteAdmin.inc at line 159 (adminmodulesview::loadtemplate)
* in modules/core/classes/GalleryView.class at line 214 (siteadminview::loadtemplate)
* in main.php at line 302 (siteadminview::doloadtemplate)
* in main.php at line 86
* in main.php at line 77
Other info:
Gallery version 2.0-beta-3
PHP version 4.3.11 apache2handler
Webserver Apache/2.0.54 (Gentoo/Linux) PHP/4.3.11
Database mysql 4.0.24
Toolkits ImageMagick, NetPBM, Gd
Operating system Linux devil 2.6.11-gentoo-r8 #5 SMP Sat May 14 10:11:34 GMT 2005 i686
Browser Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
Please help me out as i would really like to use this module
Posts: 8601
did you add <?php at the top and ?> at the bottom?
you'll need to update the required core api for the module too.
Posts: 14
Yes, if orgot to add the php tags.
I have the API issue too:
Incompatible module!
Core API Required: 3.0 (available: 5.8)
Module API Required: 0.9 (available: 0.11)
I guess i need to edit the file with the api versions i have?
edit: changed the core api in.inc from 3, 0 to 5 ,8 and it works perfectly
Posts: 1
I had this module installed and activated, but when I logged in as a registered user and upload an item, the delete option is not there? did I missed out any setting here?
thanks.
Posts: 1
Great functionality !
Suppose I wanted to do the same for 'EDITING' functionality (A user can only edit their own pictures within a shared album) do I just copy the code and replace 'core.delete' with 'core.edit' ?
Regards,
iBuZze
Posts: 22
I also tried to install this module and have some strange effects.
In AccessMap the correct entry is created, but in AccessSubscriberMap
another entry (I think the album default permissions) are linked to the new image. But my log file says that AccessSubscriberMap has been set to the new accesslistid.
Extract from log:
2005-09-09 09:21:48 [d725ee1d71ef29abb7e3ed3d49b2b0aa] <hr>
(mysql): INSERT INTO g2_AccessMap (g_accessListId, g_userId, g_groupId, g_permission) VALUES (3324,1698,0,128) & <code></code>
<hr>
2005-09-09 09:21:48 [d725ee1d71ef29abb7e3ed3d49b2b0aa] <hr>
(mysql): UPDATE g2_AccessSubscriberMap SET g_accessListId=3324 WHERE g_itemId IN (3323) & <code></code>
<hr>
In the database I found only accesslistid 2273 set for item 3323. When I edit the database and set it to 3324 I can't see the item because it now has ONLY delete permissions.
I hope someone can help because this module is really great!
Aktarus
Posts: 560
any idea if it works with current 2.0.1?..
Posts: 32509
it should. haven't tested it though.
you'll at least have to change
$this->setRequiredCoreApi(array(3, 0));
$this->setRequiredModuleApi(array(0, 9));
to 6, 0 and 2, 0
Posts: 560
well..it's saidly not workin!
with some search and after checkin the database -as bharat recommended- i've found that the code does update/insert into table g2_AccessMap (for example values like this: 71213 31621 0 128 ), but inserts nothing into table g2_AccessSubscriberMap! so this 71213 g_accessListId does not have a pair in that table..
..and it's not workin :/
any idea how can it be broken at this stage? :o
Posts: 32509
update / insert into accessMap without an update / insert in AccessSubscriberMap is fine, as long as the ACL id from accessMap is also listed in accesssubscribermap
Posts: 560
;) must be my english, but what i tried to wrote is that the ACLid from accessMap is _not_ listed in accesssubscribermap
so it's definitely not fine i guess
Posts: 3
Any plans to turn this into a normal module that can be uploaded to an existing site. I like the functionality but do not have the ability to install this from the instructions included here.
Posts: 4
That would be really cool as I am an official 'Php Numpty' (ie I just don't get it) But this does look like a cool module that would solve a lot of problems.
Kandi
Posts: 8601
There's the code with the php tags added and version numbers updated.
Just create modules/jensperms from your gallery2 directory and save the above code as module.inc
Posts: 560
..and as far as i know this won't work with current g2(.0.x) .
(Dev.note: As we tested it and got this result..and it is why we need that 'save->_save' change..)
Posts: 9
Anyone know how to get this working with g2.0.2?
Posts: 8601
joe7: ah right, forgot about that problem.
This should work in 2.0.x:
Posts: 9
awesome thanks.
Posts: 32
Thank you for this module. This is exactly what I was looking for. I installed it with 2.0.2 and it works great!
Posts: 72
I get the following when I click on the modules link in the Admin section:
I have Gallery 2.02
and I used the last version of the code posted here.
Posts: 8194
Look at the file you added, especially line 1 and 2. I think you'll find there is something added, probably a rogue backslash.
--Andy
Consider giving back to Gallery
Posts: 8601
Code for current CVS / nightly snapshot: