Completed
Push — master ( 034246...d4e9a8 )
by
unknown
19:42 queued 13s
created
lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
 		if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
62 62
 			[$remoteGroup, $serverUrl] = $this->splitGroupRemote($search);
63 63
 			$result['exact'][] = [
64
-				'label' => $remoteGroup . " ($serverUrl)",
64
+				'label' => $remoteGroup." ($serverUrl)",
65 65
 				'guid' => $remoteGroup,
66 66
 				'name' => $remoteGroup,
67 67
 				'value' => [
Please login to merge, or discard this patch.
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -14,59 +14,59 @@
 block discarded – undo
14 14
 use OCP\Share\IShare;
15 15
 
16 16
 class RemoteGroupPlugin implements ISearchPlugin {
17
-	private bool $enabled = false;
17
+    private bool $enabled = false;
18 18
 
19
-	public function __construct(
20
-		ICloudFederationProviderManager $cloudFederationProviderManager,
21
-		private ICloudIdManager $cloudIdManager,
22
-	) {
23
-		try {
24
-			$fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file');
25
-			$supportedShareTypes = $fileSharingProvider->getSupportedShareTypes();
26
-			if (in_array('group', $supportedShareTypes)) {
27
-				$this->enabled = true;
28
-			}
29
-		} catch (\Exception $e) {
30
-			// do nothing, just don't enable federated group shares
31
-		}
32
-	}
19
+    public function __construct(
20
+        ICloudFederationProviderManager $cloudFederationProviderManager,
21
+        private ICloudIdManager $cloudIdManager,
22
+    ) {
23
+        try {
24
+            $fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file');
25
+            $supportedShareTypes = $fileSharingProvider->getSupportedShareTypes();
26
+            if (in_array('group', $supportedShareTypes)) {
27
+                $this->enabled = true;
28
+            }
29
+        } catch (\Exception $e) {
30
+            // do nothing, just don't enable federated group shares
31
+        }
32
+    }
33 33
 
34
-	public function search($search, $limit, $offset, ISearchResult $searchResult): bool {
35
-		$result = ['wide' => [], 'exact' => []];
36
-		$resultType = new SearchResultType('remote_groups');
34
+    public function search($search, $limit, $offset, ISearchResult $searchResult): bool {
35
+        $result = ['wide' => [], 'exact' => []];
36
+        $resultType = new SearchResultType('remote_groups');
37 37
 
38
-		if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
39
-			[$remoteGroup, $serverUrl] = $this->splitGroupRemote($search);
40
-			$result['exact'][] = [
41
-				'label' => $remoteGroup . " ($serverUrl)",
42
-				'guid' => $remoteGroup,
43
-				'name' => $remoteGroup,
44
-				'value' => [
45
-					'shareType' => IShare::TYPE_REMOTE_GROUP,
46
-					'shareWith' => $search,
47
-					'server' => $serverUrl,
48
-				],
49
-			];
50
-		}
38
+        if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
39
+            [$remoteGroup, $serverUrl] = $this->splitGroupRemote($search);
40
+            $result['exact'][] = [
41
+                'label' => $remoteGroup . " ($serverUrl)",
42
+                'guid' => $remoteGroup,
43
+                'name' => $remoteGroup,
44
+                'value' => [
45
+                    'shareType' => IShare::TYPE_REMOTE_GROUP,
46
+                    'shareWith' => $search,
47
+                    'server' => $serverUrl,
48
+                ],
49
+            ];
50
+        }
51 51
 
52
-		$searchResult->addResultSet($resultType, $result['wide'], $result['exact']);
52
+        $searchResult->addResultSet($resultType, $result['wide'], $result['exact']);
53 53
 
54
-		return true;
55
-	}
54
+        return true;
55
+    }
56 56
 
57
-	/**
58
-	 * split group and remote from federated cloud id
59
-	 *
60
-	 * @param string $address federated share address
61
-	 * @return array [user, remoteURL]
62
-	 * @throws \InvalidArgumentException
63
-	 */
64
-	public function splitGroupRemote($address): array {
65
-		try {
66
-			$cloudId = $this->cloudIdManager->resolveCloudId($address);
67
-			return [$cloudId->getUser(), $cloudId->getRemote()];
68
-		} catch (\InvalidArgumentException $e) {
69
-			throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
70
-		}
71
-	}
57
+    /**
58
+     * split group and remote from federated cloud id
59
+     *
60
+     * @param string $address federated share address
61
+     * @return array [user, remoteURL]
62
+     * @throws \InvalidArgumentException
63
+     */
64
+    public function splitGroupRemote($address): array {
65
+        try {
66
+            $cloudId = $this->cloudIdManager->resolveCloudId($address);
67
+            return [$cloudId->getUser(), $cloudId->getRemote()];
68
+        } catch (\InvalidArgumentException $e) {
69
+            throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
70
+        }
71
+    }
72 72
 }
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/Plugin.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -31,46 +31,46 @@
 block discarded – undo
31 31
 use Sabre\DAV\Server;
32 32
 
33 33
 class Plugin extends \Sabre\CardDAV\Plugin {
34
-	public function initialize(Server $server) {
35
-		$server->on('propFind', [$this, 'propFind']);
36
-		parent::initialize($server);
37
-	}
34
+    public function initialize(Server $server) {
35
+        $server->on('propFind', [$this, 'propFind']);
36
+        parent::initialize($server);
37
+    }
38 38
 
39
-	/**
40
-	 * Returns the addressbook home for a given principal
41
-	 *
42
-	 * @param string $principal
43
-	 * @return string|null
44
-	 */
45
-	protected function getAddressbookHomeForPrincipal($principal) {
46
-		if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) {
47
-			[, $principalId] = \Sabre\Uri\split($principal);
48
-			return self::ADDRESSBOOK_ROOT . '/users/' . $principalId;
49
-		}
50
-		if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) {
51
-			[, $principalId] = \Sabre\Uri\split($principal);
52
-			return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId;
53
-		}
54
-		if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) {
55
-			[, $principalId] = \Sabre\Uri\split($principal);
56
-			return self::ADDRESSBOOK_ROOT . '/system/' . $principalId;
57
-		}
58
-	}
39
+    /**
40
+     * Returns the addressbook home for a given principal
41
+     *
42
+     * @param string $principal
43
+     * @return string|null
44
+     */
45
+    protected function getAddressbookHomeForPrincipal($principal) {
46
+        if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) {
47
+            [, $principalId] = \Sabre\Uri\split($principal);
48
+            return self::ADDRESSBOOK_ROOT . '/users/' . $principalId;
49
+        }
50
+        if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) {
51
+            [, $principalId] = \Sabre\Uri\split($principal);
52
+            return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId;
53
+        }
54
+        if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) {
55
+            [, $principalId] = \Sabre\Uri\split($principal);
56
+            return self::ADDRESSBOOK_ROOT . '/system/' . $principalId;
57
+        }
58
+    }
59 59
 
60
-	/**
61
-	 * Adds all CardDAV-specific properties
62
-	 *
63
-	 * @param PropFind $propFind
64
-	 * @param INode $node
65
-	 * @return void
66
-	 */
67
-	public function propFind(PropFind $propFind, INode $node) {
68
-		$ns = '{http://owncloud.org/ns}';
60
+    /**
61
+     * Adds all CardDAV-specific properties
62
+     *
63
+     * @param PropFind $propFind
64
+     * @param INode $node
65
+     * @return void
66
+     */
67
+    public function propFind(PropFind $propFind, INode $node) {
68
+        $ns = '{http://owncloud.org/ns}';
69 69
 
70
-		if ($node instanceof AddressBook) {
71
-			$propFind->handle($ns . 'groups', function () use ($node) {
72
-				return new Groups($node->getContactsGroups());
73
-			});
74
-		}
75
-	}
70
+        if ($node instanceof AddressBook) {
71
+            $propFind->handle($ns . 'groups', function () use ($node) {
72
+                return new Groups($node->getContactsGroups());
73
+            });
74
+        }
75
+    }
76 76
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -45,15 +45,15 @@  discard block
 block discarded – undo
45 45
 	protected function getAddressbookHomeForPrincipal($principal) {
46 46
 		if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) {
47 47
 			[, $principalId] = \Sabre\Uri\split($principal);
48
-			return self::ADDRESSBOOK_ROOT . '/users/' . $principalId;
48
+			return self::ADDRESSBOOK_ROOT.'/users/'.$principalId;
49 49
 		}
50 50
 		if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) {
51 51
 			[, $principalId] = \Sabre\Uri\split($principal);
52
-			return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId;
52
+			return self::ADDRESSBOOK_ROOT.'/groups/'.$principalId;
53 53
 		}
54 54
 		if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) {
55 55
 			[, $principalId] = \Sabre\Uri\split($principal);
56
-			return self::ADDRESSBOOK_ROOT . '/system/' . $principalId;
56
+			return self::ADDRESSBOOK_ROOT.'/system/'.$principalId;
57 57
 		}
58 58
 	}
59 59
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		$ns = '{http://owncloud.org/ns}';
69 69
 
