Add some utils and update the memory database to "store" rows
This commit is contained in:
parent
9694d72dd0
commit
6b35c10106
4 changed files with 220 additions and 60 deletions
30
module/utils/filterPrivateRows.mjs
Normal file
30
module/utils/filterPrivateRows.mjs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* Filters an array of database rows based on if the current user would
|
||||
* be able to see them based on the privacy level.
|
||||
*
|
||||
* @param {Array<any>} rows The rows to filter
|
||||
* @param {string} userID The user's ID who the rows belong to
|
||||
* @param {"all"|"me"|"none"} privacy The privacy level we're filtering for
|
||||
* @returns The filtered rows
|
||||
*/
|
||||
export function filterPrivateRows(rows, userID, privacy) {
|
||||
console.log(rows, userID, privacy);
|
||||
const filtered = [];
|
||||
|
||||
const isMe = userID === game.user.id;
|
||||
// TODO: make this use a permission rather than just isGM
|
||||
const canSeeAll = game.user.isGM;
|
||||
|
||||
for (const row of rows) {
|
||||
|
||||
let allowed = !row.isPrivate;
|
||||
allowed ||= privacy === `all` && canSeeAll;
|
||||
allowed ||= privacy === `my` && isMe;
|
||||
|
||||
if (allowed) {
|
||||
filtered.push(row);
|
||||
};
|
||||
};
|
||||
|
||||
return filtered;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue