[full-ci] getting personal space by userId instead of userName (#1553)

* getting personal space by userId instead of userName

* delete geting userId via api call

* add new created user id to user list

* fix after review
This commit is contained in:
Viktor Scharf
2025-09-26 10:51:41 +02:00
committed by GitHub
parent e7b7ceafd5
commit 723340dba6
13 changed files with 126 additions and 83 deletions
+15 -15
View File
@@ -516,7 +516,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorCreatesFolder(string $folder, string $user): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$fullPath = "$storagePath/$userUuid/$folder";
@@ -537,7 +537,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorCheckUsersFolder(string $user): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$body = [
"command" => "ls -la $storagePath/$userUuid",
@@ -556,7 +556,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorCreatesFile(string $file, string $content, string $user): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$fullPath = "$storagePath/$userUuid/$file";
$safeContent = escapeshellarg($content);
@@ -593,7 +593,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorCreatesLargeFileWithSize(string $file, string $size, string $user): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$size = strtolower($size);
@@ -624,7 +624,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorCreatesFilesSequentially(int $count, string $dir, string $user): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath() . "/$userUuid/$dir";
$cmd = '';
for ($i = 1; $i <= $count; $i++) {
@@ -649,7 +649,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorCreatesFilesInParallel(int $count, string $dir, string $user): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath() . "/$userUuid/$dir";
$cmd = "mkdir -p $storagePath; ";
for ($i = 1; $i <= $count; $i++) {
@@ -675,7 +675,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorChangesFileContent(string $content, string $file, string $user): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$safeContent = escapeshellarg($content);
$body = [
@@ -696,7 +696,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorReadsTheFileContent(string $user, string $file): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$body = [
"command" => "cat $storagePath/$userUuid/$file",
@@ -715,7 +715,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorCopiesFileToFolder(string $user, string $file, string $folder): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$source = "$storagePath/$userUuid/$file";
@@ -739,7 +739,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorRenamesFile(string $user, string $file, string $newName): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$source = "$storagePath/$userUuid/$file";
@@ -763,7 +763,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorMovesFileToFolder(string $user, string $file, string $folder): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$source = "$storagePath/$userUuid/$file";
@@ -786,7 +786,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorDeletesFile(string $file, string $user): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$body = [
@@ -806,7 +806,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorDeletesFolder(string $folder, string $user): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$body = [
@@ -827,7 +827,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdministratorCopiesFileToSpace(string $user, string $file, string $space): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$usersStoragePath = $this->getUsersStoragePath();
$projectsStoragePath = $this->getProjectsStoragePath();
$spaceId = $this->spacesContext->getSpaceIdByName($this->featureContext->getAdminUsername(), $space);
@@ -874,7 +874,7 @@ class CliContext implements Context {
* @return void
*/
public function theAdminChecksTheAttributeOfFileForUser(string $attribute, string $file, string $user): void {
$userUuid = $this->featureContext->getUserIdByUserName($user);
$userUuid = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$storagePath = $this->getUsersStoragePath();
$body = [
"command" => "xattr -p -slz " . escapeshellarg($attribute) . " $storagePath/$userUuid/$file",
+4 -28
View File
@@ -2333,9 +2333,9 @@ class FeatureContext extends BehatVariablesContext {
[
"code" => "%user_id%",
"function" => [
$this, "getUserIdByUserName"
$this, "getAttributeOfCreatedUser"
],
"parameter" => [$userName]
"parameter" => [$userName, 'id']
],
[
"code" => "%group_id%",
@@ -2511,8 +2511,8 @@ class FeatureContext extends BehatVariablesContext {
[
"code" => "%user_id%",
"function" =>
[$this, "getUserIdByUserName"],
"parameter" => [$userName]
[$this, "getAttributeOfCreatedUser"],
"parameter" => [$userName, 'id']
],
[
"code" => "%group_id%",
@@ -2868,30 +2868,6 @@ class FeatureContext extends BehatVariablesContext {
return $body;
}
/**
* The method returns userId
*
* @param string $userName
*
* @return string
* @throws Exception|GuzzleException
*/
public function getUserIdByUserName(string $userName): string {
$response = GraphHelper::getUser(
$this->getBaseUrl(),
$this->getStepLineRef(),
$this->getAdminUsername(),
$this->getAdminPassword(),
$userName
);
$data = \json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
if (isset($data["id"])) {
return $data["id"];
} else {
throw new Exception(__METHOD__ . " accounts-list is empty");
}
}
/**
* The method returns groupId
*
+27 -10
View File
@@ -353,7 +353,7 @@ class GraphContext implements Context {
* @throws GuzzleException
*/
public function theUserDeletesAUserUsingTheGraphAPI(string $byUser, string $user): void {
$userId = $this->featureContext->getUserIdByUserName($user);
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$this->featureContext->setResponse($this->deleteUserByUserIdUsingTheGraphApi($userId, $byUser));
}
@@ -688,15 +688,14 @@ class GraphContext implements Context {
$rows["displayName"]
);
// add created user to list except for the user with an empty name
// because request /graph/v1.0/users/emptyUserName exits with 200
// and we cannot check that the user with empty name doesn't exist
if (!empty($rows["userName"])) {
$responseData = \json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
if ($response->getStatusCode() === 201) {
$this->featureContext->addUserToCreatedUsersList(
$rows["userName"],
$rows["password"],
$rows["displayName"],
$rows["email"]
$rows["email"],
$responseData['id']
);
}
$this->featureContext->setResponse($response);
@@ -2454,8 +2453,7 @@ class GraphContext implements Context {
* @throws GuzzleException
*/
public function getAssignedRole(string $user): ResponseInterface {
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id')
?: $this->featureContext->getUserIdByUserName($user);
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
return (
GraphHelper::getAssignedRole(
$this->featureContext->getBAseUrl(),
@@ -2844,7 +2842,7 @@ class GraphContext implements Context {
* @throws JsonException
*/
public function theUserHasChangedItsOwnUsernameTo(string $byUser, string $userName): void {
$userId = $this->featureContext->getUserIdByUserName($byUser);
$userId = $this->featureContext->getAttributeOfCreatedUser($byUser, 'id');
$response = GraphHelper::editUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
@@ -2991,7 +2989,7 @@ class GraphContext implements Context {
*
* @return void
*/
public function userListsTheActivitiesOfSpaceUsingTheGraphApi(string $user, string $spaceName): void {
public function userListsTheActivitiesOfProjectSpaceUsingTheGraphApi(string $user, string $spaceName): void {
$spaceId = ($this->featureContext->spacesContext->getSpaceByName($user, $spaceName))["id"];
$response = GraphHelper::getActivities(
$this->featureContext->getBaseUrl(),
@@ -3003,6 +3001,25 @@ class GraphContext implements Context {
$this->featureContext->setResponse($response);
}
/**
* @When user :user lists the activities of personal space using the Graph API
*
* @param string $user
*
* @return void
*/
public function userListsTheActivitiesOfPersonalSpaceUsingTheGraphApi(string $user): void {
$space = $this->featureContext->spacesContext->getPersonalSpace($user);
$response = GraphHelper::getActivities(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$space["id"]
);
$this->featureContext->setResponse($response);
}
/**
* @When the public tries to check the activities of space :spaceName owned by user :user with password :password using the Graph API
*
+57 -7
View File
@@ -218,6 +218,31 @@ class SpacesContext implements Context {
return $spaces[$spaceName];
}
/**
* @param string $user
*
* @return string
* @throws GuzzleException
* @throws JsonException
*/
public function getPersonalSpace(string $user): array {
$resource = GraphHelper::getUserWithDriveInformation(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$this->featureContext->getAttributeOfCreatedUser($user, 'id'),
$this->featureContext->getStepLineRef()
);
$space = json_decode($resource->getBody()->getContents(), true);
Assert::assertIsArray($space);
Assert::assertArrayHasKey('drive', $space, "Drive information not found for user '$user'");
Assert::assertArrayHasKey('id', $space['drive'], "Drive ID not found for user '$user'");
return $space["drive"];
}
/**
* The method finds available spaces to the user and returns the spaceId by spaceName
*
@@ -1057,7 +1082,7 @@ class SpacesContext implements Context {
"No space with name $spaceName found"
);
$permissions = $spaceAsArray["root"]["permissions"];
$userId = $this->featureContext->getUserIdByUserName($grantedUser);
$userId = $this->featureContext->getAttributeOfCreatedUser($grantedUser, 'id');
$userRole = "";
foreach ($permissions as $permission) {
@@ -1519,6 +1544,32 @@ class SpacesContext implements Context {
);
}
/**
* @param string $user
* @param string $targetUser
* @param array $bodyData
*
* @return ResponseInterface
* @throws GuzzleException
* @throws JsonException
*/
public function updatePersonalSpace(
string $user,
string $targetUser,
array $bodyData,
): ResponseInterface {
$body = json_encode($bodyData, JSON_THROW_ON_ERROR);
$space = $this->getPersonalSpace($targetUser);
return GraphHelper::updateSpace(
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$body,
$space["id"],
$this->featureContext->getStepLineRef()
);
}
/**
* @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)"$/
* @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/
@@ -1620,11 +1671,10 @@ class SpacesContext implements Context {
}
/**
* @Given /^user "([^"]*)" has changed the quota of the personal space of "([^"]*)" space to "([^"]*)"$/
* @Given /^user "([^"]*)" has changed the quota of the "([^"]*)" space to "([^"]*)"$/
* @Given /^user "([^"]*)" has changed the quota of the personal space of user "([^"]*)" space to "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $targetUser
* @param int $newQuota
*
* @return void
@@ -1633,11 +1683,11 @@ class SpacesContext implements Context {
*/
public function userHasChangedTheQuotaOfTheSpaceTo(
string $user,
string $spaceName,
string $targetUser,
int $newQuota
): void {
$bodyData = ["quota" => ["total" => $newQuota]];
$response = $this->updateSpace($user, $spaceName, $bodyData);
$response = $this->updatePersonalSpace($user, $targetUser, $bodyData);
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"Expected response status code should be 200",
@@ -4629,7 +4679,7 @@ class SpacesContext implements Context {
"No space with name $spaceName found"
);
$recipientType === 'user' ?
$recipientId = $this->featureContext->getUserIdByUserName($recipient)
$recipientId = $this->featureContext->getAttributeOfCreatedUser($recipient, 'id')
: $recipientId = $this->featureContext->getGroupIdByGroupName($recipient);
$foundRoleInResponse = false;
foreach ($spaceAsArray['root']['permissions'] as $permission) {