A call for the "Ultimate" answer with User Albums and Custom Permissions

RCurtis

Joined: 2008-01-21
Posts: 19
Posted: Mon, 2008-01-28 15:13

Not sure if this belongs in this topic area, but since I would consider it a "customization" that is why I picked it... Moderators, feel free to move to another area if appropriate.

The User Albums plugin seems to fill the need for so many people....almost! Almost without exception I would think that anyone activating this module *probably* has an issue with the default permissions assigned. Yes, you can get fairly close by setting the perms in the parent album but *many* admins (it would appear) don't want users to be able to delete the album, move it, DEFINITELY not set perms and often times don't want the ability for the user to "edit" the album. Those abilities just open up such a large can of worms!!! Not to mention that the average user probably will not know what to do once they get into those areas.

I've seen *many* questions posed about changing these perms... from what I understand it is done in the UserAlbumHelper.class file. I have looked at this file and even though I can *usually* muddle through altering PHP code....this one is VERY intimidating.

I understand that the goal for a support forum is to get the user to learn for himself...the old "Teach a man to fish" bit, but it would seem that this particular topic seems to hit so many people and questions keep rolling in.

Please...Would it be possible once and for all to provide a "cookbook" type of approach for an answer to this? I can't help but feel that it would EXTREMELY benefit the forum as a whole to have a definitive posting.

All of the below assume that the User Albums module is installed and the site admin wants to remove a few of those defaults:
Suggestion: How to remove the "edit album", "Edit Permissions", "Move Album"... etc.

9 times out of 10 the site admin wants to "lock" a user into their personal album and just let him/her upload and delete their pictures. *Maybe" create sub-albums...maybe not.

How 'bout it? Anybody up to the challenge of providing the "ultimate answer" here?

 
RCurtis

Joined: 2008-01-21
Posts: 19
Posted: Tue, 2008-01-29 14:31

Anybody?

I've given this a bit more thought since the original posting... This could be accomplished by some "re-tooling" of the UserAlbumHelper.class file. If someone knowledgeable could propose a new file that had some variables defined near the beginning that allowed for a manual edit of each perm by setting it "True" or "False"; "1" or "0"...whatever. This way, users could easily pick and choose their desired perms.

Is this feasible? Would it not be worthwhile to enhance the usabilty?

 
RCurtis

Joined: 2008-01-21
Posts: 19
Posted: Thu, 2008-01-31 03:51

Nobody? Perhaps this is not as big an issue as I suspected, although judging by the number of requests for help in this area it's not a trivial matter to many.

At a minimum, it would really be nice if someone that *has* modified the UserAlbumHelper.class file to post their altered file and explain what their mod does...perhaps we can use that as a guide.

 
afrohead

Joined: 2008-01-28
Posts: 8
Posted: Wed, 2008-01-30 23:37

Wow this post is excellent and I can't believe no one has responded to this. That is very unfortunate. I can't agree more with RCurtis that something needs to be said or done about the lack of user permissions in Gallery 2. There definately needs to be Add Photo and Delete photo permissions without having to give the user rights to move album, edit system paths, etc. Is there a mod for this? Without this ability Gallery 2 is unfortunately not an album solution for those who have a large user groups that contribute to the Albums.

http://www.iowadeer.com

 
RCurtis

Joined: 2008-01-21
Posts: 19
Posted: Thu, 2008-01-31 03:50

***THANK YOU ***

I was beginning to think that maybe I was out in left field as far as the request!

Surely *somebody* has addressed this issue and will share their work with the rest of us....

 
bauchi

Joined: 2007-11-11
Posts: 70
Posted: Thu, 2008-01-31 12:59

RCurtis,
it might take some hours to search the forum for the right threads, but there are already a few solutions to limit the user permissions.
One of them is to install the module "jenspermissions".
http://gallery.menalto.com/node/26165
I did it plus I changed the redirection link as described by "kordobes" in this thread:
http://gallery.menalto.com/node/54371

