[SOLVED] Object owner permissions

rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Mon, 2005-02-07 18:46

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:

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-02-07 19:32

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.

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Mon, 2005-02-07 20:13

Firstly, thank you for your quick reply. Now:

mindless wrote:
you can write a custom module to do this.

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...

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-02-07 21:05

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...)

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Mon, 2005-02-07 21:32

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.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-02-07 22:49

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'

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Mon, 2005-02-07 23:33
mindless wrote:
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...)

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

 
virshu
virshu's picture

Joined: 2003-09-13
Posts: 314
Posted: Tue, 2005-02-08 00:08

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

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Tue, 2005-02-08 00:17
virshu wrote:
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

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.

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Tue, 2005-02-08 09:38

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?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-02-08 10:44

just did a cvs update and visited install/index.php, everything works fine.
Try again... replace your G2 files with current cvs files.

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Tue, 2005-02-08 11:36

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

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2005-02-08 18:56

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!

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Tue, 2005-02-08 19:17
mindless wrote:
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!

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

 
supercn

Joined: 2004-11-10
Posts: 17
Posted: Tue, 2005-02-08 19:44
rastafari wrote:
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?

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!

 
virshu
virshu's picture

Joined: 2003-09-13
Posts: 314
Posted: Tue, 2005-02-08 19:51

supercn,

at 11:08am Pacific Time mindless wrote:
update from cvs later today and this will be fixed, sorry!

'later' usually means in 6-8 hours (depending on SF schedule) or, for sure with tomorrow's (2005-02-09) nightly build

 
supercn

Joined: 2004-11-10
Posts: 17
Posted: Tue, 2005-02-08 20:59

thank you very much!

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Thu, 2005-02-10 14:15

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:

Quote:
Fatal error: Cannot use object of type GalleryStatus as array in /var/www/htdocs/gallery2/modules/core/classes/helpers/GalleryEventHelper_simple.class on line 124

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

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2005-02-10 15:51

where's your code?

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Thu, 2005-02-10 16:56

Here:
EDIT: removed link

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2005-02-10 17:53

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);

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Thu, 2005-02-10 22:56

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

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2005-02-10 23:48

looks good, just remove the releaseLocks call you have in there.

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Fri, 2005-02-11 06:58

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

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-02-11 16:21

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.

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Fri, 2005-02-11 17:19
mindless wrote:
i dub thy module complete.. nice work.

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:

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);
        }
    }
}

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-02-11 19:20

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.

 
rastafari
rastafari's picture

Joined: 2005-02-07
Posts: 14
Posted: Fri, 2005-02-11 20:32
mindless wrote:
rastafari , thanks to you for demonstrating the power of G2..

I'm only lucky you helped me out! Wouldn't have managed to do it else.

mindless wrote:
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!

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?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-02-11 21:44

either would work, but since your module is just for your site i think you can just add to your existing module..

 
qba

Joined: 2005-05-20
Posts: 14
Posted: Sat, 2005-05-21 14:42

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

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sat, 2005-05-21 16:19

did you add <?php at the top and ?> at the bottom?
you'll need to update the required core api for the module too.

 
qba

Joined: 2005-05-20
Posts: 14
Posted: Sat, 2005-05-21 16:55

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

 
magicwizard

Joined: 2005-06-05
Posts: 1
Posted: Sun, 2005-06-05 06:24

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.

 
iBuZze

Joined: 2005-06-29
Posts: 1
Posted: Wed, 2005-06-29 18:13

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

 
Aktarus

Joined: 2005-08-07
Posts: 22
Posted: Fri, 2005-09-09 07:28
magicwizard wrote:
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.

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

 
joe7rocks
joe7rocks's picture

Joined: 2004-10-07
Posts: 560
Posted: Thu, 2005-10-27 11:49

any idea if it works with current 2.0.1?..

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-10-27 13:59

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

 
joe7rocks
joe7rocks's picture