70 70
 		if ($node instanceof AddressBook) {
71
-			$propFind->handle($ns . 'groups', function () use ($node) {
71
+			$propFind->handle($ns.'groups', function() use ($node) {
72 72
 				return new Groups($node->getContactsGroups());
73 73
 			});
74 74
 		}
Please login to merge, or discard this patch.
apps/dav/lib/Traits/PrincipalProxyTrait.php 2 patches
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -36,190 +36,190 @@
 block discarded – undo
36 36
  */
37 37
 trait PrincipalProxyTrait {
38 38
 
39
-	/**
40
-	 * Returns the list of members for a group-principal
41
-	 *
42
-	 * @param string $principal
43
-	 * @return string[]
44
-	 * @throws Exception
45
-	 */
46
-	public function getGroupMemberSet($principal) {
47
-		$members = [];
48
-
49
-		if ($this->isProxyPrincipal($principal)) {
50
-			$realPrincipal = $this->getPrincipalUriFromProxyPrincipal($principal);
51
-			$principalArray = $this->getPrincipalByPath($realPrincipal);
52
-			if (!$principalArray) {
53
-				throw new Exception('Principal not found');
54
-			}
55
-
56
-			$proxies = $this->proxyMapper->getProxiesOf($principalArray['uri']);
57
-			foreach ($proxies as $proxy) {
58
-				if ($this->isReadProxyPrincipal($principal) && $proxy->getPermissions() === ProxyMapper::PERMISSION_READ) {
59
-					$members[] = $proxy->getProxyId();
60
-				}
61
-
62
-				if ($this->isWriteProxyPrincipal($principal) && $proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) {
63
-					$members[] = $proxy->getProxyId();
64
-				}
65
-			}
66
-		}
67
-
68
-		return $members;
69
-	}
70
-
71
-	/**
72
-	 * Returns the list of groups a principal is a member of
73
-	 *
74
-	 * @param string $principal
75
-	 * @param bool $needGroups
76
-	 * @return array
77
-	 * @throws Exception
78
-	 */
79
-	public function getGroupMembership($principal, $needGroups = false) {
80
-		[$prefix, $name] = \Sabre\Uri\split($principal);
81
-
82
-		if ($prefix !== $this->principalPrefix) {
83
-			return [];
84
-		}
85
-
86
-		$principalArray = $this->getPrincipalByPath($principal);
87
-		if (!$principalArray) {
88
-			throw new Exception('Principal not found');
89
-		}
90
-
91
-		$groups = [];
92
-		$proxies = $this->proxyMapper->getProxiesFor($principal);
93
-		foreach ($proxies as $proxy) {
94
-			if ($proxy->getPermissions() === ProxyMapper::PERMISSION_READ) {
95
-				$groups[] = $proxy->getOwnerId() . '/calendar-proxy-read';
96
-			}
97
-
98
-			if ($proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) {
99
-				$groups[] = $proxy->getOwnerId() . '/calendar-proxy-write';
100
-			}
101
-		}
102
-
103
-		return $groups;
104
-	}
105
-
106
-	/**
107
-	 * Updates the list of group members for a group principal.
108
-	 *
109
-	 * The principals should be passed as a list of uri's.
110
-	 *
111
-	 * @param string $principal
112
-	 * @param string[] $members
113
-	 * @throws Exception
114
-	 */
115
-	public function setGroupMemberSet($principal, array $members) {
116
-		[$principalUri, $target] = \Sabre\Uri\split($principal);
117
-
118
-		if ($target !== 'calendar-proxy-write' && $target !== 'calendar-proxy-read') {
119
-			throw new Exception('Setting members of the group is not supported yet');
120
-		}
121
-
122
-		$masterPrincipalArray = $this->getPrincipalByPath($principalUri);
123
-		if (!$masterPrincipalArray) {
124
-			throw new Exception('Principal not found');
125
-		}
126
-
127
-		$permission = ProxyMapper::PERMISSION_READ;
128
-		if ($target === 'calendar-proxy-write') {
129
-			$permission |= ProxyMapper::PERMISSION_WRITE;
130
-		}
131
-
132
-		[$prefix, $owner] = \Sabre\Uri\split($principalUri);
133
-		$proxies = $this->proxyMapper->getProxiesOf($principalUri);
134
-
135
-		foreach ($members as $member) {
136
-			[$prefix, $name] = \Sabre\Uri\split($member);
137
-
138
-			if ($prefix !== $this->principalPrefix) {
139
-				throw new Exception('Invalid member group prefix: ' . $prefix);
140
-			}
141
-
142
-			$principalArray = $this->getPrincipalByPath($member);
143
-			if (!$principalArray) {
144
-				throw new Exception('Principal not found');
145
-			}
146
-
147
-			$found = false;
148
-			foreach ($proxies as $proxy) {
149
-				if ($proxy->getProxyId() === $member) {
150
-					$found = true;
151
-					$proxy->setPermissions($proxy->getPermissions() | $permission);
152
-					$this->proxyMapper->update($proxy);
153
-
154
-					$proxies = array_filter($proxies, function (Proxy $p) use ($proxy) {
155
-						return $p->getId() !== $proxy->getId();
156
-					});
157
-					break;
158
-				}
159
-			}
160
-
161
-			if ($found === false) {
162
-				$proxy = new Proxy();
163
-				$proxy->setOwnerId($principalUri);
164
-				$proxy->setProxyId($member);
165
-				$proxy->setPermissions($permission);
166
-				$this->proxyMapper->insert($proxy);
167
-			}
168
-		}
169
-
170
-		// Delete all remaining proxies
171
-		foreach ($proxies as $proxy) {
172
-			// Write and Read Proxies have individual requests,
173
-			// so only delete proxies of this permission
174
-			if ($proxy->getPermissions() === $permission) {
175
-				$this->proxyMapper->delete($proxy);
176
-			}
177
-		}
178
-	}
179
-
180
-	/**
181
-	 * @param string $principalUri
182
-	 * @return bool
183
-	 */
184
-	private function isProxyPrincipal(string $principalUri):bool {
185
-		[$realPrincipalUri, $proxy] = \Sabre\Uri\split($principalUri);
186
-		[$prefix, $userId] = \Sabre\Uri\split($realPrincipalUri);
187
-
188
-		if (!isset($prefix) || !isset($userId)) {
189
-			return false;
190
-		}
191
-		if ($prefix !== $this->principalPrefix) {
192
-			return false;
193
-		}
194
-
195
-		return $proxy === 'calendar-proxy-read'
196
-			|| $proxy === 'calendar-proxy-write';
197
-	}
198
-
199
-	/**
200
-	 * @param string $principalUri
201
-	 * @return bool
202
-	 */
203
-	private function isReadProxyPrincipal(string $principalUri):bool {
204
-		[, $proxy] = \Sabre\Uri\split($principalUri);
205
-		return $proxy === 'calendar-proxy-read';
206
-	}
207
-
208
-	/**
209
-	 * @param string $principalUri
210
-	 * @return bool
211
-	 */
212
-	private function isWriteProxyPrincipal(string $principalUri):bool {
213
-		[, $proxy] = \Sabre\Uri\split($principalUri);
214
-		return $proxy === 'calendar-proxy-write';
215
-	}
216
-
217
-	/**
218
-	 * @param string $principalUri
219
-	 * @return string
220
-	 */
221
-	private function getPrincipalUriFromProxyPrincipal(string $principalUri):string {
222
-		[$realPrincipalUri, ] = \Sabre\Uri\split($principalUri);
223
-		return $realPrincipalUri;
224
-	}
39
+    /**
40
+     * Returns the list of members for a group-principal
41
+     *
42
+     * @param string $principal
43
+     * @return string[]
44
+     * @throws Exception
45
+     */
46
+    public function getGroupMemberSet($principal) {
47
+        $members = [];
48
+
49
+        if ($this->isProxyPrincipal($principal)) {
50
+            $realPrincipal = $this->getPrincipalUriFromProxyPrincipal($principal);
51
+            $principalArray = $this->getPrincipalByPath($realPrincipal);
52
+            if (!$principalArray) {
53
+                throw new Exception('Principal not found');
54
+            }
55
+
56
+            $proxies = $this->proxyMapper->getProxiesOf($principalArray['uri']);
57
+            foreach ($proxies as $proxy) {
58
+                if ($this->isReadProxyPrincipal($principal) && $proxy->getPermissions() === ProxyMapper::PERMISSION_READ) {
59
+                    $members[] = $proxy->getProxyId();
60
+                }
61
+
62
+                if ($this->isWriteProxyPrincipal($principal) && $proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) {
63
+                    $members[] = $proxy->getProxyId();
64
+                }
65
+            }
66
+        }
67
+
68
+        return $members;
69
+    }
70
+
71
+    /**
72
+     * Returns the list of groups a principal is a member of
73
+     *
74
+     * @param string $principal
75
+     * @param bool $needGroups
76
+     * @return array
77
+     * @throws Exception
78
+     */
79
+    public function getGroupMembership($principal, $needGroups = false) {
80
+        [$prefix, $name] = \Sabre\Uri\split($principal);
81
+
82
+        if ($prefix !== $this->principalPrefix) {
83
+            return [];
84
+        }
85
+
86
+        $principalArray = $this->getPrincipalByPath($principal);
87
+        if (!$principalArray) {
88
+            throw new Exception('Principal not found');
89
+        }
90
+
91
+        $groups = [];
92
+        $proxies = $this->proxyMapper->getProxiesFor($principal);
93
+        foreach ($proxies as $proxy) {
94
+            if ($proxy->getPermissions() === ProxyMapper::PERMISSION_READ) {
95
+                $groups[] = $proxy->getOwnerId() . '/calendar-proxy-read';
96
+            }
97
+
98
+            if ($proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) {
99
+                $groups[] = $proxy->getOwnerId() . '/calendar-proxy-write';
100
+            }
101
+        }
102
+
103
+        return $groups;
104
+    }
105
+
106
+    /**
107
+     * Updates the list of group members for a group principal.
108
+     *
109
+     * The principals should be passed as a list of uri's.
110
+     *
111
+     * @param string $principal
112
+     * @param string[] $members
113
+     * @throws Exception
114
+     */
115
+    public function setGroupMemberSet($principal, array $members) {
116
+        [$principalUri, $target] = \Sabre\Uri\split($principal);
117
+
118
+        if ($target !== 'calendar-proxy-write' && $target !== 'calendar-proxy-read') {
119
+            throw new Exception('Setting members of the group is not supported yet');
120
+        }
121
+
122
+        $masterPrincipalArray = $this->getPrincipalByPath($principalUri);
123
+        if (!$masterPrincipalArray) {
124
+            throw new Exception('Principal not found');
125
+        }
126
+
127
+        $permission = ProxyMapper::PERMISSION_READ;
128
+        if ($target === 'calendar-proxy-write') {
129
+            $permission |= ProxyMapper::PERMISSION_WRITE;
130
+        }
131
+
132
+        [$prefix, $owner] = \Sabre\Uri\split($principalUri);
133
+        $proxies = $this->proxyMapper->getProxiesOf($principalUri);
134
+
135
+        foreach ($members as $member) {
136
+            [$prefix, $name] = \Sabre\Uri\split($member);
137
+
138
+            if ($prefix !== $this->principalPrefix) {
139
+                throw new Exception('Invalid member group prefix: ' . $prefix);
140
+            }
141
+
142
+            $principalArray = $this->getPrincipalByPath($member);
143
+            if (!$principalArray) {
144
+                throw new Exception('Principal not found');
145
+            }
146
+
147
+            $found = false;
148
+            foreach ($proxies as $proxy) {
149
+                if ($proxy->getProxyId() === $member) {
150
+                    $found = true;
151
+                    $proxy->setPermissions($proxy->getPermissions() | $permission);
152
+                    $this->proxyMapper->update($proxy);
153
+
154
+                    $proxies = array_filter($proxies, function (Proxy $p) use ($proxy) {
155
+                        return $p->getId() !== $proxy->getId();
156
+                    });
157
+                    break;
158
+                }
159
+            }
160
+
161
+            if ($found === false) {
162
+                $proxy = new Proxy();
163
+                $proxy->setOwnerId($principalUri);
164
+                $proxy->setProxyId($member);
165
+                $proxy->setPermissions($permission);
166
+                $this->proxyMapper->insert($proxy);
167
+            }
168
+        }
169
+
170
+        // Delete all remaining proxies
171
+        foreach ($proxies as $proxy) {
172
+            // Write and Read Proxies have individual requests,
173
+            // so only delete proxies of this permission
174
+            if ($proxy->getPermissions() === $permission) {
175
+                $this->proxyMapper->delete($proxy);
176
+            }
177
+        }
178
+    }
179
+
180
+    /**
181
+     * @param string $principalUri
182
+     * @return bool
183
+     */
184
+    private function isProxyPrincipal(string $principalUri):bool {
185
+        [$realPrincipalUri, $proxy] = \Sabre\Uri\split($principalUri);
186
+        [$prefix, $userId] = \Sabre\Uri\split($realPrincipalUri);
187
+
188
+        if (!isset($prefix) || !isset($userId)) {
189
+            return false;
190
+        }
191
+        if ($prefix !== $this->principalPrefix) {
192
+            return false;
193
+        }
194
+
195
+        return $proxy === 'calendar-proxy-read'
196
+            || $proxy === 'calendar-proxy-write';
197
+    }
198
+
199
+    /**
200
+     * @param string $principalUri
201
+     * @return bool
202
+     */
203
+    private function isReadProxyPrincipal(string $principalUri):bool {
204
+        [, $proxy] = \Sabre\Uri\split($principalUri);
205
+        return $proxy === 'calendar-proxy-read';
206
+    }
207
+
208
+    /**
209
+     * @param string $principalUri
210
+     * @return bool
211
+     */
212
+    private function isWriteProxyPrincipal(string $principalUri):bool {
213
+        [, $proxy] = \Sabre\Uri\split($principalUri);
214
+        return $proxy === 'calendar-proxy-write';
215
+    }
216
+
217
+    /**
218
+     * @param string $principalUri
219
+     * @return string
220
+     */
221
+    private function getPrincipalUriFromProxyPrincipal(string $principalUri):string {
222
+        [$realPrincipalUri, ] = \Sabre\Uri\split($principalUri);
223
+        return $realPrincipalUri;
224
+    }
225 225
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
 		$proxies = $this->proxyMapper->getProxiesFor($principal);
93 93
 		foreach ($proxies as $proxy) {
94 94
 			if ($proxy->getPermissions() === ProxyMapper::PERMISSION_READ) {
95
-				$groups[] = $proxy->getOwnerId() . '/calendar-proxy-read';
95
+				$groups[] = $proxy->getOwnerId().'/calendar-proxy-read';
96 96
 			}
97 97
 
98 98
 			if ($proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) {
99
-				$groups[] = $proxy->getOwnerId() . '/calendar-proxy-write';
99
+				$groups[] = $proxy->getOwnerId().'/calendar-proxy-write';
100 100
 			}
101 101
 		}
102 102
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 			[$prefix, $name] = \Sabre\Uri\split($member);
137 137
 
138 138
 			if ($prefix !== $this->principalPrefix) {
139
-				throw new Exception('Invalid member group prefix: ' . $prefix);
139
+				throw new Exception('Invalid member group prefix: '.$prefix);
140 140
 			}
141 141
 
142 142
 			$principalArray = $this->getPrincipalByPath($member);
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 					$proxy->setPermissions($proxy->getPermissions() | $permission);
152 152
 					$this->proxyMapper->update($proxy);
153 153
 
154
-					$proxies = array_filter($proxies, function (Proxy $p) use ($proxy) {
154
+					$proxies = array_filter($proxies, function(Proxy $p) use ($proxy) {
155 155
 						return $p->getId() !== $proxy->getId();
156 156
 					});
157 157
 					break;
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Plugin.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -26,30 +26,30 @@
 block discarded – undo
26 26
 namespace OCA\DAV\CalDAV;
27 27
 
28 28
 class Plugin extends \Sabre\CalDAV\Plugin {
29
-	public const SYSTEM_CALENDAR_ROOT = 'system-calendars';
29
+    public const SYSTEM_CALENDAR_ROOT = 'system-calendars';
30 30
 
31
-	/**
32
-	 * Returns the path to a principal's calendar home.
33
-	 *
34
-	 * The return url must not end with a slash.
35
-	 * This function should return null in case a principal did not have
36
-	 * a calendar home.
37
-	 *
38
-	 * @param string $principalUrl
39
-	 * @return string|null
40
-	 */
41
-	public function getCalendarHomeForPrincipal($principalUrl) {
42
-		if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
43
-			[, $principalId] = \Sabre\Uri\split($principalUrl);
44
-			return self::CALENDAR_ROOT . '/' . $principalId;
45
-		}
46
-		if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) {
47
-			[, $principalId] = \Sabre\Uri\split($principalUrl);
48
-			return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId;
49
-		}
50
-		if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) {
51
-			[, $principalId] = \Sabre\Uri\split($principalUrl);
52
-			return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId;
53
-		}
54
-	}
31
+    /**
32
+     * Returns the path to a principal's calendar home.
33
+     *
34
+     * The return url must not end with a slash.
35
+     * This function should return null in case a principal did not have
36
+     * a calendar home.
37
+     *
38
+     * @param string $principalUrl
39
+     * @return string|null
40
+     */
41
+    public function getCalendarHomeForPrincipal($principalUrl) {
42
+        if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
43
+            [, $principalId] = \Sabre\Uri\split($principalUrl);
44
+            return self::CALENDAR_ROOT . '/' . $principalId;
45
+        }
46
+        if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) {
47
+            [, $principalId] = \Sabre\Uri\split($principalUrl);
48
+            return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId;
49
+        }
50
+        if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) {
51
+            [, $principalId] = \Sabre\Uri\split($principalUrl);
52
+            return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId;
53
+        }
54
+    }
55 55
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,15 +41,15 @@
 block discarded – undo
41 41
 	public function getCalendarHomeForPrincipal($principalUrl) {
42 42
 		if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
43 43
 			[, $principalId] = \Sabre\Uri\split($principalUrl);
44
-			return self::CALENDAR_ROOT . '/' . $principalId;
44
+			return self::CALENDAR_ROOT.'/'.$principalId;
45 45
 		}
46 46
 		if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) {
47 47
 			[, $principalId] = \Sabre\Uri\split($principalUrl);
48
-			return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId;
48
+			return self::SYSTEM_CALENDAR_ROOT.'/calendar-resources/'.$principalId;
49 49
 		}
50 50
 		if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) {
51 51
 			[, $principalId] = \Sabre\Uri\split($principalUrl);
52
-			return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId;
52
+			return self::SYSTEM_CALENDAR_ROOT.'/calendar-rooms/'.$principalId;
53 53
 		}
54 54
 	}
55 55
 }
Please login to merge, or discard this patch.
apps/settings/lib/Listener/AppPasswordCreatedActivityListener.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
 		try {
66 66
 			$this->activityManager->publish($activity);
67 67
 		} catch (BadMethodCallException $e) {
68
-			$this->logger->warning('Could not publish activity: ' . $e->getMessage(), [
68
+			$this->logger->warning('Could not publish activity: '.$e->getMessage(), [
69 69
 				'exception' => $e
70 70
 			]);
71 71
 		}
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -21,32 +21,32 @@
 block discarded – undo
21 21
  * @template-implements IEventListener<\OC\Authentication\Events\AppPasswordCreatedEvent>
22 22
  */
23 23
 class AppPasswordCreatedActivityListener implements IEventListener {
24
-	public function __construct(
25
-		private IActivityManager $activityManager,
26
-		private IUserSession $userSession,
27
-		private LoggerInterface $logger,
28
-	) {
29
-	}
24
+    public function __construct(
25
+        private IActivityManager $activityManager,
26
+        private IUserSession $userSession,
27
+        private LoggerInterface $logger,
28
+    ) {
29
+    }
30 30
 
31
-	public function handle(Event $event): void {
32
-		if (!($event instanceof AppPasswordCreatedEvent)) {
33
-			return;
34
-		}
31
+    public function handle(Event $event): void {
32
+        if (!($event instanceof AppPasswordCreatedEvent)) {
33
+            return;
34
+        }
35 35
 
36
-		$activity = $this->activityManager->generateEvent();
37
-		$activity->setApp('settings')
38
-			->setType('security')
39
-			->setAffectedUser($event->getToken()->getUID())
40
-			->setAuthor($this->userSession->getUser() ? $this->userSession->getUser()->getUID() : '')
41
-			->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $event->getToken()->getName()])
42
-			->setObject('app_token', $event->getToken()->getId());
36
+        $activity = $this->activityManager->generateEvent();
37
+        $activity->setApp('settings')
38
+            ->setType('security')
39
+            ->setAffectedUser($event->getToken()->getUID())
40
+            ->setAuthor($this->userSession->getUser() ? $this->userSession->getUser()->getUID() : '')
41
+            ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $event->getToken()->getName()])
42
+            ->setObject('app_token', $event->getToken()->getId());
43 43
 
44
-		try {
45
-			$this->activityManager->publish($activity);
46
-		} catch (BadMethodCallException $e) {
47
-			$this->logger->warning('Could not publish activity: ' . $e->getMessage(), [
48
-				'exception' => $e
49
-			]);
50
-		}
51
-	}
44
+        try {
45
+            $this->activityManager->publish($activity);
46
+        } catch (BadMethodCallException $e) {
47
+            $this->logger->warning('Could not publish activity: ' . $e->getMessage(), [
48
+                'exception' => $e
49
+            ]);
50
+        }
51
+    }
52 52
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/DBConfigService.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 		$stmt->closeCursor();
141 141
 
