summaryrefslogtreecommitdiffstats
path: root/lib/private/share20/manager.php
blob: f32d8ee3bbf772489a04b8bc829bc341b7367ca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
/**
 * @author Roeland Jago Douma <rullzer@owncloud.com>
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
namespace OC\Share20;


use OCP\IAppConfig;
use OCP\IUserManager;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\ILogger;
use OCP\Files\Folder;

use OC\Share20\Exceptions\ShareNotFoundException;
use OC\Share20\Exception\PreconditionFailed;

/**
 * This class is the communication hub for all sharing related operations.
 */
class Manager {

	/**
	 * @var IShareProvider[]
	 */
	private $shareProviders;

	/**
	 * @var string[]
	 */
	private $shareTypeToProviderId;

	/** @var IUser */
	private $currentUser;

	/** @var IUserManager */
	private $userManager;

	/** @var IGroupManager */
	private $groupManager;

	/** @var ILogger */
	private $logger;

	/** @var IAppConfig */
	private $appConfig;

	/** @var IFolder */
	private $userFolder;

	public function __construct(IUser $user,
								IUserManager $userManager,
								IGroupManager $groupManager,
								ILogger $logger,
								IAppConfig $appConfig,
								Folder $userFolder,
								IShareProvider $defaultProvider) {
		$this->currentUser = $user;
		$this->userManager = $userManager;
		$this->groupManager = $groupManager;
		$this->logger = $logger;
		$this->appConfig = $appConfig;
		$this->userFolder = $userFolder;

		// TEMP SOLUTION JUST TO GET STARTED
		$this->shareProviders['ocdef'] = $defaultProvider;
		$this->shareTypeToProviderId = [
			\OCP\Share::SHARE_TYPE_USER  => 'ocdef',
			\OCP\Share::SHARE_TYPE_GROUP => 'ocdef',
			\OCP\Share::SHARE_TYPE_LINK  => 'ocdef',
		];

		// TODO: Get storage share provider from primary storage
	}

	/**
	 * Get a ShareProvider
	 *
	 * @param string $id
	 * @return IShareProvider
	 */
	private function getShareProvider($id) {
		if (!isset($this->shareProviders[$id])) {
			//Throw exception;
		}

		// Check if we have instanciated this provider yet
		if (!($this->shareProviders[$id] instanceOf \OC\Share20\IShareProvider)) {
			throw new \Exception();
		}

		return $this->shareProviders[$id];
	}

	/**
	 * Get shareProvider based on shareType
	 *
	 * @param int $shareType
	 * @return IShareProvider
	 */
	private function getShareProviderByType($shareType) {
		if (!isset($this->shareTypeToProviderId[$shareType])) {
			//Throw exception
		}

		return $this->getShareProvider($this->shareTypeToProviderId[$shareType]);
	}

	/**
	 * Share a path
	 * 
	 * @param Share $share
	 * @return Share The share object
	 */
	public function createShare(Share $share) {
		throw new \Exception();
	}

	/**
	 * Update a share
	 *
	 * @param Share $share
	 * @return Share The share object
	 */
	public function updateShare(Share $share) {
		throw new \Exception();
	}

	/**
	 * Delete a share
	 *
	 * @param Share $share
	 */
	public function deleteShare(Share $share) {
		throw new \Exception();
	}

	/**
	 * Retrieve all shares by the current user
	 *
	 * @param int $page
	 * @param int $perPage
	 * @return Share[]
	 */
	public function getShares($page=0, $perPage=50) {
		throw new \Exception();
	}

	/**
	 * Retrieve a share by the share id
	 *
	 * @param string $id
	 * @return Share
	 *
	 * @throws ShareNotFoundException
	 */
	public function getShareById($id) {
		throw new \Exception();
	}

	/**
	 * Get all the shares for a given path
	 *
	 * @param \OCP\Files\Node $path
	 * @param int $page
	 * @param int $perPage
	 *
	 * @return Share[]
	 */
	public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) {
		throw new \Exception();
	}

	/**
	 * Get all shares that are shared with the current user
	 *
	 * @param int $shareType
	 * @param int $page
	 * @param int $perPage
	 *
	 * @return Share[]
	 */
	public function getSharedWithMe($shareType = null, $page=0, $perPage=50) {
		throw new \Exception();
	}

	/**
	 * Get the share by token possible with password
	 *
	 * @param string $token
	 * @param string $password
	 *
	 * @return Share
	 *
	 * @throws ShareNotFoundException
	 */
	public function getShareByToken($token, $password=null) {
		throw new \Exception();
	}

	/**
	 * Get access list to a path. This means
	 * all the users and groups that can access a given path.
	 *
	 * Consider:
	 * -root
	 * |-folder1
	 *  |-folder2
	 *   |-fileA
	 *
	 * fileA is shared with user1
	 * folder2 is shared with group2
	 * folder1 is shared with user2
	 *
	 * Then the access list will to '/folder1/folder2/fileA' is:
	 * [
	 * 	'users' => ['user1', 'user2'],
	 *  'groups' => ['group2']
	 * ]
	 *
	 * This is required for encryption
	 *
	 * @param \OCP\Files\Node $path
	 */
	public function getAccessList(\OCP\Files\Node $path) {
		throw new \Exception();
	}
}