Merge pull request #14892 from nextcloud/bugfix/noid/collections

Bugfix/noid/collections
This commit is contained in:
Roeland Jago Douma 2019-03-29 10:25:59 +01:00 committed by GitHub
commit fb5eebd33b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 86 additions and 31 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -27,13 +27,6 @@
<script>
import { CollectionList } from 'nextcloud-vue-collections'
/**
* Those translations will be used by the vue component but they should be shipped with the server
* t('files_sharing', 'Add to a collection')
* t('files_sharing', 'Details')
* t('files_sharing', 'Rename collection')
*/
export default {
name: 'CollaborationView',
computed: {

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
namespace OC\Core\Controller;
use Exception;
use OCP\AppFramework\Http;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Http\DataResponse;
@ -30,6 +31,7 @@ use OCP\Collaboration\Resources\ICollection;
use OCP\Collaboration\Resources\IManager;
use OCP\Collaboration\Resources\IResource;
use OCP\Collaboration\Resources\ResourceException;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
@ -37,20 +39,23 @@ class CollaborationResourcesController extends OCSController {
/** @var IManager */
private $manager;
/** @var IUserSession */
private $userSession;
/** @var ILogger */
private $logger;
public function __construct(
string $appName,
IRequest $request,
IManager $manager,
IUserSession $userSession
IUserSession $userSession,
ILogger $logger
) {
parent::__construct($appName, $request);
$this->manager = $manager;
$this->userSession = $userSession;
$this->logger = $logger;
}
/**
@ -81,7 +86,7 @@ class CollaborationResourcesController extends OCSController {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
return new DataResponse($this->prepareCollection($collection));
return $this->respondCollection($collection);
}
/**
@ -97,7 +102,7 @@ class CollaborationResourcesController extends OCSController {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
return new DataResponse(array_map([$this, 'prepareCollection'], $collections));
return new DataResponse($this->prepareCollections($collections));
}
/**
@ -126,7 +131,7 @@ class CollaborationResourcesController extends OCSController {
} catch (ResourceException $e) {
}
return new DataResponse($this->prepareCollection($collection));
return $this->respondCollection($collection);
}
/**
@ -152,7 +157,7 @@ class CollaborationResourcesController extends OCSController {
$collection->removeResource($resource);
return new DataResponse($this->prepareCollection($collection));
return $this->respondCollection($collection);
}
/**
@ -173,7 +178,7 @@ class CollaborationResourcesController extends OCSController {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
return new DataResponse(array_map([$this, 'prepareCollection'], $resource->getCollections()));
return new DataResponse($this->prepareCollections($resource->getCollections()));
}
/**
@ -202,7 +207,7 @@ class CollaborationResourcesController extends OCSController {
$collection = $this->manager->newCollection($name);
$collection->addResource($resource);
return new DataResponse($this->prepareCollection($collection));
return $this->respondCollection($collection);
}
/**
@ -221,24 +226,65 @@ class CollaborationResourcesController extends OCSController {
$collection->setName($collectionName);
return new DataResponse($this->prepareCollection($collection));
return $this->respondCollection($collection);
}
protected function respondCollection(ICollection $collection): DataResponse {
try {
return new DataResponse($this->prepareCollection($collection));
} catch (CollectionException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (Exception $e) {
$this->logger->logException($e);
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}
protected function prepareCollections(array $collections): array {
$result = [];
foreach ($collections as $collection) {
try {
$result[] = $this->prepareCollection($collection);
} catch (CollectionException $e) {
} catch (Exception $e) {
$this->logger->logException($e);
}
}
return $result;
}
protected function prepareCollection(ICollection $collection): array {
if (!$collection->canAccess($this->userSession->getUser())) {
return null;
throw new CollectionException('Can not access collection');
}
return [
'id' => $collection->getId(),
'name' => $collection->getName(),
'resources' => array_values(array_filter(array_map([$this, 'prepareResources'], $collection->getResources()))),
'resources' => $this->prepareResources($collection->getResources()),
];
}
protected function prepareResources(IResource $resource): ?array {
protected function prepareResources(array $resources): ?array {
$result = [];
foreach ($resources as $resource) {
try {
$result[] = $this->prepareResource($resource);
} catch (ResourceException $e) {
} catch (Exception $e) {
$this->logger->logException($e);
}
}
return $result;
}
protected function prepareResource(IResource $resource): array {
if (!$resource->canAccess($this->userSession->getUser())) {
return null;
throw new ResourceException('Can not access resource');
}
return $resource->getRichObject();

BIN
core/js/dist/main.js vendored

Binary file not shown.

Binary file not shown.

View file

@ -32,6 +32,17 @@
**/
let types = {};
/**
* Those translations will be used by the vue component but they should be shipped with the server
* t('core', 'Add to a collection')
* t('core', 'Show details')
* t('core', 'Hide details')
* t('core', 'Rename collection')
* t('core', 'Failed to rename collection')
* t('core', 'Failed to create collection')
* t('core', 'Failed to add resource to collection')
*/
export default {
/**
*
@ -51,7 +62,7 @@ export default {
return types[type].typeIconClass || '';
},
getLabel(type) {
return t('files_sharing', 'Link to a {label}', { label: types[type].typeString || type }, 1)
return t('core', 'Link to a {label}', { label: types[type].typeString || type }, 1)
},
getLink(type, id) {
/* TODO: Allow action to be executed instead of href as well */

View file

@ -138,11 +138,15 @@ class Manager implements IManager {
$query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
)
)
->where($query->expr()->iLike('c.name', $query->createNamedParameter($filter, IQueryBuilder::PARAM_STR)))
->andWhere($query->expr()->eq('a.access', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
->where($query->expr()->eq('a.access', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
->orderBy('c.id')
->setMaxResults($limit)
->setFirstResult($start);
if ($filter !== '') {
$query->where($query->expr()->iLike('c.name', $query->createNamedParameter('%' . $this->connection->escapeLikeParameter($filter) . '%')));
}
$result = $query->execute();
$collections = [];
@ -158,7 +162,7 @@ class Manager implements IManager {
$result->closeCursor();
if (empty($collections) && $foundResults === $limit) {
$this->searchCollections($user, $filter, $limit, $start + $limit);
return $this->searchCollections($user, $filter, $limit, $start + $limit);
}
return $collections;

13
package-lock.json generated
View file

@ -4812,10 +4812,11 @@
}
},
"nextcloud-vue-collections": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/nextcloud-vue-collections/-/nextcloud-vue-collections-0.2.0.tgz",
"integrity": "sha512-LDbJyUZffu8ZIkkXAMXkfqkUK36GaUiuS4IdgoOLe/z9prV/Iic7uwrDME015FsCv9GmfheOs7cfiU6xBIidGA==",
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/nextcloud-vue-collections/-/nextcloud-vue-collections-0.3.0.tgz",
"integrity": "sha512-XW95X75XF4fxL9HBNPf4tsPbSjjtFzdCGz8rlh67upA8QBbaLkn9cEiveORlpgBviVPuiCVLQqVfxOWbsZ+dAw==",
"requires": {
"lodash": "^4.17.11",
"nextcloud-axios": "^0.1.2",
"nextcloud-vue": "^0.9.0",
"v-tooltip": "^2.0.0-rc.33",
@ -4825,9 +4826,9 @@
},
"dependencies": {
"nextcloud-vue": {
"version": "0.9.1",
"resolved": "https://registry.npmjs.org/nextcloud-vue/-/nextcloud-vue-0.9.1.tgz",
"integrity": "sha512-8Lmout8Y6+zNPHqZ8rV7GcuKRbFpM8EserkvhkXAJYymq9mblz2NkfmOzhOGxhRICfPHnZ/xFUTxUuaSus4p+Q==",
"version": "0.9.5",
"resolved": "https://registry.npmjs.org/nextcloud-vue/-/nextcloud-vue-0.9.5.tgz",
"integrity": "sha512-JWioquKIHnmt2O+8eS+7zd5Pg7DuouKKQlVBoLlm7bOPFTZuhn53B3lYiOnL8N/91ba8RnffHmDixz33m7/s8w==",
"requires": {
"hammerjs": "^2.0.8",
"md5": "^2.2.1",

View file

@ -44,7 +44,7 @@
"nextcloud-axios": "^0.1.3",
"nextcloud-password-confirmation": "^0.4.1",
"nextcloud-vue": "^0.8.0",
"nextcloud-vue-collections": "^0.2.0",
"nextcloud-vue-collections": "^0.3.0",
"snap.js": "^2.0.9",
"strengthify": "git+https://github.com/MorrisJobke/strengthify.git#0.5.8",
"underscore": "^1.9.1",