permissions.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /**
  43. * set the permissions of a file
  44. *
  45. * @param int $fileId
  46. * @param string $user
  47. * @param int $permissions
  48. */
  49. public function set($fileId, $user, $permissions) {
  50. // Not a valid action for Shared Permissions
  51. }
  52. /**
  53. * get the permissions of multiply files
  54. *
  55. * @param int[] $fileIds
  56. * @param string $user
  57. * @return int[]
  58. */
  59. public function getMultiple($fileIds, $user) {
  60. if (count($fileIds) === 0) {
  61. return array();
  62. }
  63. foreach ($fileIds as $fileId) {
  64. $filePermissions[$fileId] = self::get($fileId, $user);
  65. }
  66. return $filePermissions;
  67. }
  68. /**
  69. * get the permissions for all files in a folder
  70. *
  71. * @param int $parentId
  72. * @param string $user
  73. * @return int[]
  74. */
  75. public function getDirectoryPermissions($parentId, $user) {
  76. // Root of the Shared folder
  77. if ($parentId === -1) {
  78. return \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_PERMISSIONS);
  79. }
  80. $permissions = $this->get($parentId, $user);
  81. $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `parent` = ?');
  82. $result = $query->execute(array($parentId));
  83. $filePermissions = array();
  84. while ($row = $result->fetchRow()) {
  85. $filePermissions[$row['fileid']] = $permissions;
  86. }
  87. return $filePermissions;
  88. }
  89. /**
  90. * remove the permissions for a file
  91. *
  92. * @param int $fileId
  93. * @param string $user
  94. */
  95. public function remove($fileId, $user = null) {
  96. // Not a valid action for Shared Permissions
  97. }
  98. public function removeMultiple($fileIds, $user) {
  99. // Not a valid action for Shared Permissions
  100. }
  101. }