From 595013cfbf6cb20d33d4250a13d66ab7f8a9df57 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 22 Jun 2017 11:36:20 +0545 Subject: [PATCH 1/5] Implement group add delete removeuser in occ command Signed-off-by: Phil Davis --- core/Command/Group/Add.php | 94 +++++++++++++++++++++ core/Command/Group/Delete.php | 68 +++++++++++++++ core/Command/Group/RemoveUser.php | 91 ++++++++++++++++++++ core/register_command.php | 4 + tests/Core/Command/Group/DeleteTest.php | 105 ++++++++++++++++++++++++ 5 files changed, 362 insertions(+) create mode 100644 core/Command/Group/Add.php create mode 100644 core/Command/Group/Delete.php create mode 100644 core/Command/Group/RemoveUser.php create mode 100644 tests/Core/Command/Group/DeleteTest.php diff --git a/core/Command/Group/Add.php b/core/Command/Group/Add.php new file mode 100644 index 000000000000..a9b0ca5c3345 --- /dev/null +++ b/core/Command/Group/Add.php @@ -0,0 +1,94 @@ + + * + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + * + */ + +namespace OC\Core\Command\Group; + +use OCP\IGroupManager; +use OCP\IUserManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputArgument; + +class Add extends Command { + /** @var \OCP\IGroupManager */ + protected $groupManager; + + /** + * @param IGroupManager $groupManager + */ + public function __construct(IGroupManager $groupManager, IUserManager $userManager) { + parent::__construct(); + $this->groupManager = $groupManager; + $this->userManager = $userManager; + } + + protected function configure() { + $this + ->setName('group:add') + ->setDescription('adds a group') + ->addArgument( + 'group', + InputArgument::REQUIRED, + 'Name of the group' + ) + ->addOption( + 'user', + 'u', + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + 'existing users that should be added to the group' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $groupName = $input->getArgument('group'); + $group = $this->groupManager->get($groupName); + if (!$group) { + $this->groupManager->createGroup($groupName); + $group = $this->groupManager->get($groupName); + if ($group) { + $output->writeln('Created group "' . $group->getGID() . '"'); + } else { + $output->writeln('Group "' . $groupName . '" could not be created'); + return 1; + } + } else { + $output->writeln('The group "' . $group->getGID() . '" already exists'); + } + + $users = $input->getOption('user'); + + foreach ($users as $userName) { + $user = $this->userManager->get($userName); + if ($user) { + if ($group->inGroup($user)) { + $output->writeln('User "' . $user->getUID() . '" is already a member of group "' . $group->getGID() . '"'); + } else { + $group->addUser($user); + $output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"'); + } + } else { + $output->writeln('User "' . $userName . '" could not be found - not added to group "' . $group->getGID() . '"'); + } + } + } +} diff --git a/core/Command/Group/Delete.php b/core/Command/Group/Delete.php new file mode 100644 index 000000000000..00230347cbf7 --- /dev/null +++ b/core/Command/Group/Delete.php @@ -0,0 +1,68 @@ + + * + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + * + */ + +namespace OC\Core\Command\Group; + +use OCP\IGroupManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputArgument; + +class Delete extends Command { + /** @var IGroupManager */ + protected $groupManager; + + /** + * @param IGroupManager $groupManager + */ + public function __construct(IGroupManager $groupManager) { + $this->groupManager = $groupManager; + parent::__construct(); + } + + protected function configure() { + $this + ->setName('group:delete') + ->setDescription('deletes the specified group') + ->addArgument( + 'group', + InputArgument::REQUIRED, + 'the group name' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $groupName = $input->getArgument('group'); + $group = $this->groupManager->get($groupName); + if (is_null($group)) { + $output->writeln('Group does not exist'); + return; + } + + if ($group->delete()) { + $output->writeln('The specified group was deleted'); + return; + } + + $output->writeln('The specified group could not be deleted. Please check the logs.'); + } +} diff --git a/core/Command/Group/RemoveUser.php b/core/Command/Group/RemoveUser.php new file mode 100644 index 000000000000..286a27c29a47 --- /dev/null +++ b/core/Command/Group/RemoveUser.php @@ -0,0 +1,91 @@ + + * + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + * + */ + +namespace OC\Core\Command\Group; + +use OCP\IGroupManager; +use OCP\IUserManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputArgument; + +class RemoveUser extends Command { + /** @var \OCP\IGroupManager */ + protected $groupManager; + + /** + * @param IGroupManager $groupManager + */ + public function __construct(IGroupManager $groupManager, IUserManager $userManager) { + parent::__construct(); + $this->groupManager = $groupManager; + $this->userManager = $userManager; + } + + protected function configure() { + $this + ->setName('group:removeuser') + ->setDescription('remove user(s) from a group') + ->addArgument( + 'group', + InputArgument::REQUIRED, + 'Name of the group' + ) + ->addOption( + 'user', + 'u', + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + 'user that should be removed from the group' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $groupName = $input->getArgument('group'); + $group = $this->groupManager->get($groupName); + if (!$group) { + $output->writeln('Group "' . $groupName . '" does not exist'); + return 1; + } + + $users = $input->getOption('user'); + + if (!count($users)) { + $output->writeln('No users specified'); + return 1; + } + + foreach ($users as $userName) { + $user = $this->userManager->get($userName); + if ($user) { + if ($group->inGroup($user)) { + $group->removeUser($user); + $output->writeln('User "' . $user->getUID() . '" removed from group "' . $group->getGID() . '"'); + } else { + $output->writeln('User "' . $userName . '" could not be found in group "' . $group->getGID() . '"'); + } + } else { + $output->writeln('User "' . $userName . '" could not be found - not removed from group "' . $group->getGID() . '"'); + } + } + } +} diff --git a/core/register_command.php b/core/register_command.php index 590560aec914..4fdd66133314 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -145,6 +145,10 @@ $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); $application->add(new OC\Core\Command\User\SyncBackend(\OC::$server->getAccountMapper(), \OC::$server->getConfig(), \OC::$server->getUserManager(), \OC::$server->getLogger())); + $application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager(), \OC::$server->getUserManager())); + $application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager())); + $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getGroupManager(), \OC::$server->getUserManager())); + $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); diff --git a/tests/Core/Command/Group/DeleteTest.php b/tests/Core/Command/Group/DeleteTest.php new file mode 100644 index 000000000000..2df2b5b2d087 --- /dev/null +++ b/tests/Core/Command/Group/DeleteTest.php @@ -0,0 +1,105 @@ + + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + * + */ + +namespace Tests\Core\Command\Group; + +use OC\Core\Command\Group\Delete; +use Test\TestCase; + +class DeleteTest extends TestCase { + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $groupManager; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $consoleInput; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $consoleOutput; + + /** @var \Symfony\Component\Console\Command\Command */ + protected $command; + + protected function setUp() { + parent::setUp(); + + $groupManager = $this->groupManager = $this->getMockBuilder('OCP\IGroupManager') + ->disableOriginalConstructor() + ->getMock(); + $this->consoleInput = $this->createMock('Symfony\Component\Console\Input\InputInterface'); + $this->consoleOutput = $this->createMock('Symfony\Component\Console\Output\OutputInterface'); + + /** @var \OCP\IGroupManager $groupManager */ + $this->command = new Delete($groupManager); + } + + + public function validGroupLastSeen() { + return [ + [true, 'The specified group was deleted'], + [false, 'The specified group could not be deleted'], + ]; + } + + /** + * @dataProvider validGroupLastSeen + * + * @param bool $deleteSuccess + * @param string $expectedString + */ + public function testValidGroup($deleteSuccess, $expectedString) { + $group = $this->createMock('OCP\IGroup'); + $group->expects($this->once()) + ->method('delete') + ->willReturn($deleteSuccess); + + $this->groupManager->expects($this->once()) + ->method('get') + ->with('group') + ->willReturn($group); + + $this->consoleInput->expects($this->once()) + ->method('getArgument') + ->with('group') + ->willReturn('group'); + + $this->consoleOutput->expects($this->once()) + ->method('writeln') + ->with($this->stringContains($expectedString)); + + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); + } + + public function testInvalidGroup() { + $this->groupManager->expects($this->once()) + ->method('get') + ->with('group') + ->willReturn(null); + + $this->consoleInput->expects($this->once()) + ->method('getArgument') + ->with('group') + ->willReturn('group'); + + $this->consoleOutput->expects($this->once()) + ->method('writeln') + ->with($this->stringContains('Group does not exist')); + + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); + } +} From 08139852b3f0098f53b56747a27036783302d232 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 22 Jun 2017 11:47:07 +0545 Subject: [PATCH 2/5] Infrastructure to use groups in UI tests Signed-off-by: Phil Davis --- tests/ui/config/behat.yml | 4 +- .../ui/features/bootstrap/BasicStructure.php | 77 ++++++++++++++++++- tests/ui/features/lib/setupHelper.php | 46 +++++++++++ 3 files changed, 124 insertions(+), 3 deletions(-) diff --git a/tests/ui/config/behat.yml b/tests/ui/config/behat.yml index e28fef3c4e8a..c48b457d690f 100644 --- a/tests/ui/config/behat.yml +++ b/tests/ui/config/behat.yml @@ -13,7 +13,9 @@ default: ocPath: ./ regularUserPassword: 123456 regularUserName: regularuser - regularUserNames: user1,user2,user3,user4,user5 + regularUserNames: user1,user2,user3,usergrp,grpuser + regularGroupName: regulargrp + regularGroupNames: grp1,grp2,grp3,usergrp,grpuser contexts: - FeatureContext: - LoginContext: diff --git a/tests/ui/features/bootstrap/BasicStructure.php b/tests/ui/features/bootstrap/BasicStructure.php index 22687efd2402..1cefec616001 100644 --- a/tests/ui/features/bootstrap/BasicStructure.php +++ b/tests/ui/features/bootstrap/BasicStructure.php @@ -34,6 +34,9 @@ trait BasicStructure private $regularUserName; private $regularUserNames = array(); private $createdUserNames = array(); + private $regularGroupName; + private $regularGroupNames = array(); + private $createdGroupNames = array(); private $ocPath; /** @@ -84,18 +87,66 @@ public function regularUsersExist() } } + /** + * @Given a regular group exists + */ + public function aRegularGroupExists() + { + $group = $this->regularGroupName; + $result=SetupHelper::createGroup($this->ocPath, $group); + if ($result["code"] != 0) { + throw new Exception("could not create group. " . $result["stdOut"] . " " . $result["stdErr"]); + } + array_push($this->createdGroupNames, $group); + } + + /** + * @Given regular groups exist + */ + public function regularGroupsExist() + { + foreach ($this->regularGroupNames as $group) { + $group = trim($group); + $result=SetupHelper::createGroup($this->ocPath, $group); + if ($result["code"] != 0) { + throw new Exception("could not create group. " . $result["stdOut"] . " " . $result["stdErr"]); + } + array_push($this->createdGroupNames, $group); + } + } + + /** + * @Given a regular user is in a regular group + */ + public function aRegularUserIsInARegularGroup() + { + $group = $this->regularGroupName; + $user = $this->regularUserName; + if (!in_array($user, $this->createdUserNames)) { + $this->aRegularUserExists(); + } + + $result=SetupHelper::addUserToGroup($this->ocPath, $group, $user); + if ($result["code"] != 0) { + throw new Exception("could not add user to group. " . $result["stdOut"] . " " . $result["stdErr"]); + } + array_push($this->createdGroupNames, $group); + } + /** @BeforeScenario */ - public function setUpScenarioGetRegularUsersList(BeforeScenarioScope $scope) + public function setUpScenarioGetRegularUsersAndGroups(BeforeScenarioScope $scope) { $suiteParameters = $scope->getEnvironment()->getSuite()->getSettings() ['context'] ['parameters']; $this->regularUserNames = explode(",", $suiteParameters['regularUserNames']); $this->regularUserName = $suiteParameters['regularUserName']; $this->regularUserPassword = $suiteParameters['regularUserPassword']; + $this->regularGroupNames = explode(",", $suiteParameters['regularGroupNames']); + $this->regularGroupName = $suiteParameters['regularGroupName']; $this->ocPath = rtrim($suiteParameters['ocPath'], '/') . '/'; } /** @AfterScenario */ - public function tearDownScenarioDeleteCreatedUsers(AfterScenarioScope $scope) + public function tearDownScenarioDeleteCreatedUsersAndGroups(AfterScenarioScope $scope) { foreach ($this->createdUserNames as $user) { $result=SetupHelper::deleteUser($this->ocPath, $user); @@ -103,6 +154,13 @@ public function tearDownScenarioDeleteCreatedUsers(AfterScenarioScope $scope) throw new Exception("could not delete user. " . $result["stdOut"] . " " . $result["stdErr"]); } } + + foreach ($this->createdGroupNames as $group) { + $result=SetupHelper::deleteGroup($this->ocPath, $group); + if ($result["code"] != 0) { + throw new Exception("could not delete group. " . $result["stdOut"] . " " . $result["stdErr"]); + } + } } public function getRegularUserPassword () @@ -124,4 +182,19 @@ public function getCreatedUserNames () { return $this->createdUserNames; } + + public function getRegularGroupName () + { + return $this->regularGroupName; + } + + public function getRegularGroupNames () + { + return $this->regularGroupNames; + } + + public function getCreatedGroupNames () + { + return $this->createdGroupNames; + } } diff --git a/tests/ui/features/lib/setupHelper.php b/tests/ui/features/lib/setupHelper.php index bdfe5d6292b2..331f2323815f 100644 --- a/tests/ui/features/lib/setupHelper.php +++ b/tests/ui/features/lib/setupHelper.php @@ -51,6 +51,52 @@ public static function changeUserSetting($ocPath, $userName, $app, $key, $value) return self::runOcc(['user:setting', '--value '.$value, $userName, $app, $key], $ocPath); } + /** + * creates a group + * @param string $ocPath + * @param string $groupName + * @return string[] associated array with "code", "stdOut", "stdErr" + */ + public static function createGroup($ocPath, $groupName) + { + return self::runOcc(['group:add', $groupName], $ocPath); + } + + /** + * adds an existing user to a group, creating the group if it does not exist + * @param string $ocPath + * @param string $groupName + * @param string $userName + * @return string[] associated array with "code", "stdOut", "stdErr" + */ + public static function addUserToGroup($ocPath, $groupName, $userName) + { + return self::runOcc(['group:add', '--user '.$userName, $groupName], $ocPath); + } + + /** + * removes a user from a group + * @param string $ocPath + * @param string $groupName + * @param string $userName + * @return string[] associated array with "code", "stdOut", "stdErr" + */ + public static function removeUserFromGroup($ocPath, $groupName, $userName) + { + return self::runOcc(['group:removeuser', '--user '.$userName, $groupName], $ocPath); + } + + /** + * deletes a group + * @param string $ocPath + * @param string $groupName + * @return string[] associated array with "code", "stdOut", "stdErr" + */ + public static function deleteGroup($ocPath, $groupName) + { + return self::runOcc(['group:delete', $groupName], $ocPath); + } + /** * invokes an OCC command * From 760e570081cc5ec645ae0a6a1a533c3dffec0d6f Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 22 Jun 2017 11:47:52 +0545 Subject: [PATCH 3/5] Test groups in sharee autocompletion Signed-off-by: Phil Davis --- .../ui/features/bootstrap/SharingContext.php | 54 ++++++++++----- tests/ui/features/lib/SharingDialog.php | 65 +++++++++++++++---- .../ui/features/shareeAutocompletion.feature | 32 +++++++-- 3 files changed, 118 insertions(+), 33 deletions(-) diff --git a/tests/ui/features/bootstrap/SharingContext.php b/tests/ui/features/bootstrap/SharingContext.php index c9804a9f7854..6e147a50d232 100644 --- a/tests/ui/features/bootstrap/SharingContext.php +++ b/tests/ui/features/bootstrap/SharingContext.php @@ -37,6 +37,8 @@ class SharingContext extends RawMinkContext implements Context private $sharingDialog; private $regularUserName; private $regularUserNames; + private $regularGroupName; + private $regularGroupNames; public function __construct(FilesPage $filesPage) { @@ -55,6 +57,18 @@ public function theFileFolderIsSharedWithTheUser($folder, $user) $this->sharingDialog->shareWithUser($user, $this->getSession()); } + /** + * @Given the file/folder :folder is shared with the group :group + */ + public function theFileFolderIsSharedWithTheGroup($folder, $group) + { + $this->filesPage->waitTillPageIsloaded($this->getSession()); + $this->sharingDialog = $this->filesPage->openSharingDialog( + $folder, $this->getSession() + ); + $this->sharingDialog->shareWithGroup($group, $this->getSession()); + } + /** * @Given the share dialog for the file/folder :name is open */ @@ -75,31 +89,39 @@ public function iTypeInTheShareWithField($input) } /** - * @Then all users that contain the string :requiredString in their username should be listed in the autocomplete list + * @Then all users and groups that contain the string :requiredString in their name should be listed in the autocomplete list */ - public function allUsersThatContainTheStringInTheirUsernameShouldBeListedInTheAutocompleteList($requiredString) + public function allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedInTheAutocompleteList($requiredString) { - $this->allUsersThatContainTheStringInTheirUsernameShouldBeListedInTheAutocompleteListExcept($requiredString, ''); + $this->allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedInTheAutocompleteListExcept($requiredString, '', ''); } /** - * @Then all users that contain the string :requiredString in their username should be listed in the autocomplete list except :notToBeListed + * @Then all users and groups that contain the string :requiredString in their name should be listed in the autocomplete list except :userOrGroup :notToBeListed */ - public function allUsersThatContainTheStringInTheirUsernameShouldBeListedInTheAutocompleteListExcept($requiredString, $notToBeListed) + public function allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedInTheAutocompleteListExcept($requiredString, $userOrGroup, $notToBeListed) { - $autocompleteUsers = $this->sharingDialog->getAutocompleteUsersList(); - foreach ( $this->regularUserNames as $regularUser ) { - if (strpos($regularUser, $requiredString) !== false - && $regularUser !== $notToBeListed) { + if ($userOrGroup === 'group') { + $notToBeListed = $this->sharingDialog->groupStringsToMatchAutoComplete($notToBeListed); + } + $autocompleteItems = $this->sharingDialog->getAutocompleteItemsList(); + foreach ( + array_merge( + $this->regularUserNames, + $this->sharingDialog->groupStringsToMatchAutoComplete($this->regularGroupNames) + ) as $regularUserOrGroup ) { + + if (strpos($regularUserOrGroup, $requiredString) !== false + && $regularUserOrGroup !== $notToBeListed) { PHPUnit_Framework_Assert::assertContains( - $regularUser, - $autocompleteUsers, - "'" . $regularUser . "' not in autocomplete list"); + $regularUserOrGroup, + $autocompleteItems, + "'" . $regularUserOrGroup . "' not in autocomplete list"); } } PHPUnit_Framework_Assert::assertNotContains( $notToBeListed, - $this->sharingDialog->getAutocompleteUsersList() + $this->sharingDialog->getAutocompleteItemsList() ); } @@ -110,7 +132,7 @@ public function myOwnNameShouldNotBeListedInTheAutocompleteList() { PHPUnit_Framework_Assert::assertNotContains( $this->regularUserName, - $this->sharingDialog->getAutocompleteUsersList() + $this->sharingDialog->getAutocompleteItemsList() ); } @@ -131,7 +153,7 @@ public function aTooltipWithTheTextShouldBeShownNearTheShareWithField($text) public function theAutocompleteListShouldNotBeDisplayed() { PHPUnit_Framework_Assert::assertEmpty( - $this->sharingDialog->getAutocompleteUsersList() + $this->sharingDialog->getAutocompleteItemsList() ); } @@ -148,5 +170,7 @@ public function before (BeforeScenarioScope $scope) $featureContext = $environment->getContext('FeatureContext'); $this->regularUserNames = $featureContext->getRegularUserNames(); $this->regularUserName = $featureContext->getRegularUserName(); + $this->regularGroupNames = $featureContext->getRegularGroupNames(); + $this->regularGroupName = $featureContext->getRegularGroupName(); } } diff --git a/tests/ui/features/lib/SharingDialog.php b/tests/ui/features/lib/SharingDialog.php index 655a60f49e59..0d2b6333da8a 100644 --- a/tests/ui/features/lib/SharingDialog.php +++ b/tests/ui/features/lib/SharingDialog.php @@ -84,26 +84,45 @@ public function getAutocompleteNodeElement() } /** - * gets the users listed in the autocomplete list as array + * returns the group names as they could appear in an autocomplete list + * @param string|array $groupNames + * @return array + */ + public function groupStringsToMatchAutoComplete($groupNames) + { + if (is_array($groupNames)) { + $autocompleteStrings = array(); + foreach ($groupNames as $groupName) { + $autocompleteStrings[] = $groupName . $this->suffixToIdentifyGroups; + } + } else { + $autocompleteStrings = $groupNames . $this->suffixToIdentifyGroups; + } + return $autocompleteStrings; + } + + /** + * gets the items (users, groups) listed in the autocomplete list as an array * @return array * @throws \SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException */ - public function getAutocompleteUsersList() + public function getAutocompleteItemsList() { - $usersArray = array(); - $userElements = $this->getAutocompleteNodeElement()->findAll( + $itemsArray = array(); + $itemElements = $this->getAutocompleteNodeElement()->findAll( "xpath", $this->autocompleteItemsTextXpath ); - foreach ( $userElements as $user ) { - array_push($usersArray,$user->getText()); + foreach ( $itemElements as $item ) { + array_push($itemsArray,$item->getText()); } - return $usersArray; + return $itemsArray; } /** * - * @param string $name + * @param string $nameToType what to type in the share with field + * @param string $nameToMatch what exact item to select * @param Session $session * @param bool $canShare not implemented yet * @param bool $canEdit not implemented yet @@ -112,7 +131,7 @@ public function getAutocompleteUsersList() * @param bool $deletePermission not implemented yet * @throws \SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException */ - public function shareWithUser($name, Session $session, $canShare = true, $canEdit = true, + private function shareWithUserOrGroup($nameToType, $nameToMatch, Session $session, $canShare = true, $canEdit = true, $createPermission = true, $changePermission = true, $deletePermission = true) { @@ -121,14 +140,14 @@ public function shareWithUser($name, Session $session, $canShare = true, $canEdi $deletePermission !== true) { throw new \Exception("this function is not implemented"); } - $autocompleteNodeElement = $this->fillShareWithField($name, $session); + $autocompleteNodeElement = $this->fillShareWithField($nameToType, $session); $userElements = $autocompleteNodeElement->findAll( "xpath", $this->autocompleteItemsTextXpath ); $userFound = false; foreach ( $userElements as $user ) { - if ($user->getText() === $name) { + if ($user->getText() === $nameToMatch) { $user->click(); $this->waitForAjaxCallsToStartAndFinish($session); $userFound = true; @@ -141,6 +160,25 @@ public function shareWithUser($name, Session $session, $canShare = true, $canEdi } } + /** + * + * @param string $name + * @param Session $session + * @param bool $canShare not implemented yet + * @param bool $canEdit not implemented yet + * @param bool $createPermission not implemented yet + * @param bool $changePermission not implemented yet + * @param bool $deletePermission not implemented yet + * @throws \SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException + */ + public function shareWithUser($name, Session $session, $canShare = true, $canEdit = true, + $createPermission = true, $changePermission = true, + $deletePermission = true) + { + return $this->shareWithUserOrGroup($name, $name, $session, + $canShare, $canEdit, $createPermission, $changePermission, $deletePermission); + } + /** * * @param string $name @@ -152,11 +190,12 @@ public function shareWithUser($name, Session $session, $canShare = true, $canEdi * @param bool $deletePermission not implemented yet * @throws \SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException */ - public function shareWithGroup($name, Session $session,$canShare = true, $canEdit = true, + public function shareWithGroup($name, Session $session, $canShare = true, $canEdit = true, $createPermission = true, $changePermission = true, $deletePermission = true) { - return $this->shareWithUser($name . $this->suffixToIdentifyGroups); + return $this->shareWithUserOrGroup($name, $name . $this->suffixToIdentifyGroups, $session, + $canShare, $canEdit, $createPermission, $changePermission, $deletePermission); } /** diff --git a/tests/ui/features/shareeAutocompletion.feature b/tests/ui/features/shareeAutocompletion.feature index 212392af901b..7eec7aa9aa48 100644 --- a/tests/ui/features/shareeAutocompletion.feature +++ b/tests/ui/features/shareeAutocompletion.feature @@ -3,13 +3,21 @@ Feature: Sharee - autocompletion Background: Given regular users exist And a regular user exists + And regular groups exist + And a regular group exists And I am logged in as a regular user And I am on the files page Scenario: autocompletion of regular existing users And the share dialog for the folder "simple-folder" is open And I type "user" in the share-with-field - Then all users that contain the string "user" in their username should be listed in the autocomplete list + Then all users and groups that contain the string "user" in their name should be listed in the autocomplete list + And my own name should not be listed in the autocomplete list + + Scenario: autocompletion of regular existing groups + And the share dialog for the folder "simple-folder" is open + And I type "grp" in the share-with-field + Then all users and groups that contain the string "grp" in their name should be listed in the autocomplete list And my own name should not be listed in the autocomplete list Scenario: autocompletion for a pattern that does not match any user or group @@ -22,12 +30,26 @@ Feature: Sharee - autocompletion And the folder "simple-folder" is shared with the user "user1" And the share dialog for the folder "simple-folder" is open And I type "user" in the share-with-field - Then all users that contain the string "user" in their username should be listed in the autocomplete list except "user1" + Then all users and groups that contain the string "user" in their name should be listed in the autocomplete list except user "user1" And my own name should not be listed in the autocomplete list Scenario: autocompletion of a pattern that matches regular existing users but also a user whith whom the item is already shared (file) - And the file "data.zip" is shared with the user "user1" + And the file "data.zip" is shared with the user "usergrp" And the share dialog for the file "data.zip" is open And I type "user" in the share-with-field - Then all users that contain the string "user" in their username should be listed in the autocomplete list except "user1" - And my own name should not be listed in the autocomplete list \ No newline at end of file + Then all users and groups that contain the string "user" in their name should be listed in the autocomplete list except user "usergrp" + And my own name should not be listed in the autocomplete list + + Scenario: autocompletion of a pattern that matches regular existing groups but also a group with whom the item is already shared (folder) + And the folder "simple-folder" is shared with the group "grp1" + And the share dialog for the folder "simple-folder" is open + And I type "grp" in the share-with-field + Then all users and groups that contain the string "grp" in their name should be listed in the autocomplete list except group "grp1" + And my own name should not be listed in the autocomplete list + + Scenario: autocompletion of a pattern that matches regular existing groups but also a group whith whom the item is already shared (file) + And the file "data.zip" is shared with the group "grpuser" + And the share dialog for the file "data.zip" is open + And I type "grp" in the share-with-field + Then all users and groups that contain the string "grp" in their name should be listed in the autocomplete list except group "grpuser" + And my own name should not be listed in the autocomplete list From 59ebd76d17ce68bcd5ff10ee719bf61487c97985 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 29 Jun 2017 18:30:03 +0545 Subject: [PATCH 4/5] Provide addmember removemember and return statuses Signed-off-by: Phil Davis --- core/Command/Group/Add.php | 31 +----- .../Group/{RemoveUser.php => AddMember.php} | 35 ++++--- core/Command/Group/Delete.php | 3 +- core/Command/Group/RemoveMember.php | 98 +++++++++++++++++++ core/Command/User/Delete.php | 3 +- core/register_command.php | 5 +- tests/ui/features/lib/setupHelper.php | 4 +- 7 files changed, 132 insertions(+), 47 deletions(-) rename core/Command/Group/{RemoveUser.php => AddMember.php} (72%) create mode 100644 core/Command/Group/RemoveMember.php diff --git a/core/Command/Group/Add.php b/core/Command/Group/Add.php index a9b0ca5c3345..deda581c46d7 100644 --- a/core/Command/Group/Add.php +++ b/core/Command/Group/Add.php @@ -22,7 +22,6 @@ namespace OC\Core\Command\Group; use OCP\IGroupManager; -use OCP\IUserManager; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -36,10 +35,9 @@ class Add extends Command { /** * @param IGroupManager $groupManager */ - public function __construct(IGroupManager $groupManager, IUserManager $userManager) { + public function __construct(IGroupManager $groupManager) { parent::__construct(); $this->groupManager = $groupManager; - $this->userManager = $userManager; } protected function configure() { @@ -50,12 +48,6 @@ protected function configure() { 'group', InputArgument::REQUIRED, 'Name of the group' - ) - ->addOption( - 'user', - 'u', - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - 'existing users that should be added to the group' ); } @@ -66,29 +58,14 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->groupManager->createGroup($groupName); $group = $this->groupManager->get($groupName); if ($group) { - $output->writeln('Created group "' . $group->getGID() . '"'); + $output->writeln('Created group "' . $group->getGID() . '"'); } else { $output->writeln('Group "' . $groupName . '" could not be created'); return 1; } } else { - $output->writeln('The group "' . $group->getGID() . '" already exists'); - } - - $users = $input->getOption('user'); - - foreach ($users as $userName) { - $user = $this->userManager->get($userName); - if ($user) { - if ($group->inGroup($user)) { - $output->writeln('User "' . $user->getUID() . '" is already a member of group "' . $group->getGID() . '"'); - } else { - $group->addUser($user); - $output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"'); - } - } else { - $output->writeln('User "' . $userName . '" could not be found - not added to group "' . $group->getGID() . '"'); - } + $output->writeln('The group "' . $group->getGID() . '" already exists'); + return 1; } } } diff --git a/core/Command/Group/RemoveUser.php b/core/Command/Group/AddMember.php similarity index 72% rename from core/Command/Group/RemoveUser.php rename to core/Command/Group/AddMember.php index 286a27c29a47..81f1684f7835 100644 --- a/core/Command/Group/RemoveUser.php +++ b/core/Command/Group/AddMember.php @@ -29,7 +29,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; -class RemoveUser extends Command { +class Add extends Command { /** @var \OCP\IGroupManager */ protected $groupManager; @@ -44,18 +44,18 @@ public function __construct(IGroupManager $groupManager, IUserManager $userManag protected function configure() { $this - ->setName('group:removeuser') - ->setDescription('remove user(s) from a group') + ->setName('group:addmember') + ->setDescription('add members to a group') ->addArgument( 'group', InputArgument::REQUIRED, 'Name of the group' ) ->addOption( - 'user', - 'u', + 'member', + 'm', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - 'user that should be removed from the group' + 'member that should be added to the group' ); } @@ -67,25 +67,32 @@ protected function execute(InputInterface $input, OutputInterface $output) { return 1; } - $users = $input->getOption('user'); + $members = $input->getOption('member'); - if (!count($users)) { - $output->writeln('No users specified'); + if (!count($members)) { + $output->writeln('No members specified'); return 1; } - foreach ($users as $userName) { + $memberExistsError = false; + + foreach ($members as $userName) { $user = $this->userManager->get($userName); if ($user) { if ($group->inGroup($user)) { - $group->removeUser($user); - $output->writeln('User "' . $user->getUID() . '" removed from group "' . $group->getGID() . '"'); + $output->writeln('User "' . $user->getUID() . '" is already a member of group "' . $group->getGID() . '"'); } else { - $output->writeln('User "' . $userName . '" could not be found in group "' . $group->getGID() . '"'); + $group->addUser($user); + $output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"'); } } else { - $output->writeln('User "' . $userName . '" could not be found - not removed from group "' . $group->getGID() . '"'); + $output->writeln('User "' . $userName . '" could not be found - not added to group "' . $group->getGID() . '"'); + $memberExistsError = true; } } + + if ($memberExistsError) { + return 1; + } } } diff --git a/core/Command/Group/Delete.php b/core/Command/Group/Delete.php index 00230347cbf7..ab6069d0068d 100644 --- a/core/Command/Group/Delete.php +++ b/core/Command/Group/Delete.php @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $group = $this->groupManager->get($groupName); if (is_null($group)) { $output->writeln('Group does not exist'); - return; + return 1; } if ($group->delete()) { @@ -64,5 +64,6 @@ protected function execute(InputInterface $input, OutputInterface $output) { } $output->writeln('The specified group could not be deleted. Please check the logs.'); + return 1; } } diff --git a/core/Command/Group/RemoveMember.php b/core/Command/Group/RemoveMember.php new file mode 100644 index 000000000000..dc6d2a38fadc --- /dev/null +++ b/core/Command/Group/RemoveMember.php @@ -0,0 +1,98 @@ + + * + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + * + */ + +namespace OC\Core\Command\Group; + +use OCP\IGroupManager; +use OCP\IUserManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputArgument; + +class RemoveMember extends Command { + /** @var \OCP\IGroupManager */ + protected $groupManager; + + /** + * @param IGroupManager $groupManager + */ + public function __construct(IGroupManager $groupManager, IUserManager $userManager) { + parent::__construct(); + $this->groupManager = $groupManager; + $this->userManager = $userManager; + } + + protected function configure() { + $this + ->setName('group:removemember') + ->setDescription('remove member(s) from a group') + ->addArgument( + 'group', + InputArgument::REQUIRED, + 'Name of the group' + ) + ->addOption( + 'member', + 'm', + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + 'member that should be removed from the group' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $groupName = $input->getArgument('group'); + $group = $this->groupManager->get($groupName); + if (!$group) { + $output->writeln('Group "' . $groupName . '" does not exist'); + return 1; + } + + $members = $input->getOption('member'); + + if (!count($members)) { + $output->writeln('No members specified'); + return 1; + } + + $memberExistsError = false; + + foreach ($members as $userName) { + $user = $this->userManager->get($userName); + if ($user) { + if ($group->inGroup($user)) { + $group->removeUser($user); + $output->writeln('Member "' . $user->getUID() . '" removed from group "' . $group->getGID() . '"'); + } else { + $output->writeln('Member "' . $userName . '" could not be found in group "' . $group->getGID() . '"'); + } + } else { + $output->writeln('Member "' . $userName . '" does not exist - not removed from group "' . $group->getGID() . '"'); + $memberExistsError = true; + } + } + + if ($memberExistsError) { + return 1; + } + } +} diff --git a/core/Command/User/Delete.php b/core/Command/User/Delete.php index 546eef80851b..17cef6078ab1 100644 --- a/core/Command/User/Delete.php +++ b/core/Command/User/Delete.php @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $user = $this->userManager->get($input->getArgument('uid')); if (is_null($user)) { $output->writeln('User does not exist'); - return; + return 1; } if ($user->delete()) { @@ -66,5 +66,6 @@ protected function execute(InputInterface $input, OutputInterface $output) { } $output->writeln('The specified user could not be deleted. Please check the logs.'); + return 1; } } diff --git a/core/register_command.php b/core/register_command.php index 4fdd66133314..5a3605212e9c 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -145,9 +145,10 @@ $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); $application->add(new OC\Core\Command\User\SyncBackend(\OC::$server->getAccountMapper(), \OC::$server->getConfig(), \OC::$server->getUserManager(), \OC::$server->getLogger())); - $application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager(), \OC::$server->getUserManager())); + $application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager())); $application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getGroupManager(), \OC::$server->getUserManager())); + $application->add(new OC\Core\Command\Group\AddMember(\OC::$server->getGroupManager(), \OC::$server->getUserManager())); + $application->add(new OC\Core\Command\Group\RemoveMember(\OC::$server->getGroupManager(), \OC::$server->getUserManager())); $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); diff --git a/tests/ui/features/lib/setupHelper.php b/tests/ui/features/lib/setupHelper.php index 331f2323815f..121512999847 100644 --- a/tests/ui/features/lib/setupHelper.php +++ b/tests/ui/features/lib/setupHelper.php @@ -71,7 +71,7 @@ public static function createGroup($ocPath, $groupName) */ public static function addUserToGroup($ocPath, $groupName, $userName) { - return self::runOcc(['group:add', '--user '.$userName, $groupName], $ocPath); + return self::runOcc(['group:addmember', '--member '.$userName, $groupName], $ocPath); } /** @@ -83,7 +83,7 @@ public static function addUserToGroup($ocPath, $groupName, $userName) */ public static function removeUserFromGroup($ocPath, $groupName, $userName) { - return self::runOcc(['group:removeuser', '--user '.$userName, $groupName], $ocPath); + return self::runOcc(['group:removemember', '--member '.$userName, $groupName], $ocPath); } /** From 8ec0b9fc36739a1bbf7139008cd81a6554f3241c Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 29 Jun 2017 18:33:24 +0545 Subject: [PATCH 5/5] Fix AddMember class name Signed-off-by: Phil Davis --- core/Command/Group/AddMember.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Command/Group/AddMember.php b/core/Command/Group/AddMember.php index 81f1684f7835..0efff9b32cde 100644 --- a/core/Command/Group/AddMember.php +++ b/core/Command/Group/AddMember.php @@ -29,7 +29,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; -class Add extends Command { +class AddMember extends Command { /** @var \OCP\IGroupManager */ protected $groupManager;