Skip to content

refactor(server): access permissions - #2910

Merged
alextran1502 merged 6 commits into
mainfrom
refactor/access-permissions
Jun 28, 2023
Merged

alextran1502 merged 6 commits into
mainfrom
refactor/access-permissions

Conversation

@jrasm91

@jrasm91 jrasm91 commented Jun 22, 2023 •

Copy link
Copy Markdown
Member

Create an AccessCore where all asset, album, etc. access checks can be consolidated. Eventually, hopefully, this logic can be enhanced with additional modifiers (additional share settings set on the user, album, asset, api key, etc.)

@vercel

vercel Bot commented Jun 22, 2023 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
immich ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 28, 2023 1:12am

@jrasm91
jrasm91 force-pushed the refactor/access-permissions branch from 9e57248 to cd46f29 Compare June 22, 2023 04:24

@brighteyed brighteyed left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like this solution! It really simplifies permission-checking for services

Comment on lines +421 to +422
const asset = await this._assetRepository.get(id);
if (!asset) {
const hasAccess = asset && (await this.access.hasPermission(authUser, Permission.ASSET_DELETE, id));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not a big deal, but maybe this code looks more natural:

      const hasAccess = await this.access.hasPermission(authUser, Permission.ASSET_DELETE, id);
      if (!hasAccess) {
        result.push({ id, status: DeleteAssetStatusEnum.FAILED });
        continue;
      }
      const asset = await this._assetRepository.get(id);
      if (!asset) {
        result.push({ id, status: DeleteAssetStatusEnum.FAILED });
        continue;
      }

if (dto.userId && dto.userId !== authUser.id) {
await this.checkUserAccess(authUser, dto.userId);
}
await this.access.requirePermission(authUser, Permission.LIBRARY_READ, dto.userId || authUser.id);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to extract variable const userId = dto.userId || authUser.id like in getAssetByTimeBucket and getAssetCountByTimeBucket

@alextran1502

Copy link
Copy Markdown
Member

Issue 1

Not sure if this is related to this PR. In public shared links, drag and drop to upload returns forbidden status while clicking on the upload button to choose assets from the file explorer works.

Issue 2

Cosmetic - on the web, with shared link disabled download, while multi selection enabled, the app bar showed the download button, although it doesn't work.

Let me know if you want to address those two issues in this PR or we can do it in a subsequent one

// TODO: fix this to not use authUser.id for shared link access control
return this.repository.asset.hasOwnerAccess(authUser.id, id);

// case Permission.ALBUM_READ:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this for debugging, should we keep or remove these lines?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can remove them if you want. I believe all the commented out lines will be used in the future as more things migrate to this permission model.

import { IAccessRepository } from './access.repository';

export enum Permission {
// ASSET_CREATE = 'asset.create',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we planning to use these commented-out permission later?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I added in everything when i was designing it, but decided not to add permission checks where none previously existed in this PR. In a subsequent one these will be enabled and used.

@jrasm91

jrasm91 commented Jun 28, 2023

Copy link
Copy Markdown
Member Author

I'd guess issue one and two are pre-existing, and if so they can be fixed in a separate PR. If they are new bugs I'll fix them obviously. Those are good finds though and I can probably take a look at fixing them soon.

@jrasm91

jrasm91 commented Jun 28, 2023

Copy link
Copy Markdown
Member Author

I confirmed issue one and two exist in the demo site today, so they're not introduced with this PR.

@jrasm91

jrasm91 commented Jun 28, 2023

Copy link
Copy Markdown
Member Author

@alextran1502
alextran1502 merged commit e98398c into main Jun 28, 2023
@alextran1502
alextran1502 deleted the refactor/access-permissions branch June 28, 2023 13:56

This branch was previously deployed

1 inactive deployment
Preview — b5b60b73 Deployed Jun 28, 2023 by vercel[bot]
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.

3 participants