- Introduce isShared() and isMounted() on FileInfo class
- Reuse these methods on determineIcon() - Generate permission string for the desktop client - expose {http://owncloud.org/ns}permissions as additional WebDAV property containing the permission string
This commit is contained in:
parent
49d9631eee
commit
c92c577b5e
|
@ -27,21 +27,12 @@ class Helper
|
||||||
*/
|
*/
|
||||||
public static function determineIcon($file) {
|
public static function determineIcon($file) {
|
||||||
if($file['type'] === 'dir') {
|
if($file['type'] === 'dir') {
|
||||||
$dir = $file['directory'];
|
|
||||||
$icon = \OC_Helper::mimetypeIcon('dir');
|
$icon = \OC_Helper::mimetypeIcon('dir');
|
||||||
$absPath = $file->getPath();
|
if ($file->isShared()) {
|
||||||
$mount = \OC\Files\Filesystem::getMountManager()->find($absPath);
|
|
||||||
if (!is_null($mount)) {
|
|
||||||
$sid = $mount->getStorageId();
|
|
||||||
if (!is_null($sid)) {
|
|
||||||
$sid = explode(':', $sid);
|
|
||||||
if ($sid[0] === 'shared') {
|
|
||||||
$icon = \OC_Helper::mimetypeIcon('dir-shared');
|
$icon = \OC_Helper::mimetypeIcon('dir-shared');
|
||||||
} elseif ($sid[0] !== 'local' and $sid[0] !== 'home') {
|
} elseif ($file->isMounted()) {
|
||||||
$icon = \OC_Helper::mimetypeIcon('dir-external');
|
$icon = \OC_Helper::mimetypeIcon('dir-external');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
$icon = \OC_Helper::mimetypeIcon($file->getMimetype());
|
$icon = \OC_Helper::mimetypeIcon($file->getMimetype());
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin
|
||||||
|
|
||||||
$server->xmlNamespaces[self::NS_OWNCLOUD] = 'oc';
|
$server->xmlNamespaces[self::NS_OWNCLOUD] = 'oc';
|
||||||
$server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}id';
|
$server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}id';
|
||||||
|
$server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}permissions';
|
||||||
|
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties'));
|
$this->server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties'));
|
||||||
|
@ -57,15 +58,24 @@ class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin
|
||||||
|
|
||||||
if ($node instanceof OC_Connector_Sabre_Node) {
|
if ($node instanceof OC_Connector_Sabre_Node) {
|
||||||
|
|
||||||
$fileid_propertyname = '{' . self::NS_OWNCLOUD . '}id';
|
$fileIdPropertyName = '{' . self::NS_OWNCLOUD . '}id';
|
||||||
if (array_search($fileid_propertyname, $requestedProperties)) {
|
$permissionsPropertyName = '{' . self::NS_OWNCLOUD . '}permissions';
|
||||||
unset($requestedProperties[array_search($fileid_propertyname, $requestedProperties)]);
|
if (array_search($fileIdPropertyName, $requestedProperties)) {
|
||||||
|
unset($requestedProperties[array_search($fileIdPropertyName, $requestedProperties)]);
|
||||||
|
}
|
||||||
|
if (array_search($permissionsPropertyName, $requestedProperties)) {
|
||||||
|
unset($requestedProperties[array_search($permissionsPropertyName, $requestedProperties)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var $node OC_Connector_Sabre_Node */
|
/** @var $node OC_Connector_Sabre_Node */
|
||||||
$fileId = $node->getFileId();
|
$fileId = $node->getFileId();
|
||||||
if (!is_null($fileId)) {
|
if (!is_null($fileId)) {
|
||||||
$returnedProperties[200][$fileid_propertyname] = $fileId;
|
$returnedProperties[200][$fileIdPropertyName] = $fileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
$permissions = $node->getDavPermissions();
|
||||||
|
if (!is_null($fileId)) {
|
||||||
|
$returnedProperties[200][$permissionsPropertyName] = $permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,4 +237,33 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getDavPermissions() {
|
||||||
|
$p ='';
|
||||||
|
if ($this->info->isShared()) {
|
||||||
|
$p .= 'S';
|
||||||
|
}
|
||||||
|
if ($this->info->isShareable()) {
|
||||||
|
$p .= 'R';
|
||||||
|
}
|
||||||
|
if ($this->info->isMounted()) {
|
||||||
|
$p .= 'M';
|
||||||
|
}
|
||||||
|
if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
|
||||||
|
if ($this->info->isUpdateable()) {
|
||||||
|
$p .= 'W';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($this->info->isDeletable()) {
|
||||||
|
$p .= 'D';
|
||||||
|
}
|
||||||
|
if ($this->info->isUpdateable()) {
|
||||||
|
$p .= 'CK';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,4 +196,28 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
|
||||||
public function isShareable() {
|
public function isShareable() {
|
||||||
return $this->checkPermissions(\OCP\PERMISSION_SHARE);
|
return $this->checkPermissions(\OCP\PERMISSION_SHARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a file or folder is shared
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isShared() {
|
||||||
|
$sid = $this->getStorage()->getId();
|
||||||
|
if (!is_null($sid)) {
|
||||||
|
$sid = explode(':', $sid);
|
||||||
|
return ($sid[0] === 'shared');
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isMounted() {
|
||||||
|
$sid = $this->getStorage()->getId();
|
||||||
|
if (!is_null($sid)) {
|
||||||
|
$sid = explode(':', $sid);
|
||||||
|
return ($sid[0] !== 'local' and $sid[0] !== 'home');
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,4 +135,18 @@ interface FileInfo {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isShareable();
|
public function isShareable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a file or folder is shared
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isShared();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a file or folder is mounted
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isMounted();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue