Completed
Pull Request — master (#9550)
by Georg
18:24
created
apps/dav/appinfo/v1/carddav.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -35,20 +35,20 @@  discard block
 block discarded – undo
35 35
 use Sabre\CardDAV\Plugin;
36 36
 
37 37
 $authBackend = new Auth(
38
-	\OC::$server->getSession(),
39
-	\OC::$server->getUserSession(),
40
-	\OC::$server->getRequest(),
41
-	\OC::$server->getTwoFactorAuthManager(),
42
-	\OC::$server->getBruteForceThrottler(),
43
-	'principals/'
38
+    \OC::$server->getSession(),
39
+    \OC::$server->getUserSession(),
40
+    \OC::$server->getRequest(),
41
+    \OC::$server->getTwoFactorAuthManager(),
42
+    \OC::$server->getBruteForceThrottler(),
43
+    'principals/'
44 44
 );
45 45
 $principalBackend = new Principal(
46
-	\OC::$server->getUserManager(),
47
-	\OC::$server->getGroupManager(),
48
-	\OC::$server->getShareManager(),
49
-	\OC::$server->getUserSession(),
50
-	\OC::$server->getConfig(),
51
-	'principals/'
46
+    \OC::$server->getUserManager(),
47
+    \OC::$server->getGroupManager(),
48
+    \OC::$server->getShareManager(),
49
+    \OC::$server->getUserSession(),
50
+    \OC::$server->getConfig(),
51
+    'principals/'
52 52
 );
53 53
 $db = \OC::$server->getDatabaseConnection();
54 54
 $cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->getEventDispatcher());
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 $addressBookRoot->disableListing = !$debugging; // Disable listing
64 64
 
65 65
 $nodes = array(
66
-	$principalCollection,
67
-	$addressBookRoot,
66
+    $principalCollection,
67
+    $addressBookRoot,
68 68
 );
69 69
 
70 70
 // Fire up server
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 
80 80
 $server->addPlugin(new LegacyDAVACL());
81 81
 if ($debugging) {
82
-	$server->addPlugin(new Sabre\DAV\Browser\Plugin());
82
+    $server->addPlugin(new Sabre\DAV\Browser\Plugin());
83 83
 }
84 84
 
85 85
 $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
Please login to merge, or discard this patch.
apps/dav/appinfo/v1/caldav.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -34,20 +34,20 @@  discard block
 block discarded – undo
34 34
 use OCA\DAV\Connector\Sabre\Principal;
35 35
 
36 36
 $authBackend = new Auth(
37
-	\OC::$server->getSession(),
38
-	\OC::$server->getUserSession(),
39
-	\OC::$server->getRequest(),
40
-	\OC::$server->getTwoFactorAuthManager(),
41
-	\OC::$server->getBruteForceThrottler(),
42
-	'principals/'
37
+    \OC::$server->getSession(),
38
+    \OC::$server->getUserSession(),
39
+    \OC::$server->getRequest(),
40
+    \OC::$server->getTwoFactorAuthManager(),
41
+    \OC::$server->getBruteForceThrottler(),
42
+    'principals/'
43 43
 );
44 44
 $principalBackend = new Principal(
45
-	\OC::$server->getUserManager(),
46
-	\OC::$server->getGroupManager(),
47
-	\OC::$server->getShareManager(),
48
-	\OC::$server->getUserSession(),
49
-	\OC::$server->getConfig(),
50
-	'principals/'
45
+    \OC::$server->getUserManager(),
46
+    \OC::$server->getGroupManager(),
47
+    \OC::$server->getShareManager(),
48
+    \OC::$server->getUserSession(),
49
+    \OC::$server->getConfig(),
50
+    'principals/'
51 51
 );
52 52
 $db = \OC::$server->getDatabaseConnection();
53 53
 $userManager = \OC::$server->getUserManager();
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
 $addressBookRoot->disableListing = !$debugging; // Disable listing
68 68
 
69 69
 $nodes = array(
70
-	$principalCollection,
71
-	$addressBookRoot,
70
+    $principalCollection,
71
+    $addressBookRoot,
72 72
 );
73 73
 
74 74
 // Fire up server
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 
85 85
 $server->addPlugin(new LegacyDAVACL());
86 86
 if ($debugging) {
87
-	$server->addPlugin(new Sabre\DAV\Browser\Plugin());
87
+    $server->addPlugin(new Sabre\DAV\Browser\Plugin());
88 88
 }
89 89
 
90 90
 $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
93 93
 
94 94
 if ($sendInvitations) {
95
-	$server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
95
+    $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
96 96
 }
97 97
 $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger()));
98 98
 
Please login to merge, or discard this patch.
apps/dav/lib/Command/CreateCalendar.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -35,57 +35,57 @@
 block discarded – undo
35 35
 
