Add Admin Panel setting to block avatar uploads (#4740).
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>
This commit is contained in:
1 parent
a35e5dc12c
commit
8e2dacd856
8 files changed
+86
-12
No files matched your search
@@ -125,6 +125,13 @@ template(name="attachments")
|
||||
each attachmentTransferLimitUnitOptions 'apiDownloadMaxBytes'
|
||||
option(value=value selected=selected) {{_ labelKey}}
|
||||
|
||||
li
|
||||
.title {{_ 'avatars-upload-blocked-label'}}
|
||||
.form-group
|
||||
label
|
||||
input.js-avatars-upload-blocked(type="checkbox" checked=avatarsUploadBlocked)
|
||||
| {{_ 'avatars-upload-blocked-description'}}
|
||||
|
||||
li
|
||||
button.js-save-attachment-transfer-limits.primary {{_ 'save'}}
|
||||
else if isFilesystemActive
|
||||
|
||||
@@ -82,6 +82,7 @@ const DEFAULT_LIMIT_SETTINGS = {
|
||||
attachmentsDownloadMaxBytes: 0,
|
||||
apiUploadMaxBytes: 0,
|
||||
apiDownloadMaxBytes: 0,
|
||||
avatarsUploadBlocked: false,
|
||||
};
|
||||
|
||||
function toNonNegativeInteger(value, fallback = 0) {
|
||||
@@ -114,6 +115,7 @@ function normalizeLimitSettings(settingsDoc) {
|
||||
? toNonNegativeInteger(fromDoc.apiDownloadMaxBytes, DEFAULT_LIMIT_SETTINGS.apiDownloadMaxBytes)
|
||||
: DEFAULT_LIMIT_SETTINGS.apiDownloadMaxBytes,
|
||||
attachmentsUploadBlocked: fromDoc.attachmentsUploadBlocked === true,
|
||||
avatarsUploadBlocked: fromDoc.avatarsUploadBlocked === true,
|
||||
attachmentsDownloadBlocked: fromDoc.attachmentsDownloadBlocked === true,
|
||||
apiUploadBlocked: fromDoc.apiUploadBlocked === true,
|
||||
apiDownloadBlocked: fromDoc.apiDownloadBlocked === true,
|
||||
@@ -296,6 +298,10 @@ Template.attachments.helpers({
|
||||
isGcsActive() {
|
||||
return Template.instance().activeSection.get() === 'gcs';
|
||||
},
|
||||
avatarsUploadBlocked() {
|
||||
const settings = Template.instance().attachmentStorageSettings.get();
|
||||
return settings?.limitSettings?.avatarsUploadBlocked === true;
|
||||
},
|
||||
defaultStorageOptions() {
|
||||
const settings = Template.instance().attachmentStorageSettings.get();
|
||||
const selected = settings?.defaultStorage || 'fs';
|
||||
@@ -631,6 +637,10 @@ Template.attachments.events({
|
||||
nextLimitSettings[field.fieldName] = bytesValue;
|
||||
}
|
||||
|
||||
// Avatar uploads are a simple on/off block (no size mode). Default off so
|
||||
// avatars stay enabled unless an admin explicitly blocks them.
|
||||
nextLimitSettings.avatarsUploadBlocked = tpl.$('.js-avatars-upload-blocked').is(':checked');
|
||||
|
||||
const nextSettings = {
|
||||
...currentSettings,
|
||||
uploadSettings: {
|
||||
|
||||
@@ -84,17 +84,18 @@ template(name="changeAvatarPopup")
|
||||
if noAvatarUrl
|
||||
i.fa.fa-check
|
||||
p.sub-name {{_ 'default-avatar'}}
|
||||
input.hide.js-upload-avatar-input(accept="image/*;capture=camera" type="file")
|
||||
if Meteor.settings.public.avatarsUploadMaxSize
|
||||
| {{_ 'max-avatar-filesize'}} {{Meteor.settings.public.avatarsUploadMaxSize}}
|
||||
br
|
||||
if Meteor.settings.public.avatarsUploadMimeTypes
|
||||
| {{_ 'allowed-avatar-filetypes'}} {{Meteor.settings.public.avatarsUploadMimeTypes}}
|
||||
br
|
||||
| {{_ 'invalid-file'}}
|
||||
button.full.js-upload-avatar
|
||||
i.fa.fa-upload
|
||||
| {{_ 'upload-avatar' }}
|
||||
unless avatarUploadBlocked
|
||||
input.hide.js-upload-avatar-input(accept="image/*;capture=camera" type="file")
|
||||
if Meteor.settings.public.avatarsUploadMaxSize
|
||||
| {{_ 'max-avatar-filesize'}} {{Meteor.settings.public.avatarsUploadMaxSize}}
|
||||
br
|
||||
if Meteor.settings.public.avatarsUploadMimeTypes
|
||||
| {{_ 'allowed-avatar-filetypes'}} {{Meteor.settings.public.avatarsUploadMimeTypes}}
|
||||
br
|
||||
| {{_ 'invalid-file'}}
|
||||
button.full.js-upload-avatar
|
||||
i.fa.fa-upload
|
||||
| {{_ 'upload-avatar' }}
|
||||
|
||||
template(name="deleteAvatarPopup")
|
||||
p {{_ 'delete-avatar-confirm'}}
|
||||
|
||||
@@ -167,6 +167,13 @@ Template.boardTeamName.helpers({
|
||||
Template.changeAvatarPopup.onCreated(function () {
|
||||
this.error = new ReactiveVar('');
|
||||
this.avatarUpdateCounter = new ReactiveVar(0); // Trigger to force helper re-evaluation
|
||||
// Whether an admin has blocked avatar uploads (Admin Panel > Attachments >
|
||||
// Transfer limits). Default false (avatars enabled); when true the upload
|
||||
// option is hidden and the upload is also rejected server-side.
|
||||
this.avatarUploadBlocked = new ReactiveVar(false);
|
||||
Meteor.call('isAvatarUploadBlocked', (err, blocked) => {
|
||||
if (!err) this.avatarUploadBlocked.set(blocked === true);
|
||||
});
|
||||
Meteor.subscribe('my-avatars');
|
||||
});
|
||||
|
||||
@@ -174,6 +181,9 @@ Template.changeAvatarPopup.helpers({
|
||||
error() {
|
||||
return Template.instance().error;
|
||||
},
|
||||
avatarUploadBlocked() {
|
||||
return Template.instance().avatarUploadBlocked.get();
|
||||
},
|
||||
uploadedAvatars() {
|
||||
Template.instance().avatarUpdateCounter.get(); // Create dependency on update counter
|
||||
const ret = ReactiveCache.getAvatars({ userId: Meteor.userId() }, {}, true);
|
||||
|
||||
@@ -823,6 +823,8 @@
|
||||
"attachment-transfer-limits-save-failed": "Failed to save attachment transfer limits",
|
||||
"attachment-transfer-limits-invalid-value": "Please enter a valid positive limit value",
|
||||
"attachment-upload-limit-label": "Attachments upload max file size",
|
||||
"avatars-upload-blocked-label": "Avatars",
|
||||
"avatars-upload-blocked-description": "Block users from uploading new avatars (useful when avatars are synced from another source). Avatars are enabled by default.",
|
||||
"attachment-download-limit-label": "Attachments download max file size",
|
||||
"api-upload-limit-label": "API upload max file size",
|
||||
"api-download-limit-label": "API download max file size",
|
||||
|
||||
@@ -159,6 +159,13 @@ AttachmentStorageSettings.attachSchema(
|
||||
label: 'Attachments Upload Blocked'
|
||||
},
|
||||
|
||||
'limitSettings.avatarsUploadBlocked': {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
defaultValue: false,
|
||||
label: 'Avatars Upload Blocked'
|
||||
},
|
||||
|
||||
'limitSettings.attachmentsDownloadMaxBytes': {
|
||||
type: Number,
|
||||
optional: true,
|
||||
|
||||
@@ -237,6 +237,7 @@ Meteor.methods({
|
||||
attachmentsUploadMaxBytes: process.env.ATTACHMENTS_UPLOAD_MAX_SIZE
|
||||
? parseNonNegativeInt(process.env.ATTACHMENTS_UPLOAD_MAX_SIZE, 0) : 0,
|
||||
attachmentsUploadBlocked: false,
|
||||
avatarsUploadBlocked: false,
|
||||
attachmentsDownloadMaxBytes: 0,
|
||||
attachmentsDownloadBlocked: false,
|
||||
apiUploadMaxBytes: process.env.ATTACHMENT_API_MAX_UPLOAD_BYTES
|
||||
@@ -266,6 +267,20 @@ Meteor.methods({
|
||||
return maskStorageSecrets(settings);
|
||||
},
|
||||
|
||||
// Whether avatar uploads are blocked board-wide (Admin Panel > Attachments >
|
||||
// Transfer limits). Readable by any logged-in user so the avatar popup can
|
||||
// hide its upload option; the actual upload is also blocked server-side in
|
||||
// server/permissions/avatars.js. Default false (avatars enabled).
|
||||
async isAvatarUploadBlocked() {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('not-authorized', 'Must be logged in');
|
||||
}
|
||||
const settings = await AttachmentStorageSettings.findOneAsync(
|
||||
{}, { fields: { 'limitSettings.avatarsUploadBlocked': 1 } },
|
||||
);
|
||||
return settings?.limitSettings?.avatarsUploadBlocked === true;
|
||||
},
|
||||
|
||||
async getGridFsStorageStats() {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('not-authorized', 'Must be logged in');
|
||||
|
||||
@@ -1,11 +1,33 @@
|
||||
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({
|
||||
insert: isOwner,
|
||||
async insert(userId, doc) {
|
||||
if (await avatarUploadsBlocked()) {
|
||||
return false;
|
||||
}
|
||||
return isOwner(userId, doc);
|
||||
},
|
||||
update: isOwner,
|
||||
remove: isOwner,
|
||||
fetch: ['userId'],
|
||||
|
||||
Reference in new issue
Block a user