Skip to content

Commit

Permalink
Merge pull request #188 from owncloud/re-allow-avatar-change
Browse files Browse the repository at this point in the history
reallow avatars to be changed if not provided by ldap
  • Loading branch information
Vincent Petry authored Mar 6, 2019
2 parents 05393c3 + 7c5a1f9 commit f76f60d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
12 changes: 9 additions & 3 deletions lib/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OCA\User_LDAP\User;

use OC\Cache\CappedMemoryCache;
use OC\ServerNotAvailableException;
use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection;
use OCA\User_LDAP\Exceptions\DoesNotExistOnLDAPException;
Expand Down Expand Up @@ -117,11 +118,11 @@ public function setLdapAccess(IUserTools $access) {

/**
* @brief checks whether the Access instance has been set
* @throws \Exception if Access has not been set
* @throws \BadMethodCallException if Access has not been set
*/
private function checkAccess() {
if ($this->access === null) {
throw new \Exception('LDAP Access instance must be set first');
throw new \BadMethodCallException('LDAP Access instance must be set first');
}
}

Expand Down Expand Up @@ -188,9 +189,14 @@ public function getAttributes($minimal = false) {

/**
* Gets an UserEntry from the LDAP server from a distinguished name
*
* @param $dn
* @return UserEntry
* @throws \OutOfBoundsException
* @throws \InvalidArgumentException
* @throws \BadMethodCallException
* @throws DoesNotExistOnLDAPException when the dn supplied cannot be found on LDAP
* @throws ServerNotAvailableException
*/
public function getUserEntryByDn($dn) {
$result = $this->access->executeRead(
Expand All @@ -211,7 +217,7 @@ public function getUserEntryByDn($dn) {
* @brief returns a User object by the DN in an ldap entry
* @param array $ldapEntry the ldap entry used to prefill the user properties
* @return \OCA\User_LDAP\User\UserEntry
* @throws \Exception when connection could not be established
* @throws \BadMethodCallException when access object has not been set
* @throws \InvalidArgumentException if entry does not contain a dn
* @throws \OutOfBoundsException when username could not be determined
*/
Expand Down
7 changes: 6 additions & 1 deletion lib/User_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace OCA\User_LDAP;

use OC\ServerNotAvailableException;
use OC\User\Backend;
use OC\User\NoUserException;
use OCA\User_LDAP\Exceptions\DoesNotExistOnLDAPException;
Expand Down Expand Up @@ -174,9 +175,13 @@ public function getUsers($search = '', $limit = 10, $offset = 0) {

/**
* check if a user exists
*
* @param string $uid the username
* @return boolean
* @throws \Exception when connection could not be established
* @throws \OutOfBoundsException
* @throws \InvalidArgumentException
* @throws \BadMethodCallException
* @throws ServerNotAvailableException when connection could not be established
*/
public function userExists($uid) {
// check if an LdapEntry has been cached already
Expand Down
15 changes: 14 additions & 1 deletion lib/User_Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

namespace OCA\User_LDAP;

use OC\ServerNotAvailableException;
use OCA\User_LDAP\Exceptions\DoesNotExistOnLDAPException;
use OCP\IConfig;
use OCP\IUserBackend;
use OCP\User\IProvidesEMailBackend;
Expand Down Expand Up @@ -224,11 +226,22 @@ public function getDisplayName($uid) {

/**
* checks whether the user is allowed to change his avatar in ownCloud
*
* @param string $uid the ownCloud user name
* @return bool either the user can or cannot
* @throws \OutOfBoundsException
* @throws \InvalidArgumentException
* @throws \BadMethodCallException
* @throws ServerNotAvailableException
* @throws DoesNotExistOnLDAPException
*/
public function canChangeAvatar($uid) {
return $this->handleRequest($uid, 'canChangeAvatar', [$uid]);
foreach ($this->backends as $backend) {
if ($backend->userExists($uid)) {
return $backend->canChangeAvatar($uid);
}
}
throw new DoesNotExistOnLDAPException($uid);
}

/**
Expand Down

0 comments on commit f76f60d

Please sign in to comment.