Passed
Push — master ( 873501...d2df81 )
by Maxence
14:59 queued 12s
created
lib/private/Security/Hasher.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -96,14 +96,14 @@  discard block
 block discarded – undo
96 96
 		$alg = $this->getPrefferedAlgorithm();
97 97
 
98 98
 		if (\defined('PASSWORD_ARGON2ID') && $alg === PASSWORD_ARGON2ID) {
99
-			return 3 . '|' . password_hash($message, PASSWORD_ARGON2ID, $this->options);
99
+			return 3.'|'.password_hash($message, PASSWORD_ARGON2ID, $this->options);
100 100
 		}
101 101
 
102 102
 		if (\defined('PASSWORD_ARGON2I') && $alg === PASSWORD_ARGON2I) {
103
-			return 2 . '|' . password_hash($message, PASSWORD_ARGON2I, $this->options);
103
+			return 2.'|'.password_hash($message, PASSWORD_ARGON2I, $this->options);
104 104
 		}
105 105
 
106
-		return 1 . '|' . password_hash($message, PASSWORD_BCRYPT, $this->options);
106
+		return 1.'|'.password_hash($message, PASSWORD_BCRYPT, $this->options);
107 107
 	}
108 108
 
109 109
 	/**
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	protected function splitHash(string $prefixedHash) {
115 115
 		$explodedString = explode('|', $prefixedHash, 2);
116 116
 		if (\count($explodedString) === 2) {
117
-			if ((int)$explodedString[0] > 0) {
118
-				return ['version' => (int)$explodedString[0], 'hash' => $explodedString[1]];
117
+			if ((int) $explodedString[0] > 0) {
118
+				return ['version' => (int) $explodedString[0], 'hash' => $explodedString[1]];
119 119
 			}
120 120
 		}
121 121
 
Please login to merge, or discard this patch.
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -51,168 +51,168 @@
 block discarded – undo
51 51
  * @package OC\Security
52 52
  */
53 53
 class Hasher implements IHasher {
54
-	/** @var IConfig */
55
-	private $config;
56
-	/** @var array Options passed to password_hash and password_needs_rehash */
57
-	private $options = [];
58
-	/** @var string Salt used for legacy passwords */
59
-	private $legacySalt = null;
60
-
61
-	/**
62
-	 * @param IConfig $config
63
-	 */
64
-	public function __construct(IConfig $config) {
65
-		$this->config = $config;
66
-
67
-		if (\defined('PASSWORD_ARGON2ID') || \defined('PASSWORD_ARGON2I')) {
68
-			// password_hash fails, when the minimum values are undershot.
69
-			// In this case, apply minimum.
70
-			$this->options['threads'] = max($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS), 1);
71
-			// The minimum memory cost is 8 KiB per thread.
72
-			$this->options['memory_cost'] = max($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST), $this->options['threads'] * 8);
73
-			$this->options['time_cost'] = max($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST), 1);
74
-		}
75
-
76
-		$hashingCost = $this->config->getSystemValue('hashingCost', null);
77
-		if (!\is_null($hashingCost)) {
78
-			$this->options['cost'] = $hashingCost;
79
-		}
80
-	}
81
-
82
-	/**
83
-	 * Hashes a message using PHP's `password_hash` functionality.
84
-	 * Please note that the size of the returned string is not guaranteed
85
-	 * and can be up to 255 characters.
86
-	 *
87
-	 * @param string $message Message to generate hash from
88
-	 * @return string Hash of the message with appended version parameter
89
-	 */
90
-	public function hash(string $message): string {
91
-		$alg = $this->getPrefferedAlgorithm();
92
-
93
-		if (\defined('PASSWORD_ARGON2ID') && $alg === PASSWORD_ARGON2ID) {
94
-			return 3 . '|' . password_hash($message, PASSWORD_ARGON2ID, $this->options);
95
-		}
96
-
97
-		if (\defined('PASSWORD_ARGON2I') && $alg === PASSWORD_ARGON2I) {
98
-			return 2 . '|' . password_hash($message, PASSWORD_ARGON2I, $this->options);
99
-		}
100
-
101
-		return 1 . '|' . password_hash($message, PASSWORD_BCRYPT, $this->options);
102
-	}
103
-
104
-	/**
105
-	 * Get the version and hash from a prefixedHash
106
-	 * @param string $prefixedHash
107
-	 * @return null|array Null if the hash is not prefixed, otherwise array('version' => 1, 'hash' => 'foo')
108
-	 */
109
-	protected function splitHash(string $prefixedHash) {
110
-		$explodedString = explode('|', $prefixedHash, 2);
111
-		if (\count($explodedString) === 2) {
112
-			if ((int)$explodedString[0] > 0) {
113
-				return ['version' => (int)$explodedString[0], 'hash' => $explodedString[1]];
114
-			}
115
-		}
116
-
117
-		return null;
118
-	}
119
-
120
-	/**
121
-	 * Verify legacy hashes
122
-	 * @param string $message Message to verify
123
-	 * @param string $hash Assumed hash of the message
124
-	 * @param null|string &$newHash Reference will contain the updated hash
125
-	 * @return bool Whether $hash is a valid hash of $message
126
-	 */
127
-	protected function legacyHashVerify($message, $hash, &$newHash = null): bool {
128
-		if (empty($this->legacySalt)) {
129
-			$this->legacySalt = $this->config->getSystemValue('passwordsalt', '');
130
-		}
131
-
132
-		// Verify whether it matches a legacy PHPass or SHA1 string
133
-		$hashLength = \strlen($hash);
134
-		if (($hashLength === 60 && password_verify($message.$this->legacySalt, $hash)) ||
135
-			($hashLength === 40 && hash_equals($hash, sha1($message)))) {
136
-			$newHash = $this->hash($message);
137
-			return true;
138
-		}
139
-
140
-		// Verify whether it matches a legacy PHPass or SHA1 string
141
-		// Retry with empty passwordsalt for cases where it was not set
142
-		$hashLength = \strlen($hash);
143
-		if (($hashLength === 60 && password_verify($message, $hash)) ||
144
-			($hashLength === 40 && hash_equals($hash, sha1($message)))) {
145
-			$newHash = $this->hash($message);
146
-			return true;
147
-		}
148
-
149
-		return false;
150
-	}
151
-
152
-	/**
153
-	 * Verify V1 (blowfish) hashes
154
-	 * Verify V2 (argon2i) hashes
155
-	 * Verify V3 (argon2id) hashes
156
-	 * @param string $message Message to verify
157
-	 * @param string $hash Assumed hash of the message
158
-	 * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
159
-	 * @return bool Whether $hash is a valid hash of $message
160
-	 */
161
-	protected function verifyHash(string $message, string $hash, &$newHash = null): bool {
162
-		if (password_verify($message, $hash)) {
163
-			if ($this->needsRehash($hash)) {
164
-				$newHash = $this->hash($message);
165
-			}
166
-			return true;
167
-		}
168
-
169
-		return false;
170
-	}
171
-
172
-	/**
173
-	 * @param string $message Message to verify
174
-	 * @param string $hash Assumed hash of the message
175
-	 * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
176
-	 * @return bool Whether $hash is a valid hash of $message
177
-	 */
178
-	public function verify(string $message, string $hash, &$newHash = null): bool {
179
-		$splittedHash = $this->splitHash($hash);
180
-
181
-		if (isset($splittedHash['version'])) {
182
-			switch ($splittedHash['version']) {
183
-				case 3:
184
-				case 2:
185
-				case 1:
186
-					return $this->verifyHash($message, $splittedHash['hash'], $newHash);
187
-			}
188
-		} else {
189
-			return $this->legacyHashVerify($message, $hash, $newHash);
190
-		}
191
-
192
-		return false;
193
-	}
194
-
195
-	private function needsRehash(string $hash): bool {
196
-		$algorithm = $this->getPrefferedAlgorithm();
197
-
198
-		return password_needs_rehash($hash, $algorithm, $this->options);
199
-	}
200
-
201
-	private function getPrefferedAlgorithm() {
202
-		$default = PASSWORD_BCRYPT;
203
-		if (\defined('PASSWORD_ARGON2I')) {
204
-			$default = PASSWORD_ARGON2I;
205
-		}
206
-
207
-		if (\defined('PASSWORD_ARGON2ID')) {
208
-			$default = PASSWORD_ARGON2ID;
209
-		}
210
-
211
-		// Check if we should use PASSWORD_DEFAULT
212
-		if ($this->config->getSystemValue('hashing_default_password', false) === true) {
213
-			$default = PASSWORD_DEFAULT;
214
-		}
215
-
216
-		return $default;
217
-	}
54
+    /** @var IConfig */
55
+    private $config;
56
+    /** @var array Options passed to password_hash and password_needs_rehash */
57
+    private $options = [];
58
+    /** @var string Salt used for legacy passwords */
59
+    private $legacySalt = null;
60
+
61
+    /**
62
+     * @param IConfig $config
63
+     */
64
+    public function __construct(IConfig $config) {
65
+        $this->config = $config;
66
+
67
+        if (\defined('PASSWORD_ARGON2ID') || \defined('PASSWORD_ARGON2I')) {
68
+            // password_hash fails, when the minimum values are undershot.
69
+            // In this case, apply minimum.
70
+            $this->options['threads'] = max($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS), 1);
71
+            // The minimum memory cost is 8 KiB per thread.
72
+            $this->options['memory_cost'] = max($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST), $this->options['threads'] * 8);
73
+            $this->options['time_cost'] = max($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST), 1);
74
+        }
75
+
76
+        $hashingCost = $this->config->getSystemValue('hashingCost', null);
77
+        if (!\is_null($hashingCost)) {
78
+            $this->options['cost'] = $hashingCost;
79
+        }
80
+    }
81
+
82
+    /**
83
+     * Hashes a message using PHP's `password_hash` functionality.
84
+     * Please note that the size of the returned string is not guaranteed
85
+     * and can be up to 255 characters.
86
+     *
87
+     * @param string $message Message to generate hash from
88
+     * @return string Hash of the message with appended version parameter
89
+     */
90
+    public function hash(string $message): string {
91
+        $alg = $this->getPrefferedAlgorithm();
92
+
93
+        if (\defined('PASSWORD_ARGON2ID') && $alg === PASSWORD_ARGON2ID) {
94
+            return 3 . '|' . password_hash($message, PASSWORD_ARGON2ID, $this->options);
95
+        }
96
+
97
+        if (\defined('PASSWORD_ARGON2I') && $alg === PASSWORD_ARGON2I) {
98
+            return 2 . '|' . password_hash($message, PASSWORD_ARGON2I, $this->options);
99
+        }
100
+
101
+        return 1 . '|' . password_hash($message, PASSWORD_BCRYPT, $this->options);
102
+    }
103
+
104
+    /**
105
+     * Get the version and hash from a prefixedHash
106
+     * @param string $prefixedHash
107
+     * @return null|array Null if the hash is not prefixed, otherwise array('version' => 1, 'hash' => 'foo')
108
+     */
109
+    protected function splitHash(string $prefixedHash) {
110
+        $explodedString = explode('|', $prefixedHash, 2);
111
+        if (\count($explodedString) === 2) {
112
+            if ((int)$explodedString[0] > 0) {
113
+                return ['version' => (int)$explodedString[0], 'hash' => $explodedString[1]];
114
+            }
115
+        }
116
+
117
+        return null;
118
+    }
119
+
120
+    /**
121
+     * Verify legacy hashes
122
+     * @param string $message Message to verify
123
+     * @param string $hash Assumed hash of the message
124
+     * @param null|string &$newHash Reference will contain the updated hash
125
+     * @return bool Whether $hash is a valid hash of $message
126
+     */
127
+    protected function legacyHashVerify($message, $hash, &$newHash = null): bool {
128
+        if (empty($this->legacySalt)) {
129
+            $this->legacySalt = $this->config->getSystemValue('passwordsalt', '');
130
+        }
131
+
132
+        // Verify whether it matches a legacy PHPass or SHA1 string
133
+        $hashLength = \strlen($hash);
134
+        if (($hashLength === 60 && password_verify($message.$this->legacySalt, $hash)) ||
135
+            ($hashLength === 40 && hash_equals($hash, sha1($message)))) {
136
+            $newHash = $this->hash($message);
137
+            return true;
138
+        }
139
+
140
+        // Verify whether it matches a legacy PHPass or SHA1 string
141
+        // Retry with empty passwordsalt for cases where it was not set
142
+        $hashLength = \strlen($hash);
143
+        if (($hashLength === 60 && password_verify($message, $hash)) ||
144
+            ($hashLength === 40 && hash_equals($hash, sha1($message)))) {
145
+            $newHash = $this->hash($message);
146
+            return true;
147
+        }
148
+
149
+        return false;
150
+    }
151
+
152
+    /**
153
+     * Verify V1 (blowfish) hashes
154
+     * Verify V2 (argon2i) hashes
155
+     * Verify V3 (argon2id) hashes
156
+     * @param string $message Message to verify
157
+     * @param string $hash Assumed hash of the message
158
+     * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
159
+     * @return bool Whether $hash is a valid hash of $message
160
+     */
161
+    protected function verifyHash(string $message, string $hash, &$newHash = null): bool {
162
+        if (password_verify($message, $hash)) {
163
+            if ($this->needsRehash($hash)) {
164
+                $newHash = $this->hash($message);
165
+            }
166
+            return true;
167
+        }
168
+
169
+        return false;
170
+    }
171
+
172
+    /**
173
+     * @param string $message Message to verify
174
+     * @param string $hash Assumed hash of the message
175
+     * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
176
+     * @return bool Whether $hash is a valid hash of $message
177
+     */
178
+    public function verify(string $message, string $hash, &$newHash = null): bool {
179
+        $splittedHash = $this->splitHash($hash);
180
+
181
+        if (isset($splittedHash['version'])) {
182
+            switch ($splittedHash['version']) {
183
+                case 3:
184
+                case 2:
185
+                case 1:
186
+                    return $this->verifyHash($message, $splittedHash['hash'], $newHash);
187
+            }
188
+        } else {
189
+            return $this->legacyHashVerify($message, $hash, $newHash);
190
+        }
191
+
192
+        return false;
193
+    }
194
+
195
+    private function needsRehash(string $hash): bool {
196
+        $algorithm = $this->getPrefferedAlgorithm();
197
+
198
+        return password_needs_rehash($hash, $algorithm, $this->options);
199
+    }
200
+
201
+    private function getPrefferedAlgorithm() {
202
+        $default = PASSWORD_BCRYPT;
203
+        if (\defined('PASSWORD_ARGON2I')) {
204
+            $default = PASSWORD_ARGON2I;
205
+        }
206
+
207
+        if (\defined('PASSWORD_ARGON2ID')) {
208
+            $default = PASSWORD_ARGON2ID;
209
+        }
210
+
211
+        // Check if we should use PASSWORD_DEFAULT
212
+        if ($this->config->getSystemValue('hashing_default_password', false) === true) {
213
+            $default = PASSWORD_DEFAULT;
214
+        }
215
+
216
+        return $default;
217
+    }
218 218
 }