So now the only permissions users of my gallery have are
-adding albums/items
-deleting their own albums/items (optional, can be removed if I like to)

All options like editing albums, setting up user permissions, thumbnail size and so on are removed like it is if you use the "simple module".

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Thu, 2008-01-31 15:00

Can somebody that has used "jenspermissions" please create a codex page to show how it works. If you need help with that let me know and I can create the page but need somebody that has used it to 'flesh it out a bit'.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
bauchi

Joined: 2007-11-11
Posts: 70
Posted: Thu, 2008-01-31 17:30
Quote:
Can somebody that has used "jenspermissions" please create a codex page to show how it works.

I can test the module on a fresh gallery 2.2.4 installation and see if I can find out how to add and remove specific permissions. If I get some useful results from this, I´ll let you know.

 
RCurtis

Joined: 2008-01-21
Posts: 19
Posted: Thu, 2008-01-31 19:10
bauchi wrote:
RCurtis,
it might take some hours to search the forum for the right threads, but there are already a few solutions to limit the user permissions.
One of them is to install the module "jenspermissions".

I promise you...I *have* spent several hours in the forums. I guarantee I have read every single post involving user permissions. I *did* find this refernce to the "jenspermissions" module. Quite frankly, I could never find what appeared to be a final version...there are several postings where a different version is listed. I guess you could always say "well the obvious correct one is the last one...".

I was never able to find an official "download" for this module, so I was very nervous about activating code that had such sparse documentation and only "lived" in a forom posting. If this module truly performs, why is it not available as a "real" downloadable module?

 
afrohead

Joined: 2008-01-28
Posts: 8
Posted: Thu, 2008-01-31 20:00

Once again another great post from RCurtis. First of all why are these permissions not a part of the base install. This seems to be a serious lack of oversight with the 2.x version. It appears that the upload photo and delete photo type permissions were a part of 1.1 based on other information I have read on here. Why would such essential permissions be removed in the latest version? If you read the jensperms post I am not the only one scratching my head at the lack of these permissions in the base install. Back to RCurtis' last post. The lack of a recognized official version plus the fact there is no codex page for this mod makes it a troubling mod to install. Also - how do you install such a mod where there is just raw source code pasted into a forum post? Although there is docmentation (http://codex.gallery2.org/Gallery2:Installing_Additional_Components) on installing user contributed plugins for which there is a codex page there is nothing I can find on installing a mod such as this. Thanks
http://www.iowadeer.com

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Thu, 2008-01-31 20:04
Quote:
why is it not available as a "real" downloadable module?

somebody has to maintain it and add it to the gallery-contrib SVN repository. Once that is done then it would be available via downloadable plugins.
So the short answer is somebody needs to do it. Anybody volunteering?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
RCurtis

Joined: 2008-01-21
Posts: 19
Posted: Fri, 2008-02-01 01:09

