Completed
Pull Request — master (#6328)
by Blizzz
13:24
created
lib/public/Collaboration/Collaborators/ISearchResult.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -25,44 +25,44 @@
 block discarded – undo
25 25
 
26 26
 
27 27
 interface ISearchResult {
28
-	/**
29
-	 * @param string $type one of: users, groups, remotes, email, circles, lookup
30
-	 * @param array $matches
31
-	 * @param array|null $exactMatches
32
-	 * @since 13.0.0
33
-	 */
34
-	public function addResultSet($type, array $matches, array $exactMatches = null);
28
+    /**
29
+     * @param string $type one of: users, groups, remotes, email, circles, lookup
30
+     * @param array $matches
31
+     * @param array|null $exactMatches
32
+     * @since 13.0.0
33
+     */
34
+    public function addResultSet($type, array $matches, array $exactMatches = null);
35 35
 
36
-	/**
37
-	 * @param string $type one of: users, groups, remotes, email, circles, lookup
38
-	 * @param string $collaboratorId
39
-	 * @return bool
40
-	 * @since 13.0.0
41
-	 */
42
-	public function hasResult($type, $collaboratorId);
36
+    /**
37
+     * @param string $type one of: users, groups, remotes, email, circles, lookup
38
+     * @param string $collaboratorId
39
+     * @return bool
40
+     * @since 13.0.0
41
+     */
42
+    public function hasResult($type, $collaboratorId);
43 43
 
44
-	/**
45
-	 * @param string $type one of: users, groups, remotes, email, circles, lookup
46
-	 * @since 13.0.0
47
-	 */
48
-	public function unsetResult($type);
44
+    /**
45
+     * @param string $type one of: users, groups, remotes, email, circles, lookup
46
+     * @since 13.0.0
47
+     */
48
+    public function unsetResult($type);
49 49
 
50
-	/**
51
-	 * @param string $type one of: users, groups, remotes, email, circles, lookup
52
-	 * @since 13.0.0
53
-	 */
54
-	public function markExactIdMatch($type);
50
+    /**
51
+     * @param string $type one of: users, groups, remotes, email, circles, lookup
52
+     * @since 13.0.0
53
+     */
54
+    public function markExactIdMatch($type);
55 55
 
56
-	/**
57
-	 * @param string $type one of: users, groups, remotes, email, circles, lookup
58
-	 * @return bool
59
-	 * @since 13.0.0
60
-	 */
61
-	public function hasExactIdMatch($type);
56
+    /**
57
+     * @param string $type one of: users, groups, remotes, email, circles, lookup
58
+     * @return bool
59
+     * @since 13.0.0
60
+     */
61
+    public function hasExactIdMatch($type);
62 62
 
63
-	/**
64
-	 * @return array
65
-	 * @since 13.0.0
66
-	 */
67
-	public function asArray();
63
+    /**
64
+     * @return array
65
+     * @since 13.0.0
66
+     */
67
+    public function asArray();
68 68
 }
Please login to merge, or discard this patch.
lib/public/Collaboration/Collaborators/ISearchPlugin.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -25,13 +25,13 @@
 block discarded – undo
25 25
 
26 26
 
27 27
 interface ISearchPlugin {
28
-	/**
29
-	 * @param string $search
30
-	 * @param int $limit
31
-	 * @param int $offset
32
-	 * @param ISearchResult $searchResult
33
-	 * @return bool whether the plugin has more results
34
-	 * @since 13.0.0
35
-	 */
36
-	public function search($search, $limit, $offset, ISearchResult $searchResult);
28
+    /**
29
+     * @param string $search
30
+     * @param int $limit
31
+     * @param int $offset
32
+     * @param ISearchResult $searchResult
33
+     * @return bool whether the plugin has more results
34
+     * @since 13.0.0
35
+     */
36
+    public function search($search, $limit, $offset, ISearchResult $searchResult);
37 37
 }
Please login to merge, or discard this patch.
lib/public/Collaboration/Collaborators/ISearch.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -24,14 +24,14 @@
 block discarded – undo
24 24
 namespace OCP\Collaboration\Collaborators;
25 25
 
26 26
 interface ISearch {
27
-	/**
28
-	 * @param string $search
29
-	 * @param array $shareTypes
30
-	 * @param bool $lookup
31
-	 * @param int $limit
32
-	 * @param int $offset
33
-	 * @return array with two elements, 1st ISearchResult as array, 2nd a bool indicating whether more result are available
34
-	 * @since 13.0.0
35
-	 */
36
-	public function search($search, array $shareTypes, $lookup, $limit, $offset);
27
+    /**
28
+     * @param string $search
29
+     * @param array $shareTypes
30
+     * @param bool $lookup
31
+     * @param int $limit
32
+     * @param int $offset
33
+     * @return array with two elements, 1st ISearchResult as array, 2nd a bool indicating whether more result are available
34
+     * @since 13.0.0
35
+     */
36
+    public function search($search, array $shareTypes, $lookup, $limit, $offset);
37 37
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/SearchResult.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -28,70 +28,70 @@
 block discarded – undo
28 28
 
29 29
 class SearchResult implements ISearchResult {
30 30
 
31
-	protected $result = [
32
-		'exact' => [
33
-			'users' => [],
34
-			'groups' => [],
35
-			'remotes' => [],
36
-			'emails' => [],
37
-			'circles' => [],
38
-		],
39
-		'users' => [],
40
-		'groups' => [],
41
-		'remotes' => [],
42
-		'emails' => [],
43
-		'lookup' => [],
44
-		'circles' => [],
45
-	];
46
-
47
-	protected $exactIdMatches = [];
48
-
49
-	public function addResultSet($type, array $matches, array $exactMatches = null) {
50
-		if(!isset($this->result[$type])) {
51
-			throw new \InvalidArgumentException('Invalid type provided');
52
-		}
53
-
54
-		$this->result[$type] = array_merge($this->result[$type], $matches);
55
-		if(is_array($exactMatches)) {
56
-			$this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches);
57
-		}
58
-	}
59
-
60
-	public function markExactIdMatch($type) {
61
-		$this->exactIdMatches[$type] = 1;
62
-	}
63
-
64
-	public function hasExactIdMatch($type) {
65
-		return isset($this->exactIdMatches[$type]);
66
-	}
67
-
68
-	public function hasResult($type, $collaboratorId) {
69
-		if(!isset($this->result[$type])) {
70
-			throw new \InvalidArgumentException('Invalid type provided');
71
-		}
72
-
73
-		$resultArrays = [$this->result['exact'][$type], $this->result[$type]];
74
-		foreach($resultArrays as $resultArray) {
75
-			if ($resultArray['value']['shareWith'] === $collaboratorId) {
76
-				return true;
77
-			}
78
-		}
79
-
80
-		return false;
81
-	}
82
-
83
-	public function asArray() {
84
-		return $this->result;
85
-	}
86
-
87
-	public function unsetResult($type) {
88
-		if(!isset($this->result[$type])) {
89
-			throw new \InvalidArgumentException('Invalid type provided');
90
-		}
91
-
92
-		$this->result[$type] = [];
93
-		if(isset($this->$result['exact'][$type])) {
94
-			$this->result['exact'][$type] = [];
95
-		}
96
-	}
31
+    protected $result = [
32
+        'exact' => [
33
+            'users' => [],
34
+            'groups' => [],
35
+            'remotes' => [],
36
+            'emails' => [],
37
+            'circles' => [],
38
+        ],
39
+        'users' => [],
40
+        'groups' => [],
41
+        'remotes' => [],
42
+        'emails' => [],
43
+        'lookup' => [],
44
+        'circles' => [],
45
+    ];
46
+
47
+    protected $exactIdMatches = [];
48
+
49
+    public function addResultSet($type, array $matches, array $exactMatches = null) {
50
+        if(!isset($this->result[$type])) {
51
+            throw new \InvalidArgumentException('Invalid type provided');
52
+        }
53
+
54
+        $this->result[$type] = array_merge($this->result[$type], $matches);
55
+        if(is_array($exactMatches)) {
56
+            $this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches);
57
+        }
58
+    }
59
+
60
+    public function markExactIdMatch($type) {
61
+        $this->exactIdMatches[$type] = 1;
62
+    }
63
+
64
+    public function hasExactIdMatch($type) {
65
+        return isset($this->exactIdMatches[$type]);
66
+    }
67
+
68
+    public function hasResult($type, $collaboratorId) {
69
+        if(!isset($this->result[$type])) {
70
+            throw new \InvalidArgumentException('Invalid type provided');
71
+        }
72
+
73
+        $resultArrays = [$this->result['exact'][$type], $this->result[$type]];
74
+        foreach($resultArrays as $resultArray) {
75
+            if ($resultArray['value']['shareWith'] === $collaboratorId) {
76
+                return true;
77
+            }
78
+        }
79
+
80
+        return false;
81
+    }
82
+
83
+    public function asArray() {
84
+        return $this->result;
85
+    }
86
+
87
+    public function unsetResult($type) {
88
+        if(!isset($this->result[$type])) {
89
+            throw new \InvalidArgumentException('Invalid type provided');
90
+        }
91
+
92
+        $this->result[$type] = [];
93
+        if(isset($this->$result['exact'][$type])) {
94
+            $this->result['exact'][$type] = [];
95
+        }
96
+    }
97 97
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/CirclePlugin.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -29,21 +29,21 @@
 block discarded – undo
29 29
 use OCP\Collaboration\Collaborators\ISearchResult;
30 30
 
31 31
 class CirclePlugin implements ISearchPlugin {
32
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
33
-		$result = ['wide' => [], 'exact' => []];
32
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
33
+        $result = ['wide' => [], 'exact' => []];
34 34
 
35
-		if(\OC_App::isEnabled('circles')) {
36
-			$circles = Sharees::search($search);
37
-			if (array_key_exists('circles', $circles['exact'])) {
38
-				$result['exact'] = $circles['exact']['circles'];
39
-			}
40
-			if (array_key_exists('circles', $circles)) {
41
-				$result['wide'] = $circles['circles'];
42
-			}
35
+        if(\OC_App::isEnabled('circles')) {
36
+            $circles = Sharees::search($search);
37
+            if (array_key_exists('circles', $circles['exact'])) {
38
+                $result['exact'] = $circles['exact']['circles'];
39
+            }
40
+            if (array_key_exists('circles', $circles)) {
41
+                $result['wide'] = $circles['circles'];
42
+            }
43 43
 
44
-			$searchResult->addResultSet('circles', $result['wide'], $result['exact']);
45
-		}
44
+            $searchResult->addResultSet('circles', $result['wide'], $result['exact']);
45
+        }
46 46
 
47
-		return false;
48
-	}
47
+        return false;
48
+    }
49 49
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/RemotePlugin.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -32,104 +32,104 @@
 block discarded – undo
