Put all the relevant privacy helpers into their own module

This commit is contained in:
Oliver-Akins 2025-05-04 21:35:54 -06:00
parent 8b488f488b
commit f2f742e65a
2 changed files with 20 additions and 1 deletions

View file

@ -1,30 +0,0 @@
/**
* 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;
};