Please login to merge, or discard this patch.
lib/private/Command/QueueBus.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -27,48 +27,48 @@
 block discarded – undo
27 27
 use OCP\Command\ICommand;
28 28
 
29 29
 class QueueBus implements IBus {
30
-	/**
31
-	 * @var ICommand[]|callable[]
32
-	 */
33
-	private $queue = [];
30
+    /**
31
+     * @var ICommand[]|callable[]
32
+     */
33
+    private $queue = [];
34 34
 
35
-	/**
36
-	 * Schedule a command to be fired
37
-	 *
38
-	 * @param \OCP\Command\ICommand | callable $command
39
-	 */
40
-	public function push($command) {
41
-		$this->queue[] = $command;
42
-	}
35
+    /**
36
+     * Schedule a command to be fired
37
+     *
38
+     * @param \OCP\Command\ICommand | callable $command
39
+     */
40
+    public function push($command) {
41
+        $this->queue[] = $command;
42
+    }
43 43
 
44
-	/**
45
-	 * Require all commands using a trait to be run synchronous
46
-	 *
47
-	 * @param string $trait
48
-	 */
49
-	public function requireSync($trait) {
50
-	}
44
+    /**
45
+     * Require all commands using a trait to be run synchronous
46
+     *
47
+     * @param string $trait
48
+     */
49
+    public function requireSync($trait) {
50
+    }
51 51
 
52
-	/**
53
-	 * @param \OCP\Command\ICommand | callable $command
54
-	 */
55
-	private function runCommand($command) {
56
-		if ($command instanceof ICommand) {
57
-			// ensure the command can be serialized
58
-			$serialized = serialize($command);
59
-			if (strlen($serialized) > 4000) {
60
-				throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)');
61
-			}
62
-			$unserialized = unserialize($serialized);
63
-			$unserialized->handle();
64
-		} else {
65
-			$command();
66
-		}
67
-	}
52
+    /**
53
+     * @param \OCP\Command\ICommand | callable $command
54
+     */
55
+    private function runCommand($command) {
56
+        if ($command instanceof ICommand) {
57
+            // ensure the command can be serialized
58
+            $serialized = serialize($command);
59
+            if (strlen($serialized) > 4000) {
60
+                throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)');
61
+            }
62
+            $unserialized = unserialize($serialized);
63
+            $unserialized->handle();
64
+        } else {
65
+            $command();
66
+        }
67
+    }
68 68
 
69
-	public function run() {
70
-		while ($command = array_shift($this->queue)) {
71
-			$this->runCommand($command);
72
-		}
73
-	}
69
+    public function run() {
70
+        while ($command = array_shift($this->queue)) {
71
+            $this->runCommand($command);
72
+        }
73
+    }
74 74
 }
Please login to merge, or discard this patch.
lib/private/NavigationManager.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
 		$result = $this->entries;
