Skip to content

Commit

Permalink
Merge pull request #7 from owncloud/dav-endpoint
Browse files Browse the repository at this point in the history
DAV endpoint
  • Loading branch information
DeepDiver1975 authored Feb 3, 2017
2 parents 4ae443d + 1f2b0e3 commit ad4d5ab
Show file tree
Hide file tree
Showing 23 changed files with 3,379 additions and 97 deletions.
29 changes: 14 additions & 15 deletions appinfo/Migrations/Version20161209151129.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

namespace OCA\CustomGroups\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use OCP\Migration\ISchemaMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
* Create initial tables for the customgroups app
*/
class Version20161209151129 extends AbstractMigration {
class Version20161209151129 implements ISchemaMigration {
/**
* @param Schema $schema
*/
public function up(Schema $schema) {
$this->createGroupsTable($schema);
$this->createMembersTable($schema);
public function changeSchema(Schema $schema, array $options) {
$prefix = $options['tablePrefix'];
$this->createGroupsTable($prefix, $schema);
$this->createMembersTable($prefix, $schema);
}

private function createGroupsTable(Schema $schema) {
$prefix = $this->connection->getPrefix();
private function createGroupsTable($prefix, Schema $schema) {
$table = $schema->createTable("${prefix}custom_group");
$table->addColumn('group_id', 'integer', [
$table->addColumn('group_id', 'bigint', [
'autoincrement' => true,
'unsigned' => true,
'notnull' => true,
'length' => 4,
'length' => 20,
]);
$table->addColumn('uri', 'string', [
'length' => 255,
Expand All @@ -39,19 +39,18 @@ private function createGroupsTable(Schema $schema) {
$table->setPrimaryKey(['group_id']);
}

private function createMembersTable(Schema $schema) {
$prefix = $this->connection->getPrefix();
private function createMembersTable($prefix, Schema $schema) {
$table = $schema->createTable("${prefix}custom_group_member");
$table->addColumn('group_id', 'integer', [
$table->addColumn('group_id', 'bigint', [
'unsigned' => true,
'notnull' => true,
'length' => 4,
'length' => 20,
]);
$table->addColumn('user_id', 'string', [
'length' => 64,
'notnull' => true,
]);
$table->addColumn('is_admin', 'integer', [
$table->addColumn('role', 'integer', [
'length' => 4,
'notnull' => true,
'default' => 0,
Expand Down
10 changes: 9 additions & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
</types>
<use-migrations>true</use-migrations>
<dependencies>
<owncloud min-version="9.2" max-version="9.2" />
<owncloud min-version="10.0" max-version="10.0" />
</dependencies>
<sabre>
<plugins>
<plugin>OCA\CustomGroups\Dav\CustomGroupsPlugin</plugin>
</plugins>
<collections>
<collection>OCA\CustomGroups\Dav\RootCollection</collection>
</collections>
</sabre>
</info>
2 changes: 1 addition & 1 deletion lib/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
Expand Down
34 changes: 20 additions & 14 deletions lib/CustomGroupsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud GmbH.
* @copyright Copyright (c) 2016, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
Expand All @@ -29,10 +29,17 @@ class CustomGroupsBackend implements \OCP\GroupInterface {
const GROUP_ID_PREFIX = 'customgroup_';

/**
* Custom groups handler
*
* @var CustomGroupsDatabaseHandler
*/
private $handler;

/**
* Constructor
*
* @param CustomGroupsDatabaseHandler $handler custom groups handler
*/
public function __construct(
CustomGroupsDatabaseHandler $handler
) {
Expand All @@ -54,7 +61,7 @@ public function implementsActions($actions) {
*
* @param string $uid uid of the user
* @param string $gid gid of the group
* @return bool
* @return boolean true if user is in group, false otherwise
*/
public function inGroup($uid, $gid) {
$numericGroupId = $this->extractNumericGroupId($gid);
Expand All @@ -72,10 +79,10 @@ public function inGroup($uid, $gid) {
* @return array an array of group names
*/
public function getUserGroups($uid) {
$groups = $this->handler->getUserGroups($uid);
return array_map(function($numericGroupId) {
return $this->formatGroupId($numericGroupId);
}, $groups);
$memberInfos = $this->handler->getUserMemberships($uid, null);
return array_map(function ($memberInfo) {
return $this->formatGroupId($memberInfo['group_id']);
}, $memberInfos);
}

/**
Expand All @@ -87,11 +94,10 @@ public function getUserGroups($uid) {
* @param int $limit limit or -1 to disable
* @param int $offset offset
* @return array an array of group names
*
*/
public function getGroups($search = '', $limit = -1, $offset = 0) {
$groups = $this->handler->searchGroups($search, $limit, $offset);
return array_map(function($groupInfo) {
return array_map(function ($groupInfo) {
return $this->formatGroupId($groupInfo['group_id']);
}, $groups);
}
Expand Down Expand Up @@ -129,13 +135,13 @@ public function getGroupDetails($gid) {
}

/**
* Returns a list of all users in a group
* Not supported, returns an empty array.
*
* @param string $gid
* @param string $search
* @param int $limit
* @param int $offset
* @return array an array of user ids
* @param string $gid group id
* @param string $search search string
* @param int $limit limit
* @param int $offset offset
* @return array empty array
*/
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
// not exposed to regular user management
Expand Down
Loading

0 comments on commit ad4d5ab

Please sign in to comment.