Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Example SQL script in README file
- Fixed misspelling

### Changed
- Support for Nextcloud 14 only
- Group backend implementation
- User backend implementation

### Fixed
- Table and column autocomplete in settings panel

## [v4.0.0-rc2] - 2018-06-14
## [4.0.0-rc2] - 2018-06-14
### Added
- User active column

Expand Down Expand Up @@ -79,6 +84,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Supported version of ownCloud, Nextcloud: ownCloud 10, Nextcloud 12

[Unreleased]: https://github.com/nextcloud/user_sql/compare/v4.0.0-rc2...develop
[v4.0.0-rc2]: https://github.com/nextcloud/user_sql/compare/v4.0.0-rc1...v4.0.0-rc2
[4.0.0-rc2]: https://github.com/nextcloud/user_sql/compare/v4.0.0-rc1...v4.0.0-rc2
[4.0.0-rc1]: https://github.com/nextcloud/user_sql/compare/v3.1.0...v4.0.0-rc1
[3.1.0]: https://github.com/nextcloud/user_sql/compare/v2.4.0...v3.1.0
6 changes: 3 additions & 3 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</description>
<version>4.0.0-dev</version>
<licence>agpl</licence>
<author>Andreas Böhler &lt;dev (at) aboehler (dot) at&gt;</author>
<author>Marcin Łojewski &lt;dev@mlojewski.me&gt;</author>
<author>Marcin Łojewski</author>
<author>Andreas Böhler</author>
<namespace>UserSQL</namespace>
<bugs>https://github.com/nextcloud/user_sql/issues</bugs>
<repository>https://github.com/nextcloud/user_sql</repository>
Expand All @@ -22,7 +22,7 @@
<category>auth</category>
<dependencies>
<php min-version="7.0"/>
<nextcloud min-version="13" max-version="13"/>
<nextcloud min-version="14" max-version="14"/>
</dependencies>
<settings>
<admin>\OCA\UserSQL\Settings\Admin</admin>
Expand Down
58 changes: 22 additions & 36 deletions lib/Backend/GroupBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,26 @@

namespace OCA\UserSQL\Backend;

use OC\Group\Backend;
use OCA\UserSQL\Cache;
use OCA\UserSQL\Constant\DB;
use OCA\UserSQL\Model\Group;
use OCA\UserSQL\Properties;
use OCA\UserSQL\Repository\GroupRepository;
use OCP\Group\Backend\ABackend;
use OCP\Group\Backend\ICountUsersBackend;
use OCP\Group\Backend\IGroupDetailsBackend;
use OCP\Group\Backend\IIsAdminBackend;
use OCP\ILogger;