122 122
 		if ($type !== 'all') {
123
-			$result = array_filter($this->entries, function ($entry) use ($type) {
123
+			$result = array_filter($this->entries, function($entry) use ($type) {
124 124
 				return $entry['type'] === $type;
125 125
 			});
126 126
 		}
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	 * @return array
136 136
 	 */
137 137
 	private function proceedNavigation(array $list): array {
138
-		uasort($list, function ($a, $b) {
138
+		uasort($list, function($a, $b) {
139 139
 			if (isset($a['order']) && isset($b['order'])) {
140 140
 				return ($a['order'] < $b['order']) ? -1 : 1;
141 141
 			} elseif (isset($a['order']) || isset($b['order'])) {
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 					continue;
289 289
 				}
290 290
 				$l = $this->l10nFac->get($app);
291
-				$id = $nav['id'] ?? $app . ($key === 0 ? '' : $key);
291
+				$id = $nav['id'] ?? $app.($key === 0 ? '' : $key);
292 292
 				$order = isset($nav['order']) ? $nav['order'] : 100;
293 293
 				$type = isset($nav['type']) ? $nav['type'] : 'link';
294 294
 				$route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : '';
Please login to merge, or discard this patch.
Indentation   +314 added lines, -314 removed lines patch added patch discarded remove patch
@@ -46,318 +46,318 @@
 block discarded – undo
46 46
  */
47 47
 
48 48
 class NavigationManager implements INavigationManager {
49
-	protected $entries = [];
50
-	protected $closureEntries = [];
51
-	protected $activeEntry;
52
-	protected $unreadCounters = [];
53
-
54
-	/** @var bool */
55
-	protected $init = false;
56
-	/** @var IAppManager|AppManager */
57
-	protected $appManager;
58
-	/** @var IURLGenerator */
59
-	private $urlGenerator;
60
-	/** @var IFactory */
61
-	private $l10nFac;
62
-	/** @var IUserSession */
63
-	private $userSession;
64
-	/** @var IGroupManager|Manager */
65
-	private $groupManager;
66
-	/** @var IConfig */
67
-	private $config;
68
-
69
-	public function __construct(IAppManager $appManager,
70
-						 IURLGenerator $urlGenerator,
71
-						 IFactory $l10nFac,
72
-						 IUserSession $userSession,
73
-						 IGroupManager $groupManager,
74
-						 IConfig $config) {
75
-		$this->appManager = $appManager;
76
-		$this->urlGenerator = $urlGenerator;
77
-		$this->l10nFac = $l10nFac;
78
-		$this->userSession = $userSession;
79
-		$this->groupManager = $groupManager;
80
-		$this->config = $config;
81
-	}
82
-
83
-	/**
84
-	 * @inheritDoc
85
-	 */
86
-	public function add($entry) {
87
-		if ($entry instanceof \Closure) {
88
-			$this->closureEntries[] = $entry;
89
-			return;
90
-		}
91
-
92
-		$entry['active'] = false;
93
-		if (!isset($entry['icon'])) {
94
-			$entry['icon'] = '';
95
-		}
96
-		if (!isset($entry['classes'])) {
97
-			$entry['classes'] = '';
98
-		}
99
-		if (!isset($entry['type'])) {
100
-			$entry['type'] = 'link';
101
-		}
102
-
103
-		$id = $entry['id'];
104
-		$entry['unread'] = isset($this->unreadCounters[$id]) ? $this->unreadCounters[$id] : 0;
105
-
106
-		$this->entries[$id] = $entry;
107
-	}
108
-
109
-	/**
110
-	 * @inheritDoc
111
-	 */
112
-	public function getAll(string $type = 'link'): array {
113
-		$this->init();
114
-		foreach ($this->closureEntries as $c) {
115
-			$this->add($c());
116
-		}
117
-		$this->closureEntries = [];
118
-
119
-		$result = $this->entries;
120
-		if ($type !== 'all') {
121
-			$result = array_filter($this->entries, function ($entry) use ($type) {
122
-				return $entry['type'] === $type;
123
-			});
124
-		}
125
-
126
-		return $this->proceedNavigation($result);
127
-	}
128
-
129
-	/**
130
-	 * Sort navigation entries by order, name and set active flag
131
-	 *
132
-	 * @param array $list
133
-	 * @return array
134
-	 */
135
-	private function proceedNavigation(array $list): array {
136
-		uasort($list, function ($a, $b) {
137
-			if (isset($a['order']) && isset($b['order'])) {
138
-				return ($a['order'] < $b['order']) ? -1 : 1;
139
-			} elseif (isset($a['order']) || isset($b['order'])) {
140
-				return isset($a['order']) ? -1 : 1;
141
-			} else {
142
-				return ($a['name'] < $b['name']) ? -1 : 1;
143
-			}
144
-		});
145
-
146
-		$activeApp = $this->getActiveEntry();
147
-		if ($activeApp !== null) {
148
-			foreach ($list as $index => &$navEntry) {
149
-				if ($navEntry['id'] == $activeApp) {
150
-					$navEntry['active'] = true;
151
-				} else {
152
-					$navEntry['active'] = false;
153
-				}
154
-			}
155
-			unset($navEntry);
156
-		}
157
-
158
-		return $list;
159
-	}
160
-
161
-
162
-	/**
163
-	 * removes all the entries
164
-	 */
165
-	public function clear($loadDefaultLinks = true) {
166
-		$this->entries = [];
167
-		$this->closureEntries = [];
168
-		$this->init = !$loadDefaultLinks;
169
-	}
170
-
171
-	/**
172
-	 * @inheritDoc
173
-	 */
174
-	public function setActiveEntry($id) {
175
-		$this->activeEntry = $id;
176
-	}
177
-
178
-	/**
179
-	 * @inheritDoc
180
-	 */
181
-	public function getActiveEntry() {
182
-		return $this->activeEntry;
183
-	}
184
-
185
-	private function init() {
186
-		if ($this->init) {
187
-			return;
188
-		}
189
-		$this->init = true;
190
-
191
-		$l = $this->l10nFac->get('lib');
192
-		if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
193
-			$this->add([
194
-				'type' => 'settings',
195
-				'id' => 'help',
196
-				'order' => 99998,
197
-				'href' => $this->urlGenerator->linkToRoute('settings.Help.help'),
198
-				'name' => $l->t('Help'),
199
-				'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
200
-			]);
201
-		}
202
-
203
-		if ($this->userSession->isLoggedIn()) {
204
-			// Accessibility settings
205
-			if ($this->appManager->isEnabledForUser('theming', $this->userSession->getUser())) {
206
-				$this->add([
207
-					'type' => 'settings',
208
-					'id' => 'accessibility_settings',
209
-					'order' => 2,
210
-					'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'theming']),
211
-					'name' => $l->t('Appearance and accessibility'),
212
-					'icon' => $this->urlGenerator->imagePath('theming', 'accessibility-dark.svg'),
213
-				]);
214
-			}
215
-			if ($this->isAdmin()) {
216
-				// App management
217
-				$this->add([
218
-					'type' => 'settings',
219
-					'id' => 'core_apps',
220
-					'order' => 5,
221
-					'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
222
-					'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
223
-					'name' => $l->t('Apps'),
224
-				]);
225
-
226
-				// Personal settings
227
-				$this->add([
228
-					'type' => 'settings',
229
-					'id' => 'settings',
230
-					'order' => 3,
231
-					'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
232
-					'name' => $l->t('Personal settings'),
233
-					'icon' => $this->urlGenerator->imagePath('settings', 'personal.svg'),
234
-				]);
235
-
236
-				// Admin settings
237
-				$this->add([
238
-					'type' => 'settings',
239
-					'id' => 'admin_settings',
240
-					'order' => 4,
241
-					'href' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'overview']),
242
-					'name' => $l->t('Administration settings'),
243
-					'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
244
-				]);
245
-			} else {
246
-				// Personal settings
247
-				$this->add([
248
-					'type' => 'settings',
249
-					'id' => 'settings',
250
-					'order' => 3,
251
-					'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
252
-					'name' => $l->t('Settings'),
253
-					'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
254
-				]);
255
-			}
256
-
257
-			$logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
258
-			if ($logoutUrl !== '') {
259
-				// Logout
260
-				$this->add([
261
-					'type' => 'settings',
262
-					'id' => 'logout',
263
-					'order' => 99999,
264
-					'href' => $logoutUrl,
265
-					'name' => $l->t('Log out'),
266
-					'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
267
-				]);
268
-			}
269
-
270
-			if ($this->isSubadmin()) {
271
-				// User management
272
-				$this->add([
273
-					'type' => 'settings',
274
-					'id' => 'core_users',
275
-					'order' => 6,
276
-					'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'),
277
-					'name' => $l->t('Users'),
278
-					'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
279
-				]);
280
-			}
281
-		}
282
-
283
-		if ($this->appManager === 'null') {
284
-			return;
285
-		}
286
-
287
-		if ($this->userSession->isLoggedIn()) {
288
-			$apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
289
-		} else {
290
-			$apps = $this->appManager->getInstalledApps();
291
-		}
292
-
293
-		foreach ($apps as $app) {
294
-			if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
295
-				continue;
296
-			}
297
-
298
-			// load plugins and collections from info.xml
299
-			$info = $this->appManager->getAppInfo($app);
300
-			if (!isset($info['navigations']['navigation'])) {
301
-				continue;
302
-			}
303
-			foreach ($info['navigations']['navigation'] as $key => $nav) {
304
-				if (!isset($nav['name'])) {
305
-					continue;
306
-				}
307
-				if (!isset($nav['route'])) {
308
-					continue;
309
-				}
310
-				$role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
311
-				if ($role === 'admin' && !$this->isAdmin()) {
312
-					continue;
313
-				}
314
-				$l = $this->l10nFac->get($app);
315
-				$id = $nav['id'] ?? $app . ($key === 0 ? '' : $key);
316
-				$order = isset($nav['order']) ? $nav['order'] : 100;
317
-				$type = isset($nav['type']) ? $nav['type'] : 'link';
318
-				$route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : '';
319
-				$icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
320
-				foreach ([$icon, "$app.svg"] as $i) {
321
-					try {
322
-						$icon = $this->urlGenerator->imagePath($app, $i);
323
-						break;
324
-					} catch (\RuntimeException $ex) {
325
-						// no icon? - ignore it then
326
-					}
327
-				}
328
-				if ($icon === null) {
329
-					$icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
330
-				}
331
-
332
-				$this->add([
333
-					'id' => $id,
334
-					'order' => $order,
335
-					'href' => $route,
336
-					'icon' => $icon,
337
-					'type' => $type,
338
-					'name' => $l->t($nav['name']),
339
-				]);
340
-			}
341
-		}
342
-	}
343
-
344
-	private function isAdmin() {
345
-		$user = $this->userSession->getUser();
346
-		if ($user !== null) {
347
-			return $this->groupManager->isAdmin($user->getUID());
348
-		}
349
-		return false;
350
-	}
351
-
352
-	private function isSubadmin() {
353
-		$user = $this->userSession->getUser();
354
-		if ($user !== null) {
355
-			return $this->groupManager->getSubAdmin()->isSubAdmin($user);
356
-		}
357
-		return false;
358
-	}
359
-
360
-	public function setUnreadCounter(string $id, int $unreadCounter): void {
361
-		$this->unreadCounters[$id] = $unreadCounter;
362
-	}
49
+    protected $entries = [];
50
+    protected $closureEntries = [];
51
+    protected $activeEntry;
52
+    protected $unreadCounters = [];
53
+
54
+    /** @var bool */
55
+    protected $init = false;
56
+    /** @var IAppManager|AppManager */
57
+    protected $appManager;
58
+    /** @var IURLGenerator */
59
+    private $urlGenerator;
60
+    /** @var IFactory */
61
+    private $l10nFac;
62
+    /** @var IUserSession */
63
+    private $userSession;
64
+    /** @var IGroupManager|Manager */
65
+    private $groupManager;
66
+    /** @var IConfig */
67
+    private $config;
68
+
69
+    public function __construct(IAppManager $appManager,
70
+                            IURLGenerator $urlGenerator,
71
+                            IFactory $l10nFac,
72
+                            IUserSession $userSession,
73
+                            IGroupManager $groupManager,
74
+                            IConfig $config) {
75
+        $this->appManager = $appManager;
76
+        $this->urlGenerator = $urlGenerator;
77
+        $this->l10nFac = $l10nFac;
78
+        $this->userSession = $userSession;
79
+        $this->groupManager = $groupManager;
80
+        $this->config = $config;
81
+    }
82
+
83
+    /**
84
+     * @inheritDoc
85
+     */
86
+    public function add($entry) {
87
+        if ($entry instanceof \Closure) {
88
+            $this->closureEntries[] = $entry;
89
+            return;
90
+        }
91
+
92
+        $entry['active'] = false;
93
+        if (!isset($entry['icon'])) {
94
+            $entry['icon'] = '';
95
+        }
96
+        if (!isset($entry['classes'])) {
97
+            $entry['classes'] = '';
98
+        }
99
+        if (!isset($entry['type'])) {
100
+            $entry['type'] = 'link';
101
+        }
102
+
103
+        $id = $entry['id'];
104
+        $entry['unread'] = isset($this->unreadCounters[$id]) ? $this->unreadCounters[$id] : 0;
105
+
106
+        $this->entries[$id] = $entry;
107
+    }
108
+
109
+    /**
110
+     * @inheritDoc
111
+     */
112
+    public function getAll(string $type = 'link'): array {
113
+        $this->init();
114
+        foreach ($this->closureEntries as $c) {
115
+            $this->add($c());
116
+        }
117
+        $this->closureEntries = [];
118
+
119
+        $result = $this->entries;
120
+        if ($type !== 'all') {
121
+            $result = array_filter($this->entries, function ($entry) use ($type) {
122
+                return $entry['type'] === $type;
123
+            });
124
+        }
125
+
126
+        return $this->proceedNavigation($result);
127
+    }
128
+
129
+    /**
130
+     * Sort navigation entries by order, name and set active flag
131
+     *
132
+     * @param array $list
133
+     * @return array
134
+     */
135
+    private function proceedNavigation(array $list): array {
136
+        uasort($list, function ($a, $b) {
137
+            if (isset($a['order']) && isset($b['order'])) {
138
+                return ($a['order'] < $b['order']) ? -1 : 1;
139
+            } elseif (isset($a['order']) || isset($b['order'])) {
140
+                return isset($a['order']) ? -1 : 1;
141
+            } else {
142
+                return ($a['name'] < $b['name']) ? -1 : 1;
143
+            }
144
+        });
145
+
146
+        $activeApp = $this->getActiveEntry();
147
+        if ($activeApp !== null) {
148
+            foreach ($list as $index => &$navEntry) {
149
+                if ($navEntry['id'] == $activeApp) {
150
+                    $navEntry['active'] = true;
151
+                } else {
152
+                    $navEntry['active'] = false;
153
+                }
154
+            }
155
+            unset($navEntry);
156
+        }
157
+
158
+        return $list;
159
+    }
160
+
161
+
162
+    /**
163
+     * removes all the entries
164
+     */
165
+    public function clear($loadDefaultLinks = true) {
166
+        $this->entries = [];
167
+        $this->closureEntries = [];
168
+        $this->init = !$loadDefaultLinks;
169
+    }
170
+
171
+    /**
172
+     * @inheritDoc
173
+     */
174
+    public function setActiveEntry($id) {
175
+        $this->activeEntry = $id;
176
+    }
177
+
178
+    /**
179
+     * @inheritDoc
180
+     */
181
+    public function getActiveEntry() {
182
+        return $this->activeEntry;
183
+    }
184
+
185
+    private function init() {
186
+        if ($this->init) {
187
+            return;
188
+        }
189
+        $this->init = true;
190
+
191
+        $l = $this->l10nFac->get('lib');
192
+        if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
193
+            $this->add([
194
+                'type' => 'settings',
195
+                'id' => 'help',
196
+                'order' => 99998,
197
+                'href' => $this->urlGenerator->linkToRoute('settings.Help.help'),
198
+                'name' => $l->t('Help'),
199
+                'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
200
+            ]);
201
+        }
202
+
203
+        if ($this->userSession->isLoggedIn()) {
204
+            // Accessibility settings
205
+            if ($this->appManager->isEnabledForUser('theming', $this->userSession->getUser())) {
206
+                $this->add([
207
+                    'type' => 'settings',
208
+                    'id' => 'accessibility_settings',
209
+                    'order' => 2,
210
+                    'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'theming']),
211
+                    'name' => $l->t('Appearance and accessibility'),
212
+                    'icon' => $this->urlGenerator->imagePath('theming', 'accessibility-dark.svg'),
213
+                ]);
214
+            }
215
+            if ($this->isAdmin()) {
216
+                // App management
217
+                $this->add([
218
+                    'type' => 'settings',
219
+                    'id' => 'core_apps',
220
+                    'order' => 5,
221
+                    'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
222
+                    'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
223
+                    'name' => $l->t('Apps'),
224
+                ]);
225
+
226
+                // Personal settings
227
+                $this->add([
228
+                    'type' => 'settings',
229
+                    'id' => 'settings',
230
+                    'order' => 3,
231
+                    'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
232
+                    'name' => $l->t('Personal settings'),
233
+                    'icon' => $this->urlGenerator->imagePath('settings', 'personal.svg'),
234
+                ]);
235
+
236
+                // Admin settings
237
+                $this->add([
238
+                    'type' => 'settings',
239
+                    'id' => 'admin_settings',
240
+                    'order' => 4,
241
+                    'href' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'overview']),
242
+                    'name' => $l->t('Administration settings'),
243
+                    'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
244
+                ]);
245
+            } else {
246
+                // Personal settings
247
+                $this->add([
248
+                    'type' => 'settings',
249
+                    'id' => 'settings',
250
+                    'order' => 3,
251
+                    'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
252
+                    'name' => $l->t('Settings'),
253
+                    'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
254
+                ]);
255
+            }
256
+
257
+            $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
258
+            if ($logoutUrl !== '') {
259
+                // Logout
260
+                $this->add([
261
+                    'type' => 'settings',
262
+                    'id' => 'logout',
263
+                    'order' => 99999,
264
+                    'href' => $logoutUrl,
265
+                    'name' => $l->t('Log out'),
266
+                    'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
267
+                ]);
268
+            }
269
+
270
+            if ($this->isSubadmin()) {
271
+                // User management
272
+                $this->add([
273
+                    'type' => 'settings',
274
+                    'id' => 'core_users',
275
+                    'order' => 6,
276
+                    'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'),
277
+                    'name' => $l->t('Users'),
278
+                    'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
279
+                ]);
280
+            }
281
+        }
282
+
283
+        if ($this->appManager === 'null') {
284
+            return;
285
+        }
286
+
287
+        if ($this->userSession->isLoggedIn()) {
288
+            $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
289
+        } else {
290
+            $apps = $this->appManager->getInstalledApps();
291
+        }
292
+
293
+        foreach ($apps as $app) {
294
+            if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
295
+                continue;
296
+            }
297
+
298
+            // load plugins and collections from info.xml
299
+            $info = $this->appManager->getAppInfo($app);
300
+            if (!isset($info['navigations']['navigation'])) {
301
+                continue;
302
+            }
303
+            foreach ($info['navigations']['navigation'] as $key => $nav) {
304
+                if (!isset($nav['name'])) {
305
+                    continue;
306
+                }
307
+                if (!isset($nav['route'])) {
308
+                    continue;
309
+                }
310
+                $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
311
+                if ($role === 'admin' && !$this->isAdmin()) {
312
+                    continue;
313
+                }
314
+                $l = $this->l10nFac->get($app);
315
+                $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key);
316
+                $order = isset($nav['order']) ? $nav['order'] : 100;
317
+                $type = isset($nav['type']) ? $nav['type'] : 'link';
318
+                $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : '';
319
+                $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
320
+                foreach ([$icon, "$app.svg"] as $i) {
321
+                    try {
322
+                        $icon = $this->urlGenerator->imagePath($app, $i);
323
+                        break;
324
+                    } catch (\RuntimeException $ex) {
325
+                        // no icon? - ignore it then
326
+                    }
327
+                }
328
+                if ($icon === null) {
329
+                    $icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
330
+                }
331
+
332
+                $this->add([
333
+                    'id' => $id,
334
+                    'order' => $order,
335
+                    'href' => $route,
336
+                    'icon' => $icon,
337
+                    'type' => $type,
338
+                    'name' => $l->t($nav['name']),
339
+                ]);
340
+            }
341
+        }
342
+    }
343
+
344
+    private function isAdmin() {
345
+        $user = $this->userSession->getUser();
346
+        if ($user !== null) {
347
+            return $this->groupManager->isAdmin($user->getUID());
348
+        }
349
+        return false;
350
+    }
351
+
352
+    private function isSubadmin() {
353
+        $user = $this->userSession->getUser();
354
+        if ($user !== null) {
355
+            return $this->groupManager->getSubAdmin()->isSubAdmin($user);
356
+        }
357
+        return false;
358
+    }
359
+
360
+    public function setUnreadCounter(string $id, int $unreadCounter): void {
361
+        $this->unreadCounters[$id] = $unreadCounter;
362
+    }
363 363
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/MailPlugin.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@
 block discarded – undo
