You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

358 lines
7.3 KiB

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