32 32
 use OCP\Share;
33 33
 
34 34
 class RemotePlugin implements ISearchPlugin {
35
-	protected $shareeEnumeration;
35
+    protected $shareeEnumeration;
36 36
 
37
-	/** @var IManager */
38
-	private $contactsManager;
39
-	/** @var ICloudIdManager */
40
-	private $cloudIdManager;
41
-	/** @var IConfig */
42
-	private $config;
37
+    /** @var IManager */
38
+    private $contactsManager;
39
+    /** @var ICloudIdManager */
40
+    private $cloudIdManager;
41
+    /** @var IConfig */
42
+    private $config;
43 43
 
44
-	public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) {
45
-		$this->contactsManager = $contactsManager;
46
-		$this->cloudIdManager = $cloudIdManager;
47
-		$this->config = $config;
44
+    public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) {
45
+        $this->contactsManager = $contactsManager;
46
+        $this->cloudIdManager = $cloudIdManager;
47
+        $this->config = $config;
48 48
 
49
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
50
-	}
49
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
50
+    }
51 51
 
52
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
53
-		$result = ['wide' => [], 'exact' => []];
52
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
53
+        $result = ['wide' => [], 'exact' => []];
54 54
 
55
-		// Search in contacts
56
-		//@todo Pagination missing
57
-		$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']);
58
-		foreach ($addressBookContacts as $contact) {
59
-			if (isset($contact['isLocalSystemBook'])) {
60
-				continue;
61
-			}
62
-			if (isset($contact['CLOUD'])) {
63
-				$cloudIds = $contact['CLOUD'];
64
-				if (!is_array($cloudIds)) {
65
-					$cloudIds = [$cloudIds];
66
-				}
67
-				$lowerSearch = strtolower($search);
68
-				foreach ($cloudIds as $cloudId) {
69
-					try {
70
-						list(, $serverUrl) = $this->splitUserRemote($cloudId);
71
-					} catch (\InvalidArgumentException $e) {
72
-						continue;
73
-					}
55
+        // Search in contacts
56
+        //@todo Pagination missing
57
+        $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']);
58
+        foreach ($addressBookContacts as $contact) {
59
+            if (isset($contact['isLocalSystemBook'])) {
60
+                continue;
61
+            }
62
+            if (isset($contact['CLOUD'])) {
63
+                $cloudIds = $contact['CLOUD'];
64
+                if (!is_array($cloudIds)) {
65
+                    $cloudIds = [$cloudIds];
66
+                }
67
+                $lowerSearch = strtolower($search);
68
+                foreach ($cloudIds as $cloudId) {
69
+                    try {
70
+                        list(, $serverUrl) = $this->splitUserRemote($cloudId);
71
+                    } catch (\InvalidArgumentException $e) {
72
+                        continue;
73
+                    }
74 74
 
75
-					if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
76
-						if (strtolower($cloudId) === $lowerSearch) {
77
-							$searchResult->hasExactIdMatch('remotes');
78
-						}
79
-						$result['exact'][] = [
80
-							'label' => $contact['FN'] . " ($cloudId)",
81
-							'value' => [
82
-								'shareType' => Share::SHARE_TYPE_REMOTE,
83
-								'shareWith' => $cloudId,
84
-								'server' => $serverUrl,
85
-							],
86
-						];
87
-					} else {
88
-						$result['wide'][] = [
89
-							'label' => $contact['FN'] . " ($cloudId)",
90
-							'value' => [
91
-								'shareType' => Share::SHARE_TYPE_REMOTE,
92
-								'shareWith' => $cloudId,
93
-								'server' => $serverUrl,
94
-							],
95
-						];
96
-					}
97
-				}
98
-			}
99
-		}
75
+                    if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
76
+                        if (strtolower($cloudId) === $lowerSearch) {
77
+                            $searchResult->hasExactIdMatch('remotes');
78
+                        }
79
+                        $result['exact'][] = [
80
+                            'label' => $contact['FN'] . " ($cloudId)",
81
+                            'value' => [
82
+                                'shareType' => Share::SHARE_TYPE_REMOTE,
83
+                                'shareWith' => $cloudId,
84
+                                'server' => $serverUrl,
85
+                            ],
86
+                        ];
87
+                    } else {
88
+                        $result['wide'][] = [
89
+                            'label' => $contact['FN'] . " ($cloudId)",
90
+                            'value' => [
91
+                                'shareType' => Share::SHARE_TYPE_REMOTE,
92
+                                'shareWith' => $cloudId,
93
+                                'server' => $serverUrl,
94
+                            ],
95
+                        ];
96
+                    }
97
+                }
98
+            }
99
+        }
100 100
 
