diff --git a/appinfo/routes.php b/appinfo/routes.php index e051902..72735f6 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -60,7 +60,5 @@ return [ ['name' => 'api#insertSubmission', 'url' => '/api/v1/submission/insert', 'verb' => 'POST'], ['name' => 'api#deleteSubmission', 'url' => '/api/v1/submission/{id}', 'verb' => 'DELETE'], - - ['name' => 'system#get_site_users_and_groups', 'url' => '/get/siteusers', 'verb' => 'POST'], ] ]; diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 13fef69..c82fa1b 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -26,6 +26,7 @@ namespace OCA\Forms\Controller; +use Exception; use OCA\Forms\Db\Answer; use OCA\Forms\Db\AnswerMapper; use OCA\Forms\Db\Form; @@ -127,6 +128,7 @@ class ApiController extends Controller { 'hash' => $form->getHash(), 'title' => $form->getTitle(), 'expires' => $form->getExpires(), + 'partial' => true ]; } @@ -210,6 +212,21 @@ class ApiController extends Controller { return new Http\JSONResponse([], Http::STATUS_FORBIDDEN); } + // Make sure we only store id + try { + if ($keyValuePairs['access']) { + $keyValuePairs['access']['users'] = array_map(function (array $user): string { + return $user['shareWith']; + }, $keyValuePairs['access']['users']); + $keyValuePairs['access']['groups'] = array_map(function (array $group): string { + return $group['shareWith']; + }, $keyValuePairs['access']['groups']); + } + } catch (Exception $e) { + $this->logger->debug('Malformed access'); + return new Http\JSONResponse(['message' => 'Malformed access'], Http::STATUS_BAD_REQUEST); + } + // Create FormEntity with given Params & Id. $form = Form::fromParams($keyValuePairs); $form->setId($id); diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php deleted file mode 100644 index 72e12bc..0000000 --- a/lib/Controller/SystemController.php +++ /dev/null @@ -1,95 +0,0 @@ - - * - * @author affan98 - * @author John Molakvoæ (skjnldsv) - * @author Roeland Jago Douma - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -namespace OCA\Forms\Controller; - -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http; -use OCP\AppFramework\Http\DataResponse; - -use OCP\IGroupManager; -use OCP\IUserManager; -use OCP\IRequest; - -class SystemController extends Controller { - public function __construct( - string $appName, - IGroupManager $groupManager, - IUserManager $userManager, - IRequest $request - ) { - parent::__construct($appName, $request); - $this->groupManager = $groupManager; - $this->userManager = $userManager; - } - - /** - * Get a list of NC users and groups - * @NoAdminRequired - * @return DataResponse - */ - public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers = true, $skipGroups = [], $skipUsers = []) { - $list = []; - $data = []; - if ($getGroups) { - $groups = $this->groupManager->search($query); - foreach ($groups as $group) { - if (!in_array($group->getGID(), $skipGroups)) { - $list[] = [ - 'id' => $group->getGID(), - 'user' => $group->getGID(), - 'type' => 'group', - 'desc' => 'group', - 'icon' => 'icon-group', - 'displayName' => $group->getGID(), - 'avatarURL' => '' - ]; - } - } - } - - if ($getUsers) { - $users = $this->userManager->searchDisplayName($query); - foreach ($users as $user) { - if (!in_array($user->getUID(), $skipUsers)) { - $list[] = [ - 'id' => $user->getUID(), - 'user' => $user->getUID(), - 'type' => 'user', - 'desc' => 'user', - 'icon' => 'icon-user', - 'displayName' => $user->getDisplayName(), - 'avatarURL' => '', - 'lastLogin' => $user->getLastLogin(), - 'cloudId' => $user->getCloudId() - ]; - } - } - } - - $data['siteusers'] = $list; - return new DataResponse($data, Http::STATUS_OK); - } -} diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php index 115c01d..ee16c69 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -29,8 +29,12 @@ use OCA\Forms\Db\QuestionMapper; use OCA\Forms\Db\SubmissionMapper; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\IMapperException; +use OCP\IGroup; use OCP\IGroupManager; +use OCP\IUser; +use OCP\IUserManager; use OCP\IUserSession; +use OCP\Share\IShare; /** * Trait for getting forms information in a service @@ -51,6 +55,9 @@ class FormsService { /** @var IGroupManager */ private $groupManager; + + /** @var IUserManager */ + private $userManager; /** @var IUserSession */ private $userSession; @@ -60,12 +67,14 @@ class FormsService { OptionMapper $optionMapper, SubmissionMapper $submissionMapper, IGroupManager $groupManager, + IUserManager $userManager, IUserSession $userSession) { $this->formMapper = $formMapper; $this->questionMapper = $questionMapper; $this->optionMapper = $optionMapper; $this->submissionMapper = $submissionMapper; $this->groupManager = $groupManager; + $this->userManager = $userManager; $this->userSession = $userSession; } @@ -112,6 +121,15 @@ class FormsService { $result = $form->read(); $result['questions'] = $this->getQuestions($id); + // Set proper user/groups properties + + // Make sure we have the bare minimum + $result['access'] = array_merge(['users' => [], 'groups' => []], $result['access']); + + // Properly format users & groups + $result['access']['users'] = array_map([$this, 'formatUsers'], $result['access']['users']); + $result['access']['groups'] = array_map([$this, 'formatGroups'], $result['access']['groups']); + return $result; } @@ -205,4 +223,40 @@ class FormsService { // None of the possible access-options matched. return false; } + + /** + * Format users access + * + * @param string $userId + * @return array + */ + private function formatUsers(string $userId): array { + $user = $this->userManager->get($userId); + if ($user instanceof IUser) { + return [ + 'shareWith' => $userId, + 'displayName' => $user->getDisplayName(), + 'shareType' => IShare::TYPE_USER + ]; + } + return []; + } + + /** + * Format groups access + * + * @param string $groupId + * @return array + */ + private function formatGroups(string $groupId): array { + $group = $this->groupManager->get($groupId); + if ($group instanceof IGroup) { + return [ + 'shareWith' => $groupId, + 'displayName' => $group->getDisplayName(), + 'shareType' => IShare::TYPE_GROUP + ]; + } + return []; + } } diff --git a/src/Forms.vue b/src/Forms.vue index 13f2036..e910fc3 100644 --- a/src/Forms.vue +++ b/src/Forms.vue @@ -58,7 +58,9 @@ diff --git a/src/components/ShareDiv.vue b/src/components/ShareDiv.vue new file mode 100644 index 0000000..5d6cf4c --- /dev/null +++ b/src/components/ShareDiv.vue @@ -0,0 +1,398 @@ + + + + + + + diff --git a/src/components/_base-UserDiv.vue b/src/components/UserDiv.vue similarity index 60% rename from src/components/_base-UserDiv.vue rename to src/components/UserDiv.vue index 196a4bc..aa46ca5 100644 --- a/src/components/_base-UserDiv.vue +++ b/src/components/UserDiv.vue @@ -20,79 +20,47 @@ - --> -/* global Vue, oc_userconfig */ - - diff --git a/src/mixins/ShareTypes.js b/src/mixins/ShareTypes.js new file mode 100644 index 0000000..b84dbf9 --- /dev/null +++ b/src/mixins/ShareTypes.js @@ -0,0 +1,39 @@ +/** + * @copyright Copyright (c) 2019 John Molakvoæ + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +export default { + data() { + return { + SHARE_TYPES: { + SHARE_TYPE_USER: OC.Share.SHARE_TYPE_USER, + SHARE_TYPE_GROUP: OC.Share.SHARE_TYPE_GROUP, + SHARE_TYPE_LINK: OC.Share.SHARE_TYPE_LINK, + SHARE_TYPE_EMAIL: OC.Share.SHARE_TYPE_EMAIL, + SHARE_TYPE_REMOTE: OC.Share.SHARE_TYPE_REMOTE, + SHARE_TYPE_CIRCLE: OC.Share.SHARE_TYPE_CIRCLE, + SHARE_TYPE_GUEST: OC.Share.SHARE_TYPE_GUEST, + SHARE_TYPE_REMOTE_GROUP: OC.Share.SHARE_TYPE_REMOTE_GROUP, + SHARE_TYPE_ROOM: OC.Share.SHARE_TYPE_ROOM, + }, + } + }, +} diff --git a/src/views/Sidebar.vue b/src/views/Sidebar.vue index 02022aa..593bce6 100644 --- a/src/views/Sidebar.vue +++ b/src/views/Sidebar.vue @@ -21,7 +21,7 @@ -->