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

Commit

Permalink
Implement accept / decline remote shares.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Mar 1, 2016
1 parent 855b780 commit 698e1e4
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 24 deletions.
10 changes: 10 additions & 0 deletions core/src/plugins/action.share/class.CompositeShare.php
Expand Up @@ -134,6 +134,16 @@ public function toJson($watcher, $rightsManager, $publicAccessManager, $messages
);
$jsonData["links"] = array();
foreach ($this->shareLinks as $shareLink) {
$uniqueUser = $shareLink->getUniqueUser();
$found = false;
foreach($sharedEntries as $entry){
if($entry["ID"] == $uniqueUser) $found = true;
}
if(!$found){
// STRANGE, THE ASSOCIATED USER IS MISSING
error_log("Found shareLink orphan with uniqueUser ".$uniqueUser);
continue;
}
$jsonData["links"][$shareLink->getHash()] = $shareLink->getJsonData($publicAccessManager, $messages);
}
return $jsonData;
Expand Down
3 changes: 3 additions & 0 deletions core/src/plugins/action.share/res/react-share-form.css
Expand Up @@ -267,6 +267,9 @@ div#react_share_form div.user-badge div.user-badge-menu-box div.mui-menu span.ic
div#react_share_form div.user-badge span.user-badge-rights-container {
float: right;
padding: 11px;
color: gray;
font-size: 11px;
line-height: 25px;
}
div#react_share_form div.user-badge span.user-badge-rights-container input[name="write"] {
margin-left: 28px;
Expand Down
3 changes: 3 additions & 0 deletions core/src/plugins/action.share/res/react-share-form.less
Expand Up @@ -295,6 +295,9 @@ div#react_share_form {
span.user-badge-rights-container {
float: right;
padding: 11px;
color: gray;
font-size: 11px;
line-height: 25px;
input[name="write"] {
margin-left: 28px;
}
Expand Down
46 changes: 27 additions & 19 deletions core/src/plugins/action.share/res/react/ShareDialog.js
Expand Up @@ -634,26 +634,22 @@
});
},

buildLabel: function(){
getStatus:function(){
var link = this.props.linkData;
if(!link.invitation) return -1;
else return link.invitation.STATUS;
},

var status;
if(!link.invitation){
status = '214';
}else {
if(link.invitation.STATUS == 1){
status = '211';
}else if(link.invitation.STATUS == 2){
status = '212';
}else if(link.invitation.STATUS == 4){
status = '213';
}
}
status = this.context.getMessage(status);
getStatusString: function(){
const statuses = {'s-1':214, 's1':211, 's2':212, 's4':213};
return this.context.getMessage(statuses['s'+this.getStatus()]);
},

buildLabel: function(){
var link = this.props.linkData;
var host = link.HOST || link.invitation.HOST;
var user = link.USER || link.invitation.USER;
return user + " @ " + host + " (" + status + ")";
return user + " @ " + host ;
},

removeUser: function(){
Expand All @@ -673,17 +669,29 @@
callback:this.removeUser
}];
}
var status = this.getStatus();
var additionalItem;
if(status == 2){
additionalItem = (
<span className="user-badge-rights-container">
<input type="checkbox" name="read" disabled={this.context.isReadonly()} checked={this.state.internalUser.RIGHT.indexOf('r') !== -1} onChange={this.onUpdateRight}/>
<input type="checkbox" name="write" disabled={this.context.isReadonly()} checked={this.state.internalUser.RIGHT.indexOf('w') !== -1} onChange={this.onUpdateRight}/>
</span>
);
}else{
additionalItem = (
<span className="user-badge-rights-container">{this.getStatusString()}</span>
);
}

return (
<UserBadge
label={this.buildLabel()}
avatar={null}
type={"remote_user"}
menus={menuItems}
>
<span className="user-badge-rights-container">
<input type="checkbox" name="read" disabled={this.context.isReadonly()} checked={this.state.internalUser.RIGHT.indexOf('r') !== -1} onChange={this.onUpdateRight}/>
<input type="checkbox" name="write" disabled={this.context.isReadonly()} checked={this.state.internalUser.RIGHT.indexOf('w') !== -1} onChange={this.onUpdateRight}/>
</span>
{additionalItem}
</UserBadge>
);
}
Expand Down
Expand Up @@ -426,7 +426,6 @@
}

