-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Changes from 1 commit
1e6af0a
0e58403
03be039
89e9486
96456ff
3ed3284
58e9c95
dfb7542
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
||
if ($password == '') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$password = null; | ||
} | ||
|
||
//If passwords are enforced the password can't be null | ||
if (self::enforcePassword() && $password == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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` = ?'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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; | ||
} | ||
} |
There was a problem hiding this comment.
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?