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

Refactor permissions #3700

Merged
merged 265 commits into from Aug 27, 2022
Merged

Conversation

abnegate
Copy link
Contributor

@abnegate abnegate commented Aug 19, 2022

What does this PR do?

  • [BREAKING] Introduce new permissions syntax replacing write permission with create, update and delete.
  • [BREAKING] Remove $read attribute from Documents
  • [BREAKING] Remove $write attribute from Documents
  • Add $permissions array attribute to Documents
  • WIP Update UI to account for new permissions
  • Update all ID usages to use new ID helper

Test Plan

Existing tests + new tests to cover changed functionality

Related PRs and Issues

Original PR

#3668

Copy link
Member

@lohanidamodar lohanidamodar left a comment

Choose a reason for hiding this comment

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

I think there are some small typos as well as I have few queries.

app/controllers/api/storage.php Outdated Show resolved Hide resolved
app/controllers/api/storage.php Outdated Show resolved Hide resolved
app/controllers/api/storage.php Show resolved Hide resolved
app/controllers/api/storage.php Outdated Show resolved Hide resolved
app/controllers/api/storage.php Outdated Show resolved Hide resolved
app/controllers/api/storage.php Outdated Show resolved Hide resolved
abnegate and others added 4 commits August 26, 2022 14:52
Co-authored-by: Damodar Lohani <lohanidamodar@users.noreply.github.com>
…write/appwrite into refactor-permissions-inc-console-fix
@@ -59,13 +61,14 @@ protected function createPerPeriodMetric(string $projectId, string $metric, int

// Required for billing
if ($monthly) {
$time = strtotime("first day of the month");
$time = DateTime::createFromFormat('Y-m-d\TH:i:s.v', \date('Y-m-01\T00:00:00.000'))->format(DateTime::RFC3339);
Copy link
Member

Choose a reason for hiding this comment

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

Would have been great if we had a single consistent class to handle dates. We could also address later with @fogelito

src/Appwrite/Utopia/Response/Model/Bucket.php Outdated Show resolved Hide resolved
src/Appwrite/Utopia/Response/Model/Bucket.php Show resolved Hide resolved
if (!Auth::isAppUser($roles) && !Auth::isPrivilegedUser($roles)) {
foreach (Database::PERMISSIONS as $type) {
foreach ($permissions as $permission) {
$permission = Permission::parse($permission);
Copy link
Member

Choose a reason for hiding this comment

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

This is OK, as its similar to the previous implementation. We could consider to have this logic available on the database library to reduce complexity in this layer. We can handle it individually later.

Copy link
Member

@eldadfux eldadfux left a comment

Choose a reason for hiding this comment

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

Looks great!

Copy link
Member

@lohanidamodar lohanidamodar left a comment

Choose a reason for hiding this comment

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

Just a query. Database controller looks good. Can we change the PR to 0.16.x or origin/datetime-attributes have some other changes

app/controllers/api/databases.php Show resolved Hide resolved
Copy link
Member

@lohanidamodar lohanidamodar left a comment

Choose a reason for hiding this comment

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

Looks good. Focused my review on databases, storage and usage.

app/controllers/api/functions.php Show resolved Hide resolved
app/views/console/settings/index.phtml Outdated Show resolved Hide resolved
app/views/console/storage/bucket.phtml Show resolved Hide resolved
"utopia-php/cache": "0.6.*",
"utopia-php/cli": "0.13.*",
"utopia-php/config": "0.2.*",
"utopia-php/database": "0.20.*",
"utopia-php/database": "dev-refactor-permissions as 0.22.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Reminder to use released version here

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 are already on 0.23.x 😎

composer.json Show resolved Hide resolved
tests/unit/Auth/AuthTest.php Outdated Show resolved Hide resolved
tests/unit/Auth/AuthTest.php Outdated Show resolved Hide resolved
tests/unit/Auth/AuthTest.php Outdated Show resolved Hide resolved
app/controllers/api/storage.php Outdated Show resolved Hide resolved
tests/e2e/Services/Databases/DatabasesBase.php Outdated Show resolved Hide resolved
Copy link
Contributor

@gewenyu99 gewenyu99 left a comment

Choose a reason for hiding this comment

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

I tried to make these descriptions more concise. See if you like the suggestions and accept the comments you agree with :)

  • I think "and get a full list of available permissions" is redundant after "Learn more about permissions".
  • I suggested a reword for documentSecurity and fileSecurity.

app/controllers/api/databases.php Outdated Show resolved Hide resolved
app/controllers/api/databases.php Outdated Show resolved Hide resolved
app/controllers/api/databases.php Outdated Show resolved Hide resolved
app/controllers/api/databases.php Outdated Show resolved Hide resolved
app/controllers/api/databases.php Outdated Show resolved Hide resolved
app/controllers/api/databases.php Outdated Show resolved Hide resolved
app/controllers/api/storage.php Outdated Show resolved Hide resolved
app/controllers/api/storage.php Outdated Show resolved Hide resolved
app/controllers/api/storage.php Outdated Show resolved Hide resolved
app/controllers/api/storage.php Outdated Show resolved Hide resolved
Copy link
Member

@christyjacob4 christyjacob4 left a comment

Choose a reason for hiding this comment

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

some tiny comments.. Looks great 👍

app/controllers/api/account.php Show resolved Hide resolved
app/controllers/api/account.php Show resolved Hide resolved
app/controllers/api/account.php Outdated Show resolved Hide resolved
tests/unit/Messaging/MessagingChannelsTest.php Outdated Show resolved Hide resolved
phpunit.xml Outdated Show resolved Hide resolved
app/views/console/storage/bucket.phtml Show resolved Hide resolved
Comment on lines +1661 to +1664
'permissions' => [
Permission::create(Role::any()),
Permission::read(Role::any()),
],
Copy link
Member

Choose a reason for hiding this comment

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

Do empty permissions map to any ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Omitted individual permissions are not granted to anyone. If the permissions parameter is not passed at all, all permissions are granted to the current user. Empty array means no one has permission for anything (excluding admin/API keys)

Copy link
Member

Choose a reason for hiding this comment

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

Empty array means no one has permission for anything (excluding admin/API keys)

I assumed so too.

If you look at the diff here. Previously the permissions were empty which means no one has access to the document. Now its been replaced with ::any which means anyone can access it. Which is the complete opposite of what it was previously. Is this expected ?

Screenshot 2022-08-27 at 10 00 36 AM

Copy link
Contributor Author

@abnegate abnegate Aug 27, 2022

Choose a reason for hiding this comment

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

We used to skip checking collection permissions if document-level were enabled, so having empty permissions on the collection worked in later tests like createDocument. In the new model, the collection permissions are always checked, and the document permissions are additionally checked if enabled.

So for the test referenced, we needed to add at least create permission for the current user, or no one could create any documents. I will update as such.

@abnegate abnegate changed the base branch from origin/datetime-attributes to 0.16.x August 27, 2022 08:32
@christyjacob4 christyjacob4 merged commit d97c3a0 into 0.16.x Aug 27, 2022
@stnguyen90 stnguyen90 deleted the refactor-permissions-inc-console-fix branch February 14, 2023 01:17
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.

None yet

9 participants