99 99
 						$emailAddressType = $emailAddressData['type'];
100 100
 					}
101 101
 					if (isset($contact['FN'])) {
102
-						$displayName = $contact['FN'] . ' (' . $emailAddress . ')';
102
+						$displayName = $contact['FN'].' ('.$emailAddress.')';
103 103
 					}
104 104
 					$exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
105 105
 
Please login to merge, or discard this patch.
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -41,251 +41,251 @@
 block discarded – undo
41 41
 use OCP\Mail\IMailer;
42 42
 
43 43
 class MailPlugin implements ISearchPlugin {
44
-	/* @var bool */
45
-	protected $shareWithGroupOnly;
46
-	/* @var bool */
47
-	protected $shareeEnumeration;
48
-	/* @var bool */
49
-	protected $shareeEnumerationInGroupOnly;
50
-	/* @var bool */
51
-	protected $shareeEnumerationPhone;
52
-	/* @var bool */
53
-	protected $shareeEnumerationFullMatch;
54
-	/* @var bool */
55
-	protected $shareeEnumerationFullMatchEmail;
44
+    /* @var bool */
45
+    protected $shareWithGroupOnly;
46
+    /* @var bool */
47
+    protected $shareeEnumeration;
48
+    /* @var bool */
49
+    protected $shareeEnumerationInGroupOnly;
50
+    /* @var bool */
51
+    protected $shareeEnumerationPhone;
52
+    /* @var bool */
53
+    protected $shareeEnumerationFullMatch;
54
+    /* @var bool */
55
+    protected $shareeEnumerationFullMatchEmail;
56 56
 
57
-	/** @var IManager */
58
-	private $contactsManager;
59
-	/** @var ICloudIdManager */
60
-	private $cloudIdManager;
61
-	/** @var IConfig */
62
-	private $config;
57
+    /** @var IManager */
58
+    private $contactsManager;
59
+    /** @var ICloudIdManager */
60
+    private $cloudIdManager;
61
+    /** @var IConfig */
62
+    private $config;
63 63
 
64
-	/** @var IGroupManager */
65
-	private $groupManager;
66
-	/** @var KnownUserService */
67
-	private $knownUserService;
68
-	/** @var IUserSession */
69
-	private $userSession;
70
-	/** @var IMailer */
71
-	private $mailer;
64
+    /** @var IGroupManager */
65
+    private $groupManager;
66
+    /** @var KnownUserService */
67
+    private $knownUserService;
68
+    /** @var IUserSession */
69
+    private $userSession;
70
+    /** @var IMailer */
71
+    private $mailer;
72 72
 
73
-	public function __construct(IManager $contactsManager,
74
-								ICloudIdManager $cloudIdManager,
75
-								IConfig $config,
76
-								IGroupManager $groupManager,
77
-								KnownUserService $knownUserService,
78
-								IUserSession $userSession,
79
-								IMailer $mailer) {
80
-		$this->contactsManager = $contactsManager;
81
-		$this->cloudIdManager = $cloudIdManager;
82
-		$this->config = $config;
83
-		$this->groupManager = $groupManager;
84
-		$this->knownUserService = $knownUserService;
85
-		$this->userSession = $userSession;
86
-		$this->mailer = $mailer;
73
+    public function __construct(IManager $contactsManager,
74
+                                ICloudIdManager $cloudIdManager,
75
+                                IConfig $config,
76
+                                IGroupManager $groupManager,
77
+                                KnownUserService $knownUserService,
78
+                                IUserSession $userSession,
79
+                                IMailer $mailer) {
80
+        $this->contactsManager = $contactsManager;
81
+        $this->cloudIdManager = $cloudIdManager;
82
+        $this->config = $config;
83
+        $this->groupManager = $groupManager;
84
+        $this->knownUserService = $knownUserService;
85
+        $this->userSession = $userSession;
86
+        $this->mailer = $mailer;
87 87
 
88
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
89
-		$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
90
-		$this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
91
-		$this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
92
-		$this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
93
-		$this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
94
-	}
88
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
89
+        $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
90
+        $this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
91
+        $this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
92
+        $this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
93
+        $this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
94
+    }
95 95
 
96
-	/**
97
-	 * {@inheritdoc}
98
-	 */
99
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
100
-		if ($this->shareeEnumerationFullMatch && !$this->shareeEnumerationFullMatchEmail) {
101
-			return false;
102
-		}
96
+    /**
97
+     * {@inheritdoc}
98
+     */
99
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
100
+        if ($this->shareeEnumerationFullMatch && !$this->shareeEnumerationFullMatchEmail) {
101
+            return false;
102
+        }
103 103
 
104
-		// Extract the email address from "Foo Bar <[email protected]>" and then search with "[email protected]" instead
105
-		$result = preg_match('/<([^@]+@.+)>$/', $search, $matches);
106
-		if ($result && filter_var($matches[1], FILTER_VALIDATE_EMAIL)) {
107
-			return $this->search($matches[1], $limit, $offset, $searchResult);
108
-		}
104
+        // Extract the email address from "Foo Bar <[email protected]>" and then search with "[email protected]" instead
105
+        $result = preg_match('/<([^@]+@.+)>$/', $search, $matches);
106
+        if ($result && filter_var($matches[1], FILTER_VALIDATE_EMAIL)) {
107
+            return $this->search($matches[1], $limit, $offset, $searchResult);
108
+        }
109 109
 
110
-		$currentUserId = $this->userSession->getUser()->getUID();
110
+        $currentUserId = $this->userSession->getUser()->getUID();
111 111
 
112
-		$result = $userResults = ['wide' => [], 'exact' => []];
113
-		$userType = new SearchResultType('users');
114
-		$emailType = new SearchResultType('emails');
112
+        $result = $userResults = ['wide' => [], 'exact' => []];
113
+        $userType = new SearchResultType('users');
114
+        $emailType = new SearchResultType('emails');
115 115
 
116
-		// Search in contacts
117
-		$addressBookContacts = $this->contactsManager->search(
118
-			$search,
119
-			['EMAIL', 'FN'],
120
-			[
121
-				'limit' => $limit,
122
-				'offset' => $offset,
123
-				'enumeration' => (bool) $this->shareeEnumeration,
124
-				'fullmatch' => (bool) $this->shareeEnumerationFullMatch,
125
-			]
126
-		);
127
-		$lowerSearch = strtolower($search);
128
-		foreach ($addressBookContacts as $contact) {
129
-			if (isset($contact['EMAIL'])) {
130
-				$emailAddresses = $contact['EMAIL'];
131
-				if (\is_string($emailAddresses)) {
132
-					$emailAddresses = [$emailAddresses];
133
-				}
134
-				foreach ($emailAddresses as $type => $emailAddress) {
135
-					$displayName = $emailAddress;
136
-					$emailAddressType = null;
137
-					if (\is_array($emailAddress)) {
138
-						$emailAddressData = $emailAddress;
139
-						$emailAddress = $emailAddressData['value'];
140
-						$emailAddressType = $emailAddressData['type'];
141
-					}
142
-					if (isset($contact['FN'])) {
143
-						$displayName = $contact['FN'] . ' (' . $emailAddress . ')';
144
-					}
145
-					$exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
116
+        // Search in contacts
117
+        $addressBookContacts = $this->contactsManager->search(
118
+            $search,
119
+            ['EMAIL', 'FN'],
120
+            [
121
+                'limit' => $limit,
122
+                'offset' => $offset,
123
+                'enumeration' => (bool) $this->shareeEnumeration,
124
+                'fullmatch' => (bool) $this->shareeEnumerationFullMatch,
125
+            ]
126
+        );
127
+        $lowerSearch = strtolower($search);
128
+        foreach ($addressBookContacts as $contact) {
129
+            if (isset($contact['EMAIL'])) {
130
+                $emailAddresses = $contact['EMAIL'];
131
+                if (\is_string($emailAddresses)) {
132
+                    $emailAddresses = [$emailAddresses];
133
+                }
134
+                foreach ($emailAddresses as $type => $emailAddress) {
135
+                    $displayName = $emailAddress;
136
+                    $emailAddressType = null;
137
+                    if (\is_array($emailAddress)) {
138
+                        $emailAddressData = $emailAddress;
139
+                        $emailAddress = $emailAddressData['value'];
140
+                        $emailAddressType = $emailAddressData['type'];
141
+                    }
142
+                    if (isset($contact['FN'])) {
143
+                        $displayName = $contact['FN'] . ' (' . $emailAddress . ')';
144
+                    }
145
+                    $exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
146 146
 
147
-					if (isset($contact['isLocalSystemBook'])) {
148
-						if ($this->shareWithGroupOnly) {
149
-							/*
147
+                    if (isset($contact['isLocalSystemBook'])) {
148
+                        if ($this->shareWithGroupOnly) {
149
+                            /*
150 150
 							 * Check if the user may share with the user associated with the e-mail of the just found contact
151 151
 							 */
152
-							$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
153
-							$found = false;
154
-							foreach ($userGroups as $userGroup) {
155
-								if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
156
-									$found = true;
157
-									break;
158
-								}
159
-							}
160
-							if (!$found) {
161
-								continue;
162
-							}
163
-						}
164
-						if ($exactEmailMatch && $this->shareeEnumerationFullMatch) {
165
-							try {
166
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
167
-							} catch (\InvalidArgumentException $e) {
168
-								continue;
169
-							}
152
+                            $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
153
+                            $found = false;
154
+                            foreach ($userGroups as $userGroup) {
155
+                                if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
156
+                                    $found = true;
157
+                                    break;
158
+                                }
159
+                            }
160
+                            if (!$found) {
161
+                                continue;
162
+                            }
163
+                        }
164
+                        if ($exactEmailMatch && $this->shareeEnumerationFullMatch) {
165
+                            try {
166
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
167
+                            } catch (\InvalidArgumentException $e) {
168
+                                continue;
169
+                            }
170 170
 
171
-							if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
172
-								$singleResult = [[
173
-									'label' => $displayName,
174
-									'uuid' => $contact['UID'] ?? $emailAddress,
175
-									'name' => $contact['FN'] ?? $displayName,
176
-									'value' => [
177
-										'shareType' => IShare::TYPE_USER,
178
-										'shareWith' => $cloud->getUser(),
179
-									],
180
-									'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
171
+                            if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
172
+                                $singleResult = [[
173
+                                    'label' => $displayName,
174
+                                    'uuid' => $contact['UID'] ?? $emailAddress,
175
+                                    'name' => $contact['FN'] ?? $displayName,
176
+                                    'value' => [
177
+                                        'shareType' => IShare::TYPE_USER,
178
+                                        'shareWith' => $cloud->getUser(),
179
+                                    ],
180
+                                    'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
181 181
 
182
-								]];
183
-								$searchResult->addResultSet($userType, [], $singleResult);
184
-								$searchResult->markExactIdMatch($emailType);
185
-							}
186
-							return false;
187
-						}
182
+                                ]];
183
+                                $searchResult->addResultSet($userType, [], $singleResult);
184
+                                $searchResult->markExactIdMatch($emailType);
185
+                            }
186
+                            return false;
187
+                        }
188 188
 
189
-						if ($this->shareeEnumeration) {
190
-							try {
191
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
192
-							} catch (\InvalidArgumentException $e) {
193
-								continue;
194
-							}
189
+                        if ($this->shareeEnumeration) {
190
+                            try {
191
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
192
+                            } catch (\InvalidArgumentException $e) {
193
+                                continue;
194
+                            }
195 195
 
196
-							$addToWide = !($this->shareeEnumerationInGroupOnly || $this->shareeEnumerationPhone);
197
-							if (!$addToWide && $this->shareeEnumerationPhone && $this->knownUserService->isKnownToUser($currentUserId, $contact['UID'])) {
198
-								$addToWide = true;
199
-							}
196
+                            $addToWide = !($this->shareeEnumerationInGroupOnly || $this->shareeEnumerationPhone);
197
+                            if (!$addToWide && $this->shareeEnumerationPhone && $this->knownUserService->isKnownToUser($currentUserId, $contact['UID'])) {
198
+                                $addToWide = true;
199
+                            }
200 200
 
201
-							if (!$addToWide && $this->shareeEnumerationInGroupOnly) {
202
-								$addToWide = false;
203
-								$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
204
-								foreach ($userGroups as $userGroup) {
205
-									if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
206
-										$addToWide = true;
207
-										break;
208
-									}
209
-								}
210
-							}
211
-							if ($addToWide && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
212
-								$userResults['wide'][] = [
213
-									'label' => $displayName,
214
-									'uuid' => $contact['UID'] ?? $emailAddress,
215
-									'name' => $contact['FN'] ?? $displayName,
216
-									'value' => [
217
-										'shareType' => IShare::TYPE_USER,
218
-										'shareWith' => $cloud->getUser(),
219
-									],
220
-									'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
221
-								];
222
-								continue;
223
-							}
224
-						}
225
-						continue;
226
-					}
201
+                            if (!$addToWide && $this->shareeEnumerationInGroupOnly) {
202
+                                $addToWide = false;
203
+                                $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
204
+                                foreach ($userGroups as $userGroup) {
205
+                                    if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
206
+                                        $addToWide = true;
207
+                                        break;
208
+                                    }
209
+                                }
210
+                            }
211
+                            if ($addToWide && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
212
+                                $userResults['wide'][] = [
213
+                                    'label' => $displayName,
214
+                                    'uuid' => $contact['UID'] ?? $emailAddress,
215
+                                    'name' => $contact['FN'] ?? $displayName,
216
+                                    'value' => [
217
+                                        'shareType' => IShare::TYPE_USER,
218
+                                        'shareWith' => $cloud->getUser(),
219
+                                    ],
220
+                                    'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
221
+                                ];
222
+                                continue;
223
+                            }
224
+                        }
225
+                        continue;
226
+                    }
227 227
 
