Completed
Pull Request — master (#55)
by Sander
01:51
created

ShareApiController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 52
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getShares() 0 5 2
A share() 0 11 2
A unshare() 0 5 1
A setpermissions() 0 5 1
1
<?php
2
/**
3
 * ownCloud - nextnote
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Ben Curtis <[email protected]>
9
 * @copyright Ben Curtis 2015
10
 */
11
12
namespace OCA\NextNote\Controller;
13
14
use \OCP\AppFramework\ApiController;
15
use \OCP\IRequest;
16
use OC\Share\Share;
17
use OCA\NextNote\Fixtures\ShareFix;
18
19
20
class ShareApiController extends ApiController {
21
22
	public function __construct($appName, IRequest $request) {
23
		parent::__construct($appName, $request);
24
	}
25
26
	/**
27
	 * @NoAdminRequired
28
	 * @NoCSRFRequired
29
	 */
30
	public function getShares($noteid, $shared_with_me, $reshares) {
31
		if ($reshares) {
32
			return array_values(Share::getItemShared('nextnote', $noteid, 'shares'));
33
		}
34
	}
35
36
	/**
37
	 * @NoAdminRequired
38
	 * @NoCSRFRequired
39
	 */
40
	public function share($noteid, $shareType, $shareWith, $publicUpload, $password, $permissions) {
41
		$shareType = intval($shareType);
42
		//Todo check if resharing is allowed
43
		if($shareType === 1){
44
			$result = ShareFix::shareItem('nextnote', intval($noteid), intval($shareType), $shareWith, intval($permissions));
45
		} else {
46
			$result = Share::shareItem('nextnote', intval($noteid), intval($shareType), $shareWith, intval($permissions));
47
		}
48
		\OC_Hook::emit('OCA\NextNote', 'post_share_note', ['note_id' => $noteid]);
49
		return $result;
50
	}
51
52
	/**
53
	 * @NoAdminRequired
54
	 * @NoCSRFRequired
55
	 */
56
	public function unshare($itemSource, $shareType, $shareWith) {
57
		$result = Share::unshare('nextnote', intval($itemSource), intval($shareType), $shareWith);
58
		\OC_Hook::emit('OCA\NextNote', 'post_unshare_note', ['note_id' => $itemSource]);
59
		return $result;
60
	}
61
62
	/**
63
	 * @NoAdminRequired
64
	 * @NoCSRFRequired
65
	 */
66
	public function setpermissions($itemSource, $shareType, $shareWith, $permissions) {
67
		$result = ShareFix::setPermissions('nextnote', intval($itemSource), intval($shareType), $shareWith, intval($permissions));
68
		\OC_Hook::emit('OCA\NextNote', 'post_update_note_share_permissions', ['note_id' => $itemSource]);
69
		return $result;
70
	}
71
}