36 36
 class CreateCalendar extends Command {
37 37
 
38
-	/** @var IUserManager */
39
-	protected $userManager;
38
+    /** @var IUserManager */
39
+    protected $userManager;
40 40
 
41
-	/** @var IGroupManager $groupManager */
42
-	private $groupManager;
41
+    /** @var IGroupManager $groupManager */
42
+    private $groupManager;
43 43
 
44
-	/** @var \OCP\IDBConnection */
45
-	protected $dbConnection;
44
+    /** @var \OCP\IDBConnection */
45
+    protected $dbConnection;
46 46
 
47
-	/**
48
-	 * @param IUserManager $userManager
49
-	 * @param IGroupManager $groupManager
50
-	 * @param IDBConnection $dbConnection
51
-	 */
52
-	function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
53
-		parent::__construct();
54
-		$this->userManager = $userManager;
55
-		$this->groupManager = $groupManager;
56
-		$this->dbConnection = $dbConnection;
57
-	}
47
+    /**
48
+     * @param IUserManager $userManager
49
+     * @param IGroupManager $groupManager
50
+     * @param IDBConnection $dbConnection
51
+     */
52
+    function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
53
+        parent::__construct();
54
+        $this->userManager = $userManager;
55
+        $this->groupManager = $groupManager;
56
+        $this->dbConnection = $dbConnection;
57
+    }
58 58
 
59
-	protected function configure() {
60
-		$this
61
-			->setName('dav:create-calendar')
62
-			->setDescription('Create a dav calendar')
63
-			->addArgument('user',
64
-				InputArgument::REQUIRED,
65
-				'User for whom the calendar will be created')
66
-			->addArgument('name',
67
-				InputArgument::REQUIRED,
68
-				'Name of the calendar');
69
-	}
59
+    protected function configure() {
60
+        $this
61
+            ->setName('dav:create-calendar')
62
+            ->setDescription('Create a dav calendar')
63
+            ->addArgument('user',
64
+                InputArgument::REQUIRED,
65
+                'User for whom the calendar will be created')
66
+            ->addArgument('name',
67
+                InputArgument::REQUIRED,
68
+                'Name of the calendar');
69
+    }
70 70
 
71
-	protected function execute(InputInterface $input, OutputInterface $output) {
72
-		$user = $input->getArgument('user');
73
-		if (!$this->userManager->userExists($user)) {
74
-			throw new \InvalidArgumentException("User <$user> in unknown.");
75
-		}
76
-		$principalBackend = new Principal(
77
-			$this->userManager,
78
-			$this->groupManager,
79
-			\OC::$server->getShareManager(),
80
-			\OC::$server->getUserSession(),
81
-			\OC::$server->getConfig()
82
-		);
83
-		$random = \OC::$server->getSecureRandom();
84
-		$logger = \OC::$server->getLogger();
85
-		$dispatcher = \OC::$server->getEventDispatcher();
71
+    protected function execute(InputInterface $input, OutputInterface $output) {
72
+        $user = $input->getArgument('user');
73
+        if (!$this->userManager->userExists($user)) {
74
+            throw new \InvalidArgumentException("User <$user> in unknown.");
75
+        }
76
+        $principalBackend = new Principal(
77
+            $this->userManager,
78
+            $this->groupManager,
79
+            \OC::$server->getShareManager(),
80
+            \OC::$server->getUserSession(),
81
+            \OC::$server->getConfig()
82
+        );
83
+        $random = \OC::$server->getSecureRandom();
84
+        $logger = \OC::$server->getLogger();
85
+        $dispatcher = \OC::$server->getEventDispatcher();
86 86
 
87
-		$name = $input->getArgument('name');
88
-		$caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $this->groupManager, $random, $logger, $dispatcher);
89
-		$caldav->createCalendar("principals/users/$user", $name, []);
90
-	}
87
+        $name = $input->getArgument('name');
88
+        $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $this->groupManager, $random, $logger, $dispatcher);
89
+        $caldav->createCalendar("principals/users/$user", $name, []);
90
+    }
91 91
 }
Please login to merge, or discard this patch.
apps/dav/lib/RootCollection.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -37,95 +37,95 @@
 block discarded – undo
37 37
 