101
-		if (!$this->shareeEnumeration) {
102
-			$result['wide'] = [];
103
-		}
101
+        if (!$this->shareeEnumeration) {
102
+            $result['wide'] = [];
103
+        }
104 104
 
105
-		if (!$searchResult->hasExactIdMatch('remotes') && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
106
-			$result['exact'][] = [
107
-				'label' => $search,
108
-				'value' => [
109
-					'shareType' => Share::SHARE_TYPE_REMOTE,
110
-					'shareWith' => $search,
111
-				],
112
-			];
113
-		}
105
+        if (!$searchResult->hasExactIdMatch('remotes') && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
106
+            $result['exact'][] = [
107
+                'label' => $search,
108
+                'value' => [
109
+                    'shareType' => Share::SHARE_TYPE_REMOTE,
110
+                    'shareWith' => $search,
111
+                ],
112
+            ];
113
+        }
114 114
 
115
-		$searchResult->addResultSet('remotes', $result['wide'], $result['exact']);
115
+        $searchResult->addResultSet('remotes', $result['wide'], $result['exact']);
116 116
 
117
-		return false;
118
-	}
117
+        return false;
118
+    }
119 119
 
120
-	/**
121
-	 * split user and remote from federated cloud id
122
-	 *
123
-	 * @param string $address federated share address
124
-	 * @return array [user, remoteURL]
125
-	 * @throws \InvalidArgumentException
126
-	 */
127
-	public function splitUserRemote($address) {
128
-		try {
129
-			$cloudId = $this->cloudIdManager->resolveCloudId($address);
130
-			return [$cloudId->getUser(), $cloudId->getRemote()];
131
-		} catch (\InvalidArgumentException $e) {
132
-			throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
133
-		}
134
-	}
120
+    /**
121
+     * split user and remote from federated cloud id
122
+     *
123
+     * @param string $address federated share address
124
+     * @return array [user, remoteURL]
125
+     * @throws \InvalidArgumentException
126
+     */
127
+    public function splitUserRemote($address) {
128
+        try {
129
+            $cloudId = $this->cloudIdManager->resolveCloudId($address);
130
+            return [$cloudId->getUser(), $cloudId->getRemote()];
131
+        } catch (\InvalidArgumentException $e) {
132
+            throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
133
+        }
134
+    }
135 135
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/UserPlugin.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -34,114 +34,114 @@
 block discarded – undo
