permissions.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Michael Gapczynski
  6. * @copyright 2012 Michael Gapczynski mtgap@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. namespace OC\Files\Cache;
  22. class Shared_Permissions extends Permissions {
  23. /**
  24. * get the permissions for a single file
  25. *
  26. * @param int $fileId
  27. * @param string $user
  28. * @return int (-1 if file no permissions set)
  29. */
  30. public function get($fileId, $user) {
  31. if ($fileId == -1) {
  32. return \OCP\PERMISSION_READ;
  33. }
  34. $source = \OCP\Share::getItemSharedWithBySource('file', $fileId, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE,
  35. null, true);
  36. if ($source) {
  37. return $source['permissions'];
  38. } else {
  39. return -1;
  40. }
  41. }
  42. private function getFile($fileId, $user) {
  43. if ($fileId == -1) {
  44. return \OCP\PERMISSION_READ;
  45. }
  46. $source = \OCP\Share::getItemSharedWithBySource('file', $fileId, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE,
  47. null, false);
  48. if ($source) {
  49. return $source['permissions'];
  50. } else {
  51. return -1;
  52. }
  53. }
  54. /**
  55. * set the permissions of a file
  56. *
  57. * @param int $fileId
  58. * @param string $user
  59. * @param int $permissions
  60. */
  61. public function set($fileId, $user, $permissions) {
  62. // Not a valid action for Shared Permissions
  63. }
  64. /**
  65. * get the permissions of multiply files
  66. *
  67. * @param int[] $fileIds
  68. * @param string $user
  69. * @return int[]
  70. */
  71. public function getMultiple($fileIds, $user) {
  72. if (count($fileIds) === 0) {
  73. return array();
  74. }
  75. foreach ($fileIds as $fileId) {
  76. $filePermissions[$fileId] = self::get($fileId, $user);
  77. }
  78. return $filePermissions;
  79. }
  80. /**
  81. * get the permissions for all files in a folder
  82. *
  83. * @param int $parentId
  84. * @param string $user
  85. * @return int[]
  86. */
  87. public function getDirectoryPermissions($parentId, $user) {
  88. // Root of the Shared folder
  89. if ($parentId === -1) {
  90. return \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_PERMISSIONS);
  91. }
  92. $permissions = $this->getFile($parentId, $user);
  93. $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `parent` = ?');
  94. $result = $query->execute(array($parentId));
  95. $filePermissions = array();
  96. while ($row = $result->fetchRow()) {
  97. $filePermissions[$row['fileid']] = $permissions;
  98. }
  99. return $filePermissions;
  100. }
  101. /**
  102. * remove the permissions for a file
  103. *
  104. * @param int $fileId
  105. * @param string $user
  106. */
  107. public function remove($fileId, $user = null) {
  108. // Not a valid action for Shared Permissions
  109. }
  110. public function removeMultiple($fileIds, $user) {
  111. // Not a valid action for Shared Permissions
  112. }
  113. }