Skip to content

Commit

Permalink
Delete all shares of user after deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
dpakach committed Sep 18, 2020
1 parent c731fc3 commit 9f6d8a9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
8 changes: 4 additions & 4 deletions tests/TestHelpers/OcisHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public static function getDeleteUserShareCommand() {
*
* @return void
*/
public static function deleteRevaUserShares() {
public static function deleteRevaUserShares($user = "") {
$deleteCmd = self::getDeleteUserShareCommand();
if ($deleteCmd !== false) {
if ($deleteCmd !== false && $user !== "") {
$deleteCmd = \str_replace("%s", $user[0] . '/' . $user, $deleteCmd);
\exec($deleteCmd);
}
}
Expand All @@ -90,8 +91,7 @@ public static function deleteRevaUserShares() {
public static function deleteRevaUserData($user = "") {
$deleteCmd = self::getDeleteUserDataCommand();
if ($deleteCmd !== false) {
$deleteCmd = \sprintf($deleteCmd, $user[0] . '/' . $user);
// var_dump($deleteCmd);
$deleteCmd = \str_replace("%s", $user[0] . '/' . $user, $deleteCmd);
\exec($deleteCmd);
} else {
self::recurseRmdir(self::getOcisRevaDataRoot() . "/data/" . $user);
Expand Down
13 changes: 7 additions & 6 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -4247,20 +4247,21 @@ public function theListOfGroupsReturnedByTheApiShouldBeEmpty() {
*/
public function afterScenario() {
$this->restoreParametersAfterScenario();
if ($this->isTestingWithLdap()) {
$this->deleteLdapUsersAndGroups();
}
$this->cleanupDatabaseUsers();
$this->cleanupDatabaseGroups();

if (OcisHelper::isTestingOnOcis()) {
foreach ($this->getCreatedUsers() as $user) {
OcisHelper::deleteRevaUserShares($user["actualUsername"]);
$this->deleteAllSharesForUser($user["actualUsername"]);
OcisHelper::deleteRevaUserData($user["actualUsername"]);
}
OcisHelper::deleteRevaUserShares();
} else {
$this->resetAdminUserAttributes();
}
if ($this->isTestingWithLdap()) {
$this->deleteLdapUsersAndGroups();
}
$this->cleanupDatabaseUsers();
$this->cleanupDatabaseGroups();
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -2757,6 +2757,34 @@ public function thePublicAccessesThePreviewOfTheSharedFileUsingTheSharingApi($pa
$this->getPublicPreviewOfFile($path, $token);
}

public function deleteAllSharesForUser($user) {
$user = $this->getActualUsername($user);
$url = $this->getSharesEndpointPath("?format=json");
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, "GET", $url, null
);
if ($this->response->getStatusCode() !== 200) {
return;
}
$result = $this->response->getBody()->getContents();
$usersShares = \json_decode($result, true);
if (!\is_array($usersShares)) {
throw new Exception(
__METHOD__ . " API result about shares is not valid JSON"
);
}
if (!isset($usersShares['ocs']['data'])) {
return;
}
foreach ($usersShares['ocs']['data'] as $share) {
$share_id = $share['id'];
$url = $this->getSharesEndpointPath("/$share_id");
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, "DELETE", $url, null
);
}
}

/**
* replace values from table
*
Expand Down

0 comments on commit 9f6d8a9

Please sign in to comment.