34 34
 use OCP\Share;
35 35
 
36 36
 class UserPlugin implements ISearchPlugin {
37
-	/* @var bool */
38
-	protected $shareWithGroupOnly;
39
-	protected $shareeEnumeration;
40
-
41
-	/** @var IConfig */
42
-	private $config;
43
-	/** @var IGroupManager */
44
-	private $groupManager;
45
-	/** @var IUserSession */
46
-	private $userSession;
47
-	/** @var IUserManager */
48
-	private $userManager;
49
-
50
-	public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) {
51
-		$this->config = $config;
37
+    /* @var bool */
38
+    protected $shareWithGroupOnly;
39
+    protected $shareeEnumeration;
40
+
41
+    /** @var IConfig */
42
+    private $config;
43
+    /** @var IGroupManager */
44
+    private $groupManager;
45
+    /** @var IUserSession */
46
+    private $userSession;
47
+    /** @var IUserManager */
48
+    private $userManager;
49
+
50
+    public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) {
51
+        $this->config = $config;
52 52
 		
53
-		$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
54
-		$this->groupManager = $groupManager;
55
-		$this->userSession = $userSession;
56
-		$this->userManager = $userManager;
57
-
58
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
59
-	}
60
-
61
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
62
-		$result = ['wide' => [], 'exact' => []];
63
-		$users = [];
64
-		$hasMoreResults = false;
65
-
66
-		$userGroups = [];
67
-		if ($this->shareWithGroupOnly) {
68
-			// Search in all the groups this user is part of
69
-			$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
70
-			foreach ($userGroups as $userGroup) {
71
-				$usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $limit, $offset);
72
-				foreach ($usersTmp as $uid => $userDisplayName) {
73
-					$users[$uid] = $userDisplayName;
74
-				}
75
-			}
76
-		} else {
77
-			// Search in all users
78
-			$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
79
-
80
-			foreach ($usersTmp as $user) {
81
-				$users[$user->getUID()] = $user->getDisplayName();
82
-			}
83
-		}
84
-
85
-		if (!$this->shareeEnumeration || sizeof($users) < $limit) {
86
-			$hasMoreResults = true;
87
-		}
88
-
89
-		$foundUserById = false;
90
-		$lowerSearch = strtolower($search);
91
-		foreach ($users as $uid => $userDisplayName) {
92
-			if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) {
93
-				if (strtolower($uid) === $lowerSearch) {
94
-					$foundUserById = true;
95
-				}
96
-				$result['exact'][] = [
97
-					'label' => $userDisplayName,
98
-					'value' => [
99
-						'shareType' => Share::SHARE_TYPE_USER,
100
-						'shareWith' => $uid,
101
-					],
102
-				];
103
-			} else {
104
-				$result['wide'][] = [
105
-					'label' => $userDisplayName,
106
-					'value' => [
107
-						'shareType' => Share::SHARE_TYPE_USER,
108
-						'shareWith' => $uid,
109
-					],
110
-				];
111
-			}
112
-		}
113
-
114
-		if ($offset === 0 && !$foundUserById) {
115
-			// On page one we try if the search result has a direct hit on the
116
-			// user id and if so, we add that to the exact match list
117
-			$user = $this->userManager->get($search);
118
-			if ($user instanceof IUser) {
119
-				$addUser = true;
120
-
121
-				if ($this->shareWithGroupOnly) {
122
-					// Only add, if we have a common group
123
-					$commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user));
124
-					$addUser = !empty($commonGroups);
125
-				}
126
-
127
-				if ($addUser) {
128
-					array_push($result['exact'], [
129
-						'label' => $user->getDisplayName(),
130
-						'value' => [
131
-							'shareType' => Share::SHARE_TYPE_USER,
132
-							'shareWith' => $user->getUID(),
133
-						],
134
-					]);
135
-				}
136
-			}
137
-		}
138
-
139
-		if (!$this->shareeEnumeration) {
140
-			$result['wide'] = [];
141
-		}
142
-
143
-		$searchResult->addResultSet('users', $result['wide'], $result['exact']);
144
-
145
-		return $hasMoreResults;
146
-	}
53
+        $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
54
+        $this->groupManager = $groupManager;
55
+        $this->userSession = $userSession;
56
+        $this->userManager = $userManager;
57
+
58
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
59
+    }
60
+
61
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
62
+        $result = ['wide' => [], 'exact' => []];
63
+        $users = [];
64
+        $hasMoreResults = false;
65
+
66
+        $userGroups = [];
67
+        if ($this->shareWithGroupOnly) {
68
+            // Search in all the groups this user is part of
69
+            $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
70
+            foreach ($userGroups as $userGroup) {
71
+                $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $limit, $offset);
72
+                foreach ($usersTmp as $uid => $userDisplayName) {
73
+                    $users[$uid] = $userDisplayName;
74
+                }
75
+            }
76
+        } else {
77
+            // Search in all users
78
+            $usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
79
+
80
+            foreach ($usersTmp as $user) {
81
+                $users[$user->getUID()] = $user->getDisplayName();
82
+            }
83
+        }
84
+
85
+        if (!$this->shareeEnumeration || sizeof($users) < $limit) {
86
+            $hasMoreResults = true;
87
+        }
88
+
89
+        $foundUserById = false;
90
+        $lowerSearch = strtolower($search);
91
+        foreach ($users as $uid => $userDisplayName) {
92
+            if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) {
93
+                if (strtolower($uid) === $lowerSearch) {
94
+                    $foundUserById = true;
95
+                }
96
+                $result['exact'][] = [
97
+                    'label' => $userDisplayName,
98
+                    'value' => [
99
+                        'shareType' => Share::SHARE_TYPE_USER,
100
+                        'shareWith' => $uid,
101
+                    ],
102
+                ];
103
+            } else {
104
+                $result['wide'][] = [
105
+                    'label' => $userDisplayName,
106
+                    'value' => [
107
+                        'shareType' => Share::SHARE_TYPE_USER,
108
+                        'shareWith' => $uid,
109
+                    ],
110
+                ];
111
+            }
112
+        }
113
+
114
+        if ($offset === 0 && !$foundUserById) {
115
+            // On page one we try if the search result has a direct hit on the
116
+            // user id and if so, we add that to the exact match list
117
+            $user = $this->userManager->get($search);
118
+            if ($user instanceof IUser) {
119
+                $addUser = true;
120
+
121
+                if ($this->shareWithGroupOnly) {
122
+                    // Only add, if we have a common group
123
+                    $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user));
124
+                    $addUser = !empty($commonGroups);
125
+                }
126
+
127
+                if ($addUser) {
128
+                    array_push($result['exact'], [
129
+                        'label' => $user->getDisplayName(),
130
+                        'value' => [
131
+                            'shareType' => Share::SHARE_TYPE_USER,
132
+                            'shareWith' => $user->getUID(),
133
+                        ],
134
+                    ]);
135
+                }
136
+            }
137
+        }
138
+
139
+        if (!$this->shareeEnumeration) {
140
+            $result['wide'] = [];
141
+        }
142
+
143
+        $searchResult->addResultSet('users', $result['wide'], $result['exact']);
144
+
145
+        return $hasMoreResults;
146
+    }
147 147
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/GroupPlugin.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -32,91 +32,91 @@
 block discarded – undo
