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

Commit

Permalink
Rework OCS Links
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Feb 25, 2016
1 parent 4f7feeb commit 5a434e8
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 76 deletions.
104 changes: 59 additions & 45 deletions core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -829,6 +829,13 @@ public function nodeSharedMetadata(&$ajxpNode)
if(empty($this->accessDriver) || $this->accessDriver->getId() == "access.imap") return;
$shares = array();
$this->getShareStore()->getMetaManager()->getSharesFromMeta($ajxpNode, $shares, false);
if(!empty($shares)){
$compositeShare = $this->getShareStore()->getMetaManager()->getCompositeShareForNode($ajxpNode);
if(empty($compositeShare)){
$this->getShareStore()->getMetaManager()->clearNodeMeta($ajxpNode);
return;
}
}
if(!empty($shares) && count($shares)){
$merge = array(
"ajxp_shared" => "true",
Expand Down Expand Up @@ -1442,49 +1449,78 @@ public function createSharedRepository($httpVars, &$update, $users=array(), $gro
/**
* @param array $httpVars
* @param bool $update
* @return Repository|ShareLink
* @return Repository[]|ShareLink[]
* @throws Exception
*/
public function shareNode($httpVars, &$update){

$hiddenUserEntry = null;
$hiddenUserEntries = array();
$downloadDisabled = false;
$originalHttpVars = $httpVars;
$ocsStore = new Pydio\OCS\Model\SQLStore();
$ocsClient = new Pydio\OCS\Client\OCSClient();
/**
* @var ShareLink[] $shareObjects
*/
$shareObjects = array();

// PUBLIC LINK
if(isSet($httpVars["enable_public_link"])){

$minisiteData = $httpVars;
if(isSet($httpVars["minisite"])){
$decoded = json_decode($httpVars["minisite"], true);
if(is_array($decoded)){
$minisiteData = $decoded;
}
}

// PREPARE HIDDEN USER DATA
if(isSet($httpVars["hash"])){
$shareObject = $this->getShareStore()->loadShareObject($httpVars["hash"]);
}else{
$shareObject = $this->getShareStore()->createEmptyShareObject();
}
$hiddenUserEntry = $this->prepareSharedUserEntry(
$hiddenUserEntries[] = $this->prepareSharedUserEntry(
$httpVars,
$shareObject,
isSet($httpVars["hash"]),
(isSet($httpVars["guest_user_pass"])?$httpVars["guest_user_pass"]:null)
);
$shareObject->parseHttpVars($httpVars);
$downloadDisabled = $shareObject->disableDownload();
$shareObjects[] = $shareObject;

}else if(isSet($httpVars["disable_public_link"])){

$this->getShareStore()->deleteShare("minisite", $httpVars["disable_public_link"], true);

}

if(isSet($httpVars["ocs_data"])){
$ocsData = json_decode($httpVars["ocs_data"], true);
$removeLinks = $ocsData["REMOVE"];
foreach($removeLinks as $linkHash){
// Delete Link, delete invitation(s)
$this->getShareStore()->deleteShare("minisite", $linkHash, true);
$invitations = $ocsStore->invitationsForLink($linkHash);
foreach($invitations as $invitation){
$ocsStore->deleteInvitation($invitation);
}
}
$newLinks = $ocsData["LINKS"];
foreach($newLinks as $linkData){
if(isSet($linkData["hash"])){
$link = $this->getShareStore()->loadShareObject($httpVars["hash"]);
}else{
$link = new Pydio\OCS\Model\TargettedLink($this->getShareStore());
if(AuthService::usersEnabled()) $link->setOwnerId(AuthService::getLoggedUser()->getId());
$link->prepareInvitation($linkData["HOST"], $linkData["USER"]);
}
$hiddenUserEntries[] = $this->prepareSharedUserEntry(
$linkData,
$link,
isSet($linkData["hash"]),
(isSet($linkData["guest_user_pass"])?$linkData["guest_user_pass"]:null)
);
$link->parseHttpVars($linkData);
$shareObjects[] = $link;
}
}

/*
// OCS LINK
if(isSet($httpVars["ocs_data"])){
Expand Down Expand Up @@ -1522,14 +1558,15 @@ public function shareNode($httpVars, &$update){
}
}
}
*/

$userSelection = new UserSelection($this->repository, $httpVars);
$this->filterHttpVarsForLeafPath($httpVars, $userSelection);

$users = array(); $groups = array();
$this->getRightsManager()->createUsersFromParameters($httpVars, $users, $groups);
if(isSet($hiddenUserEntry)){
$users[$hiddenUserEntry["ID"]] = $hiddenUserEntry;
foreach($hiddenUserEntries as $entry){
$users[$entry["ID"]] = $entry;
}
if(!count($users) && !count($groups)){
ob_start();
Expand All @@ -1540,47 +1577,24 @@ public function shareNode($httpVars, &$update){

$newRepo = $this->createSharedRepository($httpVars, $repoUpdate, $users, $groups, $downloadDisabled);


if(!isSet($shareObject) && !isSet($ocsLink)){

return array($newRepo);

}
$return = array();
if(isSet($shareObject)){
foreach($shareObjects as $shareObject){

$shareObject->setParentRepositoryId($this->repository->getId());
$shareObject->attachToRepository($newRepo->getId());
// STORE DATA & HASH IN SHARE STORE
$this->getPublicAccessManager()->initFolder();
$shareObject->save();
$return[] = $shareObject;

}
if(isSet($ocsLink)){

// Update OCS link
$ocsLink->setParentRepositoryId($this->repository->getId());
$ocsLink->attachToRepository($newRepo->getId());
$ocsLink->save();

if(isSet($newOcsUsers)){
foreach($newOcsUsers as $ocsUser){
$invitation = $ocsLink->createInvitation($ocsUser["HOST"], $ocsUser["USER"]);
if($shareObject instanceof \Pydio\OCS\Model\TargettedLink){
$invitation = $shareObject->getPendingInvitation();
if(!empty($invitation)){
$ocsStore->storeInvitation($invitation);
$ocsClient->sendInvitation($invitation);
}
}else{
$this->getPublicAccessManager()->initFolder();
}
$return[] = $ocsLink;
}
if(isSet($unShareInvitations)){
foreach($unShareInvitations as $invitation){
$ocsClient->cancelInvitation($invitation);
$ocsStore->deleteInvitation($invitation);
}
}

return $return;
}
$shareObjects[] = $newRepo;
return $shareObjects;

}

Expand Down
32 changes: 18 additions & 14 deletions core/src/plugins/action.share/res/react/ShareDialog.js
Expand Up @@ -78,7 +78,7 @@
}
if( (model.getNode().isLeaf() && auth.file_workspaces) || (!model.getNode().isLeaf() && auth.folder_workspaces)){
var users = model.getSharedUsers();
var ocsUsers = model.getOcsInvitations();
var ocsUsers = model.getOcsLinks();
var totalUsers = users.length + ocsUsers.length;
panels.push(
<ReactMUI.Tab key="target-users" label={'Users' + (totalUsers?' ('+totalUsers+')':'')}>
Expand Down Expand Up @@ -603,11 +603,11 @@
addUser:function(){
var h = this.refs["host"].getValue();
var u = this.refs["user"].getValue();
this.props.shareModel.addOcsInvitation(h, u);
this.props.shareModel.createRemoteLink(h, u);
},

removeUser: function(invite){
this.props.shareModel.removeOcsInvitation(invite);
removeUser: function(linkId){
this.props.shareModel.removeRemoteLink(linkId);
},

monitorInput:function(){
Expand All @@ -618,24 +618,28 @@

render: function(){

var inv = this.props.shareModel.getOcsInvitations().map(function(invite){
var inv = this.props.shareModel.getOcsLinks().map(function(link){
var rem = function(){
this.removeUser(invite);
this.removeUser(link.hash);
}.bind(this);
var status;
if(!invite.STATUS){
if(!link.invitation){
status = 'not sent';
}else if(invite.STATUS == 1){
status = 'pending';
}else if(invite.STATUS == 2){
status = 'accepted';
}else if(invite.STATUS == 4){
status = 'rejected';
}else {
if(link.invitation.STATUS == 1){
status = 'pending';
}else if(link.invitation.STATUS == 2){
status = 'accepted';
}else if(link.invitation.STATUS == 4){
status = 'rejected';
}
}
var menuItems = [{text:'Remove', callback:rem}];
var host = link.HOST || link.invitation.HOST;
var user = link.USER || link.invitation.USER;
return (
<UserBadge
label={invite.USER + " @ " + invite.HOST + " (" + status + ")"}
label={user + " @ " + host + " (" + status + ")"}
avatar={null}
type={"remote_user"}
menus={menuItems}
Expand Down
79 changes: 65 additions & 14 deletions core/src/plugins/action.share/res/react/model/ShareModel.js
Expand Up @@ -73,24 +73,19 @@
}
}
}
if(!this._pendingData['minisite']){
this._pendingData['minisite'] = {
permissions:{},
expiration:{}
};
}
if(!this._pendingData['entries']){
this._pendingData['entries'] = [];
if(this._data['entries']){
// Deep duplicate
this._pendingData['entries'] = JSON.parse(JSON.stringify(this._data['entries']));
}
}
if(!this._pendingData['ocs_invitations']){
this._pendingData['ocs_invitations'] = [];
if(this._data["ocs"]){
this._pendingData['ocs_invitations'] = JSON.parse(JSON.stringify(this._data['ocs']['invitations']));
}
if(!this._pendingData['ocs_links']){
var links = {};
this.getOcsLinks().map(function(l){
links[l.hash] = JSON.parse(JSON.stringify(l));
});
this._pendingData['ocs_links'] = links;
}
}

Expand Down Expand Up @@ -259,9 +254,12 @@
}

getOcsLinks(){
if(this._pendingData["ocs_links"]){
return Object.values(this._pendingData["ocs_links"]);
}
if(!this._data["links"]) return [];
var result = [];
for(var key in this._data['links']){
var key, result = [];
for(key in this._data['links']){
if(!this._data['links'].hasOwnProperty(key)) continue;
if(!this._data['links'][key]['public_link']){
result.push(this._data['links'][key]);
Expand Down Expand Up @@ -441,6 +439,58 @@
/*********************************/
/* OCS DATA */
/*********************************/
createRemoteLink(host, user){
this._initPendingData();
var newId = Math.random();
this._pendingData['ocs_links'][newId] = {
hash:newId,
NEW:true,
HOST:host,
USER:user
};
this._setStatus("modified");
}

removeRemoteLink(linkId){
this._initPendingData();
if(this._pendingData["ocs_links"][linkId]){
delete this._pendingData["ocs_links"][linkId];
}
this._setStatus("modified");
}

_ocsLinksToParameters(params){
var ocsData = {
LINKS:[],
REMOVE:[]
};
if(this._pendingData["ocs_links"]){
for(var key in this._data["links"]){
if(!this._data["links"].hasOwnProperty(key) || this._data["links"][key]["public_link"]) {
continue;
}
if(!this._pendingData["ocs_links"][key]){
ocsData.REMOVE.push(key);
}
}
}
this.getOcsLinks().map(function(link){
var pLinkId = link.hash;
this._permissionsToParameters(pLinkId, link);
this._expirationsToParameters(pLinkId, link);
this._passwordAsParameter(pLinkId, link);
this._templateToParameter(pLinkId, link);
if(link.NEW){
delete link['hash'];
delete link['NEW'];
}
ocsData.LINKS.push(link);
}.bind(this));
console.log(ocsData);
params["ocs_data"] = JSON.stringify(ocsData);
}

/*
hasOcsData(){
return this._data["ocs"] ? true : false;
}
Expand Down Expand Up @@ -478,6 +528,7 @@
newData["invitations"] = this.getOcsInvitations();
params["ocs_data"] = JSON.stringify(newData);
}
*/

/*********************************/
/* GENERIC: STATUS / LOAD / SAVE */
Expand Down Expand Up @@ -562,7 +613,7 @@
this._sharedUsersToParameters(params);

// OCS LINK
// this._ocsDataToParameters(params);
this._ocsLinksToParameters(params);

PydioApi.getClient().request(params, function(transport){
var _data = transport.responseJSON;
Expand Down
4 changes: 1 addition & 3 deletions core/src/plugins/core.ocs/src/Model/RemoteShare.php
Expand Up @@ -112,7 +112,7 @@ public function buildVirtualRepository(){
// Create REPO
$parts = parse_url($this->getOcsDavUrl());
$data = array(
"DISPLAY" => $this->getDocumentName(). "[remote]",
"DISPLAY" => $this->getDocumentName(). " [remote]",
"DESCRIPTION" => "Shared by ".$this->getSender(),
"AJXP_SLUG" => "remote-".$this->getOcsToken(),
"DRIVER" => "webdav",
Expand All @@ -128,13 +128,11 @@ public function buildVirtualRepository(){
$repo = \ConfService::createRepositoryFromArray($repositoryId, $data);
$repo->setWriteable(false);
$repo->setOwnerData(null, $this->getSender()." [remote]");
/*
if($this->isDocumentIsLeaf()){
$contentFilter = new \ContentFilter(array());
$contentFilter->filters["/".$this->getDocumentName()] = "/".$this->getDocumentName();
$repo->setContentFilter($contentFilter);
}
*/
return $repo;
}

Expand Down

0 comments on commit 5a434e8

Please sign in to comment.