228
-					if ($exactEmailMatch
229
-						|| (isset($contact['FN']) && strtolower($contact['FN']) === $lowerSearch)) {
230
-						if ($exactEmailMatch) {
231
-							$searchResult->markExactIdMatch($emailType);
232
-						}
233
-						$result['exact'][] = [
234
-							'label' => $displayName,
235
-							'uuid' => $contact['UID'] ?? $emailAddress,
236
-							'name' => $contact['FN'] ?? $displayName,
237
-							'type' => $emailAddressType ?? '',
238
-							'value' => [
239
-								'shareType' => IShare::TYPE_EMAIL,
240
-								'shareWith' => $emailAddress,
241
-							],
242
-						];
243
-					} else {
244
-						$result['wide'][] = [
245
-							'label' => $displayName,
246
-							'uuid' => $contact['UID'] ?? $emailAddress,
247
-							'name' => $contact['FN'] ?? $displayName,
248
-							'type' => $emailAddressType ?? '',
249
-							'value' => [
250
-								'shareType' => IShare::TYPE_EMAIL,
251
-								'shareWith' => $emailAddress,
252
-							],
253
-						];
254
-					}
255
-				}
256
-			}
257
-		}
228
+                    if ($exactEmailMatch
229
+                        || (isset($contact['FN']) && strtolower($contact['FN']) === $lowerSearch)) {
230
+                        if ($exactEmailMatch) {
231
+                            $searchResult->markExactIdMatch($emailType);
232
+                        }
233
+                        $result['exact'][] = [
234
+                            'label' => $displayName,
235
+                            'uuid' => $contact['UID'] ?? $emailAddress,
236
+                            'name' => $contact['FN'] ?? $displayName,
237
+                            'type' => $emailAddressType ?? '',
238
+                            'value' => [
239
+                                'shareType' => IShare::TYPE_EMAIL,
240
+                                'shareWith' => $emailAddress,
241
+                            ],
242
+                        ];
243
+                    } else {
244
+                        $result['wide'][] = [
245
+                            'label' => $displayName,
246
+                            'uuid' => $contact['UID'] ?? $emailAddress,
247
+                            'name' => $contact['FN'] ?? $displayName,
248
+                            'type' => $emailAddressType ?? '',
249
+                            'value' => [
250
+                                'shareType' => IShare::TYPE_EMAIL,
251
+                                'shareWith' => $emailAddress,
252
+                            ],
253
+                        ];
254
+                    }
255
+                }
256
+            }
257
+        }
258 258
 