32 32
 use OCP\Share;
33 33
 
34 34
 class GroupPlugin implements ISearchPlugin {
35
-	protected $shareeEnumeration;
36
-	protected $shareWithGroupOnly;
35
+    protected $shareeEnumeration;
36
+    protected $shareWithGroupOnly;
37 37
 
38
-	/** @var IGroupManager */
39
-	private $groupManager;
40
-	/** @var IConfig */
41
-	private $config;
42
-	/** @var IUserSession */
43
-	private $userSession;
38
+    /** @var IGroupManager */
39
+    private $groupManager;
40
+    /** @var IConfig */
41
+    private $config;
42
+    /** @var IUserSession */
43
+    private $userSession;
44 44
 
45
-	public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) {
46
-		$this->groupManager = $groupManager;
47
-		$this->config = $config;
48
-		$this->userSession = $userSession;
45
+    public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) {
46
+        $this->groupManager = $groupManager;
47
+        $this->config = $config;
48
+        $this->userSession = $userSession;
49 49
 
50
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
51
-		$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
52
-	}
50
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
51
+        $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
52
+    }
53 53
 
54
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
55
-		$hasMoreResults = false;
56
-		$result = ['wide' => [], 'exact' => []];
54
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
55
+        $hasMoreResults = false;
56
+        $result = ['wide' => [], 'exact' => []];
57 57
 