I suggest that a mod of this nature be rolled into the regular UserAlbum Module. That would seem to be the obvious place for it. How would one go about setting something like that in place? I assume that there is a degree of "ownership" from whomever actually wrote the UserAlbum module, unless it was done by the core dev team. (My apologies, I don't have a good feel yet for the "structure" or "control" group behind Gallery.)

 
bauchi

Joined: 2007-11-11
Posts: 70
Posted: Fri, 2008-02-01 12:51

I was not able to get jensperms module working in my gallery 2.2.4, but I found a pretty easy way to limit permissions on "normal" albums (not albums created by user album module!). I guess that´s not what RCurtis is looking for, but maybe someone else is interested in this "solution":

1. Create an album called for example "userphotos" with following permissions:
- Everyone [core] View all versions
- Registered User [core] Add sub-album
- Registered User [core] Add sub-item
This is the album where users should be allowed to upload their pictures and/or create their own albums.

2. Replace the file gallery2/modules/core/ItemAddAlbum.inc with the attached one

So now registered can only create albums and upload items. All permissions to edit, move and delete albums/items, choose themes and set permissions to their created albums are removed.

 
RCurtis

Joined: 2008-01-21
Posts: 19
Posted: Sat, 2008-02-02 01:19

I was not able to get the jensperms module to do anything either...of course with no documentation and no admin interface "how would you know if it *was* working?" <grin> Just kidding!

I've done quite a bit of thrashing through code and forum postings, and have come to realize that jensperms is NOT needed for what I originally asked. I'm about 90% to an answer with only modifying the UserAlbumHelper.class file. I have to admit, I was getting rather frustrated with what I perceived as a lack of support here in the forum. I've worked with quite a few open source packages to date, but this is the first one where users are *almost* told "Go look it up yourself..."

Now, I'm quite certain that doing forum level (and volunteer!) support probably does get quite old...and you see the same questions over and over, I'm sure. There's *always* going to be the guy that says "I just want my answer and I don't have time to search through a forum!" I would lose my patience very quickly with this person, too. But... when you see *so many* people asking about the same topic...and a topic so closely related to a *standard* plugin module, you begin to wonder if maybe we've lost sight of the forest for the trees! Either one of two things happened:

1) They gave up becuase they could not find the info buried within the maze, or
2) They actually *did* find a solution on their own but didn't bother to come back and share it with everybody else...after all, "I had to do all the work myself...I don't owe those people anything!"

Obviously, that's not the spirit we want to foster in people...but *something's* wrong here where so many people have asked and there's no real definitive posting.

I *will* be posting a revised version of UserAlbumHelper.class with documented sections to uncomment to accomplish various permission sets. Perhaps the powers that be will see fit to incorporate this simplified file into the UserAlbum module. There's only a couple of items I still want to achieve...maybe after I post someone will be kind enough to fill in the pieces I am missing. Stay tuned!

 
RCurtis

Joined: 2008-01-21
Posts: 19
Posted: Sat, 2008-02-02 02:50

As promised: Here is a revised UserAlbumHelper.class file that should go a long way towards helping people understand how to set user perms in the UserAlbums module. This file lives in "modules/useralbum/classes" folder.

The code as listed will function EXACTLY as the original file...you have to actively un-comment sections to make a change from the default.

Quote:
<?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2007 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/

