Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow updating of password on public share #14868

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions apps/files_sharing/api/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,7 @@ private static function updatePassword($share, $params) {
}

try {
$result = \OCP\Share::shareItem(
$itemType,
$itemSource,
\OCP\Share::SHARE_TYPE_LINK,
$shareWith,
$permissions
);
$result = \OCP\Share::setPassword($itemType, $itemSource, $shareWith);
} catch (\Exception $e) {
return new \OC_OCS_Result(null, 403, $e->getMessage());
}
Expand Down
36 changes: 36 additions & 0 deletions lib/private/share/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,38 @@ public static function setExpirationDate($itemType, $itemSource, $date, $shareTi
return true;
}

/**
* Set expiration date for a share
* @param string $itemType
* @param string $itemSource
* @param string $password
* @throws \Exception
* @return boolean
*/
public static function setPassword($itemType, $itemSource, $password) {
$user = \OC_User::getUser();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\OCP\IUserSession::getUser with a check if the user is null and throwing an exception then?


if ($password == '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=== as per code guidelines

$password = null;
}

//If passwords are enforced the password can't be null
if (self::enforcePassword() && $password == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=== or is_null

throw new \Exception('Cannot remove password');
}

$query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `share_with` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try to use the Doctrine Query Builder? – See #12502

$query->bindValue(1, is_null($password) ? null : \OC::$server->getHasher()->hash($password));
$query->bindValue(2, $itemType);
$query->bindValue(3, $itemSource);
$query->bindValue(4, $user);
$query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK);

$query->execute();

return true;
}

/**
* Checks whether a share has expired, calls unshareItem() if yes.
* @param array $item Share data (usually database row)
Expand Down Expand Up @@ -2368,4 +2400,8 @@ public static function getExpireInterval() {
return (int)\OCP\Config::getAppValue('core', 'shareapi_expire_after_n_days', '7');
}

public static function enforcePassword() {
$enforcePassword = \OCP\Config::getAppValue('core', 'shareapi_enforce_links_password', 'no');
return ($enforcePassword === "yes") ? true : false;
}
}
12 changes: 12 additions & 0 deletions lib/public/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,18 @@ public static function setExpirationDate($itemType, $itemSource, $date, $shareTi
return \OC\Share\Share::setExpirationDate($itemType, $itemSource, $date, $shareTime);
}

/**
* Set expiration date for a share
* @param string $itemType
* @param string $itemSource
* @param string $password
* @return boolean
*/
public static function setPassword($itemType, $itemSource, $password) {
return \OC\Share\Share::setPassword($itemType, $itemSource, $password);
}


/**
* Get the backend class for the specified item type
* @param string $itemType
Expand Down