58
-		$groups = $this->groupManager->search($search, $limit, $offset);
59
-		$groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups);
58
+        $groups = $this->groupManager->search($search, $limit, $offset);
59
+        $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups);
60 60
 
61
-		if (!$this->shareeEnumeration || sizeof($groups) < $limit) {
62
-			$hasMoreResults = true;
63
-		}
61
+        if (!$this->shareeEnumeration || sizeof($groups) < $limit) {
62
+            $hasMoreResults = true;
63
+        }
64 64
 
65
-		$userGroups =  [];
66
-		if (!empty($groups) && $this->shareWithGroupOnly) {
67
-			// Intersect all the groups that match with the groups this user is a member of
68
-			$userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
69
-			$userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups);
70
-			$groupIds = array_intersect($groupIds, $userGroups);
71
-		}
65
+        $userGroups =  [];
66
+        if (!empty($groups) && $this->shareWithGroupOnly) {
67
+            // Intersect all the groups that match with the groups this user is a member of
68
+            $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
69
+            $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups);
70
+            $groupIds = array_intersect($groupIds, $userGroups);
71
+        }
72 72
 
73
-		$lowerSearch = strtolower($search);
74
-		foreach ($groups as $group) {
75
-			// FIXME: use a more efficient approach
76
-			$gid = $group->getGID();
77
-			if (!in_array($gid, $groupIds)) {
78
-				continue;
79
-			}
80
-			if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) {
81
-				$result['exact'][] = [
82
-					'label' => $group->getDisplayName(),
83
-					'value' => [
84
-						'shareType' => Share::SHARE_TYPE_GROUP,
85
-						'shareWith' => $gid,
86
-					],
87
-				];
88
-			} else {
89
-				$result['wide'][] = [
90
-					'label' => $group->getDisplayName(),
91
-					'value' => [
92
-						'shareType' => Share::SHARE_TYPE_GROUP,
93
-						'shareWith' => $gid,
94
-					],
95
-				];
96
-			}
97
-		}
73
+        $lowerSearch = strtolower($search);
74
+        foreach ($groups as $group) {
75
+            // FIXME: use a more efficient approach
76
+            $gid = $group->getGID();
77
+            if (!in_array($gid, $groupIds)) {
78
+                continue;
79
+            }
80
+            if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) {
81
+                $result['exact'][] = [
82
+                    'label' => $group->getDisplayName(),
83
+                    'value' => [
84
+                        'shareType' => Share::SHARE_TYPE_GROUP,
85
+                        'shareWith' => $gid,
86
+                    ],
87
+                ];
88
+            } else {
89
+                $result['wide'][] = [
90
+                    'label' => $group->getDisplayName(),
91
+                    'value' => [
92
+                        'shareType' => Share::SHARE_TYPE_GROUP,
93
+                        'shareWith' => $gid,
94
+                    ],
95
+                ];
96
+            }
97
+        }
98 98
 