38 38
 class RootCollection extends SimpleCollection {
39 39
 
40
-	public function __construct() {
41
-		$config = \OC::$server->getConfig();
42
-		$l10n = \OC::$server->getL10N('dav');
43
-		$random = \OC::$server->getSecureRandom();
44
-		$logger = \OC::$server->getLogger();
45
-		$userManager = \OC::$server->getUserManager();
46
-		$groupManager = \OC::$server->getGroupManager();
47
-		$shareManager = \OC::$server->getShareManager();
48
-		$db = \OC::$server->getDatabaseConnection();
49
-		$dispatcher = \OC::$server->getEventDispatcher();
50
-		$userPrincipalBackend = new Principal(
51
-			$userManager,
52
-			$groupManager,
53
-			$shareManager,
54
-			\OC::$server->getUserSession(),
55
-			$config
56
-		);
57
-		$groupPrincipalBackend = new GroupPrincipalBackend($groupManager);
58
-		// as soon as debug mode is enabled we allow listing of principals
59
-		$disableListing = !$config->getSystemValue('debug', false);
40
+    public function __construct() {
41
+        $config = \OC::$server->getConfig();
42
+        $l10n = \OC::$server->getL10N('dav');
43
+        $random = \OC::$server->getSecureRandom();
44
+        $logger = \OC::$server->getLogger();
45
+        $userManager = \OC::$server->getUserManager();
46
+        $groupManager = \OC::$server->getGroupManager();
47
+        $shareManager = \OC::$server->getShareManager();
48
+        $db = \OC::$server->getDatabaseConnection();
49
+        $dispatcher = \OC::$server->getEventDispatcher();
50
+        $userPrincipalBackend = new Principal(
51
+            $userManager,
52
+            $groupManager,
53
+            $shareManager,
54
+            \OC::$server->getUserSession(),
55
+            $config
56
+        );
57
+        $groupPrincipalBackend = new GroupPrincipalBackend($groupManager);
58
+        // as soon as debug mode is enabled we allow listing of principals
59
+        $disableListing = !$config->getSystemValue('debug', false);
60 60
 
61
-		// setup the first level of the dav tree
62
-		$userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
63
-		$userPrincipals->disableListing = $disableListing;
64
-		$groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
65
-		$groupPrincipals->disableListing = $disableListing;
66
-		$systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
67
-		$systemPrincipals->disableListing = $disableListing;
68
-		$filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
69
-		$filesCollection->disableListing = $disableListing;
70
-		$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher);
71
-		$calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
72
-		$calendarRoot->disableListing = $disableListing;
73
-		$publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config);
74
-		$publicCalendarRoot->disableListing = $disableListing;
61
+        // setup the first level of the dav tree
62
+        $userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
63
+        $userPrincipals->disableListing = $disableListing;
64
+        $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
65
+        $groupPrincipals->disableListing = $disableListing;
66
+        $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
67
+        $systemPrincipals->disableListing = $disableListing;
68
+        $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
69
+        $filesCollection->disableListing = $disableListing;
70
+        $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher);
71
+        $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
72
+        $calendarRoot->disableListing = $disableListing;
73
+        $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config);
74
+        $publicCalendarRoot->disableListing = $disableListing;
75 75
 
76
-		$systemTagCollection = new SystemTag\SystemTagsByIdCollection(
77
-			\OC::$server->getSystemTagManager(),
78
-			\OC::$server->getUserSession(),
79
-			$groupManager
80
-		);
81
-		$systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
82
-			\OC::$server->getSystemTagManager(),
83
-			\OC::$server->getSystemTagObjectMapper(),
84
-			\OC::$server->getUserSession(),
85
-			$groupManager,
86
-			\OC::$server->getEventDispatcher()
87
-		);
88
-		$commentsCollection = new Comments\RootCollection(
89
-			\OC::$server->getCommentsManager(),
90
-			$userManager,
91
-			\OC::$server->getUserSession(),
92
-			\OC::$server->getEventDispatcher(),
93
-			\OC::$server->getLogger()
94
-		);
76
+        $systemTagCollection = new SystemTag\SystemTagsByIdCollection(
77
+            \OC::$server->getSystemTagManager(),
78
+            \OC::$server->getUserSession(),
79
+            $groupManager
80
+        );
81
+        $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
82
+            \OC::$server->getSystemTagManager(),
83
+            \OC::$server->getSystemTagObjectMapper(),
84
+            \OC::$server->getUserSession(),
85
+            $groupManager,
86
+            \OC::$server->getEventDispatcher()
87
+        );
88
+        $commentsCollection = new Comments\RootCollection(
89
+            \OC::$server->getCommentsManager(),
90
+            $userManager,
91
+            \OC::$server->getUserSession(),
92
+            \OC::$server->getEventDispatcher(),
93
+            \OC::$server->getLogger()
94
+        );
95 95
 
96
-		$usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
97
-		$usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users');
98
-		$usersAddressBookRoot->disableListing = $disableListing;
96
+        $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
97
+        $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users');
98
+        $usersAddressBookRoot->disableListing = $disableListing;
99 99
 
100
-		$systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
101
-		$systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system');
102
-		$systemAddressBookRoot->disableListing = $disableListing;
100
+        $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
101
+        $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system');
102
+        $systemAddressBookRoot->disableListing = $disableListing;
103 103
 
104
-		$uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users');
105
-		$uploadCollection->disableListing = $disableListing;
104
+        $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users');
105
+        $uploadCollection->disableListing = $disableListing;
106 106
 
107
-		$avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
108
-		$avatarCollection->disableListing = $disableListing;
107
+        $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
108
+        $avatarCollection->disableListing = $disableListing;
109 109
 
110
-		$children = [
111
-				new SimpleCollection('principals', [
112
-						$userPrincipals,
113
-						$groupPrincipals,
114
-						$systemPrincipals]),
115
-				$filesCollection,
116
-				$calendarRoot,
117
-				$publicCalendarRoot,
118
-				new SimpleCollection('addressbooks', [
119
-						$usersAddressBookRoot,
120
-						$systemAddressBookRoot]),
121
-				$systemTagCollection,
122
-				$systemTagRelationsCollection,
123
-				$commentsCollection,
124
-				$uploadCollection,
125
-				$avatarCollection
126
-		];
110
+        $children = [
111
+                new SimpleCollection('principals', [
112
+                        $userPrincipals,
113
+                        $groupPrincipals,
114
+                        $systemPrincipals]),
115
+                $filesCollection,
116
+                $calendarRoot,
117
+                $publicCalendarRoot,
118
+                new SimpleCollection('addressbooks', [
119
+                        $usersAddressBookRoot,
120
+                        $systemAddressBookRoot]),
121
+                $systemTagCollection,
122
+                $systemTagRelationsCollection,
123
+                $commentsCollection,
124
+                $uploadCollection,
125
+                $avatarCollection
126
+        ];
127 127
 