Joined: 2004-10-07
Posts: 560
Posted: Fri, 2005-11-11 18:35

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

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-11-11 18:39

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

 
joe7rocks
joe7rocks's picture

Joined: 2004-10-07
Posts: 560
Posted: Fri, 2005-11-11 18:45

;) 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

 
PattayaPete

Joined: 2005-12-26
Posts: 3
Posted: Sat, 2005-12-31 06:58

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.

 
Kandi

Joined: 2005-12-29
Posts: 4
Posted: Sat, 2005-12-31 11:04
PattayaPete wrote:
Any plans to turn this into a normal module

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

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sat, 2005-12-31 16:30
<?php
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(6, 0));
        $this->setRequiredModuleApi(array(2, 0));
    }

    /**
     * @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);
        }
    }
}
?>

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

 
joe7rocks
joe7rocks's picture

Joined: 2004-10-07
Posts: 560
Posted: Sat, 2005-12-31 16:44

..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..)

 
kzo

Joined: 2004-02-02
Posts: 9
Posted: Sat, 2005-12-31 19:22

Anyone know how to get this working with g2.0.2?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sat, 2005-12-31 22:47

joe7: ah right, forgot about that problem.
This should work in 2.0.x:

<?php
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.8');
        $this->setGroup('gallery', $gallery->i18n('Gallery'));
        $this->setCallbacks('registerEventListeners');
        $this->setRequiredCoreApi(array(6, 0));
        $this->setRequiredModuleApi(array(2, 0));
    }

    /**
     * @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') {
            $item = $event->getEntity();
            if (GalleryUtilities::isA($item, 'GalleryDataItem') &&
                    $item->testPersistentFlag(STORAGE_FLAG_NEWLY_CREATED)) {
        	$itemId = $item->getId();

                /* Set permissions.. */
		global $gallery;
                $userId = $gallery->getActiveUserId();
                $gallery->addShutdownAction(array('GalleryCoreApi', 'addUserPermission'),
                                            array($itemId, $userId, 'core.delete'));
            }
        }
	return array(GalleryStatus::success(), null);
    }
}
?>
 
kzo

Joined: 2004-02-02
Posts: 9
Posted: Sun, 2006-01-01 01:56

awesome thanks.

 
PatiH
PatiH's picture

Joined: 2005-12-21
Posts: 32
Posted: Fri, 2006-01-06 07:39

Thank you for this module. This is exactly what I was looking for. I installed it with 2.0.2 and it works great!

 
Dragonsys

Joined: 2004-12-27
Posts: 72
Posted: Mon, 2006-01-09 20:40

I get the following when I click on the modules link in the Admin section:

Quote:
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/dragonsy/public_html/gallery2/modules/jensperms/module.inc on line 2

Parse error: parse error, unexpected T_STRING in /home/dragonsy/public_html/gallery2/modules/jensperms/module.inc on line 2

I have Gallery 2.02
and I used the last version of the code posted here.

 
alindeman
alindeman's picture

Joined: 2002-10-06
Posts: 8194
Posted: Mon, 2006-01-09 21:12

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

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2006-01-13 18:28

Code for current CVS / nightly snapshot:

<?php
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.9.0');
        $this->setGroup('gallery', $gallery->i18n('Gallery'));
        $this->setCallbacks('registerEventListeners');
        $this->setRequiredCoreApi(array(7, 0));
        $this->setRequiredModuleApi(array(3, 0));
    }

    /**
     * @see GalleryModule::registerEventListeners()
     */
    function registerEventListeners() {
        GalleryCoreApi::registerEventListener('GalleryEntity::save', 
            new JensPermsModule(), true);   /* true=disableForUnitTest */
    }
    
    /**
     * Event handler for GalleryEntity::save event
     *
     * @param object GalleryEvent the event
     * @return object GalleryStatus a status code
     */
    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.delete');
                if ($ret) {
                    return array($ret->wrap(__FILE__, __LINE__), null);
                }
            }
        }
	return array(null, null);
    }
}
?>