Completed
Push — master ( 0cff70...dba08f )
by Morris
09:32
created

Api   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 60
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B formatMount() 0 31 4
A getUserMounts() 0 11 2
1
<?php
2
/**
3
 * @author Jesús Macias <[email protected]>
4
 * @author Joas Schilling <[email protected]>
5
 * @author Morris Jobke <[email protected]>
6
 * @author Robin McCorkell <[email protected]>
7
 * @author Vincent Petry <[email protected]>
8
 *
9
 * @copyright Copyright (c) 2016, ownCloud, Inc.
10
 * @license AGPL-3.0
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
26
namespace OCA\Files_External\Lib;
27
28
class Api {
29
30
	/**
31
	 * Formats the given mount config to a mount entry.
32
	 *
33
	 * @param string $mountPoint mount point name, relative to the data dir
34
	 * @param array $mountConfig mount config to format
35
	 *
36
	 * @return array entry
37
	 */
38
	private static function formatMount($mountPoint, $mountConfig) {
39
		// strip "/$user/files" from mount point
40
		$mountPoint = explode('/', trim($mountPoint, '/'), 3);
41
		$mountPoint = $mountPoint[2];
42
43
		// split path from mount point
44
		$path = dirname($mountPoint);
45
		if ($path === '.') {
46
			$path = '';
47
		}
48
49
		$isSystemMount = !$mountConfig['personal'];
50
51
		$permissions = \OCP\Constants::PERMISSION_READ;
52
		// personal mounts can be deleted
53
		if (!$isSystemMount) {
54
			$permissions |= \OCP\Constants::PERMISSION_DELETE;
55
		}
56
57
		$entry = array(
58
			'name' => basename($mountPoint),
59
			'path' => $path,
60
			'type' => 'dir',
61
			'backend' => $mountConfig['backend'],
62
			'scope' => ( $isSystemMount ? 'system' : 'personal' ),
63
			'permissions' => $permissions,
64
			'id' => $mountConfig['id'],
65
			'class' => $mountConfig['class']
66
		);
67
		return $entry;
68
	}
69
70
	/**
71
	 * Returns the mount points visible for this user.
72
	 *
73
	 * @param array $params
74
	 * @return \OC_OCS_Result share information
75
	 */
76
	public static function getUserMounts($params) {
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
		$entries = array();
78
		$user = \OC::$server->getUserSession()->getUser()->getUID();
79
80
		$mounts = \OC_Mount_Config::getAbsoluteMountPoints($user);
81
		foreach($mounts as $mountPoint => $mount) {
82
			$entries[] = self::formatMount($mountPoint, $mount);
83
		}
84
85
		return new \OC_OCS_Result($entries);
86
	}
87
}
88