128
-		parent::__construct('root', $children);
129
-	}
128
+        parent::__construct('root', $children);
129
+    }
130 130
 
131 131
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Principal.php 1 patch
Indentation   +319 added lines, -319 removed lines patch added patch discarded remove patch
@@ -43,324 +43,324 @@
 block discarded – undo
43 43
 
44 44
 class Principal implements BackendInterface {
45 45
 
46
-	/** @var IUserManager */
47
-	private $userManager;
48
-
49
-	/** @var IGroupManager */
50
-	private $groupManager;
51
-
52
-	/** @var IShareManager */
53
-	private $shareManager;
54
-
55
-	/** @var IUserSession */
56
-	private $userSession;
57
-
58
-	/** @var IConfig */
59
-	private $config;
60
-
61
-	/** @var string */
62
-	private $principalPrefix;
63
-
64
-	/** @var bool */
65
-	private $hasGroups;
66
-
67
-	/**
68
-	 * @param IUserManager $userManager
69
-	 * @param IGroupManager $groupManager
70
-	 * @param IShareManager $shareManager
71
-	 * @param IUserSession $userSession
72
-	 * @param IConfig $config
73
-	 * @param string $principalPrefix
74
-	 */
75
-	public function __construct(IUserManager $userManager,
76
-								IGroupManager $groupManager,
77
-								IShareManager $shareManager,
78
-								IUserSession $userSession,
79
-								IConfig $config,
80
-								$principalPrefix = 'principals/users/') {
81
-		$this->userManager = $userManager;
82
-		$this->groupManager = $groupManager;
83
-		$this->shareManager = $shareManager;
84
-		$this->userSession = $userSession;
85
-		$this->config = $config;
86
-		$this->principalPrefix = trim($principalPrefix, '/');
87
-		$this->hasGroups = ($principalPrefix === 'principals/users/');
88
-	}
89
-
90
-	/**
91
-	 * Returns a list of principals based on a prefix.
92
-	 *
93
-	 * This prefix will often contain something like 'principals'. You are only
94
-	 * expected to return principals that are in this base path.
95
-	 *
96
-	 * You are expected to return at least a 'uri' for every user, you can
97
-	 * return any additional properties if you wish so. Common properties are:
98
-	 *   {DAV:}displayname
99
-	 *
100
-	 * @param string $prefixPath
101
-	 * @return string[]
102
-	 */
103
-	public function getPrincipalsByPrefix($prefixPath) {
104
-		$principals = [];
105
-
106
-		if ($prefixPath === $this->principalPrefix) {
107
-			foreach($this->userManager->search('') as $user) {
108
-				$principals[] = $this->userToPrincipal($user);
109
-			}
110
-		}
111
-
112
-		return $principals;
113
-	}
114
-
115
-	/**
116
-	 * Returns a specific principal, specified by it's path.
117
-	 * The returned structure should be the exact same as from
118
-	 * getPrincipalsByPrefix.
119
-	 *
120
-	 * @param string $path
121
-	 * @return array
122
-	 */
123
-	public function getPrincipalByPath($path) {
124
-		list($prefix, $name) = \Sabre\Uri\split($path);
125
-
126
-		if ($prefix === $this->principalPrefix) {
127
-			$user = $this->userManager->get($name);
128
-
129
-			if ($user !== null) {
130
-				return $this->userToPrincipal($user);
131
-			}
132
-		}
133
-		return null;
134
-	}
135
-
136
-	/**
137
-	 * Returns the list of members for a group-principal
138
-	 *
139
-	 * @param string $principal
140
-	 * @return string[]
141
-	 * @throws Exception
142
-	 */
143
-	public function getGroupMemberSet($principal) {
144
-		// TODO: for now the group principal has only one member, the user itself
145
-		$principal = $this->getPrincipalByPath($principal);
146
-		if (!$principal) {
147
-			throw new Exception('Principal not found');
148
-		}
149
-
150
-		return [$principal['uri']];
151
-	}
152
-
153
-	/**
154
-	 * Returns the list of groups a principal is a member of
155
-	 *
156
-	 * @param string $principal
157
-	 * @param bool $needGroups
158
-	 * @return array
159
-	 * @throws Exception
160
-	 */
161
-	public function getGroupMembership($principal, $needGroups = false) {
162
-		list($prefix, $name) = \Sabre\Uri\split($principal);
163
-
164
-		if ($prefix === $this->principalPrefix) {
165
-			$user = $this->userManager->get($name);
166
-			if (!$user) {
167
-				throw new Exception('Principal not found');
168
-			}
169
-
170
-			if ($this->hasGroups || $needGroups) {
171
-				$groups = $this->groupManager->getUserGroups($user);
172
-				$groups = array_map(function($group) {
173
-					/** @var IGroup $group */
174
-					return 'principals/groups/' . urlencode($group->getGID());
175
-				}, $groups);
176
-
177
-				return $groups;
178
-			}
179
-		}
180
-		return [];
181
-	}
182
-
183
-	/**
184
-	 * Updates the list of group members for a group principal.
185
-	 *
186
-	 * The principals should be passed as a list of uri's.
187
-	 *
188
-	 * @param string $principal
189
-	 * @param string[] $members
190
-	 * @throws Exception
191
-	 */
192
-	public function setGroupMemberSet($principal, array $members) {
193
-		throw new Exception('Setting members of the group is not supported yet');
194
-	}
195
-
196
-	/**
197
-	 * @param string $path
198
-	 * @param PropPatch $propPatch
199
-	 * @return int
200
-	 */
201
-	function updatePrincipal($path, PropPatch $propPatch) {
202
-		return 0;
203
-	}
204
-
205
-	/**
206
-	 * Search user principals
207
-	 *
208
-	 * @param array $searchProperties
209
-	 * @param string $test
210
-	 * @return array
211
-	 */
212
-	protected function searchUserPrincipals(array $searchProperties, $test = 'allof') {
213
-		$results = [];
214
-
215
-		// If sharing is disabled (or FreeBusy was disabled on purpose), return the empty array
216
-		$shareAPIEnabled = $this->shareManager->shareApiEnabled();
217
-		$disableFreeBusy = $this->config->getAppValue('dav', 'disableFreeBusy', $shareAPIEnabled ? 'no' : 'yes');
218
-		if ($disableFreeBusy === 'yes') {
219
-			return [];
220
-		}
221
-
222
-		// If sharing is restricted to group members only,
223
-		// return only members that have groups in common
224
-		$restrictGroups = false;
225
-		if ($this->shareManager->shareWithGroupMembersOnly()) {
226
-			$user = $this->userSession->getUser();
227
-			if (!$user) {
228
-				return [];
229
-			}
230
-
231
-			$restrictGroups = $this->groupManager->getUserGroupIds($user);
232
-		}
233
-
234
-		foreach ($searchProperties as $prop => $value) {
235
-			switch ($prop) {
236
-				case '{http://sabredav.org/ns}email-address':
237
-					$users = $this->userManager->getByEmail($value);
238
-
239
-					$results[] = array_reduce($users, function(array $carry, IUser $user) use ($restrictGroups) {
240
-						// is sharing restricted to groups only?
241
-						if ($restrictGroups !== false) {
242
-							$userGroups = $this->groupManager->getUserGroupIds($user);
243
-							if (count(array_intersect($userGroups, $restrictGroups)) === 0) {
244
-								return $carry;
245
-							}
246
-						}
247
-
248
-						$carry[] = $this->principalPrefix . '/' . $user->getUID();
249
-						return $carry;
250
-					}, []);
251
-					break;
252
-
253
-				default:
254
-					$results[] = [];
255
-					break;
256
-			}
257
-		}
258
-
259
-		// results is an array of arrays, so this is not the first search result
260
-		// but the results of the first searchProperty
261
-		if (count($results) === 1) {
262
-			return $results[0];
263
-		}
264
-
265
-		switch ($test) {
266
-			case 'anyof':
267
-				return array_unique(array_merge(...$results));
268
-
269
-			case 'allof':
270
-			default:
271
-				return array_intersect(...$results);
272
-		}
273
-	}
274
-
275
-	/**
276
-	 * @param string $prefixPath
277
-	 * @param array $searchProperties
278
-	 * @param string $test
279
-	 * @return array
280
-	 */
281
-	function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
282
-		if (count($searchProperties) === 0) {
283
-			return [];
284
-		}
285
-
286
-		switch ($prefixPath) {
287
-			case 'principals/users':
288
-				return $this->searchUserPrincipals($searchProperties, $test);
289
-
290
-			default:
291
-				return [];
292
-		}
293
-	}
294
-
295
-	/**
296
-	 * @param string $uri
297
-	 * @param string $principalPrefix
298
-	 * @return string
299
-	 */
300
-	function findByUri($uri, $principalPrefix) {
301
-		// If sharing is disabled (or FreeBusy was disabled on purpose), return the empty array
302
-		$shareAPIEnabled = $this->shareManager->shareApiEnabled();
303
-		$disableFreeBusy = $this->config->getAppValue('dav', 'disableFreeBusy', $shareAPIEnabled ? 'no' : 'yes');
304
-		if ($disableFreeBusy === 'yes') {
305
-			return null;
306
-		}
307
-
308
-		// If sharing is restricted to group members only,
309
-		// return only members that have groups in common
310
-		$restrictGroups = false;
311
-		if ($this->shareManager->shareWithGroupMembersOnly()) {
312
-			$user = $this->userSession->getUser();
313
-			if (!$user) {
314
-				return null;
315
-			}
316
-
317
-			$restrictGroups = $this->groupManager->getUserGroupIds($user);
318
-		}
319
-
320
-		if (strpos($uri, 'mailto:') === 0) {
321
-			if ($principalPrefix === 'principals/users') {
322
-				$users = $this->userManager->getByEmail(substr($uri, 7));
323
-				if (count($users) !== 1) {
324
-					return null;
325
-				}
326
-				$user = $users[0];
327
-
328
-				if ($restrictGroups !== false) {
329
-					$userGroups = $this->groupManager->getUserGroupIds($user);
330
-					if (count(array_intersect($userGroups, $restrictGroups)) === 0) {
331
-						return null;
332
-					}
333
-				}
334
-
335
-				return $this->principalPrefix . '/' . $user->getUID();
336
-			}
337
-		}
338
-
339
-		return null;
340
-	}
341
-
342
-	/**
343
-	 * @param IUser $user
344
-	 * @return array
345
-	 */
346
-	protected function userToPrincipal($user) {
347
-		$userId = $user->getUID();
348
-		$displayName = $user->getDisplayName();
349
-		$principal = [
350
-				'uri' => $this->principalPrefix . '/' . $userId,
351
-				'{DAV:}displayname' => is_null($displayName) ? $userId : $displayName,
352
-		];
353
-
354
-		$email = $user->getEMailAddress();
355
-		if (!empty($email)) {
356
-			$principal['{http://sabredav.org/ns}email-address'] = $email;
357
-		}
358
-
359
-		return $principal;
360
-	}
361
-
362
-	public function getPrincipalPrefix() {
363
-		return $this->principalPrefix;
364
-	}
46
+    /** @var IUserManager */
47
+    private $userManager;
48
+
49
+    /** @var IGroupManager */
50
+    private $groupManager;
51
+
52
+    /** @var IShareManager */
53
+    private $shareManager;
54
+
55
+    /** @var IUserSession */
56
+    private $userSession;
57
+
58
+    /** @var IConfig */
59
+    private $config;
60
+
61
+    /** @var string */
62
+    private $principalPrefix;
63
+
64
+    /** @var bool */
65
+    private $hasGroups;
66
+
67
+    /**
68
+     * @param IUserManager $userManager
69
+     * @param IGroupManager $groupManager
70
+     * @param IShareManager $shareManager
71
+     * @param IUserSession $userSession
72
+     * @param IConfig $config
73
+     * @param string $principalPrefix
74
+     */
75
+    public function __construct(IUserManager $userManager,
76
+                                IGroupManager $groupManager,
77
+                                IShareManager $shareManager,
78
+                                IUserSession $userSession,
79
+                                IConfig $config,
80
+                                $principalPrefix = 'principals/users/') {
81
+        $this->userManager = $userManager;
82
+        $this->groupManager = $groupManager;
83
+        $this->shareManager = $shareManager;
84
+        $this->userSession = $userSession;
85
+        $this->config = $config;
86
+        $this->principalPrefix = trim($principalPrefix, '/');
87
+        $this->hasGroups = ($principalPrefix === 'principals/users/');
88
+    }
89
+
90
+    /**
91
+     * Returns a list of principals based on a prefix.
92
+     *
93
+     * This prefix will often contain something like 'principals'. You are only
94
+     * expected to return principals that are in this base path.
95
+     *
96
+     * You are expected to return at least a 'uri' for every user, you can
97
+     * return any additional properties if you wish so. Common properties are:
98
+     *   {DAV:}displayname
99
+     *
100
+     * @param string $prefixPath
101
+     * @return string[]
102
+     */
103
+    public function getPrincipalsByPrefix($prefixPath) {
104
+        $principals = [];
105
+
106
+        if ($prefixPath === $this->principalPrefix) {
107
+            foreach($this->userManager->search('') as $user) {
108
+                $principals[] = $this->userToPrincipal($user);
109
+            }
110
+        }
111
+
112
+        return $principals;
113
+    }
114
+
115
+    /**
116
+     * Returns a specific principal, specified by it's path.
117
+     * The returned structure should be the exact same as from
118
+     * getPrincipalsByPrefix.
119
+     *
120
+     * @param string $path
121
+     * @return array
122
+     */
123
+    public function getPrincipalByPath($path) {
124
+        list($prefix, $name) = \Sabre\Uri\split($path);
125
+
126
+        if ($prefix === $this->principalPrefix) {
127
+            $user = $this->userManager->get($name);
128
+
129
+            if ($user !== null) {
130
+                return $this->userToPrincipal($user);
131
+            }
132
+        }
133
+        return null;
134
+    }
135
+
136
+    /**
137
+     * Returns the list of members for a group-principal
138
+     *
139
+     * @param string $principal
140
+     * @return string[]
141
+     * @throws Exception
142
+     */
143
+    public function getGroupMemberSet($principal) {
144
+        // TODO: for now the group principal has only one member, the user itself
145
+        $principal = $this->getPrincipalByPath($principal);
146
+        if (!$principal) {
147
+            throw new Exception('Principal not found');
148
+        }
149
+
150
+        return [$principal['uri']];
151
+    }
152
+
153
+    /**
154
+     * Returns the list of groups a principal is a member of
155
+     *
156
+     * @param string $principal
157
+     * @param bool $needGroups
158
+     * @return array
159
+     * @throws Exception
160
+     */
161
+    public function getGroupMembership($principal, $needGroups = false) {
162
+        list($prefix, $name) = \Sabre\Uri\split($principal);
163
+
164
+        if ($prefix === $this->principalPrefix) {
165
+            $user = $this->userManager->get($name);
166
+            if (!$user) {
167
+                throw new Exception('Principal not found');
168
+            }
169
+
170
+            if ($this->hasGroups || $needGroups) {
171
+                $groups = $this->groupManager->getUserGroups($user);
172
+                $groups = array_map(function($group) {
173
+                    /** @var IGroup $group */
174
+                    return 'principals/groups/' . urlencode($group->getGID());
175
+                }, $groups);
176
+
177
+                return $groups;
178
+            }
179
+        }
180
+        return [];
181
+    }
182
+
183
+    /**
184
+     * Updates the list of group members for a group principal.
185
+     *
186
+     * The principals should be passed as a list of uri's.
187
+     *
188
+     * @param string $principal
189
+     * @param string[] $members
190
+     * @throws Exception
191
+     */
192
+    public function setGroupMemberSet($principal, array $members) {
193
+        throw new Exception('Setting members of the group is not supported yet');
194
+    }
195
+
196
+    /**
197
+     * @param string $path
198
+     * @param PropPatch $propPatch
199
+     * @return int
200
+     */
201
+    function updatePrincipal($path, PropPatch $propPatch) {
202
+        return 0;
203
+    }
204
+
205
+    /**
206
+     * Search user principals
207
+     *
208
+     * @param array $searchProperties
209
+     * @param string $test
210
+     * @return array
211
+     */
212
+    protected function searchUserPrincipals(array $searchProperties, $test = 'allof') {
213
+        $results = [];
214
+
215
+        // If sharing is disabled (or FreeBusy was disabled on purpose), return the empty array
216
+        $shareAPIEnabled = $this->shareManager->shareApiEnabled();
217
+        $disableFreeBusy = $this->config->getAppValue('dav', 'disableFreeBusy', $shareAPIEnabled ? 'no' : 'yes');
218
+        if ($disableFreeBusy === 'yes') {
219
+            return [];
220
+        }
221
+
222
+        // If sharing is restricted to group members only,
223
+        // return only members that have groups in common
224
+        $restrictGroups = false;
225
+        if ($this->shareManager->shareWithGroupMembersOnly()) {
226
+            $user = $this->userSession->getUser();
227
+            if (!$user) {
228
+                return [];
229
+            }
230
+
231
+            $restrictGroups = $this->groupManager->getUserGroupIds($user);
232
+        }
233
+
234
+        foreach ($searchProperties as $prop => $value) {
235
+            switch ($prop) {
236
+                case '{http://sabredav.org/ns}email-address':
237
+                    $users = $this->userManager->getByEmail($value);
238
+
239
+                    $results[] = array_reduce($users, function(array $carry, IUser $user) use ($restrictGroups) {
240
+                        // is sharing restricted to groups only?
241
+                        if ($restrictGroups !== false) {
242
+                            $userGroups = $this->groupManager->getUserGroupIds($user);
243
+                            if (count(array_intersect($userGroups, $restrictGroups)) === 0) {
244
+                                return $carry;
245
+                            }
246
+                        }
247
+
248
+                        $carry[] = $this->principalPrefix . '/' . $user->getUID();
249
+                        return $carry;
250
+                    }, []);
251
+                    break;
252
+
253
+                default:
254
+                    $results[] = [];
255
+                    break;
256
+            }
257
+        }
258
+
259
+        // results is an array of arrays, so this is not the first search result
260
+        // but the results of the first searchProperty
261
+        if (count($results) === 1) {
262
+            return $results[0];
263
+        }
264
+
265
+        switch ($test) {
266
+            case 'anyof':
267
+                return array_unique(array_merge(...$results));
268
+
269
+            case 'allof':
270
+            default:
271
+                return array_intersect(...$results);
272
+        }
273
+    }
274
+
275
+    /**
276
+     * @param string $prefixPath
277
+     * @param array $searchProperties
278
+     * @param string $test
279
+     * @return array
280
+     */
281
+    function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
282
+        if (count($searchProperties) === 0) {
283
+            return [];
284
+        }
285
+
286
+        switch ($prefixPath) {
287
+            case 'principals/users':
288
+                return $this->searchUserPrincipals($searchProperties, $test);
289
+
290
+            default:
291
+                return [];
292
+        }
293
+    }
294
+
295
+    /**
296
+     * @param string $uri
297
+     * @param string $principalPrefix
298
+     * @return string
299
+     */
300
+    function findByUri($uri, $principalPrefix) {
301
+        // If sharing is disabled (or FreeBusy was disabled on purpose), return the empty array
302
+        $shareAPIEnabled = $this->shareManager->shareApiEnabled();
303
+        $disableFreeBusy = $this->config->getAppValue('dav', 'disableFreeBusy', $shareAPIEnabled ? 'no' : 'yes');
304
+        if ($disableFreeBusy === 'yes') {
305
+            return null;
306
+        }
307
+
308
+        // If sharing is restricted to group members only,
309
+        // return only members that have groups in common
310
+        $restrictGroups = false;
311
+        if ($this->shareManager->shareWithGroupMembersOnly()) {
312
+            $user = $this->userSession->getUser();
313
+            if (!$user) {
314
+                return null;
315
+            }
316
+
317
+            $restrictGroups = $this->groupManager->getUserGroupIds($user);
318
+        }
319
+
320
+        if (strpos($uri, 'mailto:') === 0) {
321
+            if ($principalPrefix === 'principals/users') {
322
+                $users = $this->userManager->getByEmail(substr($uri, 7));
323
+                if (count($users) !== 1) {
324
+                    return null;
325
+                }
326
+                $user = $users[0];
327
+
328
+                if ($restrictGroups !== false) {
329
+                    $userGroups = $this->groupManager->getUserGroupIds($user);
330
+                    if (count(array_intersect($userGroups, $restrictGroups)) === 0) {
331
+                        return null;
332
+                    }
333
+                }
334
+
335
+                return $this->principalPrefix . '/' . $user->getUID();
336
+            }
337
+        }
338
+
339
+        return null;
340
+    }
341
+
342
+    /**
343
+     * @param IUser $user
344
+     * @return array
345
+     */
346
+    protected function userToPrincipal($user) {
347
+        $userId = $user->getUID();
348
+        $displayName = $user->getDisplayName();
349
+        $principal = [
350
+                'uri' => $this->principalPrefix . '/' . $userId,
351
+                '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName,
352
+        ];
353
+
354
+        $email = $user->getEMailAddress();
355
+        if (!empty($email)) {
356
+            $principal['{http://sabredav.org/ns}email-address'] = $email;
357
+        }
358
+
359
+        return $principal;
360
+    }
361
+
362
+    public function getPrincipalPrefix() {
363
+        return $this->principalPrefix;
364
+    }
365 365
 
