* Filemanager/Sharing: create different share-token for different recipients (before recipients where added to the token)

- allows to individually remove the token, otherwise new token for the other recipients need to be redistributed
- sending one email to multiple recipients still creates a single share-token for all the recipients (send multiple mails if that's not desired)
This commit is contained in:
Ralf Becker 2021-09-20 13:27:31 +02:00
parent 95ce821235
commit e4c82ac1fa

View File

@ -603,6 +603,8 @@ class Sharing
/** /**
* Create a new share * Create a new share
* *
* Only for shares with identical attributes AND recipients an existing share-token is returned.
*
* @param string $action_id Specific type of share being created, default '' * @param string $action_id Specific type of share being created, default ''
* @param string $path either path in temp_dir or vfs with optional vfs scheme * @param string $path either path in temp_dir or vfs with optional vfs scheme
* @param string $mode self::LINK: copy file in users tmp-dir or self::READABLE share given vfs file, * @param string $mode self::LINK: copy file in users tmp-dir or self::READABLE share given vfs file,
@ -626,35 +628,17 @@ class Sharing
// Check if path is mounted somewhere that needs a password // Check if path is mounted somewhere that needs a password
static::path_needs_password($path); static::path_needs_password($path);
// check if file has been shared before, with identical attributes // check if file has been shared before, with identical attributes AND recipients
if (($share = static::$db->select(static::TABLE, '*', $extra+array( if (($share = static::$db->select(static::TABLE, '*', $extra+array(
'share_path' => $path, 'share_path' => $path,
'share_owner' => Vfs::$user, 'share_owner' => Vfs::$user,
'share_expires' => null, 'share_expires' => null,
'share_passwd' => null, 'share_passwd' => null,
'share_writable'=> false, 'share_writable'=> false,
'share_with' => implode(',', (array)$recipients),
), __LINE__, __FILE__, Db::API_APPNAME)->fetch())) ), __LINE__, __FILE__, Db::API_APPNAME)->fetch()))
{ {
// if yes, just add additional recipients // if yes, nothing to do
$share['share_with'] = $share['share_with'] ? explode(',', $share['share_with']) : array();
$need_save = false;
foreach((array)$recipients as $recipient)
{
if (!in_array($recipient, $share['share_with']))
{
$share['share_with'][] = $recipient;
$need_save = true;
}
}
$share['share_with'] = implode(',', $share['share_with']);
if ($need_save)
{
static::$db->update(static::TABLE, array(
'share_with' => $share['share_with'],
), array(
'share_id' => $share['share_id'],
), __LINE__, __FILE__, Db::API_APPNAME);
}
} }
else else
{ {