Hello!
I have downloaded the module "jensperms" because I needed the owner permissions to be auto set after a photo upload. Now I want to make it possible the users create albums but with specific auto-set permissions.
I saw that the following part in the module is setting the permissions for a photo ($item):
Quote:
function handleEvent($event) {
if ($event->getEventName() == 'GalleryEntity::save') {
$item = $event->getEntity();
if (GalleryUtilities::isA($item, 'GalleryDataItem') &&
$item->testPersistentFlag(STORAGE_FLAG_NEWLY_CREATED)) {
/* Set permissions */
global $gallery;
$userId = $gallery->getActiveUserId();
$ret = GalleryCoreApi::addUserPermission(
$item->getId(), $userId, 'core.all');
if ($ret) {
return array($ret->wrap(__FILE__, __LINE__), null);
}
}
}
return array(null, null);
}
I think that if I add the following code:
Quote:
if (GalleryUtilities::isA($item, 'GalleryDataItem') &&
$item->testPersistentFlag(STORAGE_FLAG_NEWLY_CREATED)) {
/* Set permissions */
global $gallery;
$userId = $gallery->getActiveUserId();
$ret = GalleryCoreApi::addUserPermission(
$item->getId(), $userId, 'core.all');
if ($ret) {
return array($ret->wrap(__FILE__, __LINE__), null);
}
}
right before closing the following IF statement:
Quote:
if ($event->getEventName() == 'GalleryEntity::save') {
will do the work. I KNOW that I need to change the code that should be inserted but I don't know with what variables I should change "$item", "GalleryDataItem". I think if I change these two with the ones connected to Album it will set permissions for album.
The other part is that I want the user to have permissions to only EDIT the album and can't delete or set permissions for it nor deleting photos that are not owned by him/her.
I hope I described my problem clear enough
Here is the gallery info:
Gallery URL = http://www.bggallery.eu/main.php
Gallery version = 2.3 core 1.3.0
API = Core 7.54, Module 3.9, Theme 2.6, Embed 1.5
PHP version = 5.2.11 apache2handler
Webserver = Apache/2.2.13 (FreeBSD) mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2 PHP/5.2.11 with Suhosin-Patch
Database = mysqlt 5.0.86, lock.system=flock
Toolkits = ArchiveUpload, Dcraw, Exif, Ffmpeg, ImageMagick, jpegtran, LinkItemToolkit, Thumbnail, Gd, SquareThumb
Acceleration = none/900, none/0
Operating system = FreeBSD www.bggallery.eu 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:48:17 UTC 2009
:/usr/obj/usr/src/sys/GENERIC i386
Default theme = matrix
gettext = enabled
Locale = en_US
Browser = Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10
Rows in GalleryAccessMap table = 24
Rows in GalleryAccessSubscriberMap table = 349
Rows in GalleryUser table = 9
Rows in GalleryItem table = 345
Rows in GalleryAlbumItem table = 20
Rows in GalleryCacheMap table = 0
Posts: 1642
Not really
I think I sort of understand what you want to do but the actual query is lost somewhere along the line.
Can you repeat what it is you want to do without the code example and gallery Info since these are now in the original post.
Just something along the lines of: I want to assign xyz type permissions to abc type users when def type action takes place.
--
dakanji.com
Posts: 16
I will grant permissions to registered users to create albums. As the user will become owner of the album, he/she will have the possibility to edit the album, edit the permissions and delete the album. I want to use the mentioned module in the following way: when a user creates an album he,she will be the owner, but I want the only thing that user can do is to edit the album. I want to forbid the user to change permissions or delete the album. I need this, because other users can upload photos in this user's album and if the owner wants to delete the album, every photo in it will be deleted too. Is it clearer now, or I should try again?
Posts: 1642
I don't know what the jensperms module is (guessing it is an earlier form of the useralbums module) but change the handle event function to ...
I changed it to a switch to allow adding other events later if you want.
You can play with the various permission types as listed below:
Let us know if it works.
--
dakanji.com
Posts: 16
I have tried your code. I think that it will work if it is alone in a module, but I need to combine it with the quoted code below. Actually the quoted code below is the whole module which sets automaticaly full permissions to the owner of the uploaded photo. I can try to write some code, but I need to see how the gallery identifies the Album as an Album.
@Dayo - Thanks for the help! These permissions are one part of the things I needed
Posts: 1642
Try this instead ...
You need to be on G2.3.x to use this code.
PS. You might need to remove the "core.edit" permission if you don't want the user to delete items as looking at how it works, it seems that there may be a bug as it seems to bypass some other permission settings and allows the user to change permissions. Just a cursory look at it though so needs testing on your part.
--
dakanji.com
Posts: 16
I tried this code. I am still getting error. I don't understand much PHP script and everything seems OK for me. :|
Posts: 1642
"I am still getting error" is a bit vague. What error are you getting?
--
dakanji.com
Posts: 16
Error 500. It comes from the browser. It's strange for me...but I am not good at coding.
Posts: 1642
So try a few simple tests.
1. Do you get the error even if you remove the module?
2. Do you get the error with the original module before making changes?
Basically, you do a few logical eliminations to try to figure out where the problem is coming from as the error may not be related to this code.
Removing and adding stuff into a test environment to try to get an idea where an issue is coming from doesn't need coding knowledge.
--
dakanji.com
Posts: 16
Well...here is the picture. I am changing the name of the original module. After that I can refresh the modules' list and everything is OK. Then I am changing the name of the "new" file of the module in which is the "combined" code. Refresh again and the error is there. I can't even activate the module. The Gallery script gives this error (I think) when it discovers it.
Posts: 1642
PS: Have you looked at the userAlbum Module? http://codex.gallery2.org/Gallery2:Modules:useralbum
I don't think it does what you want out of the box but this can be amended as well and has other features.
--
dakanji.com
Posts: 1642
That wouldn't work without more work.
Just leave the original module as it is and only change the code in the module.inc to the one I gave you. Copy again as I made some changes.
Don't change any names.
--
dakanji.com
Posts: 16
I copied the code you gave me. The module is consisting of only 1 file - module.inc. When I replace the original code with the modified the browser get's the error. I didn't change any names and I left the module as it should be (as much as possible).
I tried again with changes made and there is no change. I will try to change some of the code these days and tell you if something happens.
Thanks for the help!