mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -05:00
This app runs with the audit-argument-checks package, so any Meteor method that
RECEIVES an argument it never check()s throws
"Did not check() all arguments during call to '<method>'" - the call fails
entirely, no matter what the method would have done.
problemDetailReport(area) had that defect but nothing had ever passed it an
argument, so it went unnoticed until the new Admin Panel / Problems / CPU usage
header started polling problemDetailReport('cpu') every 5 seconds and the server
log filled with the exception.
Auditing every server method for the same defect found five more that ARE called
with arguments from the client, so these features were failing outright:
- unlockUser(userId) - Admin Panel / People, unlocking a locked-out user
- runBackup(opts, storageName) - Admin Panel / Attachments, running a backup
- restoreBackup(zipPath, mode) - restoring a backup
- saveBackupSchedule(schedule) - saving the backup schedule
- migrateTextDatabase(direction) - the MongoDB <-> FerretDB text migration
and one with no current client caller, getServiceConfiguration(service), fixed
for the same reason.
Each now check()s its arguments against the types its call sites actually pass
(the two optional ones use Match.OneOf(String, null, undefined)), and the three
files that had no check import got one.
Thanks to xet7 !
111 lines
3.0 KiB
JavaScript
111 lines
3.0 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { check } from 'meteor/check';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
|
|
// Method to find locked users and release them if needed
|
|
Meteor.methods({
|
|
async getLockedUsers() {
|
|
// Check if user has admin rights
|
|
const userId = this.userId;
|
|
if (!userId) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user');
|
|
}
|
|
const user = await ReactiveCache.getUser(userId);
|
|
if (!user || !user.isAdmin) {
|
|
throw new Meteor.Error('error-not-allowed', 'Not allowed');
|
|
}
|
|
|
|
// Current time to check against unlockTime
|
|
const currentTime = Number(new Date());
|
|
|
|
// Find users that are locked (known users)
|
|
const lockedUsers = await Meteor.users.find(
|
|
{
|
|
'services.accounts-lockout.unlockTime': {
|
|
$gt: currentTime,
|
|
}
|
|
},
|
|
{
|
|
fields: {
|
|
_id: 1,
|
|
username: 1,
|
|
emails: 1,
|
|
'services.accounts-lockout.unlockTime': 1,
|
|
'services.accounts-lockout.failedAttempts': 1
|
|
}
|
|
}
|
|
).fetchAsync();
|
|
|
|
// Format the results for the UI
|
|
return lockedUsers.map(user => {
|
|
const email = user.emails && user.emails.length > 0 ? user.emails[0].address : 'No email';
|
|
const remainingLockTime = Math.round((user.services['accounts-lockout'].unlockTime - currentTime) / 1000);
|
|
|
|
return {
|
|
_id: user._id,
|
|
username: user.username || 'No username',
|
|
email,
|
|
failedAttempts: user.services['accounts-lockout'].failedAttempts || 0,
|
|
unlockTime: user.services['accounts-lockout'].unlockTime,
|
|
remainingLockTime // in seconds
|
|
};
|
|
});
|
|
},
|
|
|
|
async unlockUser(userId) {
|
|
check(userId, String);
|
|
// Check if user has admin rights
|
|
const adminId = this.userId;
|
|
if (!adminId) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user');
|
|
}
|
|
const admin = await ReactiveCache.getUser(adminId);
|
|
if (!admin || !admin.isAdmin) {
|
|
throw new Meteor.Error('error-not-allowed', 'Not allowed');
|
|
}
|
|
|
|
// Make sure the user to unlock exists
|
|
const userToUnlock = await Meteor.users.findOneAsync(userId);
|
|
if (!userToUnlock) {
|
|
throw new Meteor.Error('error-user-not-found', 'User not found');
|
|
}
|
|
|
|
// Unlock the user
|
|
await Meteor.users.updateAsync(
|
|
{ _id: userId },
|
|
{
|
|
$unset: {
|
|
'services.accounts-lockout': 1
|
|
}
|
|
}
|
|
);
|
|
|
|
return true;
|
|
},
|
|
|
|
async unlockAllUsers() {
|
|
// Check if user has admin rights
|
|
const adminId = this.userId;
|
|
if (!adminId) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user');
|
|
}
|
|
const admin = await ReactiveCache.getUser(adminId);
|
|
if (!admin || !admin.isAdmin) {
|
|
throw new Meteor.Error('error-not-allowed', 'Not allowed');
|
|
}
|
|
|
|
// Unlock all users
|
|
await Meteor.users.updateAsync(
|
|
{ 'services.accounts-lockout.unlockTime': { $exists: true } },
|
|
{
|
|
$unset: {
|
|
'services.accounts-lockout': 1
|
|
}
|
|
},
|
|
{ multi: true }
|
|
);
|
|
|
|
return true;
|
|
}
|
|
});
|