Skip to content

Commit 50da49c

Browse files
authored
Merge pull request #54 from nextcloud/develop-14
Merge develop-14 into develop
2 parents 4d48a58 + fe265eb commit 50da49c

5 files changed

Lines changed: 135 additions & 106 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1616
- Example SQL script in README file
1717
- Fixed misspelling
1818

19+
### Changed
20+
- Support for Nextcloud 14 only
21+
- Group backend implementation
22+
- User backend implementation
23+
1924
### Fixed
2025
- Table and column autocomplete in settings panel
2126

22-
## [v4.0.0-rc2] - 2018-06-14
27+
## [4.0.0-rc2] - 2018-06-14
2328
### Added
2429
- User active column
2530

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

8186
[Unreleased]: https://github.com/nextcloud/user_sql/compare/v4.0.0-rc2...develop
82-
[v4.0.0-rc2]: https://github.com/nextcloud/user_sql/compare/v4.0.0-rc1...v4.0.0-rc2
87+
[4.0.0-rc2]: https://github.com/nextcloud/user_sql/compare/v4.0.0-rc1...v4.0.0-rc2
8388
[4.0.0-rc1]: https://github.com/nextcloud/user_sql/compare/v3.1.0...v4.0.0-rc1
8489
[3.1.0]: https://github.com/nextcloud/user_sql/compare/v2.4.0...v3.1.0

appinfo/info.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</description>
1111
<version>4.0.0-dev</version>
1212
<licence>agpl</licence>
13-
<author>Andreas Böhler &lt;dev (at) aboehler (dot) at&gt;</author>
14-
<author>Marcin Łojewski &lt;dev@mlojewski.me&gt;</author>
13+
<author>Marcin Łojewski</author>
14+
<author>Andreas Böhler</author>
1515
<namespace>UserSQL</namespace>
1616
<bugs>https://github.com/nextcloud/user_sql/issues</bugs>
1717
<repository>https://github.com/nextcloud/user_sql</repository>
@@ -22,7 +22,7 @@
2222
<category>auth</category>
2323
<dependencies>
2424
<php min-version="7.0"/>
25-
<nextcloud min-version="13" max-version="13"/>
25+
<nextcloud min-version="14" max-version="14"/>
2626
</dependencies>
2727
<settings>
2828
<admin>\OCA\UserSQL\Settings\Admin</admin>

lib/Backend/GroupBackend.php

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,26 @@
2121

2222
namespace OCA\UserSQL\Backend;
2323

24-
use OC\Group\Backend;
2524
use OCA\UserSQL\Cache;
2625
use OCA\UserSQL\Constant\DB;
2726
use OCA\UserSQL\Model\Group;
2827
use OCA\UserSQL\Properties;
2928
use OCA\UserSQL\Repository\GroupRepository;
29+
use OCP\Group\Backend\ABackend;
30+
use OCP\Group\Backend\ICountUsersBackend;
31+
use OCP\Group\Backend\IGroupDetailsBackend;
32+
use OCP\Group\Backend\IIsAdminBackend;
3033
use OCP\ILogger;
3134