99
-		if ($offset === 0 && empty($result['exact'])) {
100
-			// On page one we try if the search result has a direct hit on the
101
-			// user id and if so, we add that to the exact match list
102
-			$group = $this->groupManager->get($search);
103
-			if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) {
104
-				array_push($result['exact'], [
105
-					'label' => $group->getDisplayName(),
106
-					'value' => [
107
-						'shareType' => Share::SHARE_TYPE_GROUP,
108
-						'shareWith' => $group->getGID(),
109
-					],
110
-				]);
111
-			}
112
-		}
99
+        if ($offset === 0 && empty($result['exact'])) {
100
+            // On page one we try if the search result has a direct hit on the
101
+            // user id and if so, we add that to the exact match list
102
+            $group = $this->groupManager->get($search);
103
+            if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) {
104
+                array_push($result['exact'], [
105
+                    'label' => $group->getDisplayName(),
106
+                    'value' => [
107
+                        'shareType' => Share::SHARE_TYPE_GROUP,
108
+                        'shareWith' => $group->getGID(),
109
+                    ],
110
+                ]);
111
+            }
112
+        }
113 113
 
114
-		if (!$this->shareeEnumeration) {
115
-			$result['wide'] = [];
116
-		}
114
+        if (!$this->shareeEnumeration) {
115
+            $result['wide'] = [];
116
+        }
117 117
 
