mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 14:45:11 -05:00
Adds limitSettings.avatarsUploadBlocked (default false — avatars enabled) to Admin Panel > Attachments > Transfer limits. When enabled, the avatar upload option is hidden in the user avatar popup and new avatar uploads are rejected server-side (server/permissions/avatars.js), mirroring the existing attachmentsUploadBlocked. Useful when avatars are synced from an external source. Thanks to xet7. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
import Avatars from '/models/avatars';
|
|
import AttachmentStorageSettings from '/models/attachmentStorageSettings';
|
|
|
|
function isOwner(userId, doc) {
|
|
return userId && userId === doc.userId;
|
|
}
|
|
|
|
// Admin-level hard stop for avatar uploads (Admin Panel > Attachments >
|
|
// Transfer limits, default off). Mirrors the attachmentsUploadBlocked check in
|
|
// server/permissions/attachments.js. When blocked, only inserts (new uploads)
|
|
// are rejected; updating/removing an existing avatar still works.
|
|
async function avatarUploadsBlocked() {
|
|
try {
|
|
const settings = await AttachmentStorageSettings.findOneAsync({});
|
|
return settings?.limitSettings?.avatarsUploadBlocked === true;
|
|
} catch (error) {
|
|
if (process.env.DEBUG === 'true') {
|
|
console.warn('Could not read avatar upload block setting:', error);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Avatars.allow({
|
|
async insert(userId, doc) {
|
|
if (await avatarUploadsBlocked()) {
|
|
return false;
|
|
}
|
|
return isOwner(userId, doc);
|
|
},
|
|
update: isOwner,
|
|
remove: isOwner,
|
|
fetch: ['userId'],
|
|
});
|