/**
* A helper class for user albums
* @package UserAlbum
* @subpackage Classes
* @author Alan Harder <alan.harder@sun.com>
* @version $Revision: 15513 $
* @static
*/
class UserAlbumHelper {

/**
* Create a new user album
*
* @param object GalleryUser $user new user
* @return object GalleryStatus a status code
*/
function createUserAlbum($user) {
list ($ret, $core) = GalleryCoreApi::fetchAllPluginParameters('module', 'core');
if ($ret) {
return $ret;
}
list ($ret, $module) = GalleryCoreApi::fetchAllPluginParameters('module', 'useralbum');
if ($ret) {
return $ret;
}

/* Create album.. */
$albumTitle = trim($user->getFullName());
if (empty($albumTitle)) {
$albumTitle = $user->getUserName();
}
$albumName = $user->getUserName();
while (true) {
list ($ret, $album) = GalleryCoreApi::createAlbum(
$module['targetLocation'], $albumName, $albumTitle, '', '', '');
if (!$ret) {
break;
}
if ($ret->getErrorCode() & ERROR_COLLISION) {
$albumName .= '_';
} else {
return $ret;
}
}

list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($album->getId());
if ($ret) {
return $ret;
}

/* Set owner.. */
$album->setOwnerId($user->getId());
$ret = $album->save();
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
$albumId = $album->getId();

/* Set permissions.. */
list ($ret, $permissions) = GalleryCoreApi::fetchAllPermissionsForItem($albumId, true);
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
$visited = array();
foreach ($permissions as $permission) {
/* don't bother for administrator group */
if (empty($permission['groupId']) || $permission['groupId'] != $core['id.adminGroup']) {
/* remove all view permissions at once */
if (strstr($permission['permission'], 'core.view') ||
($permission['permission'] == 'core.all')) {
if (!empty($permission['groupId']) && empty($visited[$permission['groupId']])) {
$ret = GalleryCoreApi::removeGroupPermission($albumId,
$permission['groupId'], 'core.viewAll');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
$visited[$permission['groupId']] = 1;
} else if (!empty($permission['userId'])
&& empty($visited[$permission['userId']])) {
$ret = GalleryCoreApi::removeUserPermission($albumId,
$permission['userId'], 'core.viewAll');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
$visited[$permission['userId']] = 1;
}
}
}
}

/* The following section is the original code section that allows:
*
* Add Album
* Add Items
* Delete Album
* Edit Album
* Edit Permissions
* Move Album
*/

$ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.all');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}

/* The following sections allow you to customize the permissions you want the user
* to have in their "owner" album created via the UserAlbums module. To activate any of the
* numbered sections, you must first un-comment the next section which will give you a "clean slate".
* Un-comment the section(s) you want to use by removing the "slash asterisk" before the $ret and
* the "astersisk slash" on the line by itself after the curly brace. Do not un-comment the
* description line(s).
*/

/* This section will remove ALL perms - you will have a clean slate in which to set what you want */
/* $ret = GalleryCoreApi::removeUserPermission($albumId, $user->getId(), 'core.all');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 1 - This section will let your user add pictures */
/* $ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.addDataItem');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 2 - This section will let your user add a Sub Album */
/* $ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.addAlbumItem');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 3 - This section will let your user Delete & Move Album, and Delete & Move Photo
* No destinations other than the user's album are shown for a move
*/
/* $ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.delete');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 4 - This section will let your user view all sizes of pictures
* There are 3 other variations of this perm: core.view, core.viewResizes and core.viewSource
* This version would appear to be the most useful
*/
/* $ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.viewAll');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 5 - This section will let your user do the following:
* Edit Album
* Edit Captions
* Reorder Items
* View Permissions
*/
/* $ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.edit');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 6 - This section will let your user do the following: Edit Permissions */
/* $ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.changePermissions');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

$viewPermissions = $module['fullSize'] ? array('core.viewAll')
: array('core.view', 'core.viewResizes');
switch ($module['view']) {
case 'everybody':
$groupId = $core['id.everybodyGroup'];
break;
case 'allusers':
$groupId = $core['id.allUserGroup'];
break;
}
if (isset($groupId)) {
foreach ($viewPermissions as $permission) {
$ret = GalleryCoreApi::addGroupPermission($albumId, $groupId, $permission);
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
}
}

$ret = GalleryCoreApi::releaseLocks($lockId);
if ($ret) {
return $ret;
}

/* Record id of album */
$ret = GalleryCoreApi::setPluginParameter(
'module', 'useralbum', 'albumId', $albumId, $user->getId());
if ($ret) {
return $ret;
}

return null;
}
}
?>

I have discovered some quirks along the way while on this journey. In Section 5, (core.edit)... For some strange reason the developers have seen fit to allow the user to View Permissions. This particular item does not seem to fit in with the "edit" theme that it deals with... Perhaps someone can explain the logic behind this...or maybe it's a mistake?

Also, Section 3, (core.delete)... this perm throws in the "move" category. This too, does not fit, at least in regards to the UserAlbums module. I realize that the perms were probably designed long before the UserAlbums module...but still it would seem to be more prudent to split "move" out as its own perm.

What's next along this same line? Well, the obvious piece that is missing is for someone to write a small admin screen that let's you set these things via the plugin. This is beyond my means at this time. Hopefully someone will pick up the ball and run with it. I hope this thread helps those looking for the answers to setting UserAlbum perms!

 
RCurtis

Joined: 2008-01-21
Posts: 19
Posted: Mon, 2008-02-04 21:29

Anybody have a clue how you would implement access to this type of function via an admin screen under SiteAdmin?

 
m_lokay

Joined: 2007-01-15
Posts: 13
Posted: Sat, 2008-07-19 17:57

thanks so much

 
serbanc

Joined: 2006-05-19
Posts: 314
Posted: Sat, 2008-07-19 19:13

