2024-11-24 23:52:52 +02:00
|
|
|
import { fetch } from "pouchdb-fetch";
|
|
|
|
|
|
|
|
|
|
const dbsSecurity = {
|
2024-12-03 13:33:37 +02:00
|
|
|
_users: {
|
2024-11-24 23:52:52 +02:00
|
|
|
admins: { roles: ["_admin"] },
|
2024-12-03 13:33:37 +02:00
|
|
|
members: { roles: ["_admin"] },
|
2024-11-24 23:52:52 +02:00
|
|
|
},
|
2024-12-03 13:33:37 +02:00
|
|
|
_replicator: {
|
2024-11-24 23:52:52 +02:00
|
|
|
admins: { roles: ["_admin"] },
|
2024-12-03 13:33:37 +02:00
|
|
|
members: { roles: ["_admin"] },
|
|
|
|
|
},
|
|
|
|
|
_global_changes: {
|
|
|
|
|
admins: { roles: ["_admin"] },
|
|
|
|
|
members: { roles: ["_admin"] },
|
2024-11-24 23:52:52 +02:00
|
|
|
},
|
2024-12-03 13:33:37 +02:00
|
|
|
|
2024-11-24 23:52:52 +02:00
|
|
|
server_settings: {
|
|
|
|
|
admins: { roles: ["_admin"] },
|
2024-12-02 08:50:25 +02:00
|
|
|
members: { roles: ["_admin"] },
|
|
|
|
|
},
|
2024-12-03 13:33:37 +02:00
|
|
|
web_push_subscriptions: {
|
|
|
|
|
admins: { roles: ["_admin"] },
|
|
|
|
|
members: { roles: [] },
|
|
|
|
|
},
|
|
|
|
|
messages: {
|
|
|
|
|
admins: { roles: ["_admin"] },
|
|
|
|
|
members: { roles: [] },
|
|
|
|
|
},
|
2024-12-02 08:50:25 +02:00
|
|
|
qr: {
|
|
|
|
|
admins: { roles: ["_admin"] },
|
|
|
|
|
members: { roles: [] },
|
|
|
|
|
},
|
|
|
|
|
public_settings: {
|
|
|
|
|
admins: { roles: ["_admin"] },
|
|
|
|
|
members: { roles: [] },
|
|
|
|
|
},
|
|
|
|
|
user_chat_settings: {
|
|
|
|
|
admins: { roles: ["_admin"] },
|
|
|
|
|
members: { roles: [] },
|
2024-11-24 23:52:52 +02:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const up = async () => {
|
|
|
|
|
for (const [dbName, dbSecurity] of Object.entries(dbsSecurity)) {
|
2024-12-02 08:50:25 +02:00
|
|
|
const responseCreateDb = await fetch(`${process.env.API_URL}/${dbName}`, {
|
2024-11-24 23:52:52 +02:00
|
|
|
method: "PUT",
|
2024-12-03 15:10:23 +02:00
|
|
|
}).then((response) => response.json());
|
|
|
|
|
|
2024-12-02 08:50:25 +02:00
|
|
|
console.assert(
|
2024-12-03 15:10:23 +02:00
|
|
|
responseCreateDb.ok,
|
|
|
|
|
`${dbName} create db error ${JSON.stringify(responseCreateDb)}`,
|
2024-12-02 08:50:25 +02:00
|
|
|
);
|
2024-12-03 15:10:23 +02:00
|
|
|
|
|
|
|
|
const responseSetSecurity = await fetch(`${process.env.API_URL}/${dbName}/_security`, {
|
2024-12-02 08:50:25 +02:00
|
|
|
method: "PUT",
|
|
|
|
|
body: JSON.stringify(dbSecurity),
|
2024-12-03 15:10:23 +02:00
|
|
|
}).then((response) => response.json());
|
|
|
|
|
|
2024-12-02 08:50:25 +02:00
|
|
|
console.assert(
|
2024-12-03 15:10:23 +02:00
|
|
|
responseSetSecurity.ok,
|
|
|
|
|
`${dbName} security error ${JSON.stringify(responseSetSecurity)}`,
|
2024-12-02 08:50:25 +02:00
|
|
|
);
|
2024-11-24 23:52:52 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const down = async () => {
|
|
|
|
|
for (const dbName of Object.keys(dbsSecurity)) {
|
2024-12-02 08:50:25 +02:00
|
|
|
const responseDeleteDb = await fetch(`${process.env.API_URL}/${dbName}`, {
|
2024-11-24 23:52:52 +02:00
|
|
|
method: "DELETE",
|
|
|
|
|
});
|
2024-12-02 08:50:25 +02:00
|
|
|
console.assert(
|
|
|
|
|
(await responseDeleteDb.json()).ok,
|
|
|
|
|
`${dbName} create db error`,
|
|
|
|
|
);
|
2024-11-24 23:52:52 +02:00
|
|
|
}
|
|
|
|
|
};
|