259
-		$reachedEnd = true;
260
-		if ($this->shareeEnumeration) {
261
-			$reachedEnd = (count($result['wide']) < $offset + $limit) &&
262
-				(count($userResults['wide']) < $offset + $limit);
259
+        $reachedEnd = true;
260
+        if ($this->shareeEnumeration) {
261
+            $reachedEnd = (count($result['wide']) < $offset + $limit) &&
262
+                (count($userResults['wide']) < $offset + $limit);
263 263
 
264
-			$result['wide'] = array_slice($result['wide'], $offset, $limit);
265
-			$userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
266
-		}
264
+            $result['wide'] = array_slice($result['wide'], $offset, $limit);
265
+            $userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
266
+        }
267 267
 
268
-		if (!$searchResult->hasExactIdMatch($emailType) && $this->mailer->validateMailAddress($search)) {
269
-			$result['exact'][] = [
270
-				'label' => $search,
271
-				'uuid' => $search,
272
-				'value' => [
273
-					'shareType' => IShare::TYPE_EMAIL,
274
-					'shareWith' => $search,
275
-				],
276
-			];
277
-		}
268
+        if (!$searchResult->hasExactIdMatch($emailType) && $this->mailer->validateMailAddress($search)) {
269
+            $result['exact'][] = [
270
+                'label' => $search,
271
+                'uuid' => $search,
272
+                'value' => [
273
+                    'shareType' => IShare::TYPE_EMAIL,
274
+                    'shareWith' => $search,
275
+                ],
276
+            ];
277
+        }
278 278
 
279
-		if (!empty($userResults['wide'])) {
280
-			$searchResult->addResultSet($userType, $userResults['wide'], []);
281
-		}
282
-		$searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
279
+        if (!empty($userResults['wide'])) {
280
+            $searchResult->addResultSet($userType, $userResults['wide'], []);
281
+        }
282
+        $searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
283 283
 
284
-		return !$reachedEnd;
285
-	}
284
+        return !$reachedEnd;
285
+    }
286 286
 
287
-	public function isCurrentUser(ICloudId $cloud): bool {
288
-		$currentUser = $this->userSession->getUser();
289
-		return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false;
290
-	}
287
+    public function isCurrentUser(ICloudId $cloud): bool {
288
+        $currentUser = $this->userSession->getUser();
289
+        return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false;
290
+    }
291 291
 }
Please login to merge, or discard this patch.
lib/private/OCS/Provider.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -25,92 +25,92 @@
 block discarded – undo
25 25
 namespace OC\OCS;
26 26
 
27 27
 class Provider extends \OCP\AppFramework\Controller {
28
-	/** @var \OCP\App\IAppManager */
29
-	private $appManager;
28
+    /** @var \OCP\App\IAppManager */
29
+    private $appManager;
30 30
 
31
-	/**
32
-	 * @param string $appName
33
-	 * @param \OCP\IRequest $request
34
-	 * @param \OCP\App\IAppManager $appManager
35
-	 */
36
-	public function __construct($appName,
37
-								\OCP\IRequest $request,
38
-								\OCP\App\IAppManager $appManager) {
39
-		parent::__construct($appName, $request);
40
-		$this->appManager = $appManager;
41
-	}
31
+    /**
32
+     * @param string $appName
33
+     * @param \OCP\IRequest $request
34
+     * @param \OCP\App\IAppManager $appManager
35
+     */
36
+    public function __construct($appName,
37
+                                \OCP\IRequest $request,
38
+                                \OCP\App\IAppManager $appManager) {
39
+        parent::__construct($appName, $request);
40
+        $this->appManager = $appManager;
41
+    }
42 42
 
43
-	/**
44
-	 * @return \OCP\AppFramework\Http\JSONResponse
45
-	 */
46
-	public function buildProviderList() {
47
-		$services = [
48
-			'PRIVATE_DATA' => [
49
-				'version' => 1,
50
-				'endpoints' => [
51
-					'store' => '/ocs/v2.php/privatedata/setattribute',
52
-					'read' => '/ocs/v2.php/privatedata/getattribute',
53
-					'delete' => '/ocs/v2.php/privatedata/deleteattribute',
54
-				],
55
-			],
56
-		];
43
+    /**
44
+     * @return \OCP\AppFramework\Http\JSONResponse
45
+     */
46
+    public function buildProviderList() {
47
+        $services = [
48
+            'PRIVATE_DATA' => [
49
+                'version' => 1,
50
+                'endpoints' => [
51
+                    'store' => '/ocs/v2.php/privatedata/setattribute',
52
+                    'read' => '/ocs/v2.php/privatedata/getattribute',
53
+                    'delete' => '/ocs/v2.php/privatedata/deleteattribute',
54
+                ],
55
+            ],
56
+        ];
57 57
 
58
-		if ($this->appManager->isEnabledForUser('files_sharing')) {
59
-			$services['SHARING'] = [
60
-				'version' => 1,
61
-				'endpoints' => [
62
-					'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
63
-				],
64
-			];
65
-			$services['FEDERATED_SHARING'] = [
66
-				'version' => 1,
67
-				'endpoints' => [
68
-					'share' => '/ocs/v2.php/cloud/shares',
69
-					'webdav' => '/public.php/webdav/',
70
-				],
71
-			];
72
-		}
58
+        if ($this->appManager->isEnabledForUser('files_sharing')) {
59
+            $services['SHARING'] = [
60
+                'version' => 1,
61
+                'endpoints' => [
62
+                    'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
63
+                ],
64
+            ];
65
+            $services['FEDERATED_SHARING'] = [
66
+                'version' => 1,
67
+                'endpoints' => [
68
+                    'share' => '/ocs/v2.php/cloud/shares',
69
+                    'webdav' => '/public.php/webdav/',
70
+                ],
71
+            ];
72
+        }
73 73
 
74
-		if ($this->appManager->isEnabledForUser('federation')) {
75
-			if (isset($services['FEDERATED_SHARING'])) {
76
-				$services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret';
77
-				$services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system';
78
-				$services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system';
79
-			} else {
80
-				$services['FEDERATED_SHARING'] = [
81
-					'version' => 1,
82
-					'endpoints' => [
83
-						'shared-secret' => '/ocs/v2.php/cloud/shared-secret',
84
-						'system-address-book' => '/remote.php/dav/addressbooks/system/system/system',
85
-						'carddav-user' => 'system'
86
-					],
87
-				];
88
-			}
89
-		}
74
+        if ($this->appManager->isEnabledForUser('federation')) {
75
+            if (isset($services['FEDERATED_SHARING'])) {
76
+                $services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret';
77
+                $services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system';
78
+                $services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system';
79
+            } else {
80
+                $services['FEDERATED_SHARING'] = [
81
+                    'version' => 1,
82
+                    'endpoints' => [
83
+                        'shared-secret' => '/ocs/v2.php/cloud/shared-secret',
84
+                        'system-address-book' => '/remote.php/dav/addressbooks/system/system/system',
85
+                        'carddav-user' => 'system'
86
+                    ],
87
+                ];
88
+            }
89
+        }
90 90
 
91
-		if ($this->appManager->isEnabledForUser('activity')) {
92
-			$services['ACTIVITY'] = [
93
-				'version' => 1,
94
-				'endpoints' => [
95
-					'list' => '/ocs/v2.php/cloud/activity',
96
-				],
97
-			];
98
-		}
91
+        if ($this->appManager->isEnabledForUser('activity')) {
92
+            $services['ACTIVITY'] = [
93
+                'version' => 1,
94
+                'endpoints' => [
95
+                    'list' => '/ocs/v2.php/cloud/activity',
96
+                ],
97
+            ];
98
+        }
99 99
 
100
-		if ($this->appManager->isEnabledForUser('provisioning_api')) {
101
-			$services['PROVISIONING'] = [
102
-				'version' => 1,
103
-				'endpoints' => [
104
-					'user' => '/ocs/v2.php/cloud/users',
105
-					'groups' => '/ocs/v2.php/cloud/groups',
106
-					'apps' => '/ocs/v2.php/cloud/apps',
107
-				],
108
-			];
109
-		}
100
+        if ($this->appManager->isEnabledForUser('provisioning_api')) {
101
+            $services['PROVISIONING'] = [
102
+                'version' => 1,
103
+                'endpoints' => [
104
+                    'user' => '/ocs/v2.php/cloud/users',
105
+                    'groups' => '/ocs/v2.php/cloud/groups',
106
+                    'apps' => '/ocs/v2.php/cloud/apps',
107
+                ],
108
+            ];
109
+        }
110 110
 
111
-		return new \OCP\AppFramework\Http\JSONResponse([
112
-			'version' => 2,
113
-			'services' => $services,
114
-		]);
115
-	}
111
+        return new \OCP\AppFramework\Http\JSONResponse([
112
+            'version' => 2,
113
+            'services' => $services,
114
+        ]);
115
+    }
116 116
 }
