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