Skip to content

Commit

Permalink
M3 migration (#866)
Browse files Browse the repository at this point in the history
* refactor(Meteor 3): 👽 Migrate collections files to Meteor 3

* style: format code with clang-format

* style: format code with prettier

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
bubonicfred and restyled-commits authored Jun 16, 2024
1 parent ca732cc commit 0876091
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 76 deletions.
32 changes: 17 additions & 15 deletions imports/collections/broadcastmessage_private.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ if (Meteor.isServer) {

// #Security: Admin sees all messages, active & inactive
// and even messages dismissed by herself!
Meteor.publish("broadcastmessageAdmin", function () {
Meteor.publish("broadcastmessageAdmin", async function () {
if (this.userId) {
const usr = Meteor.users.findOne(this.userId);
const usr = await Meteor.users.findOneAsync(this.userId);
if (usr.isAdmin) {
return BroadcastMessageSchema.find({});
}
Expand All @@ -28,26 +28,28 @@ if (Meteor.isServer) {
}

Meteor.methods({
"broadcastmessage.dismiss"() {
async "broadcastmessage.dismiss"() {
if (!Meteor.userId()) {
return;
}
console.log(`Dismissing BroadcastMessages for user: ${Meteor.userId()}`);

BroadcastMessageSchema.find({ isActive: true }).forEach((msg) => {
BroadcastMessageSchema.update(
{ _id: msg._id },
{ $addToSet: { dismissForUserIDs: Meteor.userId() } },
);
});
await BroadcastMessageSchema.find({ isActive: true }).forEachAsync(
(msg) => {
BroadcastMessageSchema.update(
{ _id: msg._id },
{ $addToSet: { dismissForUserIDs: Meteor.userId() } },
);
},
);
},

"broadcastmessage.show"(message, active = true) {
async "broadcastmessage.show"(message, active = true) {
if (!Meteor.userId()) {
return;
}
// #Security: Only admin may broadcast messages
if (!Meteor.user().isAdmin) {
if (!(await Meteor.userAsync()).isAdmin) {
throw new Meteor.Error("Cannot broadcast message", "You are not admin.");
}
if (!message) {
Expand All @@ -65,26 +67,26 @@ Meteor.methods({
return id;
},

"broadcastmessage.remove"(messageId) {
async "broadcastmessage.remove"(messageId) {
console.log(`broadcastmessage.remove: ${messageId}`);
if (!Meteor.userId()) {
return;
}
// #Security: Only admin may remove messages
if (!Meteor.user().isAdmin) {
if (!(await Meteor.userAsync()).isAdmin) {
throw new Meteor.Error("Cannot remove message", "You are not admin.");
}

BroadcastMessageSchema.remove(messageId);
},

"broadcastmessage.toggleActive"(messageId) {
async "broadcastmessage.toggleActive"(messageId) {
console.log(`broadcastmessage.toggleActive: ${messageId}`);
if (!Meteor.userId()) {
return;
}
// #Security: Only admin may remove messages
if (!Meteor.user().isAdmin) {
if (!(await Meteor.userAsync()).isAdmin) {
throw new Meteor.Error("Cannot remove message", "You are not admin.");
}

Expand Down
12 changes: 8 additions & 4 deletions imports/collections/documentgeneration_private.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export const DocumentsCollection = new FilesCollection({
const ur = new UserRoles(this.userId);
if (!ur.hasViewRoleFor(file.meta.meetingSeriesId)) {
console.log(
`Protocol download prohibited. User has no view role for meeting series: ${file.meta.meetingSeriesId}`,
`Protocol download prohibited. User has no view role for meeting series: ${
file.meta.meetingSeriesId
}`,
);
return false;
}
Expand Down Expand Up @@ -159,7 +161,7 @@ Meteor.methods({
return tmplRenderer.render();
},

"documentgeneration.createAndStoreFile"(minutesId) {
async "documentgeneration.createAndStoreFile"(minutesId) {
if (Meteor.isClient) {
return;
}
Expand Down Expand Up @@ -236,13 +238,15 @@ Meteor.methods({
if (!storeFileFunction) {
throw new Meteor.Error(
"Cannot create protocol",
`The protocol could not be created since the format assigned in the settings.json is not supported: ${Meteor.settings.public.docGeneration.format}`,
`The protocol could not be created since the format assigned in the settings.json is not supported: ${
Meteor.settings.public.docGeneration.format
}`,
);
}

// generate and store protocol
try {
const htmldata = Meteor.call(
const htmldata = await Meteor.callAsync(
"documentgeneration.createHTML",
minutesObj._id,
); // this one will run synchronous
Expand Down
29 changes: 19 additions & 10 deletions imports/collections/meetingseries_private.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { formatDateISO8601 } from "/imports/helpers/date";
import { Roles } from "meteor/alanning:roles";
import { check } from "meteor/check";
import { Meteor } from "meteor/meteor";
import { Random } from "meteor/random";
import { check } from "meteor/check";
import { MeetingSeriesSchema } from "./meetingseries.schema";
import { Roles } from "meteor/alanning:roles";
import { UserRoles } from "./../userroles";

import { GlobalSettings } from "../config/GlobalSettings";
import { formatDateISO8601 } from "/imports/helpers/date";
import { RoleChangeMailHandler } from "../mail/RoleChangeMailHandler";

import { UserRoles } from "./../userroles";
import { MeetingSeriesSchema } from "./meetingseries.schema";

if (Meteor.isServer) {
// this will publish a light-weighted overview of the meeting series, necessary for the meeting series list
// this will publish a light-weighted overview of the meeting series,
// necessary for the meeting series list
Meteor.publish("meetingSeriesOverview", function meetingSeriesPublication() {
return MeetingSeriesSchema.find(
{ visibleFor: { $in: [this.userId] } },
Expand All @@ -27,7 +30,7 @@ if (Meteor.isServer) {
);
});

//this will publish the full information for a single meeting series
// this will publish the full information for a single meeting series
Meteor.publish(
"meetingSeriesDetails",
function meetingSeriesPublication(meetingSeriesId) {
Expand Down Expand Up @@ -57,7 +60,8 @@ Meteor.methods({
);
}

// the user should not be able to define the date when this series was create - or should he?
// the user should not be able to define the date when this series was
// create - or should he?
// -> so we overwrite this field if it was set previously
const currentDate = new Date();
doc.createdAt = currentDate;
Expand Down Expand Up @@ -151,7 +155,12 @@ Meteor.methods({
}
},

"meetingseries.sendRoleChange"(userId, oldRole, newRole, meetingSeriesId) {
async "meetingseries.sendRoleChange"(
userId,
oldRole,
newRole,
meetingSeriesId,
) {
// Make sure the user is logged in before trying to send mails
if (!Meteor.userId()) {
throw new Meteor.Error("not-authorized");
Expand All @@ -175,7 +184,7 @@ Meteor.methods({
userId,
oldRole,
newRole,
Meteor.user(),
await Meteor.userAsync(),
meetingSeriesId,
);
roleChangeMailHandler.send();
Expand Down
20 changes: 10 additions & 10 deletions imports/collections/minutes_private.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if (Meteor.isServer) {
}

Meteor.methods({
"minutes.sendAgenda"(id) {
async "minutes.sendAgenda"(id) {
check(id, String);
// Make sure the user is logged in before changing collections
if (!Meteor.userId()) {
Expand All @@ -72,7 +72,7 @@ Meteor.methods({
}

if (!Meteor.isClient) {
const emails = Meteor.user().emails;
const emails = (await Meteor.userAsync()).emails;
const senderEmail =
emails && emails.length > 0
? emails[0].address
Expand Down Expand Up @@ -156,7 +156,7 @@ Meteor.methods({
* @param doc
* @returns {*|any}
*/
"minutes.updateTopic"(topicId, doc) {
async "minutes.updateTopic"(topicId, doc) {
check(topicId, String);
console.log(`updateTopic: ${topicId}`);

Expand All @@ -169,7 +169,7 @@ Meteor.methods({
}

doc.updatedAt = new Date();
doc.updatedBy = User.profileNameWithFallback(Meteor.user());
doc.updatedBy = User.profileNameWithFallback(await Meteor.userAsync());

const modifierDoc = {};
for (const property in doc) {
Expand Down Expand Up @@ -200,7 +200,7 @@ Meteor.methods({
);
},

"minutes.addTopic"(minutesId, doc, insertPlacementTop) {
async "minutes.addTopic"(minutesId, doc, insertPlacementTop) {
check(minutesId, String);
console.log(`addTopic to minute: ${minutesId}`);

Expand All @@ -226,9 +226,9 @@ Meteor.methods({

doc.createdInMinute = minutesId;
doc.createdAt = new Date();
doc.createdBy = User.profileNameWithFallback(Meteor.user());
doc.createdBy = User.profileNameWithFallback(await Meteor.userAsync());
doc.updatedAt = new Date();
doc.updatedBy = User.profileNameWithFallback(Meteor.user());
doc.updatedBy = User.profileNameWithFallback(await Meteor.userAsync());

const topicModifier = {
topics: {
Expand Down Expand Up @@ -317,7 +317,7 @@ Meteor.methods({
}
},

responsiblesSearch(partialName, participants) {
async responsiblesSearch(partialName, participants) {
check(partialName, String);
const results_participants = []; // get all the participants for the minute
const foundPartipantsNames = [];
Expand All @@ -344,14 +344,14 @@ Meteor.methods({
searchFields = { _id: 1, username: 1, "profile.name": 1 };
}

let results_otherUser = Meteor.users
let results_otherUser = await Meteor.users
.find(searchSettings, {
limit: 10 + results_participants.length, // we want to show 10 "Other user"
// as it is not known, if a user a participant or not -> get
// 10+participants
fields: searchFields,
})
.fetch();
.fetchAsync();

results_otherUser = results_otherUser.filter((user) => {
// remove duplicates
Expand Down
12 changes: 6 additions & 6 deletions imports/collections/userroles_private.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { UserRoles } from "../userroles";
if (Meteor.isServer) {
// #Security: first reset all admins, then set "isAdmin:true" for IDs in
// settings.json
Meteor.users.update(
await Meteor.users.updateAsync(
{ isAdmin: true },
{ $unset: { isAdmin: false } },
{ multi: true },
Expand All @@ -16,15 +16,15 @@ if (Meteor.isServer) {
const adminIDs = GlobalSettings.getAdminIDs();
if (adminIDs.length > 0) {
// set admins
Meteor.users.update(
await Meteor.users.updateAsync(
{ _id: { $in: adminIDs } },
{ $set: { isAdmin: true } },
{ multi: true },
);

console.log("*** Admin IDs:");
adminIDs.forEach((id) => {
const user = Meteor.users.findOne(id);
adminIDs.forEach(async (id) => {
const user = await Meteor.users.findOneAsync(id);
if (user) {
console.log(` ${user._id}: ${user.username}`);
} else {
Expand Down Expand Up @@ -63,9 +63,9 @@ if (Meteor.isServer) {
});

// #Security: Publish all user fields only to admin user
Meteor.publish("userAdmin", function () {
Meteor.publish("userAdmin", async function () {
if (this.userId) {
const usr = Meteor.users.findOne(this.userId);
const usr = await Meteor.users.findOneAsync(this.userId);
if (usr.isAdmin) {
return Meteor.users.find({});
}
Expand Down
Loading

0 comments on commit 0876091

Please sign in to comment.