Move every Meteor.user() to the ReactiveCache

This commit is contained in:
Martin Filser 2023-01-16 23:00:10 +01:00
parent 6e1ef3d94a
commit 5e3a9dc059
42 changed files with 211 additions and 252 deletions

View file

@ -739,17 +739,12 @@ Boards.helpers({
},
lists() {
//currentUser = Meteor.user();
//if (currentUser) {
// enabled = Meteor.user().hasSortBy();
//}
//return enabled ? this.newestLists() : this.draggableLists();
return this.draggableLists();
},
newestLists() {
// sorted lists from newest to the oldest, by its creation date or its cards' last modification date
const value = Meteor.user()._getListSortBy();
const value = ReactiveCache.getCurrentUser()._getListSortBy();
const sortKey = { starred: -1, [value[0]]: value[1] }; // [["starred",-1],value];
return Lists.find(
{
@ -1299,9 +1294,10 @@ Boards.mutations({
},
setBackgroundImageURL(backgroundImageURL) {
if(Meteor.user().isBoardAdmin()) {
const currentUser = ReactiveCache.getCurrentUser();
if(currentUser.isBoardAdmin()) {
return { $set: { backgroundImageURL } };
} else if (Meteor.user().isAdmin()) {
} else if (currentUser.isAdmin()) {
return { $set: { backgroundImageURL } };
} else {
return false;

View file

@ -103,7 +103,7 @@ Integrations.Const = {
const permissionHelper = {
allow(userId, doc) {
const user = ReactiveCache.getUser(userId);
const isAdmin = user && Meteor.user().isAdmin;
const isAdmin = user && ReactiveCache.getCurrentUser().isAdmin;
return isAdmin || allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
},
};

View file

@ -118,7 +118,7 @@ if (Meteor.isServer) {
orgWebsite,
orgIsActive,
) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(orgDisplayName, String);
check(orgDesc, String);
check(orgShortName, String);
@ -166,7 +166,7 @@ if (Meteor.isServer) {
}
},
setOrgDisplayName(org, orgDisplayName) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(org, Object);
check(orgDisplayName, String);
Org.update(org, {
@ -177,7 +177,7 @@ if (Meteor.isServer) {
},
setOrgDesc(org, orgDesc) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(org, Object);
check(orgDesc, String);
Org.update(org, {
@ -187,7 +187,7 @@ if (Meteor.isServer) {
},
setOrgShortName(org, orgShortName) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(org, Object);
check(orgShortName, String);
Org.update(org, {
@ -197,7 +197,7 @@ if (Meteor.isServer) {
},
setOrgIsActive(org, orgIsActive) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(org, Object);
check(orgIsActive, Boolean);
Org.update(org, {
@ -238,7 +238,7 @@ if (Meteor.isServer) {
orgWebsite,
orgIsActive,
) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(org, Object);
check(orgDisplayName, String);
check(orgDesc, String);

View file

@ -396,7 +396,7 @@ if (Meteor.isServer) {
if (!Meteor.userId()) {
throw new Meteor.Error('invalid-user');
}
const user = Meteor.user();
const user = ReactiveCache.getCurrentUser();
if (!user.emails || !user.emails[0] || !user.emails[0].address) {
throw new Meteor.Error('email-invalid');
}

View file

@ -198,11 +198,6 @@ Swimlanes.helpers({
},
lists() {
//currentUser = Meteor.user();
//if (currentUser) {
// enabled = Meteor.user().hasSortBy();
//}
//return enabled ? this.newestLists() : this.draggableLists();
return this.draggableLists();
},
newestLists() {

View file

@ -116,7 +116,7 @@ if (Meteor.isServer) {
teamWebsite,
teamIsActive,
) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(teamDisplayName, String);
check(teamDesc, String);
check(teamShortName, String);
@ -163,7 +163,7 @@ if (Meteor.isServer) {
}
},
setTeamDisplayName(team, teamDisplayName) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(team, Object);
check(teamDisplayName, String);
Team.update(team, {
@ -174,7 +174,7 @@ if (Meteor.isServer) {
},
setTeamDesc(team, teamDesc) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(team, Object);
check(teamDesc, String);
Team.update(team, {
@ -184,7 +184,7 @@ if (Meteor.isServer) {
},
setTeamShortName(team, teamShortName) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(team, Object);
check(teamShortName, String);
Team.update(team, {
@ -194,7 +194,7 @@ if (Meteor.isServer) {
},
setTeamIsActive(team, teamIsActive) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(team, Object);
check(teamIsActive, Boolean);
Team.update(team, {
@ -235,7 +235,7 @@ if (Meteor.isServer) {
teamWebsite,
teamIsActive,
) {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
check(team, Object);
check(teamDisplayName, String);
check(teamDesc, String);

View file

@ -503,8 +503,8 @@ Users.attachSchema(
Users.allow({
update(userId, doc) {
const user = ReactiveCache.getUser(userId);
if ((user && user.isAdmin) || (Meteor.user() && Meteor.user().isAdmin))
const user = ReactiveCache.getUser(userId) || ReactiveCache.getCurrentUser();
if (user?.isAdmin)
return true;
if (!user) {
return false;
@ -540,7 +540,7 @@ Users.allow({
// Non-Admin users can not change to Admin
Users.deny({
update(userId, board, fieldNames) {
return _.contains(fieldNames, 'isAdmin') && !Meteor.user().isAdmin;
return _.contains(fieldNames, 'isAdmin') && !ReactiveCache.getCurrentUser().isAdmin;
},
fetch: [],
});
@ -1140,50 +1140,50 @@ Users.mutations({
Meteor.methods({
setListSortBy(value) {
check(value, String);
Meteor.user().setListSortBy(value);
ReactiveCache.getCurrentUser().setListSortBy(value);
},
toggleDesktopDragHandles() {
const user = Meteor.user();
const user = ReactiveCache.getCurrentUser();
user.toggleDesktopHandles(user.hasShowDesktopDragHandles());
},
toggleHideCheckedItems() {
const user = Meteor.user();
const user = ReactiveCache.getCurrentUser();
user.toggleHideCheckedItems();
},
toggleSystemMessages() {
const user = Meteor.user();
const user = ReactiveCache.getCurrentUser();
user.toggleSystem(user.hasHiddenSystemMessages());
},
toggleCustomFieldsGrid() {
const user = Meteor.user();
const user = ReactiveCache.getCurrentUser();
user.toggleFieldsGrid(user.hasCustomFieldsGrid());
},
toggleCardMaximized() {
const user = Meteor.user();
const user = ReactiveCache.getCurrentUser();
user.toggleCardMaximized(user.hasCardMaximized());
},
toggleMinicardLabelText() {
const user = Meteor.user();
const user = ReactiveCache.getCurrentUser();
user.toggleLabelText(user.hasHiddenMinicardLabelText());
},
toggleRescueCardDescription() {
const user = Meteor.user();
const user = ReactiveCache.getCurrentUser();
user.toggleRescueCardDescription(user.hasRescuedCardDescription());
},
changeLimitToShowCardsCount(limit) {
check(limit, Number);
Meteor.user().setShowCardsCountAt(limit);
ReactiveCache.getCurrentUser().setShowCardsCountAt(limit);
},
changeStartDayOfWeek(startDay) {
check(startDay, Number);
Meteor.user().setStartDayOfWeek(startDay);
ReactiveCache.getCurrentUser().setStartDayOfWeek(startDay);
},
});
if (Meteor.isServer) {
Meteor.methods({
setAllUsersHideSystemMessages() {
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
// If setting is missing, add it
Users.update(
{
@ -1241,7 +1241,7 @@ if (Meteor.isServer) {
check(importUsernames, Array);
check(userOrgsArray, Array);
check(userTeamsArray, Array);
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
const nUsersWithUsername = Users.find({
username,
}).count();
@ -1283,7 +1283,7 @@ if (Meteor.isServer) {
setUsername(username, userId) {
check(username, String);
check(userId, String);
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
const nUsersWithUsername = Users.find({
username,
}).count();
@ -1301,7 +1301,7 @@ if (Meteor.isServer) {
setEmail(email, userId) {
check(email, String);
check(username, String);
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
if (Array.isArray(email)) {
email = email.shift();
}
@ -1335,7 +1335,7 @@ if (Meteor.isServer) {
check(username, String);
check(email, String);
check(userId, String);
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
if (Array.isArray(email)) {
email = email.shift();
}
@ -1346,17 +1346,15 @@ if (Meteor.isServer) {
setPassword(newPassword, userId) {
check(userId, String);
check(newPassword, String);
if (Meteor.user() && Meteor.user().isAdmin) {
if (Meteor.user().isAdmin) {
Accounts.setPassword(userId, newPassword);
}
if (ReactiveCache.getCurrentUser()?.isAdmin) {
Accounts.setPassword(userId, newPassword);
}
},
setEmailVerified(email, verified, userId) {
check(email, String);
check(verified, Boolean);
check(userId, String);
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
Users.update(userId, {
$set: {
emails: [
@ -1372,7 +1370,7 @@ if (Meteor.isServer) {
setInitials(initials, userId) {
check(initials, String);
check(userId, String);
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
Users.update(userId, {
$set: {
'profile.initials': initials,
@ -1385,7 +1383,7 @@ if (Meteor.isServer) {
check(username, String);
check(boardId, String);
const inviter = Meteor.user();
const inviter = ReactiveCache.getCurrentUser();
const board = ReactiveCache.getBoard(boardId);
const allowInvite =
inviter &&
@ -1526,11 +1524,11 @@ if (Meteor.isServer) {
if (!Meteor.users.findOne(userId))
throw new Meteor.Error(404, 'User not found');
if (!Meteor.user().isAdmin)
if (!ReactiveCache.getCurrentUser().isAdmin)
throw new Meteor.Error(403, 'Permission denied');
ImpersonatedUsers.insert({
adminId: Meteor.user()._id,
adminId: ReactiveCache.getCurrentUser()._id,
userId: userId,
reason: 'clickedImpersonate',
});
@ -1546,7 +1544,7 @@ if (Meteor.isServer) {
setUsersTeamsTeamDisplayName(teamId, teamDisplayName) {
check(teamId, String);
check(teamDisplayName, String);
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
Users.find({
teams: {
$elemMatch: { teamId: teamId },
@ -1571,7 +1569,7 @@ if (Meteor.isServer) {
setUsersOrgsOrgDisplayName(orgId, orgDisplayName) {
check(orgId, String);
check(orgDisplayName, String);
if (Meteor.user() && Meteor.user().isAdmin) {
if (ReactiveCache.getCurrentUser()?.isAdmin) {
Users.find({
orgs: {
$elemMatch: { orgId: orgId },