_permissionsToParameters(linkId, params, isSharedLink = false){
console.log(linkId);
if(this.getPublicLinkPermission(linkId, 'read')){
params['simple_right_read'] = 'on';
}
Expand Down
71 changes: 71 additions & 0 deletions core/src/plugins/core.ocs/ActionsController.php
@@ -0,0 +1,71 @@
<?php
/*
* Copyright 2007-2015 Abstrium <contact (at) pydio.com>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*/

namespace Pydio\OCS;
use Pydio\OCS\Client\OCSClient;
use Pydio\OCS\Model\SQLStore;

defined('AJXP_EXEC') or die('Access not allowed');


class ActionsController
{
public function switchActions($actionName, $httpVars, $fileVars){

switch($actionName){

case "accept_invitation":

$remoteShareId = \AJXP_Utils::sanitize($httpVars["remote_share_id"], AJXP_SANITIZE_ALPHANUM);
$store = new SQLStore();
$remoteShare = $store->remoteShareById($remoteShareId);
if($remoteShare !== null){
$client = new OCSClient();
$client->acceptInvitation($remoteShare);
$remoteShare->setStatus(OCS_INVITATION_STATUS_ACCEPTED);
$store->storeRemoteShare($remoteShare);
}

break;

case "reject_invitation":

$remoteShareId = \AJXP_Utils::sanitize($httpVars["remote_share_id"], AJXP_SANITIZE_ALPHANUM);
$store = new SQLStore();
$remoteShare = $store->remoteShareById($remoteShareId);
if($remoteShare !== null){
$client = new OCSClient();
$client->declineInvitation($remoteShare);
$store->deleteRemoteShare($remoteShare);
\ConfService::getInstance()->invalidateLoadedRepositories();
}

break;
default:
break;
}

return null;

}


}
18 changes: 18 additions & 0 deletions core/src/plugins/core.ocs/OCSPlugin.php
Expand Up @@ -20,6 +20,7 @@
*/
namespace Pydio\OCS;

use Aws\AutoScaling\Exception\ScalingActivityInProgressException;
use Pydio\OCS\Server\Dummy;

defined('AJXP_EXEC') or die('Access not allowed');
Expand All @@ -28,13 +29,30 @@

class OCSPlugin extends \AJXP_Plugin{

/**
* @var ActionsController $controller
*/
protected $controller;

public function init($options)
{
parent::init($options);
\AJXP_Controller::registerIncludeHook("repository.list", array($this, "populateRemotes"));
\AJXP_Controller::registerIncludeHook("repository.search", array($this, "remoteRepositoryById"));
}

protected function getController(){
if($this->controller == null){
require_once ("ActionsController.php");
$this->controller = new ActionsController();
}
return $this->controller;
}

public function applyActions($actionName, $httpVars, $fileVars){
return $this->getController()->switchActions($actionName, $httpVars, $fileVars);
}

public function federatedEnabled(){
return $this->getConfigs()["ENABLE_FEDERATED_SHARING"] === true;
}
Expand Down
14 changes: 14 additions & 0 deletions core/src/plugins/core.ocs/manifest.xml
Expand Up @@ -11,4 +11,18 @@
<global_param name="ENABLE_FEDERATED_SHARING" type="boolean" label="CONF_MESSAGE[Enable Federated Sharing]"
description="CONF_MESSAGE[Enable Federated Sharing]" default="true" mandatory="true" expose="true"/>
</server_settings>
<registry_contributions>
<actions>
<action name="accept_invitation">
<processing>
<serverCallback methodName="applyActions" restParams="/remote_share_id" />
</processing>
</action>
<action name="reject_invitation">
<processing>
<serverCallback methodName="applyActions" restParams="/remote_share_id" />
</processing>
</action>
</actions>
</registry_contributions>
</ajxp_plugin>
4 changes: 2 additions & 2 deletions core/src/plugins/core.ocs/src/Client/OCSClient.php
Expand Up @@ -117,7 +117,7 @@ public function cancelInvitation(ShareInvitation $invitation)
public function acceptInvitation(RemoteShare $remoteShare)
{
$client = new GuzzleClient([
'base_url' => $remoteShare->getOcsServiceUrl()
'base_url' => $remoteShare->getOcsServiceUrl()."/"
]);

$response = $client->post($remoteShare->getOcsRemoteId() . '/accept', [
Expand All @@ -144,7 +144,7 @@ public function acceptInvitation(RemoteShare $remoteShare)
public function declineInvitation(RemoteShare $remoteShare)
{
$client = new GuzzleClient([
'base_url' => $remoteShare->getOcsServiceUrl()
'base_url' => $remoteShare->getOcsServiceUrl()."/"
]);

$response = $client->post($remoteShare->getOcsRemoteId() . '/decline', [
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/core.ocs/src/Model/IStore.php
Expand Up @@ -44,7 +44,7 @@ public function invitationsForLink($linkToken);
* @param $invitationId
* @return ShareInvitation|null
*/
public function invitationById(string $invitationId);
public function invitationById($invitationId);

/**
* Delete an invitation
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/core.ocs/src/Model/SQLStore.php
Expand Up @@ -72,7 +72,7 @@ public function invitationsForLink($linkToken)
* @param $invitationId
* @return ShareInvitation|null
*/
public function invitationById(string $invitationId)
public function invitationById($invitationId)
{
$this->storage->simpleStoreGet(OCS_SQLSTORE_NS_INVITATION, $invitationId, OCS_SQLSTORE_FORMAT, $data);
return $data;
Expand Down
27 changes: 27 additions & 0 deletions core/src/plugins/core.ocs/src/Server/Federated/Server.php
Expand Up @@ -104,10 +104,37 @@ protected function actionReceive($parameters){

protected function actionAccept($remoteId, $token, $parameters){

$store = new SQLStore();
$invitation = $store->invitationById($remoteId);
if(empty($invitation)){
throw new InvalidArgumentsException();
}
if($token !== $invitation->getLinkHash()){
throw new InvalidArgumentsException();
}
$invitation->setStatus(OCS_INVITATION_STATUS_ACCEPTED);
$store->storeInvitation($invitation);
$response = $this->buildResponse("ok", 200, "Successfully accepted invitation", array("remoteId" => $remoteId));
$this->sendResponse($response, $this->getFormat($parameters));


}

protected function actionDecline($remoteId, $token, $parameters){

$store = new SQLStore();
$invitation = $store->invitationById($remoteId);
if(empty($invitation)){
throw new InvalidArgumentsException();
}
if($token !== $invitation->getLinkHash()){
throw new InvalidArgumentsException();
}
$invitation->setStatus(OCS_INVITATION_STATUS_REJECTED);
$store->storeInvitation($invitation);
$response = $this->buildResponse("ok", 200, "Successfully rejected invitation", array("remoteId" => $remoteId));
$this->sendResponse($response, $this->getFormat($parameters));

}

protected function actionUnshare($remoteId, $token, $parameters){
Expand Down

0 comments on commit 698e1e4

Please sign in to comment.