Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 5404 update doc without relation permission #5815

Closed

Conversation

fanatic75
Copy link
Contributor

@fanatic75 fanatic75 commented Jul 13, 2023

What does this PR do?

Fixes #5404 Update of document with relations without permissions of relation collection

Test Plan

Added E2E test case

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@fanatic75 fanatic75 requested a review from stnguyen90 July 13, 2023 17:47
app/controllers/api/databases.php Outdated Show resolved Hide resolved
app/controllers/api/databases.php Outdated Show resolved Hide resolved
@@ -3280,7 +3276,6 @@ function updateAttribute(
}

$data = \array_merge($document->getArrayCopy(), $data); // Merge existing data with new data
$data['$collection'] = $collection->getId(); // Make sure user doesn't switch collectionID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to remove this?

$checkPermissions($collection, $newDocument, $document, Database::PERMISSION_UPDATE);
;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this

$checkPermissions($collection, $newDocument, $document, Database::PERMISSION_UPDATE);
;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep just one line between code blocks


public function testUpdateWithoutRelationPermission(): void
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have no blank lines at the start of function

]);

$databaseId = $database['body']['$id'];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep just one line between code blocks

]);

\sleep(3);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep just one blank line between code blocks

'permissions' => [],
]);

\sleep(3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this too

]);
$this->assertEquals(201, $parentDocument['headers']['status-code']);

\sleep(3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this too

Comment on lines +3361 to +3363
$relation->removeAttribute('$collectionId');
$relation->removeAttribute('$databaseId');
$relation->setAttribute('$collection', $relatedCollection->getId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do this outside the foreach loop

Comment on lines +3393 to +3395
$newDocument->removeAttribute('$collectionId');
$newDocument->removeAttribute('$databaseId');
$newDocument->setAttribute('$collection', $collection->getId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do this outside the foreach loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Nested update, permission issue
3 participants