118
-		$searchResult->addResultSet('groups', $result['wide'], $result['exact']);
118
+        $searchResult->addResultSet('groups', $result['wide'], $result['exact']);
119 119
 
120
-		return [$result, $hasMoreResults];
121
-	}
120
+        return [$result, $hasMoreResults];
121
+    }
122 122
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/LookupPlugin.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -32,52 +32,52 @@
 block discarded – undo
32 32
 
33 33
 class LookupPlugin implements ISearchPlugin {
34 34
 
35
-	/** @var IConfig */
36
-	private $config;
37
-	/** @var IClientService */
38
-	private $clientService;
35
+    /** @var IConfig */
36
+    private $config;
37
+    /** @var IClientService */
38
+    private $clientService;
39 39
 
40
-	public function __construct(IConfig $config, IClientService $clientService) {
41
-		$this->config = $config;
42
-		$this->clientService = $clientService;
43
-	}
40
+    public function __construct(IConfig $config, IClientService $clientService) {
41
+        $this->config = $config;
42
+        $this->clientService = $clientService;
43
+    }
44 44
 
45
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
46
-		if ($this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') !== 'yes') {
47
-			return false;
48
-		}
45
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
46
+        if ($this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') !== 'yes') {
47
+            return false;
48
+        }
49 49
 
50
-		$lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
51
-		$lookupServerUrl = rtrim($lookupServerUrl, '/');
52
-		$result = ['wide' => [], 'exact' => []];
50
+        $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
51
+        $lookupServerUrl = rtrim($lookupServerUrl, '/');
52
+        $result = ['wide' => [], 'exact' => []];
53 53
 
54
-		try {
55
-			$client = $this->clientService->newClient();
56
-			$response = $client->get(
57
-				$lookupServerUrl . '/users?search=' . urlencode($search),
58
-				[
59
-					'timeout' => 10,
60
-					'connect_timeout' => 3,
61
-				]
62
-			);
54
+        try {
55
+            $client = $this->clientService->newClient();
56
+            $response = $client->get(
57
+                $lookupServerUrl . '/users?search=' . urlencode($search),
58
+                [
59
+                    'timeout' => 10,
60
+                    'connect_timeout' => 3,
61
+                ]
62
+            );
63 63
 
64
-			$body = json_decode($response->getBody(), true);
64
+            $body = json_decode($response->getBody(), true);
65 65
 
66
-			$result = [];
67
-			foreach ($body as $lookup) {
68
-				$result[] = [
69
-					'label' => $lookup['federationId'],
70
-					'value' => [
71
-						'shareType' => Share::SHARE_TYPE_REMOTE,
72
-						'shareWith' => $lookup['federationId'],
73
-					],
74
-					'extra' => $lookup,
75
-				];
76
-			}
77
-		} catch (\Exception $e) {
78
-		}
66
+            $result = [];
67
+            foreach ($body as $lookup) {
68
+                $result[] = [
69
+                    'label' => $lookup['federationId'],
70
+                    'value' => [
71
+                        'shareType' => Share::SHARE_TYPE_REMOTE,
72
+                        'shareWith' => $lookup['federationId'],
73
+                    ],
74
+                    'extra' => $lookup,
75
+                ];
76
+            }
77
+        } catch (\Exception $e) {
78
+        }
79 79
 
80
-		$searchResult->addResultSet('lookup', $result, []);
80
+        $searchResult->addResultSet('lookup', $result, []);
81 81
 
82
-	}
82
+    }
83 83
 }
Please login to merge, or discard this patch.