1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-23 02:06:15 +02:00
immich/server/test/repositories
Michael Manganiello c6f56d9591
chore(server): Check activity permissions in bulk (#5775)
Modify Access repository, to evaluate `asset` permissions in bulk.
This is the last set of permission changes, to migrate all of them to
run in bulk!
Queries have been validated to match what they currently generate for single ids.

Queries:

* `activity` owner access:

```sql
-- Before
SELECT 1 AS "row_exists" FROM (SELECT 1 AS dummy_column) "dummy_table" WHERE EXISTS (
  SELECT 1
  FROM "activity" "ActivityEntity"
  WHERE
    "ActivityEntity"."id" = $1
    AND "ActivityEntity"."userId" = $2
)
LIMIT 1

-- After
SELECT "ActivityEntity"."id" AS "ActivityEntity_id"
FROM "activity" "ActivityEntity"
WHERE
  "ActivityEntity"."id" IN ($1)
  AND "ActivityEntity"."userId" = $2
```

* `activity` album owner access:

```sql
-- Before
SELECT 1 AS "row_exists" FROM (SELECT 1 AS dummy_column) "dummy_table" WHERE EXISTS (
  SELECT 1
  FROM "activity" "ActivityEntity"
    LEFT JOIN "albums" "ActivityEntity__ActivityEntity_album"
      ON "ActivityEntity__ActivityEntity_album"."id"="ActivityEntity"."albumId"
      AND "ActivityEntity__ActivityEntity_album"."deletedAt" IS NULL
  WHERE
    "ActivityEntity"."id" = $1
    AND "ActivityEntity__ActivityEntity_album"."ownerId" = $2
)
LIMIT 1

-- After
SELECT "ActivityEntity"."id" AS "ActivityEntity_id"
FROM "activity" "ActivityEntity"
  LEFT JOIN "albums" "ActivityEntity__ActivityEntity_album"
    ON "ActivityEntity__ActivityEntity_album"."id"="ActivityEntity"."albumId"
    AND "ActivityEntity__ActivityEntity_album"."deletedAt" IS NULL
WHERE
  "ActivityEntity"."id" IN ($1)
  AND "ActivityEntity__ActivityEntity_album"."ownerId" = $2
```

* `activity` create access:

```sql
-- Before
SELECT 1 AS "row_exists" FROM (SELECT 1 AS dummy_column) "dummy_table" WHERE EXISTS (
  SELECT 1
  FROM "albums" "AlbumEntity"
    LEFT JOIN "albums_shared_users_users" "AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"
      ON "AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"."albumsId"="AlbumEntity"."id"
    LEFT JOIN "users" "AlbumEntity__AlbumEntity_sharedUsers"
      ON "AlbumEntity__AlbumEntity_sharedUsers"."id"="AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"."usersId"
      AND "AlbumEntity__AlbumEntity_sharedUsers"."deletedAt" IS NULL
  WHERE
    (
      (
        "AlbumEntity"."id" = $1
        AND "AlbumEntity"."isActivityEnabled" = $2
        AND "AlbumEntity__AlbumEntity_sharedUsers"."id" = $3
      )
      OR (
        "AlbumEntity"."id" = $4
        AND "AlbumEntity"."isActivityEnabled" = $5
        AND "AlbumEntity"."ownerId" = $6
      )
    )
    AND "AlbumEntity"."deletedAt" IS NULL
)
LIMIT 1

-- After
SELECT "AlbumEntity"."id" AS "AlbumEntity_id"
FROM "albums" "AlbumEntity"
  LEFT JOIN "albums_shared_users_users" "AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"
    ON "AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"."albumsId"="AlbumEntity"."id"
  LEFT JOIN "users" "AlbumEntity__AlbumEntity_sharedUsers"
    ON "AlbumEntity__AlbumEntity_sharedUsers"."id"="AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"."usersId"
    AND "AlbumEntity__AlbumEntity_sharedUsers"."deletedAt" IS NULL
WHERE
  (
    (
      "AlbumEntity"."id" IN ($1)
      AND "AlbumEntity"."isActivityEnabled" = $2
      AND "AlbumEntity__AlbumEntity_sharedUsers"."id" = $3
    )
    OR (
      "AlbumEntity"."id" IN ($4)
      AND "AlbumEntity"."isActivityEnabled" = $5
      AND "AlbumEntity"."ownerId" = $6
    )
  )
  AND "AlbumEntity"."deletedAt" IS NULL
```
2023-12-17 12:10:21 -06:00
..
access.repository.mock.ts chore(server): Check activity permissions in bulk (#5775) 2023-12-17 12:10:21 -06:00
activity.repository.mock.ts feat(web,server): activity (#4682) 2023-10-31 22:13:34 -05:00
album.repository.mock.ts fix(web): sorting options for albums (#5233) 2023-11-26 15:23:43 +00:00
api-key.repository.mock.ts refactor(server)*: tsconfigs (#2689) 2023-06-08 10:01:07 -05:00
asset.repository.mock.ts feat: use pgvecto.rs (#3605) 2023-12-08 11:15:46 -05:00
audit.repository.mock.ts feat(server): asset entity audit (#3824) 2023-08-24 15:28:50 -04:00
communication.repository.mock.ts feat(server): server-side events (#5669) 2023-12-13 12:23:51 -05:00
crypto.repository.mock.ts refactor(server): android motion photos (#3711) 2023-09-13 10:46:37 +07:00
index.ts feat: use pgvecto.rs (#3605) 2023-12-08 11:15:46 -05:00
job.repository.mock.ts feat(web): clear failed jobs (#5423) 2023-12-05 02:07:20 +00:00
library.repository.mock.ts feat(server,web): libraries (#3124) 2023-09-20 13:16:33 +02:00
machine-learning.repository.mock.ts refactor(server)*: tsconfigs (#2689) 2023-06-08 10:01:07 -05:00
media.repository.mock.ts feat(server): tone-mapping (#3512) 2023-08-07 15:35:25 -05:00
metadata.repository.mock.ts feat: Edit metadata (#5066) 2023-11-30 03:52:28 +00:00
move.repository.mock.ts feat(server): harden move file (#4361) 2023-10-10 21:14:44 -05:00
partner.repository.mock.ts feat(web): show partners assets on the main timeline (#4933) 2023-11-11 21:06:19 +00:00
person.repository.mock.ts feat(web): re-assign person faces (2) (#4949) 2023-12-05 09:43:15 -06:00
shared-link.repository.mock.ts refactor(server)*: tsconfigs (#2689) 2023-06-08 10:01:07 -05:00
smart-info.repository.mock.ts feat: use pgvecto.rs (#3605) 2023-12-08 11:15:46 -05:00
storage.repository.mock.ts refactor(server): make storage core singleton (#4608) 2023-10-23 11:52:21 -04:00
system-config.repository.mock.ts feat: Maplibre (#4294) 2023-11-09 10:10:56 -06:00
system-info.repository.mock.ts refactor(server, web)!: store latest immich version available on the server (#3565) 2023-10-24 11:05:42 -04:00
tag.repository.mock.ts refactor(server)*: tsconfigs (#2689) 2023-06-08 10:01:07 -05:00
user-token.repository.mock.ts refactor(server)*: tsconfigs (#2689) 2023-06-08 10:01:07 -05:00
user.repository.mock.ts refactor(server): make user core singleton (#4607) 2023-10-23 08:38:48 -04:00