142 142
 		foreach ($result as $row) {
143
-			if ((int)$row['count'] > 1) {
143
+			if ((int) $row['count'] > 1) {
144 144
 				$this->removeApplicable($row['mount_id'], $applicableType, $applicableId);
145 145
 			} else {
146 146
 				$this->removeMount($row['mount_id']);
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 	 */
215 215
 	public function getAdminMountsForMultiple($type, array $values) {
216 216
 		$builder = $this->connection->getQueryBuilder();
217
-		$params = array_map(function ($value) use ($builder) {
217
+		$params = array_map(function($value) use ($builder) {
218 218
 			return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
219 219
 		}, $values);
220 220
 
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 		}
413 413
 		$uniqueMounts = array_values($uniqueMounts);
414 414
 
415
-		$mountIds = array_map(function ($mount) {
415
+		$mountIds = array_map(function($mount) {
416 416
 			return $mount['mount_id'];
417 417
 		}, $uniqueMounts);
418 418
 		$mountIds = array_values(array_unique($mountIds));
@@ -421,9 +421,9 @@  discard block
 block discarded – undo
421 421
 		$config = $this->getConfigForMounts($mountIds);
422 422
 		$options = $this->getOptionsForMounts($mountIds);
423 423
 
424
-		return array_map(function ($mount, $applicable, $config, $options) {
425
-			$mount['type'] = (int)$mount['type'];
426
-			$mount['priority'] = (int)$mount['priority'];
424
+		return array_map(function($mount, $applicable, $config, $options) {
425
+			$mount['type'] = (int) $mount['type'];
426
+			$mount['priority'] = (int) $mount['priority'];
427 427
 			$mount['applicable'] = $applicable;
428 428
 			$mount['config'] = $config;
429 429
 			$mount['options'] = $options;
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 		}
446 446
 		$builder = $this->connection->getQueryBuilder();
447 447
 		$fields[] = 'mount_id';
448
-		$placeHolders = array_map(function ($id) use ($builder) {
448
+		$placeHolders = array_map(function($id) use ($builder) {
449 449
 			return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
450 450
 		}, $mountIds);
451 451
 		$query = $builder->select($fields)
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 		}
463 463
 		foreach ($rows as $row) {
464 464
 			if (isset($row['type'])) {
465
-				$row['type'] = (int)$row['type'];
465
+				$row['type'] = (int) $row['type'];
466 466
 			}
467 467
 			$result[$row['mount_id']][] = $row;
468 468
 		}
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	public function getOptionsForMounts($mountIds) {
494 494
 		$mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
495 495
 		$optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
496
-		return array_map(function (array $options) {
497
-			return array_map(function ($option) {
496
+		return array_map(function(array $options) {
497
+			return array_map(function($option) {
498 498
 				return json_decode($option);
499 499
 			}, $options);
500 500
 		}, $optionsMap);
@@ -505,16 +505,16 @@  discard block
 block discarded – undo
505 505
 	 * @return array ['key1' => $value1, ...]
506 506
 	 */
507 507
 	private function createKeyValueMap(array $keyValuePairs) {
508
-		$decryptedPairts = array_map(function ($pair) {
508
+		$decryptedPairts = array_map(function($pair) {
509 509
 			if ($pair['key'] === 'password') {
510 510
 				$pair['value'] = $this->decryptValue($pair['value']);
511 511
 			}
512 512
 			return $pair;
513 513
 		}, $keyValuePairs);
514
-		$keys = array_map(function ($pair) {
514
+		$keys = array_map(function($pair) {
515 515
 			return $pair['key'];
516 516
 		}, $decryptedPairts);
517
-		$values = array_map(function ($pair) {
517
+		$values = array_map(function($pair) {
518 518
 			return $pair['value'];
519 519
 		}, $decryptedPairts);
520 520
 
Please login to merge, or discard this patch.
Indentation   +482 added lines, -482 removed lines patch added patch discarded remove patch
@@ -15,486 +15,486 @@
 block discarded – undo
15 15
  * Stores the mount config in the database
16 16
  */
17 17
 class DBConfigService {
18
-	public const MOUNT_TYPE_ADMIN = 1;
19
-	public const MOUNT_TYPE_PERSONAL = 2;
20
-	/** @deprecated use MOUNT_TYPE_PERSONAL (full uppercase) instead */
21
-	public const MOUNT_TYPE_PERSONAl = 2;
22
-
23
-	public const APPLICABLE_TYPE_GLOBAL = 1;
24
-	public const APPLICABLE_TYPE_GROUP = 2;
25
-	public const APPLICABLE_TYPE_USER = 3;
26
-
27
-	public function __construct(
28
-		private IDBConnection $connection,
29
-		private ICrypto $crypto,
30
-	) {
31
-	}
32
-
33
-	public function getMountById(int $mountId): ?array {
34
-		$builder = $this->connection->getQueryBuilder();
35
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
36
-			->from('external_mounts', 'm')
37
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
38
-		$mounts = $this->getMountsFromQuery($query);
39
-		if (count($mounts) > 0) {
40
-			return $mounts[0];
41
-		} else {
42
-			return null;
43
-		}
44
-	}
45
-
46
-	/**
47
-	 * Get all configured mounts
48
-	 *
49
-	 * @return array
50
-	 */
51
-	public function getAllMounts() {
52
-		$builder = $this->connection->getQueryBuilder();
53
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
54
-			->from('external_mounts');
55
-		return $this->getMountsFromQuery($query);
56
-	}
57
-
58
-	public function getMountsForUser($userId, $groupIds) {
59
-		$builder = $this->connection->getQueryBuilder();
60
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
61
-			->from('external_mounts', 'm')
62
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
63
-			->where($builder->expr()->orX(
64
-				$builder->expr()->andX( // global mounts
65
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
66
-					$builder->expr()->isNull('a.value')
67
-				),
68
-				$builder->expr()->andX( // mounts for user
69
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
70
-					$builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
71
-				),
72
-				$builder->expr()->andX( // mounts for group
73
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
74
-					$builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))
75
-				)
76
-			));
77
-
78
-		return $this->getMountsFromQuery($query);
79
-	}
80
-
81
-	public function modifyMountsOnUserDelete(string $uid): void {
82
-		$this->modifyMountsOnDelete($uid, self::APPLICABLE_TYPE_USER);
83
-	}
84
-
85
-	public function modifyMountsOnGroupDelete(string $gid): void {
86
-		$this->modifyMountsOnDelete($gid, self::APPLICABLE_TYPE_GROUP);
87
-	}
88
-
89
-	protected function modifyMountsOnDelete(string $applicableId, int $applicableType): void {
90
-		$builder = $this->connection->getQueryBuilder();
91
-		$query = $builder->select(['a.mount_id', $builder->func()->count('a.mount_id', 'count')])
92
-			->from('external_applicable', 'a')
93
-			->leftJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id'))
94
-			->where($builder->expr()->andX(
95
-				$builder->expr()->eq('b.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)),
96
-				$builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId))
97
-			)
98
-			)
99
-			->groupBy(['a.mount_id']);
100
-		$stmt = $query->executeQuery();
101
-		$result = $stmt->fetchAll();
102
-		$stmt->closeCursor();
103
-
104
-		foreach ($result as $row) {
105
-			if ((int)$row['count'] > 1) {
106
-				$this->removeApplicable($row['mount_id'], $applicableType, $applicableId);
107
-			} else {
108
-				$this->removeMount($row['mount_id']);
109
-			}
110
-		}
111
-	}
112
-
113
-	/**
114
-	 * Get admin defined mounts
115
-	 *
116
-	 * @return array
117
-	 */
118
-	public function getAdminMounts() {
119
-		$builder = $this->connection->getQueryBuilder();
120
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
121
-			->from('external_mounts')
122
-			->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
123
-		return $this->getMountsFromQuery($query);
124
-	}
125
-
126
-	protected function getForQuery(IQueryBuilder $builder, $type, $value) {
127
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
128
-			->from('external_mounts', 'm')
129
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
130
-			->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
131
-
132
-		if (is_null($value)) {
133
-			$query = $query->andWhere($builder->expr()->isNull('a.value'));
134
-		} else {
135
-			$query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value)));
136
-		}
137
-
138
-		return $query;
139
-	}
140
-
141
-	/**
142
-	 * Get mounts by applicable
143
-	 *
144
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
145
-	 * @param string|null $value user_id, group_id or null for global mounts
146
-	 * @return array
147
-	 */
148
-	public function getMountsFor($type, $value) {
149
-		$builder = $this->connection->getQueryBuilder();
150
-		$query = $this->getForQuery($builder, $type, $value);
151
-
152
-		return $this->getMountsFromQuery($query);
153
-	}
154
-
155
-	/**
156
-	 * Get admin defined mounts by applicable
157
-	 *
158
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
159
-	 * @param string|null $value user_id, group_id or null for global mounts
160
-	 * @return array
161
-	 */
162
-	public function getAdminMountsFor($type, $value) {
163
-		$builder = $this->connection->getQueryBuilder();
164
-		$query = $this->getForQuery($builder, $type, $value);
165
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
166
-
167
-		return $this->getMountsFromQuery($query);
168
-	}
169
-
170
-	/**
171
-	 * Get admin defined mounts for multiple applicable
172
-	 *
173
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
174
-	 * @param string[] $values user_ids or group_ids
175
-	 * @return array
176
-	 */
177
-	public function getAdminMountsForMultiple($type, array $values) {
178
-		$builder = $this->connection->getQueryBuilder();
179
-		$params = array_map(function ($value) use ($builder) {
180
-			return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
181
-		}, $values);
182
-
183
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
184
-			->from('external_mounts', 'm')
185
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
186
-			->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)))
187
-			->andWhere($builder->expr()->in('a.value', $params));
188
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
189
-
190
-		return $this->getMountsFromQuery($query);
191
-	}
192
-
193
-	/**
194
-	 * Get user defined mounts by applicable
195
-	 *
196
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
197
-	 * @param string|null $value user_id, group_id or null for global mounts
198
-	 * @return array
199
-	 */
200
-	public function getUserMountsFor($type, $value) {
201
-		$builder = $this->connection->getQueryBuilder();
202
-		$query = $this->getForQuery($builder, $type, $value);
203
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAL, IQueryBuilder::PARAM_INT)));
204
-
205
-		return $this->getMountsFromQuery($query);
206
-	}
207
-
208
-	/**
209
-	 * Add a mount to the database
210
-	 *
211
-	 * @param string $mountPoint
212
-	 * @param string $storageBackend
213
-	 * @param string $authBackend
214
-	 * @param int $priority
215
-	 * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
216
-	 * @return int the id of the new mount
217
-	 */
218
-	public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
219
-		if (!$priority) {
220
-			$priority = 100;
221
-		}
222
-		$builder = $this->connection->getQueryBuilder();
223
-		$query = $builder->insert('external_mounts')
224
-			->values([
225
-				'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR),
226
-				'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR),
227
-				'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR),
228
-				'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
229
-				'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
230
-			]);
231
-		$query->executeStatement();
232
-		return $query->getLastInsertId();
233
-	}
234
-
235
-	/**
236
-	 * Remove a mount from the database
237
-	 *
238
-	 * @param int $mountId
239
-	 */
240
-	public function removeMount($mountId) {
241
-		$builder = $this->connection->getQueryBuilder();
242
-		$query = $builder->delete('external_mounts')
243
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
244
-		$query->executeStatement();
245
-
246
-		$builder = $this->connection->getQueryBuilder();
247
-		$query = $builder->delete('external_applicable')
248
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
249
-		$query->executeStatement();
250
-
251
-		$builder = $this->connection->getQueryBuilder();
252
-		$query = $builder->delete('external_config')
253
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
254
-		$query->executeStatement();
255
-
256
-		$builder = $this->connection->getQueryBuilder();
257
-		$query = $builder->delete('external_options')
258
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
259
-		$query->executeStatement();
260
-	}
261
-
262
-	/**
263
-	 * @param int $mountId
264
-	 * @param string $newMountPoint
265
-	 */
266
-	public function setMountPoint($mountId, $newMountPoint) {
267
-		$builder = $this->connection->getQueryBuilder();
268
-
269
-		$query = $builder->update('external_mounts')
270
-			->set('mount_point', $builder->createNamedParameter($newMountPoint))
271
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
272
-
273
-		$query->executeStatement();
274
-	}
275
-
276
-	/**
277
-	 * @param int $mountId
278
-	 * @param string $newAuthBackend
279
-	 */
280
-	public function setAuthBackend($mountId, $newAuthBackend) {
281
-		$builder = $this->connection->getQueryBuilder();
282
-
283
-		$query = $builder->update('external_mounts')
284
-			->set('auth_backend', $builder->createNamedParameter($newAuthBackend))
285
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
286
-
287
-		$query->executeStatement();
288
-	}
289
-
290
-	/**
291
-	 * @param int $mountId
292
-	 * @param string $key
293
-	 * @param string $value
294
-	 */
295
-	public function setConfig($mountId, $key, $value) {
296
-		if ($key === 'password') {
297
-			$value = $this->encryptValue($value);
298
-		}
299
-
300
-		try {
301
-			$builder = $this->connection->getQueryBuilder();
302
-			$builder->insert('external_config')
303
-				->setValue('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))
304
-				->setValue('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))
305
-				->setValue('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
306
-				->execute();
307
-		} catch (UniqueConstraintViolationException $e) {
308
-			$builder = $this->connection->getQueryBuilder();
309
-			$query = $builder->update('external_config')
310
-				->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
311
-				->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
312
-				->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
313
-			$query->executeStatement();
314
-		}
315
-	}
316
-
317
-	/**
318
-	 * @param int $mountId
319
-	 * @param string $key
320
-	 * @param string $value
321
-	 */
322
-	public function setOption($mountId, $key, $value) {
323
-		try {
324
-			$builder = $this->connection->getQueryBuilder();
325
-			$builder->insert('external_options')
326
-				->setValue('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))
327
-				->setValue('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))
328
-				->setValue('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
329
-				->execute();
330
-		} catch (UniqueConstraintViolationException $e) {
331
-			$builder = $this->connection->getQueryBuilder();
332
-			$query = $builder->update('external_options')
333
-				->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
334
-				->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
335
-				->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
336
-			$query->executeStatement();
337
-		}
338
-	}
339
-
340
-	public function addApplicable($mountId, $type, $value) {
341
-		try {
342
-			$builder = $this->connection->getQueryBuilder();
343
-			$builder->insert('external_applicable')
344
-				->setValue('mount_id', $builder->createNamedParameter($mountId))
345
-				->setValue('type', $builder->createNamedParameter($type))
346
-				->setValue('value', $builder->createNamedParameter($value))
347
-				->execute();
348
-		} catch (UniqueConstraintViolationException $e) {
349
-			// applicable exists already
350
-		}
351
-	}
352
-
353
-	public function removeApplicable($mountId, $type, $value) {
354
-		$builder = $this->connection->getQueryBuilder();
355
-		$query = $builder->delete('external_applicable')
356
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
357
-			->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
358
-
359
-		if (is_null($value)) {
360
-			$query = $query->andWhere($builder->expr()->isNull('value'));
361
-		} else {
362
-			$query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)));
363
-		}
364
-
365
-		$query->executeStatement();
366
-	}
367
-
368
-	private function getMountsFromQuery(IQueryBuilder $query) {
369
-		$result = $query->executeQuery();
370
-		$mounts = $result->fetchAll();
371
-		$uniqueMounts = [];
372
-		foreach ($mounts as $mount) {
373
-			$id = $mount['mount_id'];
374
-			if (!isset($uniqueMounts[$id])) {
375
-				$uniqueMounts[$id] = $mount;
376
-			}
377
-		}
378
-		$uniqueMounts = array_values($uniqueMounts);
379
-
380
-		$mountIds = array_map(function ($mount) {
381
-			return $mount['mount_id'];
382
-		}, $uniqueMounts);
383
-		$mountIds = array_values(array_unique($mountIds));
384
-
385
-		$applicable = $this->getApplicableForMounts($mountIds);
386
-		$config = $this->getConfigForMounts($mountIds);
387
-		$options = $this->getOptionsForMounts($mountIds);
388
-
389
-		return array_map(function ($mount, $applicable, $config, $options) {
390
-			$mount['type'] = (int)$mount['type'];
391
-			$mount['priority'] = (int)$mount['priority'];
392
-			$mount['applicable'] = $applicable;
393
-			$mount['config'] = $config;
394
-			$mount['options'] = $options;
395
-			return $mount;
396
-		}, $uniqueMounts, $applicable, $config, $options);
397
-	}
398
-
399
-	/**
400
-	 * Get mount options from a table grouped by mount id
401
-	 *
402
-	 * @param string $table
403
-	 * @param string[] $fields
404
-	 * @param int[] $mountIds
405
-	 * @return array [$mountId => [['field1' => $value1, ...], ...], ...]
406
-	 */
407
-	private function selectForMounts($table, array $fields, array $mountIds) {
408
-		if (count($mountIds) === 0) {
409
-			return [];
410
-		}
411
-		$builder = $this->connection->getQueryBuilder();
412
-		$fields[] = 'mount_id';
413
-		$placeHolders = array_map(function ($id) use ($builder) {
414
-			return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
415
-		}, $mountIds);
416
-		$query = $builder->select($fields)
417
-			->from($table)
418
-			->where($builder->expr()->in('mount_id', $placeHolders));
419
-
420
-		$result = $query->executeQuery();
421
-		$rows = $result->fetchAll();
422
-		$result->closeCursor();
423
-
424
-		$result = [];
425
-		foreach ($mountIds as $mountId) {
426
-			$result[$mountId] = [];
427
-		}
428
-		foreach ($rows as $row) {
429
-			if (isset($row['type'])) {
430
-				$row['type'] = (int)$row['type'];
431
-			}
432
-			$result[$row['mount_id']][] = $row;
433
-		}
434
-		return $result;
435
-	}
436
-
437
-	/**
438
-	 * @param int[] $mountIds
439
-	 * @return array [$id => [['type' => $type, 'value' => $value], ...], ...]
440
-	 */
441
-	public function getApplicableForMounts($mountIds) {
442
-		return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds);
443
-	}
444
-
445
-	/**
446
-	 * @param int[] $mountIds
447
-	 * @return array [$id => ['key1' => $value1, ...], ...]
448
-	 */
449
-	public function getConfigForMounts($mountIds) {
450
-		$mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds);
451
-		return array_map([$this, 'createKeyValueMap'], $mountConfigs);
452
-	}
453
-
454
-	/**
455
-	 * @param int[] $mountIds
456
-	 * @return array [$id => ['key1' => $value1, ...], ...]
457
-	 */
458
-	public function getOptionsForMounts($mountIds) {
459
-		$mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
460
-		$optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
461
-		return array_map(function (array $options) {
462
-			return array_map(function ($option) {
463
-				return json_decode($option);
464
-			}, $options);
465
-		}, $optionsMap);
466
-	}
467
-
468
-	/**
469
-	 * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...]
470
-	 * @return array ['key1' => $value1, ...]
471
-	 */
472
-	private function createKeyValueMap(array $keyValuePairs) {
473
-		$decryptedPairts = array_map(function ($pair) {
474
-			if ($pair['key'] === 'password') {
475
-				$pair['value'] = $this->decryptValue($pair['value']);
476
-			}
477
-			return $pair;
478
-		}, $keyValuePairs);
479
-		$keys = array_map(function ($pair) {
480
-			return $pair['key'];
481
-		}, $decryptedPairts);
482
-		$values = array_map(function ($pair) {
483
-			return $pair['value'];
484
-		}, $decryptedPairts);
485
-
486
-		return array_combine($keys, $values);
487
-	}
488
-
489
-	private function encryptValue($value) {
490
-		return $this->crypto->encrypt($value);
491
-	}
492
-
493
-	private function decryptValue($value) {
494
-		try {
495
-			return $this->crypto->decrypt($value);
496
-		} catch (\Exception $e) {
497
-			return $value;
498
-		}
499
-	}
18
+    public const MOUNT_TYPE_ADMIN = 1;
19
+    public const MOUNT_TYPE_PERSONAL = 2;
20
+    /** @deprecated use MOUNT_TYPE_PERSONAL (full uppercase) instead */
21
+    public const MOUNT_TYPE_PERSONAl = 2;
22
+
23
+    public const APPLICABLE_TYPE_GLOBAL = 1;
24
+    public const APPLICABLE_TYPE_GROUP = 2;
25
+    public const APPLICABLE_TYPE_USER = 3;
26
+
27
+    public function __construct(
28
+        private IDBConnection $connection,
29
+        private ICrypto $crypto,
30
+    ) {
31
+    }
32
+
33
+    public function getMountById(int $mountId): ?array {
34
+        $builder = $this->connection->getQueryBuilder();
35
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
36
+            ->from('external_mounts', 'm')
37
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
38
+        $mounts = $this->getMountsFromQuery($query);
39
+        if (count($mounts) > 0) {
40
+            return $mounts[0];
41
+        } else {
42
+            return null;
43
+        }
44
+    }
45
+
46
+    /**
47
+     * Get all configured mounts
48
+     *
49
+     * @return array
50
+     */
51
+    public function getAllMounts() {
52
+        $builder = $this->connection->getQueryBuilder();
53
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
54
+            ->from('external_mounts');
55
+        return $this->getMountsFromQuery($query);
56
+    }
57
+
58
+    public function getMountsForUser($userId, $groupIds) {
59
+        $builder = $this->connection->getQueryBuilder();
60
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
61
+            ->from('external_mounts', 'm')
62
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
63
+            ->where($builder->expr()->orX(
64
+                $builder->expr()->andX( // global mounts
65
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
66
+                    $builder->expr()->isNull('a.value')
67
+                ),
68
+                $builder->expr()->andX( // mounts for user
69
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
70
+                    $builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
71
+                ),
72
+                $builder->expr()->andX( // mounts for group
73
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
74
+                    $builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))
75
+                )
76
+            ));
77
+
78
+        return $this->getMountsFromQuery($query);
79
+    }
80
+
81
+    public function modifyMountsOnUserDelete(string $uid): void {
82
+        $this->modifyMountsOnDelete($uid, self::APPLICABLE_TYPE_USER);
83
+    }
84
+
85
+    public function modifyMountsOnGroupDelete(string $gid): void {
86
+        $this->modifyMountsOnDelete($gid, self::APPLICABLE_TYPE_GROUP);
87
+    }
88
+
89
+    protected function modifyMountsOnDelete(string $applicableId, int $applicableType): void {
90
+        $builder = $this->connection->getQueryBuilder();
91
+        $query = $builder->select(['a.mount_id', $builder->func()->count('a.mount_id', 'count')])
92
+            ->from('external_applicable', 'a')
93
+            ->leftJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id'))
94
+            ->where($builder->expr()->andX(
95
+                $builder->expr()->eq('b.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)),
96
+                $builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId))
97
+            )
98
+            )
99
+            ->groupBy(['a.mount_id']);
100
+        $stmt = $query->executeQuery();
101
+        $result = $stmt->fetchAll();
102
+        $stmt->closeCursor();
103
+
104
+        foreach ($result as $row) {
105
+            if ((int)$row['count'] > 1) {
106
+                $this->removeApplicable($row['mount_id'], $applicableType, $applicableId);
107
+            } else {
108
+                $this->removeMount($row['mount_id']);
109
+            }
110
+        }
111
+    }
112
+
113
+    /**
114
+     * Get admin defined mounts
115
+     *
116
+     * @return array
117
+     */
118
+    public function getAdminMounts() {
119
+        $builder = $this->connection->getQueryBuilder();
120
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
121
+            ->from('external_mounts')
122
+            ->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
123
+        return $this->getMountsFromQuery($query);
124
+    }
125
+
126
+    protected function getForQuery(IQueryBuilder $builder, $type, $value) {
127
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
128
+            ->from('external_mounts', 'm')
129
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
130
+            ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
131
+
132
+        if (is_null($value)) {
133
+            $query = $query->andWhere($builder->expr()->isNull('a.value'));
134
+        } else {
135
+            $query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value)));
136
+        }
137
+
138
+        return $query;
139
+    }
140
+
141
+    /**
142
+     * Get mounts by applicable
143
+     *
144
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
145
+     * @param string|null $value user_id, group_id or null for global mounts
146
+     * @return array
147
+     */
148
+    public function getMountsFor($type, $value) {
149
+        $builder = $this->connection->getQueryBuilder();
150
+        $query = $this->getForQuery($builder, $type, $value);
151
+
152
+        return $this->getMountsFromQuery($query);
153
+    }
154
+
155
+    /**
156
+     * Get admin defined mounts by applicable
157
+     *
158
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
159
+     * @param string|null $value user_id, group_id or null for global mounts
160
+     * @return array
161
+     */
162
+    public function getAdminMountsFor($type, $value) {
163
+        $builder = $this->connection->getQueryBuilder();
164
+        $query = $this->getForQuery($builder, $type, $value);
165
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
166
+
167
+        return $this->getMountsFromQuery($query);
168
+    }
169
+
170
+    /**
171
+     * Get admin defined mounts for multiple applicable
172
+     *
173
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
174
+     * @param string[] $values user_ids or group_ids
175
+     * @return array
176
+     */
177
+    public function getAdminMountsForMultiple($type, array $values) {
178
+        $builder = $this->connection->getQueryBuilder();
179
+        $params = array_map(function ($value) use ($builder) {
180
+            return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
181
+        }, $values);
182
+
183
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
184
+            ->from('external_mounts', 'm')
185
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
186
+            ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)))
187
+            ->andWhere($builder->expr()->in('a.value', $params));
188
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
189
+
190
+        return $this->getMountsFromQuery($query);
191
+    }
192
+
193
+    /**
194
+     * Get user defined mounts by applicable
195
+     *
196
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
197
+     * @param string|null $value user_id, group_id or null for global mounts
198
+     * @return array
199
+     */
200
+    public function getUserMountsFor($type, $value) {
201
+        $builder = $this->connection->getQueryBuilder();
202
+        $query = $this->getForQuery($builder, $type, $value);
203
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAL, IQueryBuilder::PARAM_INT)));
204
+
205
+        return $this->getMountsFromQuery($query);
206
+    }
207
+
208
+    /**
209
+     * Add a mount to the database
210
+     *
211
+     * @param string $mountPoint
212
+     * @param string $storageBackend
213
+     * @param string $authBackend
214
+     * @param int $priority
215
+     * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
216
+     * @return int the id of the new mount
217
+     */
218
+    public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
219
+        if (!$priority) {
220
+            $priority = 100;
221
+        }
222
+        $builder = $this->connection->getQueryBuilder();
223
+        $query = $builder->insert('external_mounts')
224
+            ->values([
225
+                'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR),
226
+                'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR),
227
+                'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR),
228
+                'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
229
+                'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
230
+            ]);
231
+        $query->executeStatement();
232
+        return $query->getLastInsertId();
233
+    }
234
+
235
+    /**
236
+     * Remove a mount from the database
237
+     *
238
+     * @param int $mountId
239
+     */
240
+    public function removeMount($mountId) {
241
+        $builder = $this->connection->getQueryBuilder();
242
+        $query = $builder->delete('external_mounts')
243
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
244
+        $query->executeStatement();
245
+
246
+        $builder = $this->connection->getQueryBuilder();
247
+        $query = $builder->delete('external_applicable')
248
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
249
+        $query->executeStatement();
250
+
251
+        $builder = $this->connection->getQueryBuilder();
252
+        $query = $builder->delete('external_config')
253
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
254
+        $query->executeStatement();
255
+
256
+        $builder = $this->connection->getQueryBuilder();
257
+        $query = $builder->delete('external_options')
258
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
259
+        $query->executeStatement();
260
+    }
261
+
262
+    /**
263
+     * @param int $mountId
264
+     * @param string $newMountPoint
265
+     */
266
+    public function setMountPoint($mountId, $newMountPoint) {
267
+        $builder = $this->connection->getQueryBuilder();
268
+
269
+        $query = $builder->update('external_mounts')
270
+            ->set('mount_point', $builder->createNamedParameter($newMountPoint))
271
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
272
+
273
+        $query->executeStatement();
274
+    }
275
+
276
+    /**
277
+     * @param int $mountId
278
+     * @param string $newAuthBackend
279
+     */
280
+    public function setAuthBackend($mountId, $newAuthBackend) {
281
+        $builder = $this->connection->getQueryBuilder();
282
+
283
+        $query = $builder->update('external_mounts')
284
+            ->set('auth_backend', $builder->createNamedParameter($newAuthBackend))
285
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
286
+
287
+        $query->executeStatement();
288
+    }
289
+
290
+    /**
291
+     * @param int $mountId
292
+     * @param string $key
293
+     * @param string $value
294
+     */
295
+    public function setConfig($mountId, $key, $value) {
296
+        if ($key === 'password') {
297
+            $value = $this->encryptValue($value);
298
+        }
299
+
300
+        try {
301
+            $builder = $this->connection->getQueryBuilder();
302
+            $builder->insert('external_config')
303
+                ->setValue('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))
304
+                ->setValue('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))
305
+                ->setValue('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
306
+                ->execute();
307
+        } catch (UniqueConstraintViolationException $e) {
308
+            $builder = $this->connection->getQueryBuilder();
309
+            $query = $builder->update('external_config')
310
+                ->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
311
+                ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
312
+                ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
313
+            $query->executeStatement();
314
+        }
315
+    }
316
+
317
+    /**
318
+     * @param int $mountId
319
+     * @param string $key
320
+     * @param string $value
321
+     */
322
+    public function setOption($mountId, $key, $value) {
323
+        try {
324
+            $builder = $this->connection->getQueryBuilder();
325
+            $builder->insert('external_options')
326
+                ->setValue('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))
327
+                ->setValue('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))
328
+                ->setValue('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
329
+                ->execute();
330
+        } catch (UniqueConstraintViolationException $e) {
331
+            $builder = $this->connection->getQueryBuilder();
332
+            $query = $builder->update('external_options')
333
+                ->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
334
+                ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
335
+                ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
336
+            $query->executeStatement();
337
+        }
338
+    }
339
+
340
+    public function addApplicable($mountId, $type, $value) {
341
+        try {
342
+            $builder = $this->connection->getQueryBuilder();
343
+            $builder->insert('external_applicable')
344
+                ->setValue('mount_id', $builder->createNamedParameter($mountId))
345
+                ->setValue('type', $builder->createNamedParameter($type))
346
+                ->setValue('value', $builder->createNamedParameter($value))
347
+                ->execute();
348
+        } catch (UniqueConstraintViolationException $e) {
349
+            // applicable exists already
350
+        }
351
+    }
352
+
353
+    public function removeApplicable($mountId, $type, $value) {
354
+        $builder = $this->connection->getQueryBuilder();
355
+        $query = $builder->delete('external_applicable')
356
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
357
+            ->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
358
+
359
+        if (is_null($value)) {
360
+            $query = $query->andWhere($builder->expr()->isNull('value'));
361
+        } else {
362
+            $query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)));
363
+        }
364
+
365
+        $query->executeStatement();
366
+    }
367
+
368
+    private function getMountsFromQuery(IQueryBuilder $query) {
369
+        $result = $query->executeQuery();
370
+        $mounts = $result->fetchAll();
371
+        $uniqueMounts = [];
372
+        foreach ($mounts as $mount) {
373
+            $id = $mount['mount_id'];
374
+            if (!isset($uniqueMounts[$id])) {
375
+                $uniqueMounts[$id] = $mount;
376
+            }
377
+        }
378
+        $uniqueMounts = array_values($uniqueMounts);
379
+
380
+        $mountIds = array_map(function ($mount) {
381
+            return $mount['mount_id'];
382
+        }, $uniqueMounts);
383
+        $mountIds = array_values(array_unique($mountIds));
384
+
385
+        $applicable = $this->getApplicableForMounts($mountIds);
386
+        $config = $this->getConfigForMounts($mountIds);
387
+        $options = $this->getOptionsForMounts($mountIds);
388
+
389
+        return array_map(function ($mount, $applicable, $config, $options) {
390
+            $mount['type'] = (int)$mount['type'];
391
+            $mount['priority'] = (int)$mount['priority'];
392
+            $mount['applicable'] = $applicable;
393
+            $mount['config'] = $config;
394
+            $mount['options'] = $options;
395
+            return $mount;
396
+        }, $uniqueMounts, $applicable, $config, $options);
397
+    }
398
+
399
+    /**
400
+     * Get mount options from a table grouped by mount id
401
+     *
402
+     * @param string $table
403
+     * @param string[] $fields
404
+     * @param int[] $mountIds
405
+     * @return array [$mountId => [['field1' => $value1, ...], ...], ...]
406
+     */
407
+    private function selectForMounts($table, array $fields, array $mountIds) {
408
+        if (count($mountIds) === 0) {
409
+            return [];
410
+        }
411
+        $builder = $this->connection->getQueryBuilder();
412
+        $fields[] = 'mount_id';
413
+        $placeHolders = array_map(function ($id) use ($builder) {
414
+            return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
415
+        }, $mountIds);
416
+        $query = $builder->select($fields)
417
+            ->from($table)
418
+            ->where($builder->expr()->in('mount_id', $placeHolders));
419
+
420
+        $result = $query->executeQuery();
421
+        $rows = $result->fetchAll();
422
+        $result->closeCursor();
423
+
424
+        $result = [];
425
+        foreach ($mountIds as $mountId) {
426
+            $result[$mountId] = [];
427
+        }
428
+        foreach ($rows as $row) {
429
+            if (isset($row['type'])) {
430
+                $row['type'] = (int)$row['type'];
431
+            }
432
+            $result[$row['mount_id']][] = $row;
433
+        }
434
+        return $result;
435
+    }
436
+
437
+    /**
438
+     * @param int[] $mountIds
439
+     * @return array [$id => [['type' => $type, 'value' => $value], ...], ...]
440
+     */
441
+    public function getApplicableForMounts($mountIds) {
442
+        return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds);
443
+    }
444
+
445
+    /**
446
+     * @param int[] $mountIds
447
+     * @return array [$id => ['key1' => $value1, ...], ...]
448
+     */
449
+    public function getConfigForMounts($mountIds) {
450
+        $mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds);
451
+        return array_map([$this, 'createKeyValueMap'], $mountConfigs);
452
+    }
453
+
454
+    /**
455
+     * @param int[] $mountIds
456
+     * @return array [$id => ['key1' => $value1, ...], ...]
457
+     */
458
+    public function getOptionsForMounts($mountIds) {
459
+        $mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
460
+        $optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
461
+        return array_map(function (array $options) {
462
+            return array_map(function ($option) {
463
+                return json_decode($option);
464
+            }, $options);
465
+        }, $optionsMap);
466
+    }
467
+
468
+    /**
469
+     * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...]
470
+     * @return array ['key1' => $value1, ...]
471
+     */
472
+    private function createKeyValueMap(array $keyValuePairs) {
473
+        $decryptedPairts = array_map(function ($pair) {
474
+            if ($pair['key'] === 'password') {
475
+                $pair['value'] = $this->decryptValue($pair['value']);
476
+            }
477
+            return $pair;
478
+        }, $keyValuePairs);
479
+        $keys = array_map(function ($pair) {
480
+            return $pair['key'];
481
+        }, $decryptedPairts);
482
+        $values = array_map(function ($pair) {
483
+            return $pair['value'];
484
+        }, $decryptedPairts);
485
+
486
+        return array_combine($keys, $values);
487
+    }
488
+
489
+    private function encryptValue($value) {
490
+        return $this->crypto->encrypt($value);
491
+    }
492
+
493
+    private function decryptValue($value) {
494
+        try {
495
+            return $this->crypto->decrypt($value);
496
+        } catch (\Exception $e) {
497
+            return $value;
498
+        }
499
+    }
500 500
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Settings/Personal.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@
 block discarded – undo
28 28
 use OCP\WorkflowEngine\IManager;
29 29
 
30 30
 class Personal extends ASettings {
31
-	public function getScope(): int {
32
-		return IManager::SCOPE_USER;
33
-	}
31
+    public function getScope(): int {
32
+        return IManager::SCOPE_USER;
33
+    }
34 34
 
35
-	public function getSection(): ?string {
36
-		return $this->manager->isUserScopeEnabled() ? 'workflow' : null;
37
-	}
35
+    public function getSection(): ?string {
36
+        return $this->manager->isUserScopeEnabled() ? 'workflow' : null;
37
+    }
38 38
 }
Please login to merge, or discard this patch.
lib/public/DB/QueryBuilder/ICompositeExpression.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,39 +29,39 @@
 block discarded – undo
29 29
  * @since 8.2.0
30 30
  */
31 31
 interface ICompositeExpression {
32
-	/**
33
-	 * Adds multiple parts to composite expression.
34
-	 *
35
-	 * @param array $parts
36
-	 *
37
-	 * @return ICompositeExpression
38
-	 * @since 8.2.0
39
-	 */
40
-	public function addMultiple(array $parts = []): ICompositeExpression;
32
+    /**
33
+     * Adds multiple parts to composite expression.
34
+     *
35
+     * @param array $parts
36
+     *
37
+     * @return ICompositeExpression
38
+     * @since 8.2.0
39
+     */
40
+    public function addMultiple(array $parts = []): ICompositeExpression;
41 41
 
42
-	/**
43
-	 * Adds an expression to composite expression.
44
-	 *
45
-	 * @param mixed $part
46
-	 *
47
-	 * @return ICompositeExpression
48
-	 * @since 8.2.0
49
-	 */
50
-	public function add($part): ICompositeExpression;
42
+    /**
43
+     * Adds an expression to composite expression.
44
+     *
45
+     * @param mixed $part
46
+     *
47
+     * @return ICompositeExpression
48
+     * @since 8.2.0
49
+     */
50
+    public function add($part): ICompositeExpression;
51 51
 
52
-	/**
53
-	 * Retrieves the amount of expressions on composite expression.
54
-	 *
55
-	 * @return integer
56
-	 * @since 8.2.0
57
-	 */
58
-	public function count(): int;
52
+    /**
53
+     * Retrieves the amount of expressions on composite expression.
54
+     *
55
+     * @return integer
56
+     * @since 8.2.0
57
+     */
58
+    public function count(): int;
59 59
 
60
-	/**
61
-	 * Returns the type of this composite expression (AND/OR).
62
-	 *
63
-	 * @return string
64
-	 * @since 8.2.0
65
-	 */
66
-	public function getType(): string;
60
+    /**
61
+     * Returns the type of this composite expression (AND/OR).
62
+     *
63
+     * @return string
64
+     * @since 8.2.0
65
+     */
66
+    public function getType(): string;
67 67
 }
Please login to merge, or discard this patch.
core/Command/Group/Info.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
 		$gid = $input->getArgument('groupid');
68 68
 		$group = $this->groupManager->get($gid);
69 69
 		if (!$group instanceof IGroup) {
70
-			$output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
70
+			$output->writeln('<error>Group "'.$gid.'" does not exist.</error>');
71 71
 			return 1;
72 72
 		} else {
73 73
 			$groupOutput = [
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -35,56 +35,56 @@
 block discarded – undo
35 35
 use Symfony\Component\Console\Output\OutputInterface;
36 36
 
37 37
 class Info extends Base {
38
-	public function __construct(
39
-		protected IGroupManager $groupManager,
40
-	) {
41
-		parent::__construct();
42
-	}
38
+    public function __construct(
39
+        protected IGroupManager $groupManager,
40
+    ) {
41
+        parent::__construct();
42
+    }
43 43
 
44
-	protected function configure() {
45
-		$this
46
-			->setName('group:info')
47
-			->setDescription('Show information about a group')
48
-			->addArgument(
49
-				'groupid',
50
-				InputArgument::REQUIRED,
51
-				'Group id'
52
-			)->addOption(
53
-				'output',
54
-				null,
55
-				InputOption::VALUE_OPTIONAL,
56
-				'Output format (plain, json or json_pretty, default is plain)',
57
-				$this->defaultOutputFormat
58
-			);
59
-	}
44
+    protected function configure() {
45
+        $this
46
+            ->setName('group:info')
47
+            ->setDescription('Show information about a group')
48
+            ->addArgument(
49
+                'groupid',
50
+                InputArgument::REQUIRED,
51
+                'Group id'
52
+            )->addOption(
53
+                'output',
54
+                null,
55
+                InputOption::VALUE_OPTIONAL,
56
+                'Output format (plain, json or json_pretty, default is plain)',
57
+                $this->defaultOutputFormat
58
+            );
59
+    }
60 60
 
61
-	protected function execute(InputInterface $input, OutputInterface $output): int {
62
-		$gid = $input->getArgument('groupid');
63
-		$group = $this->groupManager->get($gid);
64
-		if (!$group instanceof IGroup) {
65
-			$output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
66
-			return 1;
67
-		} else {
68
-			$groupOutput = [
69
-				'groupID' => $gid,
70
-				'displayName' => $group->getDisplayName(),
71
-				'backends' => $group->getBackendNames(),
72
-			];
61
+    protected function execute(InputInterface $input, OutputInterface $output): int {
62
+        $gid = $input->getArgument('groupid');
63
+        $group = $this->groupManager->get($gid);
64
+        if (!$group instanceof IGroup) {
65
+            $output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
66
+            return 1;
67
+        } else {
68
+            $groupOutput = [
69
+                'groupID' => $gid,
70
+                'displayName' => $group->getDisplayName(),
71
+                'backends' => $group->getBackendNames(),
72
+            ];
73 73
 
74
-			$this->writeArrayInOutputFormat($input, $output, $groupOutput);
75
-			return 0;
76
-		}
77
-	}
74
+            $this->writeArrayInOutputFormat($input, $output, $groupOutput);
75
+            return 0;
76
+        }
77
+    }
78 78
 
79
-	/**
80
-	 * @param string $argumentName
81
-	 * @param CompletionContext $context
82
-	 * @return string[]
83
-	 */
84
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
85
-		if ($argumentName === 'groupid') {
86
-			return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
87
-		}
88
-		return [];
89
-	}
79
+    /**
80
+     * @param string $argumentName
81
+     * @param CompletionContext $context
82
+     * @return string[]
83
+     */
84
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
85
+        if ($argumentName === 'groupid') {
86
+            return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
87
+        }
88
+        return [];
89
+    }
90 90
 }
Please login to merge, or discard this patch.