366 366
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/AppInfo/Application.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -30,36 +30,36 @@
 block discarded – undo
30 30
 use OCA\Files_Trashbin\Capabilities;
31 31
 
32 32
 class Application extends App {
33
-	public function __construct (array $urlParams = []) {
34
-		parent::__construct('files_trashbin', $urlParams);
33
+    public function __construct (array $urlParams = []) {
34
+        parent::__construct('files_trashbin', $urlParams);
35 35
 
36
-		$container = $this->getContainer();
37
-		/*
36
+        $container = $this->getContainer();
37
+        /*
38 38
 		 * Register capabilities
39 39
 		 */
40
-		$container->registerCapability(Capabilities::class);
40
+        $container->registerCapability(Capabilities::class);
41 41
 
42
-		/*
42
+        /*
43 43
 		 * Register expiration
44 44
 		 */
45
-		$container->registerService('Expiration', function($c) {
46
-			return  new Expiration(
47
-				$c->query('ServerContainer')->getConfig(),
48
-				$c->query(ITimeFactory::class)
49
-			);
50
-		});
45
+        $container->registerService('Expiration', function($c) {
46
+            return  new Expiration(
47
+                $c->query('ServerContainer')->getConfig(),
48
+                $c->query(ITimeFactory::class)
49
+            );
50
+        });
51 51
 
52
-		/*
52
+        /*
53 53
 		 * Register $principalBackend for the DAV collection
54 54
 		 */
55
-		$container->registerService('principalBackend', function () {
56
-			return new Principal(
57
-				\OC::$server->getUserManager(),
58
-				\OC::$server->getGroupManager(),
59
-				\OC::$server->getShareManager(),
60
-				\OC::$server->getUserSession(),
61
-				\OC::$server->getConfig()
62
-			);
63
-		});
64
-	}
55
+        $container->registerService('principalBackend', function () {
56
+            return new Principal(
57
+                \OC::$server->getUserManager(),
58
+                \OC::$server->getGroupManager(),
59
+                \OC::$server->getShareManager(),
60
+                \OC::$server->getUserSession(),
61
+                \OC::$server->getConfig()
62
+            );
63
+        });
64
+    }
65 65
 }
