Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Re-enable "Stop Sharing" in admin. Update node context accordingly wi…
Browse files Browse the repository at this point in the history
…th owner as user.

Pass total count in $cursor reference in simpleStoreList, and implement pagination in Shares List.
  • Loading branch information
cdujeu committed Jun 28, 2016
1 parent ed74633 commit aba61b7
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 25 deletions.
3 changes: 2 additions & 1 deletion core/src/plugins/access.ajxp_conf/ConfAccessDriver.php
Expand Up @@ -1744,7 +1744,8 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
if(!$repository->isTemplate()){
print "<additional_info>";
$users = UsersService::countUsersForRepository($ctx, $repId, false, true);
$shares = ConfService::getConfStorageImpl()->simpleStoreList("share", null, "", "serial", '', $repId);
$cursor = ["count"];
$shares = ConfService::getConfStorageImpl()->simpleStoreList("share", $cursor, "", "serial", '', $repId);
print('<users total="'.$users.'"/>');
print('<shares total="'.count($shares).'"/>');
$rootGroup = RolesService::getRole("AJXP_GRP_/");
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/action.share/res/react/ShareDialog.js
Expand Up @@ -229,7 +229,7 @@
);
}else{
var unshareButton;
if((this.props.shareModel.hasActiveShares() && (this.props.shareModel.currentIsOwner())) || this.props.shareModel.getStatus() === 'error'){
if((this.props.shareModel.hasActiveShares() && (this.props.shareModel.currentIsOwner())) || this.props.shareModel.getStatus() === 'error' || global.pydio.user.activeRepository === "ajxp_conf"){
unshareButton = (<ReactMUI.FlatButton secondary={true} label={this.context.getMessage('6')} onClick={this.disableAllShare}/>);
}
return (
Expand Down
20 changes: 17 additions & 3 deletions core/src/plugins/action.share/src/ShareCenter.php
Expand Up @@ -33,6 +33,7 @@
use Pydio\Access\Core\Model\UserSelection;
use Pydio\Access\Meta\Watch\WatchRegister;
use Pydio\Core\Controller\CliRunner;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Http\Message\UserMessage;
use Pydio\Core\Http\Response\SerializableResponseStream;
use Pydio\Core\Model\Context;
Expand Down Expand Up @@ -964,6 +965,9 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response

case "sharelist-load":

$itemsPerPage = 50;
$crtPage = 1;
$crtOffset = 0;
$parentRepoId = isset($httpVars["parent_repository_id"]) ? $httpVars["parent_repository_id"] : "";
$userContext = $httpVars["user_context"];
$currentUser = $ctx->getUser()->getId();
Expand All @@ -972,9 +976,19 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
}else if($userContext == "user" && $ctx->getUser()->isAdmin() && !empty($httpVars["user_id"])){
$currentUser = InputFilter::sanitize($httpVars["user_id"], InputFilter::SANITIZE_EMAILCHARS);
}
$nodes = $this->listSharesAsNodes($ctx, "/data/repositories/$parentRepoId/shares", $currentUser, $parentRepoId);
if (isSet($httpVars["dir"]) && strstr($httpVars["dir"], "%23")!==false) {
$parts = explode("%23", $httpVars["dir"]);
$crtPage = intval($parts[1]);
$crtOffset = ($crtPage - 1) * $itemsPerPage;
}
$cursor = [$crtOffset, $itemsPerPage];
$nodes = $this->listSharesAsNodes($ctx, "/data/repositories/$parentRepoId/shares", $currentUser, $parentRepoId, $cursor);
$total = $cursor["total"];

$nodesList = new NodesList();
if($total > $itemsPerPage){
$nodesList->setPaginationData($total, $crtPage, round($total / $itemsPerPage));
}
if($userContext == "current"){
$nodesList->initColumnsData("", "", "ajxp_user.shares");
$nodesList->appendColumn("ajxp_conf.8", "ajxp_label");
Expand Down Expand Up @@ -1819,7 +1833,7 @@ public function shareNode(ContextInterface $ctx, $ajxpNode, $httpVars, &$update)
* @param null $cursor
* @return array
*/
public function listShares($currentUser, $parentRepositoryId="", $cursor = null){
public function listShares($currentUser, $parentRepositoryId="", &$cursor = null){
if($currentUser === false){
$crtUser = "";
}else {
Expand All @@ -1837,7 +1851,7 @@ public function listShares($currentUser, $parentRepositoryId="", $cursor = null)
* @param bool $xmlPrint
* @return AJXP_Node[]
*/
public function listSharesAsNodes(ContextInterface $ctx, $rootPath, $currentUser, $parentRepositoryId = "", $cursor = null, $xmlPrint = false){
public function listSharesAsNodes(ContextInterface $ctx, $rootPath, $currentUser, $parentRepositoryId = "", &$cursor = null, $xmlPrint = false){

$shares = $this->listShares($currentUser, $parentRepositoryId, $cursor);
$nodes = array();
Expand Down
59 changes: 48 additions & 11 deletions core/src/plugins/action.share/src/Store/ShareStore.php
Expand Up @@ -243,7 +243,8 @@ public function updateShareProperty($hash, $pName, $pValue){
*/
public function findSharesForRepo($repositoryId){
if(!$this->sqlSupported) return [];
return $this->confStorage->simpleStoreList("share", null, "", "serial", '%"REPOSITORY";s:32:"'.$repositoryId.'"%');
$cursor = null;
return $this->confStorage->simpleStoreList("share", $cursor, "", "serial", '%"REPOSITORY";s:32:"'.$repositoryId.'"%');
}

/**
Expand All @@ -268,7 +269,7 @@ protected function updateShareType(&$shareData){
* @param null $shareType
* @return array
*/
public function listShares($limitToUser = '', $parentRepository = '', $cursor = null, $shareType = null){
public function listShares($limitToUser = '', $parentRepository = '', &$cursor = null, $shareType = null){

$dbLets = [];
if($this->sqlSupported){
Expand All @@ -283,6 +284,7 @@ public function listShares($limitToUser = '', $parentRepository = '', $cursor =
}

// Get hardcoded files
/*
$files = glob(ConfService::getGlobalConf("PUBLIC_DOWNLOAD_FOLDER")."/*.php");
if($files === false) return $dbLets;
foreach ($files as $file) {
Expand All @@ -301,6 +303,7 @@ public function listShares($limitToUser = '', $parentRepository = '', $cursor =
$publicletData["SHARE_TYPE"] = "file";
$dbLets[$id] = $publicletData;
}
*/

// Update share_type and filter if necessary
foreach($dbLets as $id => &$shareData){
Expand Down Expand Up @@ -330,14 +333,35 @@ public function listShares($limitToUser = '', $parentRepository = '', $cursor =
if(count($storedIds)){
$criteria["!uuid"] = $storedIds;
}
$otherCountOnly = false;
if(isSet($cursor)){
$offset = $cursor[0];
$limit = $cursor[1];
$loadedDbLets = count($dbLets);
$totalDbLets = $cursor["total"];
$newPosition = max(0, $offset - $totalDbLets);
if($loadedDbLets >= $limit){
//return $dbLets;
$criteria["CURSOR"] = ["OFFSET" => 0, "LIMIT" => 1];
$otherCountOnly = true;
}else{
if($loadedDbLets > 0) $limit = $limit - $loadedDbLets;
$criteria["CURSOR"] = ["OFFSET" => $newPosition, "LIMIT" => $limit];
}
}
$oldRepos = RepositoryService::listRepositoriesWithCriteria($criteria, $count);
foreach($oldRepos as $sharedWorkspace){
$dbLets['repo-'.$sharedWorkspace->getId()] = [
"SHARE_TYPE" => "repository",
"OWNER_ID" => $sharedWorkspace->getOwner(),
"REPOSITORY" => $sharedWorkspace->getUniqueId(),
"LEGACY_REPO_OR_MINI" => true
];
if(!$otherCountOnly){
foreach($oldRepos as $sharedWorkspace){
$dbLets['repo-'.$sharedWorkspace->getId()] = [
"SHARE_TYPE" => "repository",
"OWNER_ID" => $sharedWorkspace->getOwner(),
"REPOSITORY" => $sharedWorkspace->getUniqueId(),
"LEGACY_REPO_OR_MINI" => true
];
}
}
if(isSet($cursor)){
$cursor["total"] += $count;
}
}

Expand All @@ -361,8 +385,10 @@ public function testUserCanEditShare($userId, $shareData){
}
$crtUser = $this->context->getUser();
if($crtUser->getId() == $userId) return true;
if($crtUser->isAdmin()) return true;
$user = UsersService::getUserById($userId);
if($crtUser->isAdmin() && $crtUser->canAdministrate($user)) {
return true;
}
if($user->hasParent() && $user->getParent() == $crtUser->getId()){
return true;
}
Expand All @@ -375,7 +401,7 @@ public function testUserCanEditShare($userId, $shareData){
* @param String $element
* @param bool $keepRepository
* @param bool $ignoreRepoNotFound
* @param null $ajxpNode
* @param AJXP_Node $ajxpNode
* @return bool
* @throws \Exception
*/
Expand All @@ -393,18 +419,25 @@ public function deleteShare($type, $element, $keepRepository = false, $ignoreRep
if(is_array($share) && isSet($share["REPOSITORY"])){
$repo = RepositoryService::getRepositoryById($share["REPOSITORY"]);
}
if(isSet($share["OWNER_ID"])) {
$owner = $share["OWNER_ID"];
}
if($repo == null && !$ignoreRepoNotFound){
throw new \Exception(str_replace('%s', 'Cannot find associated repository', $mess["share_center.219"]));
}
}
if($repo != null){
$owner = $repo->getOwner();
$this->testUserCanEditShare($repo->getOwner(), $repo->options);
$res = RepositoryService::deleteRepository($element);
if ($res == -1) {
throw new \Exception($mess[427]);
}
}
if($ajxpNode != null){
if(isSet($owner) && $owner !== $this->context->getUser()->getId()){
$ajxpNode->setUserId($owner);
}
$this->getMetaManager()->removeShareFromMeta($ajxpNode, $element);
}
if($this->sqlSupported){
Expand All @@ -430,6 +463,7 @@ public function deleteShare($type, $element, $keepRepository = false, $ignoreRep
throw new \Exception(str_replace('%s', 'Cannot find associated repository', $mess["share_center.219"]));
}
}else{
$owner = $repo->getOwner();
$this->testUserCanEditShare($repo->getOwner(), $repo->options);
}
if(!$keepRepository){
Expand All @@ -454,6 +488,9 @@ public function deleteShare($type, $element, $keepRepository = false, $ignoreRep
$this->confStorage->simpleStoreClear("share", $element);
}
if($ajxpNode !== null){
if(isSet($owner) && $owner !== $this->context->getUser()->getId()){
$ajxpNode->setUserId($owner);
}
$this->getMetaManager()->removeShareFromMeta($ajxpNode, $element);
if(!$keepRepository){
$this->getMetaManager()->removeShareFromMeta($ajxpNode, $repoId);
Expand Down
13 changes: 8 additions & 5 deletions core/src/plugins/authfront.keystore/KeystoreAuthFrontend.php
Expand Up @@ -121,8 +121,8 @@ public function revokeUserTokens(ContextInterface $ctx, $userId)

$this->storage = ConfService::getConfStorageImpl();
if (!($this->storage instanceof \Pydio\Conf\Sql\SqlConfDriver)) return false;

$keys = $this->storage->simpleStoreList("keystore", null, "", "serial", '%"USER_ID";s:' . strlen($userId) . ':"' . $userId . '"%');
$cursor = null;
$keys = $this->storage->simpleStoreList("keystore", $cursor, "", "serial", '%"USER_ID";s:' . strlen($userId) . ':"' . $userId . '"%');
foreach ($keys as $keyId => $keyData) {
$this->storage->simpleStoreClear("keystore", $keyId);
}
Expand Down Expand Up @@ -171,7 +171,8 @@ function authTokenActions($action, $httpVars, $fileVars, ContextInterface $ctx)
if (!empty($httpVars["device"])) {
// Revoke previous tokens for this device
$device = $httpVars["device"];
$keys = $this->storage->simpleStoreList("keystore", null, "", "serial", '%"DEVICE_ID";s:' . strlen($device) . ':"' . $device . '"%');
$cursor = null;
$keys = $this->storage->simpleStoreList("keystore", $cursor, "", "serial", '%"DEVICE_ID";s:' . strlen($device) . ':"' . $device . '"%');
foreach ($keys as $keyId => $keyData) {
if ($keyData["USER_ID"] != $user) continue;
$this->storage->simpleStoreClear("keystore", $keyId);
Expand All @@ -195,7 +196,8 @@ function authTokenActions($action, $httpVars, $fileVars, ContextInterface $ctx)
$mess = LocaleService::getMessages();
$passedKeyId = "";
if (isSet($httpVars["key_id"])) $passedKeyId = $httpVars["key_id"];
$keys = $this->storage->simpleStoreList("keystore", null, $passedKeyId, "serial", '%"USER_ID";s:' . strlen($user) . ':"' . $user . '"%');
$cursor = null;
$keys = $this->storage->simpleStoreList("keystore", $cursor, $passedKeyId, "serial", '%"USER_ID";s:' . strlen($user) . ':"' . $user . '"%');
foreach ($keys as $keyId => $keyData) {
$this->storage->simpleStoreClear("keystore", $keyId);
}
Expand All @@ -209,7 +211,8 @@ function authTokenActions($action, $httpVars, $fileVars, ContextInterface $ctx)

case "keystore_list_tokens":
if (!isSet($user)) break;
$keys = $this->storage->simpleStoreList("keystore", null, "", "serial", '%"USER_ID";s:' . strlen($user) . ':"' . $user . '"%');
$cursor = null;
$keys = $this->storage->simpleStoreList("keystore", $cursor, "", "serial", '%"USER_ID";s:' . strlen($user) . ':"' . $user . '"%');
foreach ($keys as $keyId => &$keyData) {
unset($keyData["PRIVATE"]);
unset($keyData["USER_ID"]);
Expand Down
7 changes: 6 additions & 1 deletion core/src/plugins/conf.sql/SqlConfDriver.php
Expand Up @@ -1062,7 +1062,7 @@ public function simpleStoreGet($storeID, $dataID, $dataType, &$data)
* @param string $relatedObjectId
* @return array
*/
public function simpleStoreList($storeId, $cursor=null, $dataIdLike="", $dataType="serial", $serialDataLike="", $relatedObjectId=""){
public function simpleStoreList($storeId, &$cursor=null, $dataIdLike="", $dataType="serial", $serialDataLike="", $relatedObjectId=""){
$wheres = array();
$wheres[] = array('[store_id]=%s', $storeId);
if(!empty($dataIdLike)){
Expand All @@ -1075,6 +1075,11 @@ public function simpleStoreList($storeId, $cursor=null, $dataIdLike="", $dataTyp
$wheres[] = array('[related_object_id] = %s', $relatedObjectId);
}
if($cursor != null){
$total = dibi::query("SELECT count(*) FROM [ajxp_simple_store] WHERE %and", $wheres);
$cursor["total"] = $total->fetchSingle();
if(isSet($cursor["count"])) {
return [];
}
$children_results = dibi::query("SELECT * FROM [ajxp_simple_store] WHERE %and %lmt %ofs", $wheres, $cursor[1], $cursor[0]);
}else{
$children_results = dibi::query("SELECT * FROM [ajxp_simple_store] WHERE %and", $wheres);
Expand Down
9 changes: 6 additions & 3 deletions core/src/plugins/core.ocs/src/Model/SQLStore.php
Expand Up @@ -77,7 +77,8 @@ public function storeInvitation(ShareInvitation $invitation)
*/
public function invitationsForLink($linkToken)
{
return $this->storage->simpleStoreList(OCS_SQLSTORE_NS_INVITATION, null, "", OCS_SQLSTORE_FORMAT, "", $linkToken);
$cursor = null;
return $this->storage->simpleStoreList(OCS_SQLSTORE_NS_INVITATION, $cursor, "", OCS_SQLSTORE_FORMAT, "", $linkToken);
}

/**
Expand Down Expand Up @@ -126,7 +127,8 @@ public function storeRemoteShare(RemoteShare $remoteShare)
*/
public function remoteSharesForUser($userName)
{
return $this->storage->simpleStoreList(OCS_SQLSTORE_NS_REMOTE_SHARE, null, "", OCS_SQLSTORE_FORMAT, "", $userName);
$cursor = null;
return $this->storage->simpleStoreList(OCS_SQLSTORE_NS_REMOTE_SHARE, $cursor, "", OCS_SQLSTORE_FORMAT, "", $userName);
}

/**
Expand All @@ -142,7 +144,8 @@ public function remoteShareById($remoteShareId)

public function remoteShareForOcsRemoteId($ocsRemoteId){
$searchString = 's:11:"ocsRemoteId";s:'.strlen($ocsRemoteId).':"'.$ocsRemoteId.'"';
$l = $this->storage->simpleStoreList(OCS_SQLSTORE_NS_REMOTE_SHARE, null, "", OCS_SQLSTORE_FORMAT, "%$searchString%");
$cursor = null;
$l = $this->storage->simpleStoreList(OCS_SQLSTORE_NS_REMOTE_SHARE, $cursor, "", OCS_SQLSTORE_FORMAT, "%$searchString%");
if(count($l)){
return array_shift(array_values($l));
}else{
Expand Down

0 comments on commit aba61b7

Please sign in to comment.