•  » Extensions
  •  » Community ext: possible to limit to user album, but allow subalbums?

#1 2025-11-10 00:48:48

moberley
Member
2025-11-10
90

Community ext: possible to limit to user album, but allow subalbums?

I am exploring if Piwigo might be useful for my use case (which would involve allow certain user uploads).

In general the Community plugin does what I expect, but it appears that if the permissions for a group are limited to the "user album only" it becomes impossible to allow application of the permissions to sub-albums or to allow sub-album creation.

Is there a way to allow that and I just have a setting broken somewhere, or is that not possible at all?

Environment
Piwigo 15.7.0 Check for upgrade
Installed on 6 November 2025, 3 days ago
Operating system: Linux
PHP: 8.4.11 (Show info) [2025-11-09 23:41:51]
MySQL: 11.8.3-MariaDB-0+deb13u1 from Debian [2025-11-09 17:41:51]
Graphics Library: ImageMagick ImageMagick 7.1.1-43
Cache size N/A   never calculated Refresh

Activated plugin list
Add Users Notes
Additional Pages
Admin Tools
Community
Copyrights
Custom Registration Form
Extended Description
LocalFiles Editor
Photo added by
Protect Notification
Register Codes
Simple Copyright
Write Metadata

Offline

 

#2 2025-11-13 00:55:10

moberley
Member
2025-11-10
90

Re: Community ext: possible to limit to user album, but allow subalbums?

It looks like I might have a way to get the function that I was looking for using the Personal Plugin. I found that if I created a specific user permission for that user's own user album with the create subalbums and recursive options on it did more or less what I was thinking about.

However, it would be nice if I didn't have to manually create the permission for each user. So I created a function that responds to the register user trigger, uses community_get_user_album() to get the user album ID and then some code I borrowed from admin_permission.php in the community plugin to register the permission. In initial testing it seems to work.

I set a low number of photos which I seem to be able to raise later by assigning the user to a group that has "user album only" permissions but a higher upload allowance. The subalbum permissions appeared to remain functional.

It would be wonderful if I could somehow connect this idea with a user being assigned to or removed from a particular group but I couldn't find a trigger that would do that.

Code:

add_event_handler('register_user', 'personal_add_special_community_permissions', EVENT_HANDLER_PRIORITY_NEUTRAL);
function personal_add_special_community_permissions($user)
{
  $category = community_get_user_album($user['id']);
  $insert = array(
    'type' => 'user',
    'group_id' => null,
    'user_id' => $user['id'],
    'category_id' => $category,
    'user_album' => boolean_to_string(-1 == $category),
    '`recursive`' => 'true',
    'create_subcategories' => 'true',
    'moderated' => true,
    'nb_photos' => 5,
    'storage' => -1
  );  
  mass_inserts(
    COMMUNITY_PERMISSIONS_TABLE,
    array_keys($insert),
    array($insert)
  );
}

Environment
Piwigo 16.0.0RC2 Check for upgrade
Installed on 6 November 2025, 6 days ago
Operating system: Linux
PHP: 8.4.11 (Show info) [2025-11-12 23:33:02]
MySQL: 11.8.3-MariaDB-0+deb13u1 from Debian [2025-11-12 17:33:02]
Graphics Library: External ImageMagick 7.1.1-43
Cache size 14.93 Mo   calculated 2 days ago Refresh

Activated plugin list
Add Users Notes
Additional Pages
Admin Tools
Community
Copyrights
Custom Registration Form
Extended Description
LocalFiles Editor
Perso Footer
Personal Plugin
Photo added by
Protect Notification
Upload 1 menu
Write Metadata

Offline

 

#3 2025-11-14 09:53:27

moberley
Member
2025-11-10
90

Re: Community ext: possible to limit to user album, but allow subalbums?

As far as I can see users are added or removed from groups in three functions in the main Piwigo engine.

There is check_and_save_user_infos() in include/functions_user.inc.php that is called by ws_users_setInfo() and ws_users_setMyInfo() in include/ws_functions/pwg.users.php. However in the latter case setMyInfo appears to unset the group_id param before calling check_and_save_user_infos() so I guess that passing that parameter doesn't do anything in that case.

None of these mention the group_id param in the comments above the function but I'm assuming that doesn't mean anything important.

The other functions are ws_groups_addUser() and ws_groups_deleteUser() in include/ws_functions/pwg.groups.php. If I am understanding the template correctly it is normally these functions that respond to associating and disassociating users from groups on the user_list admin page.

I don't see any group specific triggers in any of these locations. All three do call invalidate_user_cache() (from admin/include/functions.php) which does have a trigger call but obviously that is called in many other places as well and doing what I want in response to that would be inefficient.

In all cases the code appears to do either an INSERT or DELETE of user_id/group_id pairs so if I can't get the function directly through Piwigo functions I might be able to do something with a TRIGGER in the database. I think that will be my next avenue of investigation.

Offline

 

#4 2025-11-15 13:52:34

moberley
Member
2025-11-10
90

Re: Community ext: possible to limit to user album, but allow subalbums?

I need to do some additional testing but it looks like the triggers are a workable solution. There are some things that seem to be behaving oddly that I need to track down yet but when using the database triggers associating or disassociating a user from a group does actually add or remove the permissions from the community permissions table.

I put together a plugin to manage this for my installation which allows me to add or remove the following triggers and specify which group should trigger the changes. The plugin also retains a function attached to the register_user trigger that calls community_get_user_album() because I wasn't sure where in the process the user album was actually created. Since that album is referenced in the trigger (through a SELECT on the categories table) that gets created on the database I wanted to make sure the user album was available.

Insert trigger

Code:

    $query = '
CREATE TRIGGER `community_extended_user_create_user_album_permission`
  AFTER INSERT ON `'. USER_GROUP_TABLE .'`
  FOR EACH ROW
  BEGIN
    IF (NEW.`group_id` = '. $config['trigger_group_id'] .') 
    THEN 
      DELETE FROM `'. COMMUNITY_PERMISSIONS_TABLE .'`
        WHERE user_id=NEW.`user_id`
        AND category_id=( SELECT id FROM `'. CATEGORIES_TABLE .'` WHERE community_user=NEW.`user_id` ); 
      INSERT INTO `'. COMMUNITY_PERMISSIONS_TABLE .'`
        (type, user_id, category_id, create_subcategories)
        VALUES (
          "user",
          NEW.`user_id`,
          ( SELECT id FROM `'. CATEGORIES_TABLE .'` where community_user=NEW.`user_id` ),
          "true"
        );
    END IF;
  END
;';
    pwg_query($query);

Delete trigger

Code:

$query = '
CREATE TRIGGER `community_extended_user_destroy_user_album_permission`
  AFTER DELETE ON `'. USER_GROUP_TABLE .'`
  FOR EACH ROW 
  BEGIN
    IF (OLD.`group_id` = '. $config['trigger_group_id'] .') 
    THEN
      DELETE FROM `'. COMMUNITY_PERMISSIONS_TABLE .'`
        WHERE user_id=OLD.`user_id`
        AND category_id=( SELECT id FROM `'. CATEGORIES_TABLE .'` WHERE community_user=OLD.`user_id` );
    END IF;
  END
;';
    pwg_query($query);

Offline

 
  •  » Extensions
  •  » Community ext: possible to limit to user album, but allow subalbums?

Board footer

Powered by FluxBB