Please login to merge, or discard this patch.
apps/files_versions/lib/AppInfo/Application.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -30,27 +30,27 @@
 block discarded – undo
30 30
 use OCA\Files_Versions\Capabilities;
31 31
 
32 32
 class Application extends App {
33
-	public function __construct(array $urlParams = array()) {
34
-		parent::__construct('files_versions', $urlParams);
33
+    public function __construct(array $urlParams = array()) {
34
+        parent::__construct('files_versions', $urlParams);
35 35
 
36
-		$container = $this->getContainer();
36
+        $container = $this->getContainer();
37 37
 
38
-		/*
38
+        /*
39 39
 		 * Register capabilities
40 40
 		 */
41
-		$container->registerCapability(Capabilities::class);
41
+        $container->registerCapability(Capabilities::class);
42 42
 
43
-		/*
43
+        /*
44 44
 		 * Register $principalBackend for the DAV collection
45 45
 		 */
46
-		$container->registerService('principalBackend', function () {
47
-			return new Principal(
48
-				\OC::$server->getUserManager(),
49
-				\OC::$server->getGroupManager(),
50
-				\OC::$server->getShareManager(),
51
-				\OC::$server->getUserSession(),
52
-				\OC::$server->getConfig()
53
-			);
54
-		});
55
-	}
46
+        $container->registerService('principalBackend', function () {
47
+            return new Principal(
48
+                \OC::$server->getUserManager(),
49
+                \OC::$server->getGroupManager(),
50
+                \OC::$server->getShareManager(),
51
+                \OC::$server->getUserSession(),
52
+                \OC::$server->getConfig()
53
+            );
54
+        });
55
+    }
56 56
 }
Please login to merge, or discard this patch.