1
0

CloudFederationShare.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Federation;
  7. use OCP\Federation\ICloudFederationShare;
  8. use OCP\Share\IShare;
  9. class CloudFederationShare implements ICloudFederationShare {
  10. private $share = [
  11. 'shareWith' => '',
  12. 'shareType' => '',
  13. 'name' => '',
  14. 'resourceType' => '',
  15. 'description' => '',
  16. 'providerId' => '',
  17. 'owner' => '',
  18. 'ownerDisplayName' => '',
  19. 'sharedBy' => '',
  20. 'sharedByDisplayName' => '',
  21. 'protocol' => []
  22. ];
  23. /**
  24. * get a CloudFederationShare Object to prepare a share you want to send
  25. *
  26. * @param string $shareWith
  27. * @param string $name resource name (e.g. document.odt)
  28. * @param string $description share description (optional)
  29. * @param string $providerId resource UID on the provider side
  30. * @param string $owner provider specific UID of the user who owns the resource
  31. * @param string $ownerDisplayName display name of the user who shared the item
  32. * @param string $sharedBy provider specific UID of the user who shared the resource
  33. * @param string $sharedByDisplayName display name of the user who shared the resource
  34. * @param string $shareType ('group' or 'user' share)
  35. * @param string $resourceType ('file', 'calendar',...)
  36. * @param string $sharedSecret
  37. */
  38. public function __construct($shareWith = '',
  39. $name = '',
  40. $description = '',
  41. $providerId = '',
  42. $owner = '',
  43. $ownerDisplayName = '',
  44. $sharedBy = '',
  45. $sharedByDisplayName = '',
  46. $shareType = '',
  47. $resourceType = '',
  48. $sharedSecret = '',
  49. ) {
  50. $this->setShareWith($shareWith);
  51. $this->setResourceName($name);
  52. $this->setDescription($description);
  53. $this->setProviderId($providerId);
  54. $this->setOwner($owner);
  55. $this->setOwnerDisplayName($ownerDisplayName);
  56. $this->setSharedBy($sharedBy);
  57. $this->setSharedByDisplayName($sharedByDisplayName);
  58. $this->setProtocol([
  59. 'name' => 'webdav',
  60. 'options' => [
  61. 'sharedSecret' => $sharedSecret,
  62. 'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions'
  63. ]
  64. ]);
  65. $this->setShareType($shareType);
  66. $this->setResourceType($resourceType);
  67. }
  68. /**
  69. * set uid of the recipient
  70. *
  71. * @param string $user
  72. *
  73. * @since 14.0.0
  74. */
  75. public function setShareWith($user) {
  76. $this->share['shareWith'] = $user;
  77. }
  78. /**
  79. * set resource name (e.g. document.odt)
  80. *
  81. * @param string $name
  82. *
  83. * @since 14.0.0
  84. */
  85. public function setResourceName($name) {
  86. $this->share['name'] = $name;
  87. }
  88. /**
  89. * set resource type (e.g. file, calendar, contact,...)
  90. *
  91. * @param string $resourceType
  92. *
  93. * @since 14.0.0
  94. */
  95. public function setResourceType($resourceType) {
  96. $this->share['resourceType'] = $resourceType;
  97. }
  98. /**
  99. * set resource description (optional)
  100. *
  101. * @param string $description
  102. *
  103. * @since 14.0.0
  104. */
  105. public function setDescription($description) {
  106. $this->share['description'] = $description;
  107. }
  108. /**
  109. * set provider ID (e.g. file ID)
  110. *
  111. * @param string $providerId
  112. *
  113. * @since 14.0.0
  114. */
  115. public function setProviderId($providerId) {
  116. $this->share['providerId'] = $providerId;
  117. }
  118. /**
  119. * set owner UID
  120. *
  121. * @param string $owner
  122. *
  123. * @since 14.0.0
  124. */
  125. public function setOwner($owner) {
  126. $this->share['owner'] = $owner;
  127. }
  128. /**
  129. * set owner display name
  130. *
  131. * @param string $ownerDisplayName
  132. *
  133. * @since 14.0.0
  134. */
  135. public function setOwnerDisplayName($ownerDisplayName) {
  136. $this->share['ownerDisplayName'] = $ownerDisplayName;
  137. }
  138. /**
  139. * set UID of the user who sends the share
  140. *
  141. * @param string $sharedBy
  142. *
  143. * @since 14.0.0
  144. */
  145. public function setSharedBy($sharedBy) {
  146. $this->share['sharedBy'] = $sharedBy;
  147. }
  148. /**
  149. * set display name of the user who sends the share
  150. *
  151. * @param $sharedByDisplayName
  152. *
  153. * @since 14.0.0
  154. */
  155. public function setSharedByDisplayName($sharedByDisplayName) {
  156. $this->share['sharedByDisplayName'] = $sharedByDisplayName;
  157. }
  158. /**
  159. * set protocol specification
  160. *
  161. * @param array $protocol
  162. *
  163. * @since 14.0.0
  164. */
  165. public function setProtocol(array $protocol) {
  166. $this->share['protocol'] = $protocol;
  167. }
  168. /**
  169. * share type (group or user)
  170. *
  171. * @param string $shareType
  172. *
  173. * @since 14.0.0
  174. */
  175. public function setShareType($shareType) {
  176. if ($shareType === 'group' || $shareType === IShare::TYPE_REMOTE_GROUP) {
  177. $this->share['shareType'] = 'group';
  178. } else {
  179. $this->share['shareType'] = 'user';
  180. }
  181. }
  182. /**
  183. * get the whole share, ready to send out
  184. *
  185. * @return array
  186. *
  187. * @since 14.0.0
  188. */
  189. public function getShare() {
  190. return $this->share;
  191. }
  192. /**
  193. * get uid of the recipient
  194. *
  195. * @return string
  196. *
  197. * @since 14.0.0
  198. */
  199. public function getShareWith() {
  200. return $this->share['shareWith'];
  201. }
  202. /**
  203. * get resource name (e.g. file, calendar, contact,...)
  204. *
  205. * @return string
  206. *
  207. * @since 14.0.0
  208. */
  209. public function getResourceName() {
  210. return $this->share['name'];
  211. }
  212. /**
  213. * get resource type (e.g. file, calendar, contact,...)
  214. *
  215. * @return string
  216. *
  217. * @since 14.0.0
  218. */
  219. public function getResourceType() {
  220. return $this->share['resourceType'];
  221. }
  222. /**
  223. * get resource description (optional)
  224. *
  225. * @return string
  226. *
  227. * @since 14.0.0
  228. */
  229. public function getDescription() {
  230. return $this->share['description'];
  231. }
  232. /**
  233. * get provider ID (e.g. file ID)
  234. *
  235. * @return string
  236. *
  237. * @since 14.0.0
  238. */
  239. public function getProviderId() {
  240. return $this->share['providerId'];
  241. }
  242. /**
  243. * get owner UID
  244. *
  245. * @return string
  246. *
  247. * @since 14.0.0
  248. */
  249. public function getOwner() {
  250. return $this->share['owner'];
  251. }
  252. /**
  253. * get owner display name
  254. *
  255. * @return string
  256. *
  257. * @since 14.0.0
  258. */
  259. public function getOwnerDisplayName() {
  260. return $this->share['ownerDisplayName'];
  261. }
  262. /**
  263. * get UID of the user who sends the share
  264. *
  265. * @return string
  266. *
  267. * @since 14.0.0
  268. */
  269. public function getSharedBy() {
  270. return $this->share['sharedBy'];
  271. }
  272. /**
  273. * get display name of the user who sends the share
  274. *
  275. * @return string
  276. *
  277. * @since 14.0.0
  278. */
  279. public function getSharedByDisplayName() {
  280. return $this->share['sharedByDisplayName'];
  281. }
  282. /**
  283. * get share type (group or user)
  284. *
  285. * @return string
  286. *
  287. * @since 14.0.0
  288. */
  289. public function getShareType() {
  290. return $this->share['shareType'];
  291. }
  292. /**
  293. * get share Secret
  294. *
  295. * @return string
  296. *
  297. * @since 14.0.0
  298. */
  299. public function getShareSecret() {
  300. return $this->share['protocol']['options']['sharedSecret'];
  301. }
  302. /**
  303. * get protocol specification
  304. *
  305. * @return array
  306. *
  307. * @since 14.0.0
  308. */
  309. public function getProtocol() {
  310. return $this->share['protocol'];
  311. }
  312. }