3235
/**
3336
* The SQL group backend manager.
3437
*
3538
* @author Marcin Łojewski <dev@mlojewski.me>
3639
*/
37-
final class GroupBackend extends Backend
40+
final class GroupBackend extends ABackend implements
41+
ICountUsersBackend,
42+
IGroupDetailsBackend,
43+
IIsAdminBackend
3844
{
3945
/**
4046
* @var string The application name.
@@ -128,14 +134,9 @@ function ($group) {
128134
}
129135

130136
/**
131-
* Returns the number of users in given group matching the search term.
132-
*
133-
* @param string $gid The group ID.
134-
* @param string $search The search term.
135-
*
136-
* @return int The number of users in given group matching the search term.
137+
* @inheritdoc
137138
*/
138-
public function countUsersInGroup($gid, $search = "")
139+
public function countUsersInGroup(string $gid, string $search = ""): int
139140
{
140141
$this->logger->debug(
141142
"Entering countUsersInGroup($gid, $search)",
@@ -355,18 +356,18 @@ public function usersInGroup($gid, $search = "", $limit = -1, $offset = 0)
355356
}
356357

357358
/**
358-
* Checks if a user is in the admin group.
359-
*
360-
* @param string $uid User ID.
361-
*
362-
* @return bool TRUE if a user is in the admin group, FALSE otherwise.
359+
* @inheritdoc
363360
*/
364-
public function isAdmin($uid)
361+
public function isAdmin(string $uid = null): bool
365362
{
366363
$this->logger->debug(
367364
"Entering isAdmin($uid)", ["app" => $this->appName]
368365
);
369366

367+
if (empty($this->properties[DB::GROUP_ADMIN_COLUMN]) || $uid === null) {
368+
return false;
369+
}
370+
370371
$cacheKey = self::class . "admin_" . $uid;
371372
$admin = $this->cache->get($cacheKey);
372373

@@ -394,18 +395,18 @@ public function isAdmin($uid)
394395
}
395396

396397
/**
397-
* Get associative array of the group details.
398-
*
399-
* @param string $gid The group ID.
400-
*
401-
* @return array Associative array of the group details.
398+
* @inheritdoc
402399
*/
403-
public function getGroupDetails($gid)
400+
public function getGroupDetails(string $gid): array
404401
{
405402
$this->logger->debug(
406403
"Entering getGroupDetails($gid)", ["app" => $this->appName]
407404
);
408405

406+
if (empty($this->properties[DB::GROUP_NAME_COLUMN])) {
407+
return [];
408+
}
409+
409410
$group = $this->getGroup($gid);
410411

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

424-
/**
425-
* @inheritdoc
426-
*/
427-
public function getSupportedActions()
428-
{
429-
$actions = parent::getSupportedActions();
430-
431-
$actions &= empty($this->properties[DB::GROUP_ADMIN_COLUMN])
432-
? ~Backend::IS_ADMIN : ~0;
433-
$actions &= empty($this->properties[DB::GROUP_NAME_COLUMN])
434-
? ~Backend::GROUP_DETAILS : ~0;
435-
436-
return $actions;
437-
}
438-
439425
/**
440426
* Check if this backend is correctly set and can be enabled.
441427
*

lib/Backend/UserBackend.php

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
namespace OCA\UserSQL\Backend;
2323

24-
use OC\User\Backend;
2524
use OCA\UserSQL\Action\EmailSync;
2625
use OCA\UserSQL\Action\IUserAction;
2726
use OCA\UserSQL\Action\QuotaSync;
@@ -36,13 +35,28 @@
3635
use OCP\IConfig;
3736
use OCP\IL10N;
3837
use OCP\ILogger;
38+
use OCP\User\Backend\ABackend;
39+
use OCP\User\Backend\ICheckPasswordBackend;
40+
use OCP\User\Backend\ICountUsersBackend;
41+
use OCP\User\Backend\IGetDisplayNameBackend;
42+
use OCP\User\Backend\IGetHomeBackend;
43+
use OCP\User\Backend\IProvideAvatarBackend;
44+
use OCP\User\Backend\ISetDisplayNameBackend;
45+
use OCP\User\Backend\ISetPasswordBackend;
3946

4047
/**
4148
* The SQL user backend manager.
4249
*
4350
* @author Marcin Łojewski <dev@mlojewski.me>
4451
*/
45-
final class UserBackend extends Backend
52+
final class UserBackend extends ABackend implements
53+
ICheckPasswordBackend,
54+
ICountUsersBackend,
55+
IGetDisplayNameBackend,
56+
IGetHomeBackend,
57+
IProvideAvatarBackend,
58+
ISetDisplayNameBackend,
59+
ISetPasswordBackend
4660
{
4761
/**
4862
* @var string The application name.
@@ -237,7 +251,7 @@ private function getUser($uid)
237251
/**
238252
* @inheritdoc
239253
*/
240-
public function getDisplayName($uid)
254+
public function getDisplayName($uid): string
241255
{
242256
$this->logger->debug(
243257
"Entering getDisplayName($uid)", ["app" => $this->appName]
@@ -267,7 +281,7 @@ public function getDisplayName($uid)
267281
*
268282
* @return string|bool The user ID on success, false otherwise.
269283
*/
270-
public function checkPassword($uid, $password)
284+
public function checkPassword(string $uid, string $password)
271285
{
272286
$this->logger->debug(
273287
"Entering checkPassword($uid, *)", ["app" => $this->appName]
@@ -346,6 +360,10 @@ public function getDisplayNames($search = "", $limit = null, $offset = null)
346360
["app" => $this->appName]
347361
);
348362

363+
if (empty($this->properties[DB::USER_NAME_COLUMN])) {
364+
return false;
365+
}
366+
349367
$users = $this->getUsers($search, $limit, $offset);
350368

351369
$names = [];
@@ -419,12 +437,16 @@ function ($user) {
419437
*
420438
* @return bool TRUE if the password has been set, FALSE otherwise.
421439
*/
422-
public function setPassword($uid, $password)
440+
public function setPassword(string $uid, string $password): bool
423441
{
424442
$this->logger->debug(
425443
"Entering setPassword($uid, *)", ["app" => "user_sql"]
426444
);
427445

446+
if (empty($this->properties[Opt::PASSWORD_CHANGE])) {
447+
return false;
448+
}
449+
428450
$passwordAlgorithm = $this->getPasswordAlgorithm();
429451
if ($passwordAlgorithm === false) {
430452
return false;
@@ -461,12 +483,16 @@ public function setPassword($uid, $password)
461483
/**
462484
* @inheritdoc
463485
*/
464-
public function getHome($uid)
486+
public function getHome(string $uid)
465487
{
466488
$this->logger->debug(
467489
"Entering getHome($uid)", ["app" => $this->appName]
468490
);
469491

492+
if (empty($this->properties[Opt::HOME_MODE])) {
493+
return false;
494+
}
495+
470496
$home = false;
471497
switch ($this->properties[Opt::HOME_MODE]) {
472498
case App::HOME_STATIC:
@@ -496,12 +522,16 @@ public function getHome($uid)
496522
*
497523
* @return bool TRUE if the user can change its avatar, FALSE otherwise.
498524
*/
499-
public function canChangeAvatar($uid)
525+
public function canChangeAvatar(string $uid): bool
500526
{
501527
$this->logger->debug(
502528
"Entering canChangeAvatar($uid)", ["app" => $this->appName]
503529
);
504530

531+
if (empty($this->properties[DB::USER_AVATAR_COLUMN])) {
532+
return false;
533+
}
534+
505535
$user = $this->userRepository->findByUid($uid);
506536
if (!($user instanceof User)) {
507537
return false;
@@ -524,13 +554,17 @@ public function canChangeAvatar($uid)
524554
*
525555
* @return bool TRUE if the password has been set, FALSE otherwise.
526556
*/
527-
public function setDisplayName($uid, $displayName)
557+
public function setDisplayName(string $uid, string $displayName): bool
528558
{
529559
$this->logger->debug(
530560
"Entering setDisplayName($uid, $displayName)",
531561
["app" => $this->appName]
532562
);
533563

564+
if (empty($this->properties[Opt::NAME_CHANGE])) {
565+
return false;
566+
}
567+
534568
$user = $this->userRepository->findByUid($uid);
535569
if (!($user instanceof User)) {
536570
return false;
@@ -550,28 +584,6 @@ public function setDisplayName($uid, $displayName)
550584
return false;
551585
}
552586

553-
/**
554-
* @inheritdoc
555-
*/
556-
public function getSupportedActions()
557-
{
558-
$actions = parent::getSupportedActions();
559-
560-
$actions &= empty($this->properties[DB::USER_NAME_COLUMN])
561-
? ~Backend::GET_DISPLAYNAME : ~0;
562-
$actions &= empty($this->properties[Opt::HOME_MODE])
563-
? ~Backend::GET_HOME : ~0;
564-
$actions &= empty($this->properties[DB::USER_AVATAR_COLUMN])
565-
? ~Backend::PROVIDE_AVATAR : ~0;
566-
$actions &= (!empty($this->properties[DB::USER_NAME_COLUMN])
567-
&& $this->properties[Opt::NAME_CHANGE]) ? ~0
568-
: ~Backend::SET_DISPLAYNAME;
569-
$actions &= $this->properties[Opt::PASSWORD_CHANGE] ? ~0
570-
: ~Backend::SET_PASSWORD;
571-
572-
return $actions;
573-
}
574-
575587
/**
576588
* Check if this backend is correctly set and can be enabled.
577589
*
@@ -589,4 +601,20 @@ public function isConfigured()
589601
&& !empty($this->properties[DB::USER_PASSWORD_COLUMN])
590602
&& !empty($this->properties[Opt::CRYPTO_CLASS]);
591603
}
604+
605+
/**
606+
* @inheritdoc
607+
*/
608+
public function getBackendName()
609+
{
610+
return "User SQL";
611+
}
612+
613+
/**
614+
* @inheritdoc
615+
*/
616+
public function deleteUser($uid)
617+
{
618+
return false;
619+
}
592620
}

0 commit comments

Comments
 (0)