* * @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 Test; use OCP\EventDispatcher\IEventDispatcher; use OCP\Group\Events\SubAdminAddedEvent; use OCP\Group\Events\SubAdminRemovedEvent; /** * @group DB */ class SubAdminTest extends \Test\TestCase { /** @var \OCP\IUserManager */ private $userManager; /** @var \OCP\IGroupManager */ private $groupManager; /** @var \OCP\IDBConnection */ private $dbConn; /** @var IEventDispatcher */ private $eventDispatcher; /** @var \OCP\IUser[] */ private $users; /** @var \OCP\IGroup[] */ private $groups; protected function setUp(): void { $this->users = []; $this->groups = []; $this->userManager = \OC::$server->getUserManager(); $this->groupManager = \OC::$server->getGroupManager(); $this->dbConn = \OC::$server->getDatabaseConnection(); $this->eventDispatcher = \OC::$server->get(IEventDispatcher::class); // Create 3 users and 3 groups for ($i = 0; $i < 3; $i++) { $this->users[] = $this->userManager->createUser('user'.$i, 'user'); $this->groups[] = $this->groupManager->createGroup('group'.$i); } // Create admin group if (!$this->groupManager->groupExists('admin')) { $this->groupManager->createGroup('admin'); } // Create "orphaned" users and groups (scenario: temporarily disabled // backend) $qb = $this->dbConn->getQueryBuilder(); $qb->insert('group_admin') ->values([ 'gid' => $qb->createNamedParameter($this->groups[0]->getGID()), 'uid' => $qb->createNamedParameter('orphanedUser') ]) ->execute(); $qb->insert('group_admin') ->values([ 'gid' => $qb->createNamedParameter('orphanedGroup'), 'uid' => $qb->createNamedParameter('orphanedUser') ]) ->execute(); $qb->insert('group_admin') ->values([ 'gid' => $qb->createNamedParameter('orphanedGroup'), 'uid' => $qb->createNamedParameter($this->users[0]->getUID()) ]) ->execute(); } protected function tearDown(): void { foreach ($this->users as $user) { $user->delete(); } foreach ($this->groups as $group) { $group->delete(); } $qb = $this->dbConn->getQueryBuilder(); $qb->delete('group_admin') ->where($qb->expr()->eq('uid', $qb->createNamedParameter('orphanedUser'))) ->orWhere($qb->expr()->eq('gid', $qb->createNamedParameter('orphanedGroup'))) ->execute(); } public function testCreateSubAdmin() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); // Look for subadmin in the database $qb = $this->dbConn->getQueryBuilder(); $result = $qb->select(['gid', 'uid']) ->from('group_admin') ->where($qb->expr()->eq('gid', $qb->createNamedParameter($this->groups[0]->getGID()))) ->andWHere($qb->expr()->eq('uid', $qb->createNamedParameter($this->users[0]->getUID()))) ->execute() ->fetch(); $this->assertEquals( [ 'gid' => $this->groups[0]->getGID(), 'uid' => $this->users[0]->getUID() ], $result); // Delete subadmin $result = $qb->delete('*PREFIX*group_admin') ->where($qb->expr()->eq('gid', $qb->createNamedParameter($this->groups[0]->getGID()))) ->andWHere($qb->expr()->eq('uid', $qb->createNamedParameter($this->users[0]->getUID()))) ->execute(); } public function testDeleteSubAdmin() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $subAdmin->deleteSubAdmin($this->users[0], $this->groups[0]); // DB query should be empty $qb = $this->dbConn->getQueryBuilder(); $result = $qb->select(['gid', 'uid']) ->from('group_admin') ->where($qb->expr()->eq('gid', $qb->createNamedParameter($this->groups[0]->getGID()))) ->andWHere($qb->expr()->eq('uid', $qb->createNamedParameter($this->users[0]->getUID()))) ->execute() ->fetch(); $this->assertEmpty($result); } public function testGetSubAdminsGroups() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $subAdmin->createSubAdmin($this->users[0], $this->groups[1]); $result = $subAdmin->getSubAdminsGroups($this->users[0]); $this->assertContains($this->groups[0], $result); $this->assertContains($this->groups[1], $result); $this->assertNotContains($this->groups[2], $result); $this->assertNotContains(null, $result); $subAdmin->deleteSubAdmin($this->users[0], $this->groups[0]); $subAdmin->deleteSubAdmin($this->users[0], $this->groups[1]); } public function testGetGroupsSubAdmins() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $subAdmin->createSubAdmin($this->users[1], $this->groups[0]); $result = $subAdmin->getGroupsSubAdmins($this->groups[0]); $this->assertContains($this->users[0], $result); $this->assertContains($this->users[1], $result); $this->assertNotContains($this->users[2], $result); $this->assertNotContains(null, $result); $subAdmin->deleteSubAdmin($this->users[0], $this->groups[0]); $subAdmin->deleteSubAdmin($this->users[1], $this->groups[0]); } public function testGetAllSubAdmin() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $subAdmin->createSubAdmin($this->users[1], $this->groups[1]); $subAdmin->createSubAdmin($this->users[2], $this->groups[1]); $result = $subAdmin->getAllSubAdmins(); $this->assertContains(['user' => $this->users[0], 'group' => $this->groups[0]], $result); $this->assertContains(['user' => $this->users[1], 'group' => $this->groups[1]], $result); $this->assertContains(['user' => $this->users[2], 'group' => $this->groups[1]], $result); $this->assertNotContains(['user' => null, 'group' => null], $result); } public function testIsSubAdminofGroup() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $this->assertTrue($subAdmin->isSubAdminOfGroup($this->users[0], $this->groups[0])); $this->assertFalse($subAdmin->isSubAdminOfGroup($this->users[0], $this->groups[1])); $this->assertFalse($subAdmin->isSubAdminOfGroup($this->users[1], $this->groups[0])); $subAdmin->deleteSubAdmin($this->users[0], $this->groups[0]); } public function testIsSubAdmin() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $this->assertTrue($subAdmin->isSubAdmin($this->users[0])); $this->assertFalse($subAdmin->isSubAdmin($this->users[1])); $subAdmin->deleteSubAdmin($this->users[0], $this->groups[0]); } public function testIsSubAdminAsAdmin() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $this->groupManager->get('admin')->addUser($this->users[0]); $this->assertTrue($subAdmin->isSubAdmin($this->users[0])); } public function testIsUserAccessible() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $this->groups[0]->addUser($this->users[1]); $this->groups[1]->addUser($this->users[1]); $this->groups[1]->addUser($this->users[2]); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $subAdmin->createSubAdmin($this->users[2], $this->groups[2]); $this->assertTrue($subAdmin->isUserAccessible($this->users[0], $this->users[1])); $this->assertFalse($subAdmin->isUserAccessible($this->users[0], $this->users[2])); $this->assertFalse($subAdmin->isUserAccessible($this->users[2], $this->users[0])); $subAdmin->deleteSubAdmin($this->users[0], $this->groups[0]); $subAdmin->deleteSubAdmin($this->users[2], $this->groups[2]); } public function testIsUserAccessibleAsUser() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $this->assertFalse($subAdmin->isUserAccessible($this->users[0], $this->users[1])); } public function testIsUserAccessibleAdmin() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $this->groupManager->get('admin')->addUser($this->users[1]); $this->assertFalse($subAdmin->isUserAccessible($this->users[0], $this->users[1])); } public function testPostDeleteUser() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $user = array_shift($this->users); foreach ($this->groups as $group) { $subAdmin->createSubAdmin($user, $group); } $user->delete(); $this->assertEmpty($subAdmin->getAllSubAdmins()); } public function testPostDeleteGroup() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $group = array_shift($this->groups); foreach ($this->users as $user) { $subAdmin->createSubAdmin($user, $group); } $group->delete(); $this->assertEmpty($subAdmin->getAllSubAdmins()); } public function testHooks() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $test = $this; $u = $this->users[0]; $g = $this->groups[0]; $count = 0; $this->eventDispatcher->addListener(SubAdminAddedEvent::class, function (SubAdminAddedEvent $event) use ($test, $u, $g, &$count) { $test->assertEquals($u->getUID(), $event->getUser()->getUID()); $test->assertEquals($g->getGID(), $event->getGroup()->getGID()); $count++; }); $this->eventDispatcher->addListener(SubAdminRemovedEvent::class, function ($event) use ($test, $u, $g, &$count) { $test->assertEquals($u->getUID(), $event->getUser()->getUID()); $test->assertEquals($g->getGID(), $event->getGroup()->getGID()); $count++; }); $subAdmin->createSubAdmin($u, $g); $this->assertEquals(1, $count); $subAdmin->deleteSubAdmin($u, $g); $this->assertEquals(2, $count); } } alm-baseline Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
summaryrefslogtreecommitdiffstats
path: root/apps/files/l10n/fr.json
blob: c8c0c1ceabfa63b60b14dfc841fe8d7dfa12fa74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117