40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
|
|
// Portiert aus bleeter/server/permissions.lua + main.lua
|
||
|
|
|
||
|
|
// Wer darf in welchem Feed posten (feed_type: 'home' | 'advertising')
|
||
|
|
const feedPostRights = {
|
||
|
|
private: { home: true },
|
||
|
|
small_business: { advertising: true },
|
||
|
|
company: { advertising: true },
|
||
|
|
authority: { home: true, advertising: true },
|
||
|
|
lifeinvader: {},
|
||
|
|
};
|
||
|
|
|
||
|
|
function canPost(profileType, feedType) {
|
||
|
|
const rights = feedPostRights[profileType || ''] || {};
|
||
|
|
return rights[feedType || ''] === true;
|
||
|
|
}
|
||
|
|
|
||
|
|
function decodeBool(v) {
|
||
|
|
return v === true || v === 1 || v === '1';
|
||
|
|
}
|
||
|
|
|
||
|
|
// Behoerden / Lifeinvader / Staff koennen nicht blockiert werden
|
||
|
|
function canProfileBeBlocked(profileType, isLifeinvaderStaff) {
|
||
|
|
return profileType !== 'authority'
|
||
|
|
&& profileType !== 'lifeinvader'
|
||
|
|
&& !decodeBool(isLifeinvaderStaff);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Lifeinvader-Moderationsrechte eines Charakters (char_id) aus DB
|
||
|
|
async function hasLifeinvaderPermission(db, charId, permission) {
|
||
|
|
if (!charId) return false;
|
||
|
|
const row = await db.q1(
|
||
|
|
`SELECT allowed FROM bleeter_lifeinvader_permissions
|
||
|
|
WHERE char_id = ? AND permission = ? LIMIT 1`,
|
||
|
|
[charId, permission]
|
||
|
|
);
|
||
|
|
return !!(row && decodeBool(row.allowed));
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = { feedPostRights, canPost, decodeBool, canProfileBeBlocked, hasLifeinvaderPermission };
|