Browse Source

Fix permissions and tweak migration

pull/6916/head
Matt Aaron 3 days ago
committed by user
parent
commit
2fd75ca681
  1. 0
      migrations/mysql/2026-03-09-005927_add_archives/down.sql
  2. 10
      migrations/mysql/2026-03-09-005927_add_archives/up.sql
  3. 10
      migrations/postgresql/2026-03-09-005927-0000_2026-03-08-200000_add_archives/up.sql
  4. 0
      migrations/postgresql/2026-03-09-005927-add_archives/down.sql
  5. 2
      migrations/postgresql/2026-03-09-005927-add_archives/up.sql
  6. 0
      migrations/sqlite/2026-03-09-005927-add_archives/down.sql
  7. 0
      migrations/sqlite/2026-03-09-005927-add_archives/up.sql
  8. 4
      src/api/core/ciphers.rs
  9. 2
      src/db/models/archive.rs

0
migrations/mysql/2026-03-09-005927-0000_2026-03-08-200000_add_archives/down.sql → migrations/mysql/2026-03-09-005927_add_archives/down.sql

10
migrations/mysql/2026-03-09-005927_add_archives/up.sql

@ -0,0 +1,10 @@
DROP TABLE IF EXISTS archives;
CREATE TABLE archives (
user_uuid CHAR(36) NOT NULL,
cipher_uuid CHAR(36) NOT NULL,
archived_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (user_uuid, cipher_uuid),
FOREIGN KEY (user_uuid) REFERENCES users (uuid) ON DELETE CASCADE,
FOREIGN KEY (cipher_uuid) REFERENCES ciphers (uuid) ON DELETE CASCADE
);

10
migrations/postgresql/2026-03-09-005927-0000_2026-03-08-200000_add_archives/up.sql

@ -1,10 +0,0 @@
DROP TABLE IF EXISTS archives;
CREATE TABLE archives (
user_uuid CHAR(36) NOT NULL,
cipher_uuid CHAR(36) NOT NULL,
archived_at TIMESTAMP NOT NULL DEFAULT now(),
PRIMARY KEY (user_uuid, cipher_uuid),
FOREIGN KEY(user_uuid) REFERENCES users(uuid) ON DELETE CASCADE,
FOREIGN KEY(cipher_uuid) REFERENCES ciphers(uuid) ON DELETE CASCADE
);

0
migrations/postgresql/2026-03-09-005927-0000_2026-03-08-200000_add_archives/down.sql → migrations/postgresql/2026-03-09-005927-add_archives/down.sql

2
migrations/sqlite/2026-03-09-005927-0000_2026-03-08-200000_add_archives/up.sql → migrations/postgresql/2026-03-09-005927-add_archives/up.sql

@ -3,6 +3,6 @@ DROP TABLE IF EXISTS archives;
CREATE TABLE archives ( CREATE TABLE archives (
user_uuid CHAR(36) NOT NULL REFERENCES users (uuid) ON DELETE CASCADE, user_uuid CHAR(36) NOT NULL REFERENCES users (uuid) ON DELETE CASCADE,
cipher_uuid CHAR(36) NOT NULL REFERENCES ciphers (uuid) ON DELETE CASCADE, cipher_uuid CHAR(36) NOT NULL REFERENCES ciphers (uuid) ON DELETE CASCADE,
archived_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, archived_at TIMESTAMP NOT NULL DEFAULT now(),
PRIMARY KEY (user_uuid, cipher_uuid) PRIMARY KEY (user_uuid, cipher_uuid)
); );

0
migrations/sqlite/2026-03-09-005927-0000_2026-03-08-200000_add_archives/down.sql → migrations/sqlite/2026-03-09-005927-add_archives/down.sql

0
migrations/mysql/2026-03-09-005927-0000_2026-03-08-200000_add_archives/up.sql → migrations/sqlite/2026-03-09-005927-add_archives/up.sql

4
src/api/core/ciphers.rs

@ -1967,8 +1967,8 @@ async fn _set_archived_cipher_by_uuid(
err!("Cipher doesn't exist") err!("Cipher doesn't exist")
}; };
if !cipher.is_write_accessible_to_user(&headers.user.uuid, conn).await { if !cipher.is_accessible_to_user(&headers.user.uuid, conn).await {
err!("Cipher can't be archived by user") err!("Cipher is not accessible for the current user")
} }
cipher.set_archived(archived, &headers.user.uuid, conn).await?; cipher.set_archived(archived, &headers.user.uuid, conn).await?;

2
src/db/models/archive.rs

@ -68,7 +68,7 @@ impl Archive {
} }
/// Return a vec with (cipher_uuid, archived_at) /// Return a vec with (cipher_uuid, archived_at)
/// This is used during a full sync so we only need one query for all folder matches /// This is used during a full sync so we only need one query for all archive matches
pub async fn find_by_user(user_uuid: &UserId, conn: &DbConn) -> Vec<(CipherId, NaiveDateTime)> { pub async fn find_by_user(user_uuid: &UserId, conn: &DbConn) -> Vec<(CipherId, NaiveDateTime)> {
db_run! { conn: { db_run! { conn: {
archives::table archives::table

Loading…
Cancel
Save