10000 enabling file permissions by shimonewman · Pull Request #4661 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

enabling file permissions #4661

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

Merged
merged 6 commits into from
Nov 15, 2022
Merged

enabling file permissions #4661

merged 6 commits into from
Nov 15, 2022

Conversation

shimonewman
Copy link
Contributor
@shimonewman shimonewman commented Nov 10, 2022
  • Enabling file permissions validation via cache preview.
  • Cache buster added to the cache key.
  • Dropped cache usage from avater::initials

@stnguyen90 stnguyen90 self-requested a review November 14, 2022 19:09
@stnguyen90 stnguyen90 linked an issue Nov 14, 2022 that may be closed by this pull request
2 tasks
Comment on lines +224 to +250
$bucketId = $parts[1] ?? null;

$bucket = Authorization::skip(fn () => $dbForProject->getDocument('buckets', $bucketId));

if ($bucket->isEmpty() || (!$bucket->getAttribute('enabled') && $mode !== APP_MODE_ADMIN)) {
throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND);
}

$fileSecurity = $bucket->getAttribute('fileSecurity', false);
$validator = new Authorization(Database::PERMISSION_READ);
$valid = $validator->isValid($bucket->getRead());
if (!$fileSecurity && !$valid) {
throw new Exception(Exception::USER_UNAUTHORIZED);
}

$parts = explode('/', $data['resource']);
$fileId = $parts[1] ?? null;

if ($fileSecurity && !$valid) {
$file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
} else {
$file = Authorization::skip(fn() => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId));
}

if ($file->isEmpty()) {
throw new Exception(Exception::STORAGE_FILE_NOT_FOUND);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I tested and confirm this does work. It's just unfortunate there's a lot of duplicate code between here and the storage API.

@christyjacob4
Copy link
Member

@shimonewman we need to remove caching from the avatars API we talked about

@shimonewman
Copy link
Contributor Author

@shimonewman we need to remove caching from the avatars API we talked about

Done

@TorstenDittmann TorstenDittmann merged commit 27ddf86 into 1.1.x Nov 15, 2022
@TorstenDittmann TorstenDittmann deleted the fix-cache-permissions branch November 15, 2022 17:03
@shimonewman
Copy link
Contributor Author
shimonewman commented Nov 15, 2022 via email

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: Urgent, Bug in File permissions
4 participants
0