CloudFederationShare.php 7.2 KB

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