mirror of
https://github.com/wekan/wekan.git
synced 2025-09-22 01:50:48 +02:00
Move every Users.findOne(idOrFirstObjectSelector, options) to the ReactiveCache
This commit is contained in:
parent
68610e5066
commit
0767f50af8
17 changed files with 43 additions and 33 deletions
|
@ -1646,7 +1646,7 @@ Template.cardAssigneesPopup.helpers({
|
|||
|
||||
Template.cardAssigneePopup.helpers({
|
||||
userData() {
|
||||
return Users.findOne(this.userId, {
|
||||
return ReactiveCache.getUser(this.userId, {
|
||||
fields: {
|
||||
profile: 1,
|
||||
username: 1,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
|
||||
export function csvGetMembersToMap(data) {
|
||||
// we will work on the list itself (an ordered array of objects) when a
|
||||
// mapping is done, we add a 'wekan' field to the object representing the
|
||||
|
@ -28,7 +30,7 @@ export function csvGetMembersToMap(data) {
|
|||
username: importedMember,
|
||||
id: importedMember,
|
||||
};
|
||||
const wekanUser = Users.findOne({ username: importedMember.username });
|
||||
const wekanUser = ReactiveCache.getUser({ username: importedMember.username });
|
||||
if (wekanUser) importedMember.wekanId = wekanUser._id;
|
||||
membersToMap.push(importedMember);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
import { trelloGetMembersToMap } from './trelloMembersMapper';
|
||||
import { wekanGetMembersToMap } from './wekanMembersMapper';
|
||||
import { csvGetMembersToMap } from './csvMembersMapper';
|
||||
|
@ -174,9 +175,9 @@ BlazeComponent.extendComponent({
|
|||
this._refreshMembers(
|
||||
this.members().map(member => {
|
||||
if (!member.wekanId) {
|
||||
let user = Users.findOne({ username: member.username });
|
||||
let user = ReactiveCache.getUser({ username: member.username });
|
||||
if (!user) {
|
||||
user = Users.findOne({ importUsernames: member.username });
|
||||
user = ReactiveCache.getUser({ importUsernames: member.username });
|
||||
}
|
||||
if (user) {
|
||||
// eslint-disable-next-line no-console
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
|
||||
export function trelloGetMembersToMap(data) {
|
||||
// we will work on the list itself (an ordered array of objects) when a
|
||||
// mapping is done, we add a 'wekan' field to the object representing the
|
||||
|
@ -5,7 +7,7 @@ export function trelloGetMembersToMap(data) {
|
|||
const membersToMap = data.members;
|
||||
// auto-map based on username
|
||||
membersToMap.forEach(importedMember => {
|
||||
const wekanUser = Users.findOne({ username: importedMember.username });
|
||||
const wekanUser = ReactiveCache.getUser({ username: importedMember.username });
|
||||
if (wekanUser) {
|
||||
importedMember.wekanId = wekanUser._id;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
|
||||
export function wekanGetMembersToMap(data) {
|
||||
// we will work on the list itself (an ordered array of objects) when a
|
||||
// mapping is done, we add a 'wekan' field to the object representing the
|
||||
|
@ -15,7 +17,7 @@ export function wekanGetMembersToMap(data) {
|
|||
importedMember.fullName = user.profile.fullname;
|
||||
}
|
||||
importedMember.username = user.username;
|
||||
const wekanUser = Users.findOne({ username: importedMember.username });
|
||||
const wekanUser = ReactiveCache.getUser({ username: importedMember.username });
|
||||
if (wekanUser) {
|
||||
importedMember.wekanId = wekanUser._id;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
|
||||
BlazeComponent.extendComponent({
|
||||
onCreated() {
|
||||
this.rulesCurrentTab = new ReactiveVar('rulesList');
|
||||
|
@ -55,7 +57,7 @@ BlazeComponent.extendComponent({
|
|||
let trigger = this.triggerVar.get();
|
||||
trigger.userId = '*';
|
||||
if (username !== undefined) {
|
||||
const userFound = Users.findOne({ username });
|
||||
const userFound = ReactiveCache.getUser({ username });
|
||||
if (userFound !== undefined) {
|
||||
trigger.userId = userFound._id;
|
||||
this.triggerVar.set(trigger);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
import { Exporter } from './exporter';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
|
@ -43,7 +44,7 @@ if (Meteor.isServer) {
|
|||
});
|
||||
} else if (!Meteor.settings.public.sandstorm) {
|
||||
Authentication.checkUserId(req.userId);
|
||||
user = Users.findOne({ _id: req.userId, isAdmin: true });
|
||||
user = ReactiveCache.getUser({ _id: req.userId, isAdmin: true });
|
||||
}
|
||||
const exporter = new Exporter(boardId);
|
||||
if (exporter.canExport(user) || impersonateDone) {
|
||||
|
@ -107,7 +108,7 @@ if (Meteor.isServer) {
|
|||
});
|
||||
} else if (!Meteor.settings.public.sandstorm) {
|
||||
Authentication.checkUserId(req.userId);
|
||||
user = Users.findOne({ _id: req.userId, isAdmin: true });
|
||||
user = ReactiveCache.getUser({ _id: req.userId, isAdmin: true });
|
||||
}
|
||||
const exporter = new Exporter(boardId, attachmentId);
|
||||
if (exporter.canExport(user) || impersonateDone) {
|
||||
|
@ -163,7 +164,7 @@ if (Meteor.isServer) {
|
|||
});
|
||||
} else if (!Meteor.settings.public.sandstorm) {
|
||||
Authentication.checkUserId(req.userId);
|
||||
user = Users.findOne({
|
||||
user = ReactiveCache.getUser({
|
||||
_id: req.userId,
|
||||
isAdmin: true,
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
import { TAPi18n } from '/imports/i18n';
|
||||
import { runOnServer } from './runOnServer';
|
||||
|
||||
|
@ -46,7 +47,7 @@ runOnServer(function() {
|
|||
});
|
||||
} else if (!Meteor.settings.public.sandstorm) {
|
||||
Authentication.checkUserId(req.userId);
|
||||
user = Users.findOne({
|
||||
user = ReactiveCache.getUser({
|
||||
_id: req.userId,
|
||||
isAdmin: true,
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
import { TAPi18n } from '/imports/i18n';
|
||||
import { runOnServer } from './runOnServer';
|
||||
|
||||
|
@ -48,7 +49,7 @@ runOnServer(function() {
|
|||
});
|
||||
} else if (!Meteor.settings.public.sandstorm) {
|
||||
Authentication.checkUserId(req.userId);
|
||||
user = Users.findOne({
|
||||
user = ReactiveCache.getUser({
|
||||
_id: req.userId,
|
||||
isAdmin: true,
|
||||
});
|
||||
|
|
|
@ -349,7 +349,7 @@ if (Meteor.isServer) {
|
|||
emails.forEach(email => {
|
||||
if (email && SimpleSchema.RegEx.Email.test(email)) {
|
||||
// Checks if the email is already link to an account.
|
||||
const userExist = Users.findOne({ email });
|
||||
const userExist = ReactiveCache.getUser({ email });
|
||||
if (userExist) {
|
||||
rc = -1;
|
||||
throw new Meteor.Error(
|
||||
|
|
|
@ -515,7 +515,7 @@ Users.allow({
|
|||
const adminsNumber = Users.find({
|
||||
isAdmin: true,
|
||||
}).count();
|
||||
const { isAdmin } = Users.findOne(
|
||||
const isAdmin = ReactiveCache.getUser(
|
||||
{
|
||||
_id: userId,
|
||||
},
|
||||
|
@ -1262,10 +1262,8 @@ if (Meteor.isServer) {
|
|||
from: 'admin',
|
||||
});
|
||||
const user =
|
||||
Users.findOne(username) ||
|
||||
Users.findOne({
|
||||
username,
|
||||
});
|
||||
ReactiveCache.getUser(username) ||
|
||||
ReactiveCache.getUser({ username });
|
||||
if (user) {
|
||||
Users.update(user._id, {
|
||||
$set: {
|
||||
|
@ -1305,7 +1303,7 @@ if (Meteor.isServer) {
|
|||
if (Array.isArray(email)) {
|
||||
email = email.shift();
|
||||
}
|
||||
const existingUser = Users.findOne(
|
||||
const existingUser = ReactiveCache.getUser(
|
||||
{
|
||||
'emails.address': email,
|
||||
},
|
||||
|
@ -1402,7 +1400,7 @@ if (Meteor.isServer) {
|
|||
const posAt = username.indexOf('@');
|
||||
let user = null;
|
||||
if (posAt >= 0) {
|
||||
user = Users.findOne({
|
||||
user = ReactiveCache.getUser({
|
||||
emails: {
|
||||
$elemMatch: {
|
||||
address: username,
|
||||
|
@ -1411,10 +1409,8 @@ if (Meteor.isServer) {
|
|||
});
|
||||
} else {
|
||||
user =
|
||||
Users.findOne(username) ||
|
||||
Users.findOne({
|
||||
username,
|
||||
});
|
||||
ReactiveCache.getUser(username) ||
|
||||
ReactiveCache.getUser({ username });
|
||||
}
|
||||
if (user) {
|
||||
if (user._id === inviter._id)
|
||||
|
|
|
@ -213,7 +213,7 @@ export class WekanCreator {
|
|||
importedMember.fullName = user.profile.fullname;
|
||||
}
|
||||
importedMember.username = user.username;
|
||||
const wekanUser = Users.findOne({ username: importedMember.username });
|
||||
const wekanUser = ReactiveCache.getUser({ username: importedMember.username });
|
||||
if (wekanUser) {
|
||||
importedMember.wekanId = wekanUser._id;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
|
||||
export function getMembersToMap(data) {
|
||||
// we will work on the list itself (an ordered array of objects) when a
|
||||
// mapping is done, we add a 'wekan' field to the object representing the
|
||||
|
@ -15,7 +17,7 @@ export function getMembersToMap(data) {
|
|||
importedMember.fullName = user.profile.fullname;
|
||||
}
|
||||
importedMember.username = user.username;
|
||||
const wekanUser = Users.findOne({ username: importedMember.username });
|
||||
const wekanUser = ReactiveCache.getUser({ username: importedMember.username });
|
||||
if (wekanUser) {
|
||||
importedMember.wekanId = wekanUser._id;
|
||||
}
|
||||
|
|
|
@ -312,7 +312,7 @@ if (isSandstorm && Meteor.isServer) {
|
|||
const username = doc.services.sandstorm.preferredHandle;
|
||||
let appendNumber = 0;
|
||||
while (
|
||||
Users.findOne({
|
||||
ReactiveCache.getUser({
|
||||
_id: { $ne: doc._id },
|
||||
username: generateUniqueUsername(username, appendNumber),
|
||||
})
|
||||
|
|
|
@ -21,7 +21,7 @@ Meteor.startup(() => {
|
|||
error.statusCode = 401;
|
||||
throw error;
|
||||
}
|
||||
const admin = Users.findOne({ _id: userId, isAdmin: true });
|
||||
const admin = ReactiveCache.getUser({ _id: userId, isAdmin: true });
|
||||
|
||||
if (admin === undefined) {
|
||||
const error = new Meteor.Error('Forbidden', 'Forbidden');
|
||||
|
@ -44,7 +44,7 @@ Meteor.startup(() => {
|
|||
// This throws an error if otherReq is false and the user is not an admin
|
||||
Authentication.checkAdminOrCondition = function(userId, otherReq) {
|
||||
if (otherReq) return;
|
||||
const admin = Users.findOne({ _id: userId, isAdmin: true });
|
||||
const admin = ReactiveCache.getUser({ _id: userId, isAdmin: true });
|
||||
if (admin === undefined) {
|
||||
const error = new Meteor.Error('Forbidden', 'Forbidden');
|
||||
error.statusCode = 403;
|
||||
|
|
|
@ -334,7 +334,7 @@ function buildSelector(queryParams) {
|
|||
if (queryParams.hasOperator(OPERATOR_USER)) {
|
||||
const users = [];
|
||||
queryParams.getPredicates(OPERATOR_USER).forEach(username => {
|
||||
const user = Users.findOne({ username });
|
||||
const user = ReactiveCache.getUser({ username });
|
||||
if (user) {
|
||||
users.push(user._id);
|
||||
} else {
|
||||
|
@ -352,7 +352,7 @@ function buildSelector(queryParams) {
|
|||
if (queryParams.hasOperator(key)) {
|
||||
const users = [];
|
||||
queryParams.getPredicates(key).forEach(username => {
|
||||
const user = Users.findOne({ username });
|
||||
const user = ReactiveCache.getUser({ username });
|
||||
if (user) {
|
||||
users.push(user._id);
|
||||
} else {
|
||||
|
|
|
@ -260,7 +260,7 @@ RulesHelper = {
|
|||
card.removeLabel(action.labelId);
|
||||
}
|
||||
if (action.actionType === 'addMember') {
|
||||
const memberId = Users.findOne({ username: action.username })._id;
|
||||
const memberId = ReactiveCache.getUser({ username: action.username })._id;
|
||||
card.assignMember(memberId);
|
||||
}
|
||||
if (action.actionType === 'removeMember') {
|
||||
|
@ -270,7 +270,7 @@ RulesHelper = {
|
|||
card.unassignMember(members[i]);
|
||||
}
|
||||
} else {
|
||||
const memberId = Users.findOne({ username: action.username })._id;
|
||||
const memberId = ReactiveCache.getUser({ username: action.username })._id;
|
||||
card.unassignMember(memberId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue