Permalink
Browse files

Clean sharing authorizations - Add global Disable Sharing and Disable…

… Resharing parameters
  • Loading branch information...
1 parent 32cd6cc commit 2ad680fea3fb364affae658066ea516ae13447ce @cdujeu cdujeu committed Jun 28, 2016
Showing with 40 additions and 80 deletions.
  1. +2 −66 core/src/plugins/action.share/manifest.xml
  2. +38 −14 core/src/plugins/action.share/src/ShareCenter.php
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<ajxp_plugin name="share" label="CONF_MESSAGE[Sharing Features]" description="CONF_MESSAGE[Share Center actions and hooks]" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd">
<server_settings>
+ <global_param name="DISABLE_ALL_SHARING" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Disable all sharing on files or folders]" label="CONF_MESSAGE[Disable all sharing]" type="boolean" default="false" expose="false"/>
+ <global_param name="DISABLE_RESHARING" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Disallow all sharing for shared workspaces]" label="CONF_MESSAGE[Disable resharing]" type="boolean" default="false" expose="false"/>
<global_param name="ENABLE_FILE_PUBLIC_LINK" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Allow users to generate public links on files]" label="CONF_MESSAGE[Files: enable public links]" type="boolean" default="true" expose="true"/>
<global_param name="ENABLE_FILE_INTERNAL_SHARING" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Enable internal file sharing (sharing with users existing or temporary users)]" label="CONF_MESSAGE[Files: enable internal sharing]" type="boolean" mandatory="true" default="true" expose="true"/>
<global_param name="ENABLE_FOLDER_PUBLIC_LINK" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Allow users to generate public links on folders]" label="CONF_MESSAGE[Folders: enable public links]" type="boolean" default="true" expose="true"/>
@@ -105,72 +107,6 @@
<serverCallback methodName="migrateLegacyShares" restParams="/dry_run"/>
</processing>
</action>
- <!--
- <action name="share-edit-shared">
- <gui src="share.png" iconClass="icon-share" text="share_center.125" title="share_center.126">
- <context dir="true" recycle="hidden" selection="true" actionBar="true" contextMenu="true" actionBarGroup="get,info_panel_share" behaviour="hidden"/>
- <selectionContext dir="true" file="true" evalMetadata="metadata.get('ajxp_shared')" recycle="false" unique="true" behaviour="hidden"/>
- </gui>
- <processing>
- <clientCallback prepareModal="true"><![CDATA[
- ResourcesManager.detectModuleToLoadAndApply('ShareCenter', function(){
- if(!pydio.getController().shareCenter) {
- pydio.getController().shareCenter = new ShareCenter();
- }
- pydio.getController().shareCenter.performShareAction();
- });
- ]]></clientCallback>
- </processing>
- </action>
- <action name="share-file-minisite">
- <gui src="share.png" iconClass="icon-share" text="292" title="292">
- <context dir="true" recycle="hidden" selection="true" actionBar="true" contextMenu="true" actionBarGroup="get,info_panel_share" />
- <selectionContext dir="false" file="true" recycle="false" unique="true" evalMetadata="!metadata.get('ajxp_shared')" />
- </gui>
- <processing>
- <clientCallback prepareModal="true"><![CDATA[
- ResourcesManager.detectModuleToLoadAndApply('ShareCenter', function(){
- if(!pydio.getController().shareCenter) {
- pydio.getController().shareCenter = new ShareCenter();
- }
- pydio.getController().shareCenter.performShare('minisite-public');
- });
- ]]></clientCallback>
- </processing>
- </action>
- <action name="share-selection-minisite">
- <gui src="share.png" iconClass="icon-share" text="share_center.123" title="share_center.124">
- <context dir="true" recycle="false" selection="true"/>
- <selectionContext dir="false" file="true" multipleOnly="true" recycle="false" unique="false"/>
- </gui>
- <processing>
- <clientCallback prepareModal="true"><![CDATA[
- ResourcesManager.detectModuleToLoadAndApply('ShareCenter', function(){
- if(!pydio.getController().shareCenter) {
- pydio.getController().shareCenter = new ShareCenter();
- }
- pydio.getController().shareCenter.performShare('minisite-public');
- });
- ]]></clientCallback>
- </processing>
- </action>
- <action name="share-folder-minisite-public">
- <gui src="share.png" iconClass="icon-share" text="292" title="292">
- <context dir="true" recycle="hidden" selection="true" actionBar="true" contextMenu="true" actionBarGroup="get,info_panel_share"/>
- <selectionContext dir="true" file="false" recycle="false" unique="true" evalMetadata="!metadata.get('ajxp_shared')" />
- </gui>
- <processing>
- <clientCallback prepareModal="true"><![CDATA[
- ResourcesManager.detectModuleToLoadAndApply('ShareCenter', function(){
- if(!pydio.getController().shareCenter) {
- pydio.getController().shareCenter = new ShareCenter();
- }
- pydio.getController().shareCenter.performShare('minisite-public');
- });
- ]]></clientCallback>
- </processing>
- </action>
- -->
<action name="load_shared_element_data">
<processing>
<serverCallback methodName="switchAction" restParams="/file+" developerComment="Loads all current sharing data for a given resource. Workspace must support metadata management (metastore).">
@@ -119,10 +119,7 @@ public function init(ContextInterface $ctx, $options = [])
{
parent::init($ctx, $options);
if(!$ctx->hasRepository()){
- //$this->enabled = false;
return;
- }else{
- //$this->enabled = true;
}
$this->repository = $ctx->getRepository();
if (!($this->repository->getDriverInstance($ctx) instanceof \Pydio\Access\Core\IAjxpWrapperProvider)) {
@@ -145,12 +142,11 @@ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$
parent::parseSpecificContributions($ctx, $contribNode);
$disableSharing = false;
$xpathesToRemove = array();
+ $selectionContext = false;
if( strpos($ctx->getRepository()->getAccessType(), "ajxp_") === 0){
- $xpathesToRemove[] = 'action[@name="share-file-minisite"]';
- $xpathesToRemove[] = 'action[@name="share-folder-minisite-public"]';
- $xpathesToRemove[] = 'action[@name="share-edit-shared"]';
+ $disableSharing = true;
}else if (UsersService::usersEnabled()) {
@@ -166,17 +162,20 @@ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$
}
if ($disableSharing) {
// All share- actions
- $xpathesToRemove[] = 'action[contains(@name, "share-")]';
+ $xpathesToRemove[] = 'action[@name="share-edit-shared"]';
+ $xpathesToRemove[] = 'action[@name="share_react"]';
+
}else{
$folderSharingAllowed = $this->getAuthorization($ctx, "folder", "any");
$fileSharingAllowed = $this->getAuthorization($ctx, "file", "any");
- if($fileSharingAllowed === false){
- // Share file button
- $xpathesToRemove[] = 'action[@name="share-file-minisite"]';
- }
- if(!$folderSharingAllowed){
- // Share folder button
- $xpathesToRemove[] = 'action[@name="share-folder-minisite-public"]';
+ if($folderSharingAllowed && !$fileSharingAllowed){
+ $selectionContext = "dir";
+ }else if(!$folderSharingAllowed && $fileSharingAllowed){
+ $selectionContext = "file";
+ }else if(!$fileSharingAllowed && !$folderSharingAllowed){
+ // All share- actions
+ $xpathesToRemove[] = 'action[@name="share-edit-shared"]';
+ $xpathesToRemove[] = 'action[@name="share_react"]';
}
}
@@ -187,6 +186,16 @@ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$
$contribNode->removeChild($shareActionNode);
}
}
+ if(isSet($selectionContext)){
+ $actionXpath=new DOMXPath($contribNode->ownerDocument);
+ $nodeList = $actionXpath->query('action[@name="share_react"]/gui/selectionContext', $contribNode);
+ if(!$nodeList->length) return;
+ /** @var \DOMElement $selectionContextNode */
+ $selectionContextNode = $nodeList->item(0);
+ if($selectionContext == "dir") $selectionContextNode->setAttribute("file", "false");
+ else if($selectionContext == "file") $selectionContextNode->setAttribute("dir", "false");
+ }
+
}
@@ -247,6 +256,21 @@ public static function publicRoute($serverBase, $route, $params){
*/
protected function getAuthorization(ContextInterface $ctx, $nodeType, $shareType = "any"){
+ $all = $this->getContextualOption($ctx, "DISABLE_ALL_SHARING");
+ if($all){
+ return false;
+ }
+ if($ctx->getRepository()->hasParent()){
+ $p = $ctx->getRepository()->getParentRepository();
+ if(!empty($p) && !$p->isTemplate()){
+ $pContext = new Context($ctx->getRepository()->getOwner(), $p->getId());
+ $all = $this->getContextualOption($pContext, "DISABLE_RESHARING");
+ if($all){
+ return false;
+ }
+ }
+ }
+
$filesMini = $this->getContextualOption($ctx, "ENABLE_FILE_PUBLIC_LINK");
$filesInternal = $this->getContextualOption($ctx, "ENABLE_FILE_INTERNAL_SHARING");
$foldersMini = $this->getContextualOption($ctx, "ENABLE_FOLDER_PUBLIC_LINK");

0 comments on commit 2ad680f

Please sign in to comment.