Fixed sidebar migrations to be per-board, not global. Clarified translations.

Thanks to xet7 !
This commit is contained in:
Lauri Ojansivu 2025-11-05 20:22:56 +02:00
parent bc5854dd29
commit e4638d5fbc
5 changed files with 160 additions and 66 deletions

View file

@ -3,7 +3,10 @@
* Removes problematic auth parameters from existing avatar URLs
*/
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { ReactiveCache } from '/imports/reactiveCache';
import Boards from '/models/boards';
import Users from '/models/users';
import { generateUniversalAvatarUrl, cleanFileUrl, extractFileIdFromUrl, isUniversalFileUrl } from '/models/lib/universalUrlGenerator';
@ -14,10 +17,17 @@ class FixAvatarUrlsMigration {
}
/**
* Check if migration is needed
* Check if migration is needed for a board
*/
needsMigration() {
const users = ReactiveCache.getUsers({});
needsMigration(boardId) {
// Get all users who are members of this board
const board = ReactiveCache.getBoard(boardId);
if (!board || !board.members) {
return false;
}
const memberIds = board.members.map(m => m.userId);
const users = ReactiveCache.getUsers({ _id: { $in: memberIds } });
for (const user of users) {
if (user.profile && user.profile.avatarUrl) {
@ -32,13 +42,23 @@ class FixAvatarUrlsMigration {
}
/**
* Execute the migration
* Execute the migration for a board
*/
async execute() {
const users = ReactiveCache.getUsers({});
async execute(boardId) {
// Get all users who are members of this board
const board = ReactiveCache.getBoard(boardId);
if (!board || !board.members) {
return {
success: false,
error: 'Board not found or has no members'
};
}
const memberIds = board.members.map(m => m.userId);
const users = ReactiveCache.getUsers({ _id: { $in: memberIds } });
let avatarsFixed = 0;
console.log(`Starting avatar URL fix migration...`);
console.log(`Starting avatar URL fix migration for board ${boardId}...`);
for (const user of users) {
if (user.profile && user.profile.avatarUrl) {
@ -96,11 +116,12 @@ class FixAvatarUrlsMigration {
}
}
console.log(`Avatar URL fix migration completed. Fixed ${avatarsFixed} avatar URLs.`);
console.log(`Avatar URL fix migration completed for board ${boardId}. Fixed ${avatarsFixed} avatar URLs.`);
return {
success: true,
avatarsFixed
avatarsFixed,
changes: [`Fixed ${avatarsFixed} avatar URLs for board members`]
};
}
}
@ -110,19 +131,43 @@ export const fixAvatarUrlsMigration = new FixAvatarUrlsMigration();
// Meteor method
Meteor.methods({
'fixAvatarUrls.execute'() {
'fixAvatarUrls.execute'(boardId) {
check(boardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized');
throw new Meteor.Error('not-authorized', 'You must be logged in');
}
// Check if user is board admin
const board = ReactiveCache.getBoard(boardId);
if (!board) {
throw new Meteor.Error('board-not-found', 'Board not found');
}
const user = ReactiveCache.getUser(this.userId);
if (!user) {
throw new Meteor.Error('user-not-found', 'User not found');
}
// Only board admins can run migrations
const isBoardAdmin = board.members && board.members.some(
member => member.userId === this.userId && member.isAdmin
);
if (!isBoardAdmin && !user.isAdmin) {
throw new Meteor.Error('not-authorized', 'Only board administrators can run migrations');
}
return fixAvatarUrlsMigration.execute();
return fixAvatarUrlsMigration.execute(boardId);
},
'fixAvatarUrls.needsMigration'() {
'fixAvatarUrls.needsMigration'(boardId) {
check(boardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized');
throw new Meteor.Error('not-authorized', 'You must be logged in');
}
return fixAvatarUrlsMigration.needsMigration();
return fixAvatarUrlsMigration.needsMigration(boardId);
}
});