Please login to merge, or discard this patch.
lib/private/Authentication/Exceptions/InvalidProviderException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 use Throwable;
31 31
 
32 32
 class InvalidProviderException extends Exception {
33
-	public function __construct(string $providerId, Throwable $previous = null) {
34
-		parent::__construct("The provider '$providerId' does not exist'", 0, $previous);
35
-	}
33
+    public function __construct(string $providerId, Throwable $previous = null) {
34
+        parent::__construct("The provider '$providerId' does not exist'", 0, $previous);
35
+    }
36 36
 }
Please login to merge, or discard this patch.
lib/private/DB/MissingIndexInformation.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,16 +28,16 @@
 block discarded – undo
28 28
 namespace OC\DB;
29 29
 
30 30
 class MissingIndexInformation {
31
-	private $listOfMissingIndexes = [];
31
+    private $listOfMissingIndexes = [];
32 32
 
33
-	public function addHintForMissingSubject(string $tableName, string $indexName) {
34
-		$this->listOfMissingIndexes[] = [
35
-			'tableName' => $tableName,
36
-			'indexName' => $indexName
37
-		];
38
-	}
33
+    public function addHintForMissingSubject(string $tableName, string $indexName) {
34
+        $this->listOfMissingIndexes[] = [
35
+            'tableName' => $tableName,
36
+            'indexName' => $indexName
37
+        ];
38
+    }
39 39
 
40
-	public function getListOfMissingIndexes(): array {
41
-		return $this->listOfMissingIndexes;
42
-	}
40
+    public function getListOfMissingIndexes(): array {
41
+        return $this->listOfMissingIndexes;
42
+    }
43 43
 }
Please login to merge, or discard this patch.
lib/private/DB/MissingColumnInformation.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -27,16 +27,16 @@
 block discarded – undo
27 27
 namespace OC\DB;
28 28
 
29 29
 class MissingColumnInformation {
30
-	private $listOfMissingColumns = [];
30
+    private $listOfMissingColumns = [];
31 31
 
32
-	public function addHintForMissingColumn(string $tableName, string $columnName): void {
33
-		$this->listOfMissingColumns[] = [
34
-			'tableName' => $tableName,
35
-			'columnName' => $columnName,
36
-		];
37
-	}
32
+    public function addHintForMissingColumn(string $tableName, string $columnName): void {
33
+        $this->listOfMissingColumns[] = [
34
+            'tableName' => $tableName,
35
+            'columnName' => $columnName,
36
+        ];
37
+    }
38 38
 
39
-	public function getListOfMissingColumns(): array {
40
-		return $this->listOfMissingColumns;
41
-	}
39
+    public function getListOfMissingColumns(): array {
40
+        return $this->listOfMissingColumns;
41
+    }
42 42
 }
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/S3Signature.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$request = $this->prepareRequest($request, $credentials);
65 65
 		$stringToSign = $this->createCanonicalizedString($request);
66 66
 		$auth = 'AWS '
67
-			. $credentials->getAccessKeyId() . ':'
67
+			. $credentials->getAccessKeyId().':'
68 68
 			. $this->signString($stringToSign, $credentials);
69 69
 
70 70
 		return $request->withHeader('Authorization', $auth);
@@ -148,11 +148,11 @@  discard block
 block discarded – undo
148 148
 		RequestInterface $request,
149 149
 		$expires = null
150 150
 	) {
151
-		$buffer = $request->getMethod() . "\n";
151
+		$buffer = $request->getMethod()."\n";
152 152
 
153 153
 		// Add the interesting headers
154 154
 		foreach ($this->signableHeaders as $header) {
155
-			$buffer .= $request->getHeaderLine($header) . "\n";
155
+			$buffer .= $request->getHeaderLine($header)."\n";
156 156
 		}
157 157
 
158 158
 		$date = $expires ?: $request->getHeaderLine('date');
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 			if (strpos($name, 'x-amz-') === 0) {
171 171
 				$value = implode(',', $header);
172 172
 				if (strlen($value) > 0) {
173
-					$headers[$name] = $name . ':' . $value;
173
+					$headers[$name] = $name.':'.$value;
174 174
 				}
175 175
 			}
176 176
 		}
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 
182 182
 		ksort($headers);
183 183
 
184
-		return implode("\n", $headers) . "\n";
184
+		return implode("\n", $headers)."\n";
185 185
 	}
186 186
 