/**
* The SQL group backend manager.
*
* @author Marcin Łojewski <dev@mlojewski.me>
*/
final class GroupBackend extends Backend
final class GroupBackend extends ABackend implements
ICountUsersBackend,
IGroupDetailsBackend,
IIsAdminBackend
{
/**
* @var string The application name.
Expand Down Expand Up @@ -128,14 +134,9 @@ function ($group) {
}

/**
* Returns the number of users in given group matching the search term.
*
* @param string $gid The group ID.
* @param string $search The search term.
*
* @return int The number of users in given group matching the search term.
* @inheritdoc
*/
public function countUsersInGroup($gid, $search = "")
public function countUsersInGroup(string $gid, string $search = ""): int
{
$this->logger->debug(
"Entering countUsersInGroup($gid, $search)",
Expand Down Expand Up @@ -355,18 +356,18 @@ public function usersInGroup($gid, $search = "", $limit = -1, $offset = 0)
}

/**
* Checks if a user is in the admin group.
*
* @param string $uid User ID.
*
* @return bool TRUE if a user is in the admin group, FALSE otherwise.
* @inheritdoc
*/
public function isAdmin($uid)
public function isAdmin(string $uid = null): bool
{
$this->logger->debug(
"Entering isAdmin($uid)", ["app" => $this->appName]
);

if (empty($this->properties[DB::GROUP_ADMIN_COLUMN]) || $uid === null) {
return false;
}

$cacheKey = self::class . "admin_" . $uid;
$admin = $this->cache->get($cacheKey);

Expand Down Expand Up @@ -394,18 +395,18 @@ public function isAdmin($uid)
}

/**
* Get associative array of the group details.
*
* @param string $gid The group ID.
*
* @return array Associative array of the group details.
* @inheritdoc
*/
public function getGroupDetails($gid)
public function getGroupDetails(string $gid): array
{
$this->logger->debug(
"Entering getGroupDetails($gid)", ["app" => $this->appName]
);

if (empty($this->properties[DB::GROUP_NAME_COLUMN])) {
return [];
}

$group = $this->getGroup($gid);

if (!($group instanceof Group)) {
Expand All @@ -421,21 +422,6 @@ public function getGroupDetails($gid)
return $details;
}

/**
* @inheritdoc
*/
public function getSupportedActions()
{
$actions = parent::getSupportedActions();

$actions &= empty($this->properties[DB::GROUP_ADMIN_COLUMN])
? ~Backend::IS_ADMIN : ~0;
$actions &= empty($this->properties[DB::GROUP_NAME_COLUMN])
? ~Backend::GROUP_DETAILS : ~0;

return $actions;
}

/**
* Check if this backend is correctly set and can be enabled.
*
Expand Down
88 changes: 58 additions & 30 deletions lib/Backend/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

namespace OCA\UserSQL\Backend;

use OC\User\Backend;
use OCA\UserSQL\Action\EmailSync;
use OCA\UserSQL\Action\IUserAction;
use OCA\UserSQL\Action\QuotaSync;
Expand All @@ -36,13 +35,28 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\User\Backend\ABackend;
use OCP\User\Backend\ICheckPasswordBackend;
use OCP\User\Backend\ICountUsersBackend;
use OCP\User\Backend\IGetDisplayNameBackend;
use OCP\User\Backend\IGetHomeBackend;
use OCP\User\Backend\IProvideAvatarBackend;
use OCP\User\Backend\ISetDisplayNameBackend;
use OCP\User\Backend\ISetPasswordBackend;

/**
* The SQL user backend manager.
*
* @author Marcin Łojewski <dev@mlojewski.me>
*/
final class UserBackend extends Backend
final class UserBackend extends ABackend implements
ICheckPasswordBackend,
ICountUsersBackend,
IGetDisplayNameBackend,
IGetHomeBackend,
IProvideAvatarBackend,
ISetDisplayNameBackend,
ISetPasswordBackend
{
/**
* @var string The application name.
Expand Down Expand Up @@ -237,7 +251,7 @@ private function getUser($uid)
/**
* @inheritdoc
*/
public function getDisplayName($uid)
public function getDisplayName($uid): string
{
$this->logger->debug(
"Entering getDisplayName($uid)", ["app" => $this->appName]
Expand Down Expand Up @@ -267,7 +281,7 @@ public function getDisplayName($uid)
*
* @return string|bool The user ID on success, false otherwise.
*/
public function checkPassword($uid, $password)
public function checkPassword(string $uid, string $password)
{
$this->logger->debug(
"Entering checkPassword($uid, *)", ["app" => $this->appName]
Expand Down Expand Up @@ -346,6 +360,10 @@ public function getDisplayNames($search = "", $limit = null, $offset = null)
["app" => $this->appName]
);

if (empty($this->properties[DB::USER_NAME_COLUMN])) {
return false;
}

$users = $this->getUsers($search, $limit, $offset);

$names = [];
Expand Down Expand Up @@ -419,12 +437,16 @@ function ($user) {
*
* @return bool TRUE if the password has been set, FALSE otherwise.
*/
public function setPassword($uid, $password)
public function setPassword(string $uid, string $password): bool
{
$this->logger->debug(
"Entering setPassword($uid, *)", ["app" => "user_sql"]
);

if (empty($this->properties[Opt::PASSWORD_CHANGE])) {
return false;
}

$passwordAlgorithm = $this->getPasswordAlgorithm();
if ($passwordAlgorithm === false) {
return false;
Expand Down Expand Up @@ -461,12 +483,16 @@ public function setPassword($uid, $password)
/**
* @inheritdoc
*/
public function getHome($uid)
public function getHome(string $uid)
{
$this->logger->debug(
"Entering getHome($uid)", ["app" => $this->appName]
);

if (empty($this->properties[Opt::HOME_MODE])) {
return false;
}

$home = false;
switch ($this->properties[Opt::HOME_MODE]) {
case App::HOME_STATIC:
Expand Down Expand Up @@ -496,12 +522,16 @@ public function getHome($uid)
*
* @return bool TRUE if the user can change its avatar, FALSE otherwise.
*/
public function canChangeAvatar($uid)
public function canChangeAvatar(string $uid): bool
{
$this->logger->debug(
"Entering canChangeAvatar($uid)", ["app" => $this->appName]
);

if (empty($this->properties[DB::USER_AVATAR_COLUMN])) {
return false;
}

$user = $this->userRepository->findByUid($uid);
if (!($user instanceof User)) {
return false;
Expand All @@ -524,13 +554,17 @@ public function canChangeAvatar($uid)
*
* @return bool TRUE if the password has been set, FALSE otherwise.
*/
public function setDisplayName($uid, $displayName)
public function setDisplayName(string $uid, string $displayName): bool
{
$this->logger->debug(
"Entering setDisplayName($uid, $displayName)",
["app" => $this->appName]
);

if (empty($this->properties[Opt::NAME_CHANGE])) {
return false;
}

$user = $this->userRepository->findByUid($uid);
if (!($user instanceof User)) {
return false;
Expand All @@ -550,28 +584,6 @@ public function setDisplayName($uid, $displayName)
return false;
}

/**
* @inheritdoc
*/
public function getSupportedActions()
{
$actions = parent::getSupportedActions();

$actions &= empty($this->properties[DB::USER_NAME_COLUMN])
? ~Backend::GET_DISPLAYNAME : ~0;
$actions &= empty($this->properties[Opt::HOME_MODE])
? ~Backend::GET_HOME : ~0;
$actions &= empty($this->properties[DB::USER_AVATAR_COLUMN])
? ~Backend::PROVIDE_AVATAR : ~0;
$actions &= (!empty($this->properties[DB::USER_NAME_COLUMN])
&& $this->properties[Opt::NAME_CHANGE]) ? ~0
: ~Backend::SET_DISPLAYNAME;
$actions &= $this->properties[Opt::PASSWORD_CHANGE] ? ~0
: ~Backend::SET_PASSWORD;

return $actions;
}

/**
* Check if this backend is correctly set and can be enabled.
*
Expand All @@ -589,4 +601,20 @@ public function isConfigured()
&& !empty($this->properties[DB::USER_PASSWORD_COLUMN])
&& !empty($this->properties[Opt::CRYPTO_CLASS]);
}

/**
* @inheritdoc
*/
public function getBackendName()
{
return "User SQL";
}

/**
* @inheritdoc
*/
public function deleteUser($uid)
{
return false;
}
}
Loading