if someone needs it, I have a functional jensperms for G2.2.4 - no admin interface!

serbanc - www.e-poze.ro

 
commander_keen
commander_keen's picture

Joined: 2008-08-04
Posts: 24
Posted: Sat, 2008-08-09 13:22

Thank you very much for your efforts this piece of code RCurtis. Although it still doesn't allow what I was looking for (http://gallery.menalto.com/node/80318#comment-282451 ) due to limited capabilities of the gallery itsself, it's nice to see someone actually "did it" and provided a useful solution, which is directly usable. (I Hope it still works in g2.2.x onwards)

btw: when reading through the forums I have to admit I share the thoughts you wrote down here in most parts...

@serbanc: if I hadn't known the /downloads on your page, I wouldn't have found your files just with that link posted here ;-)
(your GUI doesn't seem to lead there)

 
Nyhm
Nyhm's picture

Joined: 2006-05-01
Posts: 20
Posted: Sat, 2008-09-27 22:48

Nice thread! I was trying to do the very same thing in this other thread. I had minor success after hacking the ownerperms module (not User Albums), but no fully working solution (I still have to create each top-level user album by hand to set primary permissions). Other tweaks involved hiding overly-complicated functions from the interface for the sake of simplicity (but not actually fixing permissions against showing them).

Alas, it has been some time, now my Gallery is out of date, and I have sparse notes on what I did.

Many thanks to RCurtis for taking the reins on this major issue. My previous post is a perfect example of the community (and its leaders) being rather negative:

floridave wrote:
I see what you are after but I have no skill or interest in these fine grained permissions.

While I'm ranting, I'm convinced Gallery's code base is about 90% too complicated for the function of showing pictures on the Web. I'm no Web developer, so I can't do better, and Gallery is OK for hacking around with.

UPDATE: I've updated my other post to vaguely document how I create user albums with the proper permissions.

 
smilem

Joined: 2009-02-25
Posts: 118
Posted: Sun, 2009-03-01 19:49

Anyone have updated version that works with gallery 2.3? File rev. version 18064

 
smilem

Joined: 2009-02-25
Posts: 118
Posted: Wed, 2009-03-11 19:22

bump

 
insomnix

Joined: 2009-04-19
Posts: 24
Posted: Fri, 2009-04-24 05:40

With a few lines added, this works with 2.3. I am still testing, but seems to work fine.

Quote:
<?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2007 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/

/**
* A helper class for user albums
* @package UserAlbum
* @subpackage Classes
* @author Alan Harder <alan.harder@sun.com>
* @version $Revision: 15513 $
* @static
*/
class UserAlbumHelper {

/**
* Create a new user album
*
* @param object GalleryUser $user new user
* @return object GalleryStatus a status code
*/
function createUserAlbum($user) {
global $gallery;

list ($ret, $core) = GalleryCoreApi::fetchAllPluginParameters('module', 'core');
if ($ret) {
return $ret;
}
list ($ret, $module) = GalleryCoreApi::fetchAllPluginParameters('module', 'useralbum');
if ($ret) {
return $ret;
}

/* Create album.. */
$albumTitle = trim($user->getFullName());
if (empty($albumTitle)) {
$albumTitle = $user->getUserName();
}
$albumName = $user->getUserName();
while (true) {
list ($ret, $album) = GalleryCoreApi::createAlbum(
$module['targetLocation'], $albumName, $albumTitle, '', '', '');
if (!$ret) {
break;
}
if ($ret->getErrorCode() & ERROR_COLLISION) {
$albumName .= '_';
} else {
return $ret;
}
}

list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($album->getId());
if ($ret) {
return $ret;
}

/* Set owner.. */
$album->setOwnerId($user->getId());
$ret = $album->save();
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
$albumId = $album->getId();

/* Set permissions.. */

/* If the active user isn't the album owner, the default permissions should be removed */
$currentUserId = $gallery->getActiveUserId();
if ($currentUserId != $user->getId()) {
$ret = GalleryCoreApi::removeUserPermission($albumId, $currentUserId, 'core.all');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
}

/* Make sure the album owner has core.all permissions */
$ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.all');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}

list ($ret, $permissions) = GalleryCoreApi::fetchAllPermissionsForItem($albumId, true);
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
$visited = array();
foreach ($permissions as $permission) {
/* don't bother for administrator group */
if (empty($permission['groupId']) || $permission['groupId'] != $core['id.adminGroup']) {
/* remove all view permissions at once */
if (strstr($permission['permission'], 'core.view') ||
($permission['permission'] == 'core.all')) {
if (!empty($permission['groupId']) && empty($visited[$permission['groupId']])) {
$ret = GalleryCoreApi::removeGroupPermission($albumId,
$permission['groupId'], 'core.viewAll');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
$visited[$permission['groupId']] = 1;
} else if (!empty($permission['userId'])
&& empty($visited[$permission['userId']])) {
$ret = GalleryCoreApi::removeUserPermission($albumId,
$permission['userId'], 'core.viewAll');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
$visited[$permission['userId']] = 1;
}
}
}
}

/* The following section is the original code section that allows:
*
* Add Album
* Add Items
* Delete Album
* Edit Album
* Edit Permissions
* Move Album
*/

$ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.all');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}

/* The following sections allow you to customize the permissions you want the user
* to have in their "owner" album created via the UserAlbums module. To activate any of the
* numbered sections, you must first un-comment the next section which will give you a "clean slate".
* Un-comment the section(s) you want to use by removing the "slash asterisk" before the $ret and
* the "astersisk slash" on the line by itself after the curly brace. Do not un-comment the
* description line(s).
*/

/* This section will remove ALL perms - you will have a clean slate in which to set what you want */
/*$ret = GalleryCoreApi::removeUserPermission($albumId, $user->getId(), 'core.all');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 1 - This section will let your user add pictures */
/*$ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.addDataItem');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 2 - This section will let your user add a Sub Album */
/*$ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.addAlbumItem');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 3 - This section will let your user Delete & Move Album, and Delete & Move Photo
* No destinations other than the user's album are shown for a move
*/
/* $ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.delete');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 4 - This section will let your user view all sizes of pictures
* There are 3 other variations of this perm: core.view, core.viewResizes and core.viewSource
* This version would appear to be the most useful
*/
/* $ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.viewAll');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 5 - This section will let your user do the following:
* Edit Album
* Edit Captions
* Reorder Items
* View Permissions
*/
/*$ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.edit');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

/* Section 6 - This section will let your user do the following: Edit Permissions */
/* $ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.changePermissions');
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
*/

$viewPermissions = $module['fullSize'] ? array('core.viewAll')
: array('core.view', 'core.viewResizes');
switch ($module['view']) {
case 'everybody':
$groupId = $core['id.everybodyGroup'];
break;
case 'allusers':
$groupId = $core['id.allUserGroup'];
break;
}
if (isset($groupId)) {
foreach ($viewPermissions as $permission) {
$ret = GalleryCoreApi::addGroupPermission($albumId, $groupId, $permission);
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
return $ret;
}
}
}

$ret = GalleryCoreApi::releaseLocks($lockId);
if ($ret) {
return $ret;
}

/* Record id of album */
$ret = GalleryCoreApi::setPluginParameter(
'module', 'useralbum', 'albumId', $albumId, $user->getId());
if ($ret) {
return $ret;
}

return null;
}
}
?>

To bad this only works when creating new albums, it would be nice if you could make changes to all user albums with a single admin page.

Thanks to everyone and especially RCurtis for this code, this saved me a lot of work.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sat, 2009-04-25 02:54
bauchi wrote:
Quote:
Can somebody that has used "jenspermissions" please create a codex page to show how it works.

I can test the module on a fresh gallery 2.2.4 installation and see if I can find out how to add and remove specific permissions. If I get some useful results from this, I´ll let you know.

How did you make out? does the new version for G2.3 still fit the bill?

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team