187 187
 	private function createCanonicalizedResource(RequestInterface $request) {
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 		if ($data['bucket']) {
192 192
 			$buffer .= $data['bucket'];
193 193
 			if (!empty($data['key']) || !$data['path_style']) {
194
-				$buffer .= '/' . $data['key'];
194
+				$buffer .= '/'.$data['key'];
195 195
 			}
196 196
 		}
197 197
 
Please login to merge, or discard this patch.
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -35,188 +35,188 @@
 block discarded – undo
35 35
  * Legacy Amazon S3 signature implementation
36 36
  */
37 37
 class S3Signature implements SignatureInterface {
38
-	/** @var array Query string values that must be signed */
39
-	private $signableQueryString = [
40
-		'acl', 'cors', 'delete', 'lifecycle', 'location', 'logging',
41
-		'notification', 'partNumber', 'policy', 'requestPayment',
42
-		'response-cache-control', 'response-content-disposition',
43
-		'response-content-encoding', 'response-content-language',
44
-		'response-content-type', 'response-expires', 'restore', 'tagging',
45
-		'torrent', 'uploadId', 'uploads', 'versionId', 'versioning',
46
-		'versions', 'website'
47
-	];
48
-
49
-	/** @var array Sorted headers that must be signed */
50
-	private $signableHeaders = ['Content-MD5', 'Content-Type'];
51
-
52
-	/** @var \Aws\S3\S3UriParser S3 URI parser */
53
-	private $parser;
54
-
55
-	public function __construct() {
56
-		$this->parser = new S3UriParser();
57
-		// Ensure that the signable query string parameters are sorted
58
-		sort($this->signableQueryString);
59
-	}
60
-
61
-	public function signRequest(
62
-		RequestInterface $request,
63
-		CredentialsInterface $credentials
64
-	) {
65
-		$request = $this->prepareRequest($request, $credentials);
66
-		$stringToSign = $this->createCanonicalizedString($request);
67
-		$auth = 'AWS '
68
-			. $credentials->getAccessKeyId() . ':'
69
-			. $this->signString($stringToSign, $credentials);
70
-
71
-		return $request->withHeader('Authorization', $auth);
72
-	}
73
-
74
-	public function presign(
75
-		RequestInterface $request,
76
-		CredentialsInterface $credentials,
77
-		$expires,
78
-		array $options = []
79
-	) {
80
-		$query = [];
81
-		// URL encoding already occurs in the URI template expansion. Undo that
82
-		// and encode using the same encoding as GET object, PUT object, etc.
83
-		$uri = $request->getUri();
84
-		$path = S3Client::encodeKey(rawurldecode($uri->getPath()));
85
-		$request = $request->withUri($uri->withPath($path));
86
-
87
-		// Make sure to handle temporary credentials
88
-		if ($token = $credentials->getSecurityToken()) {
89
-			$request = $request->withHeader('X-Amz-Security-Token', $token);
90
-			$query['X-Amz-Security-Token'] = $token;
91
-		}
92
-
93
-		if ($expires instanceof \DateTime) {
94
-			$expires = $expires->getTimestamp();
95
-		} elseif (!is_numeric($expires)) {
96
-			$expires = strtotime($expires);
97
-		}
98
-
99
-		// Set query params required for pre-signed URLs
100
-		$query['AWSAccessKeyId'] = $credentials->getAccessKeyId();
101
-		$query['Expires'] = $expires;
102
-		$query['Signature'] = $this->signString(
103
-			$this->createCanonicalizedString($request, $expires),
104
-			$credentials
105
-		);
106
-
107
-		// Move X-Amz-* headers to the query string
108
-		foreach ($request->getHeaders() as $name => $header) {
109
-			$name = strtolower($name);
110
-			if (strpos($name, 'x-amz-') === 0) {
111
-				$query[$name] = implode(',', $header);
112
-			}
113
-		}
114
-
115
-		$queryString = http_build_query($query, null, '&', PHP_QUERY_RFC3986);
116
-
117
-		return $request->withUri($request->getUri()->withQuery($queryString));
118
-	}
119
-
120
-	/**
121
-	 * @param RequestInterface     $request
122
-	 * @param CredentialsInterface $creds
123
-	 *
124
-	 * @return RequestInterface
125
-	 */
126
-	private function prepareRequest(
127
-		RequestInterface $request,
128
-		CredentialsInterface $creds
129
-	) {
130
-		$modify = [
131
-			'remove_headers' => ['X-Amz-Date'],
132
-			'set_headers' => ['Date' => gmdate(\DateTimeInterface::RFC2822)]
133
-		];
134
-
135
-		// Add the security token header if one is being used by the credentials
136
-		if ($token = $creds->getSecurityToken()) {
137
-			$modify['set_headers']['X-Amz-Security-Token'] = $token;
138
-		}
139
-
140
-		return Psr7\Utils::modifyRequest($request, $modify);
141
-	}
142
-
143
-	private function signString($string, CredentialsInterface $credentials) {
144
-		return base64_encode(
145
-			hash_hmac('sha1', $string, $credentials->getSecretKey(), true)
146
-		);
147
-	}
148
-
149
-	private function createCanonicalizedString(
150
-		RequestInterface $request,
151
-		$expires = null
152
-	) {
153
-		$buffer = $request->getMethod() . "\n";
154
-
155
-		// Add the interesting headers
156
-		foreach ($this->signableHeaders as $header) {
157
-			$buffer .= $request->getHeaderLine($header) . "\n";
158
-		}
159
-
160
-		$date = $expires ?: $request->getHeaderLine('date');
161
-		$buffer .= "{$date}\n"
162
-			. $this->createCanonicalizedAmzHeaders($request)
163
-			. $this->createCanonicalizedResource($request);
164
-
165
-		return $buffer;
166
-	}
167
-
168
-	private function createCanonicalizedAmzHeaders(RequestInterface $request) {
169
-		$headers = [];
170
-		foreach ($request->getHeaders() as $name => $header) {
171
-			$name = strtolower($name);
172
-			if (strpos($name, 'x-amz-') === 0) {
173
-				$value = implode(',', $header);
174
-				if (strlen($value) > 0) {
175
-					$headers[$name] = $name . ':' . $value;
176
-				}
177
-			}
178
-		}
179
-
180
-		if (!$headers) {
181
-			return '';
182
-		}
183
-
184
-		ksort($headers);
185
-
186
-		return implode("\n", $headers) . "\n";
187
-	}
188
-
189
-	private function createCanonicalizedResource(RequestInterface $request) {
190
-		$data = $this->parser->parse($request->getUri());
191
-		$buffer = '/';
192
-
193
-		if ($data['bucket']) {
194
-			$buffer .= $data['bucket'];
195
-			if (!empty($data['key']) || !$data['path_style']) {
196
-				$buffer .= '/' . $data['key'];
197
-			}
198
-		}
199
-
200
-		// Add sub resource parameters if present.
201
-		$query = $request->getUri()->getQuery();
202
-
203
-		if ($query) {
204
-			$params = Psr7\Query::parse($query);
205
-			$first = true;
206
-			foreach ($this->signableQueryString as $key) {
207
-				if (array_key_exists($key, $params)) {
208
-					$value = $params[$key];
209
-					$buffer .= $first ? '?' : '&';
210
-					$first = false;
211
-					$buffer .= $key;
212
-					// Don't add values for empty sub-resources
213
-					if (strlen($value)) {
214
-						$buffer .= "={$value}";
215
-					}
216
-				}
217
-			}
218
-		}
219
-
220
-		return $buffer;
221
-	}
38
+    /** @var array Query string values that must be signed */
39
+    private $signableQueryString = [
40
+        'acl', 'cors', 'delete', 'lifecycle', 'location', 'logging',
41
+        'notification', 'partNumber', 'policy', 'requestPayment',
42
+        'response-cache-control', 'response-content-disposition',
43
+        'response-content-encoding', 'response-content-language',
44
+        'response-content-type', 'response-expires', 'restore', 'tagging',
45
+        'torrent', 'uploadId', 'uploads', 'versionId', 'versioning',
46
+        'versions', 'website'
47
+    ];
48
+
49
+    /** @var array Sorted headers that must be signed */
50
+    private $signableHeaders = ['Content-MD5', 'Content-Type'];
51
+
52
+    /** @var \Aws\S3\S3UriParser S3 URI parser */
53
+    private $parser;
54
+
55
+    public function __construct() {
56
+        $this->parser = new S3UriParser();
57
+        // Ensure that the signable query string parameters are sorted
58
+        sort($this->signableQueryString);
59
+    }
60
+
61
+    public function signRequest(
62
+        RequestInterface $request,
63
+        CredentialsInterface $credentials
64
+    ) {
65
+        $request = $this->prepareRequest($request, $credentials);
66
+        $stringToSign = $this->createCanonicalizedString($request);
67
+        $auth = 'AWS '
68
+            . $credentials->getAccessKeyId() . ':'
69
+            . $this->signString($stringToSign, $credentials);
70
+
71
+        return $request->withHeader('Authorization', $auth);
72
+    }
73
+
74
+    public function presign(
75
+        RequestInterface $request,
76
+        CredentialsInterface $credentials,
77
+        $expires,
78
+        array $options = []
79
+    ) {
80
+        $query = [];
81
+        // URL encoding already occurs in the URI template expansion. Undo that
82
+        // and encode using the same encoding as GET object, PUT object, etc.
83
+        $uri = $request->getUri();
84
+        $path = S3Client::encodeKey(rawurldecode($uri->getPath()));
85
+        $request = $request->withUri($uri->withPath($path));
86
+
87
+        // Make sure to handle temporary credentials
88
+        if ($token = $credentials->getSecurityToken()) {
89
+            $request = $request->withHeader('X-Amz-Security-Token', $token);
90
+            $query['X-Amz-Security-Token'] = $token;
91
+        }
92
+
93
+        if ($expires instanceof \DateTime) {
94
+            $expires = $expires->getTimestamp();
95
+        } elseif (!is_numeric($expires)) {
96
+            $expires = strtotime($expires);
97
+        }
98
+
99
+        // Set query params required for pre-signed URLs
100
+        $query['AWSAccessKeyId'] = $credentials->getAccessKeyId();
101
+        $query['Expires'] = $expires;
102
+        $query['Signature'] = $this->signString(
103
+            $this->createCanonicalizedString($request, $expires),
104
+            $credentials
105
+        );
106
+
107
+        // Move X-Amz-* headers to the query string
108
+        foreach ($request->getHeaders() as $name => $header) {
109
+            $name = strtolower($name);
110
+            if (strpos($name, 'x-amz-') === 0) {
111
+                $query[$name] = implode(',', $header);
112
+            }
113
+        }
114
+
115
+        $queryString = http_build_query($query, null, '&', PHP_QUERY_RFC3986);
116
+
117
+        return $request->withUri($request->getUri()->withQuery($queryString));
118
+    }
119
+
120
+    /**
121
+     * @param RequestInterface     $request
122
+     * @param CredentialsInterface $creds
123
+     *
124
+     * @return RequestInterface
125
+     */
126
+    private function prepareRequest(
127
+        RequestInterface $request,
128
+        CredentialsInterface $creds
129
+    ) {
130
+        $modify = [
131
+            'remove_headers' => ['X-Amz-Date'],
132
+            'set_headers' => ['Date' => gmdate(\DateTimeInterface::RFC2822)]
133
+        ];
134
+
135
+        // Add the security token header if one is being used by the credentials
136
+        if ($token = $creds->getSecurityToken()) {
137
+            $modify['set_headers']['X-Amz-Security-Token'] = $token;
138
+        }
139
+
140
+        return Psr7\Utils::modifyRequest($request, $modify);
141
+    }
142
+
143
+    private function signString($string, CredentialsInterface $credentials) {
144
+        return base64_encode(
145
+            hash_hmac('sha1', $string, $credentials->getSecretKey(), true)
146
+        );
147
+    }
148
+
149
+    private function createCanonicalizedString(
150
+        RequestInterface $request,
151
+        $expires = null
152
+    ) {
153
+        $buffer = $request->getMethod() . "\n";
154
+
155
+        // Add the interesting headers
156
+        foreach ($this->signableHeaders as $header) {
157
+            $buffer .= $request->getHeaderLine($header) . "\n";
158
+        }
159
+
160
+        $date = $expires ?: $request->getHeaderLine('date');
161
+        $buffer .= "{$date}\n"
162
+            . $this->createCanonicalizedAmzHeaders($request)
163
+            . $this->createCanonicalizedResource($request);
164
+
165
+        return $buffer;
166
+    }
167
+
168
+    private function createCanonicalizedAmzHeaders(RequestInterface $request) {
169
+        $headers = [];
170
+        foreach ($request->getHeaders() as $name => $header) {
171
+            $name = strtolower($name);
172
+            if (strpos($name, 'x-amz-') === 0) {
173
+                $value = implode(',', $header);
174
+                if (strlen($value) > 0) {
175
+                    $headers[$name] = $name . ':' . $value;
176
+                }
177
+            }
178
+        }
179
+
180
+        if (!$headers) {
181
+            return '';
182
+        }
183
+
184
+        ksort($headers);
185
+
186
+        return implode("\n", $headers) . "\n";
187
+    }
188
+
189
+    private function createCanonicalizedResource(RequestInterface $request) {
190
+        $data = $this->parser->parse($request->getUri());
191
+        $buffer = '/';
192
+
193
+        if ($data['bucket']) {
194
+            $buffer .= $data['bucket'];
195
+            if (!empty($data['key']) || !$data['path_style']) {
196
+                $buffer .= '/' . $data['key'];
197
+            }
198
+        }
199
+
200
+        // Add sub resource parameters if present.
201
+        $query = $request->getUri()->getQuery();
202
+
203
+        if ($query) {
204
+            $params = Psr7\Query::parse($query);
205
+            $first = true;
206
+            foreach ($this->signableQueryString as $key) {
207
+                if (array_key_exists($key, $params)) {
208
+                    $value = $params[$key];
209
+                    $buffer .= $first ? '?' : '&';
210
+                    $first = false;
211
+                    $buffer .= $key;
212
+                    // Don't add values for empty sub-resources
213
+                    if (strlen($value)) {
214
+                        $buffer .= "={$value}";
215
+                    }
216
+                }
217
+            }
218
+        }
219
+
220
+        return $buffer;
221
+    }
222 222
 }
Please login to merge, or discard this patch.