Meteor.startup(() => { // code to run on server at startup if (Parties.find().count() === 0) { var parties = [ { 'name': 'Dubstep-Free Zone' , 'description': 'Can we please just for an evening not listen to dubstep.' , 'location': 'Palo Alto' } , { 'name': 'All dubstep all the time' , 'description': 'Get it on!' , 'location': 'Palo Alto' } , { 'name': 'Savage lounging' , 'description': 'Leisure suit required. And only fiercest manners.' , 'location': 'San Francisco' } ]; parties.forEach(function (party) { Parties.insert(party); }) } });
expect(() => Meteor.call("accounts/addressBookUpdate", "asdad", 123)).to.throw;
expect(() => Meteor.call("accounts/addressBookUpdate", getAddress(), account2._id)).to.throw;
expect(function () { return Meteor.call("accounts/addressBookAdd", "asdad", 123); }).to.throw;
expect(function () { return Meteor.call("accounts/addressBookAdd", getAddress(), account2._id); }).to.throw();
export function composer(props, onData) { const shopSub = Meteor.subscribe("MerchantShops", Reaction.getShopsForUser(["admin"])); if (!shopSub.ready()) return; const shop = Shops.findOne({ _id: Reaction.getShopId() }); if (!shop) throw new Error(`No shop found with shop ID ${Reaction.getShopId()}`); const searchPackage = Reaction.Apps({ provides: "ui-search" }); const user = Meteor.user(); let searchEnabled; let searchTemplate; let brandMedia; let shops; if (user && user.roles) { // Get all shops for which user has roles shops = Shops.find({ $and: [ { _id: { $in: Object.keys(user.roles) } }, { $or: [{ "workflow.status": "active" }, { _id: Reaction.getPrimaryShopId() }] } ] }).fetch(); } /** * @method * @summary Handle change in selected shop * @param {script} event DOM Event * @param {String} shopId - selected shopId * @since 1.5.8 * @return {void} * @private */ const handleShopSelectChange = (event, shopId) => { Reaction.setShopId(shopId); }; const isLoggedIn = !!(shop && user && !Roles.userIsInRole(user._id, "anonymous", shop._id)); if (searchPackage.length && isLoggedIn) { searchEnabled = true; searchTemplate = searchPackage[0].template; } else { searchEnabled = false; } if (shop && Array.isArray(shop.brandAssets)) { const brandAsset = shop.brandAssets.find((asset) => asset.type === "navbarBrandImage"); brandMedia = brandAsset && Media.findOneLocal(brandAsset.mediaId); } const hasProperPermission = Reaction.hasPermission("account/profile"); onData(null, { brandMedia, handleShopSelectChange, hasProperPermission, searchEnabled, searchTemplate, shop, shops, visibility: { hamburger: true, brand: true, tags: isLoggedIn, search: true, notifications: true, languages: true, currency: true, mainDropdown: true } }); }
import { Meteor } from 'meteor/meteor'; Meteor.startup(() => { // code to run on server at startup console.log(Meteor.settings.hello); });
import qrcode from 'yaqrcode'; window.qrcode = qrcode; Template.accountSecurity.helpers({ showImage() { return Template.instance().showImage.get(); }, imageData() { return Template.instance().imageData.get(); }, imageSecret() { return Template.instance().imageSecret.get(); }, isEnabled() { const user = Meteor.user(); return user && user.services && user.services.totp && user.services.totp.enabled; }, isRegistering() { return Template.instance().state.get() === 'registering'; }, isAllowed() { return settings.get('Accounts_TwoFactorAuthentication_Enabled'); }, codesRemaining() { if (Template.instance().codesRemaining.get()) { return t('You_have_n_codes_remaining', { number: Template.instance().codesRemaining.get() }); } }, });
import { compose, withProps } from "recompose"; import { registerComponent, composeWithTracker } from "@reactioncommerce/reaction-components"; import { Meteor } from "meteor/meteor"; import { Notifications } from "/lib/collections"; import { NotificationRoute } from "../components"; const handlers = { markAllAsRead(notificationList) { notificationList.map((notify) => Meteor.call("notification/markOneAsRead", notify._id)); }, markOneAsRead(id) { Meteor.call("notification/markOneAsRead", id); } }; function composer(props, onData) { if (Meteor.subscribe("Notification", Meteor.userId()).ready()) { const notificationList = Notifications.find({}, { sort: { timeSent: -1 } }).fetch(); const unread = Notifications.find({ status: "unread" }).count(); onData(null, { notificationList, unread }); } } registerComponent("NotificationRoute", NotificationRoute, [ composeWithTracker(composer), withProps(handlers) ]);
import { Meteor } from 'meteor/meteor'; Entities = new Mongo.Collection('entities'); Interactions = new Mongo.Collection('interactions'); EntityUpdates = new Mongo.Collection('entityUpdates'); // ROLES Meteor.publish('roles', function (){ return Meteor.roles.find({}); }); //For editing accounts Meteor.publish('adminAndExecUsers', function () { return Meteor.users.find({'roles': {$ne: 'entity-member'} }); // find all users that are not entity-member }); // used in HomeLayoutDataWrap Meteor.publish('myEntityData', function() { if(this.userId) { var user = Meteor.users.findOne(this.userId); try { var entity = Entities.find({_id: user.profile.entity}); if(!entity) { return this.ready(); } return Entities.find({_id: user.profile.entity}); } catch(e) { console.log("No entity found", e); } } });
import { Meteor } from 'meteor/meteor'; import { ServiceConfiguration } from 'meteor/service-configuration'; Meteor.startup(() => { const services = Meteor.settings.private.oAuth; if (services) { for (const service in services) { if (services.hasOwnProperty(service)) { ServiceConfiguration.configurations.upsert({ service }, { $set: services[service] }); } } } });
import { Meteor } from 'meteor/meteor'; import '../imports/api/tasks.js'; import '../imports/api/server/dlna.js'; Meteor.startup(() => { // code to run on server at startup });
import { Meteor } from 'meteor/meteor'; import { Mongo } from 'meteor/mongo'; import { check } from 'meteor/check'; export const Tasks = new Mongo.Collection('tasks'); if (Meteor.isServer) { // this code only runs on the server Meteor.publish('tasks', function taskPublication() { return Tasks.find(); }); } Meteor.methods = ({ 'tasks.insert'(text) { check(text, String); // Make sure user is logged in if (! this.userId) { throw new Meteor.Error('not-authorized'); } Tasks.insert({ text, createdAt: new Date(), owner: this.userId, username: Meteor.users.findOne(this.userId).emails[0].address, }); }, 'tasks.remove'(taskId) { check(taskId, String);
addChannel(slackChannelID, hasRetried = false) { logger.rocket.debug('Adding Rocket.Chat channel from Slack', slackChannelID); let slackResults = null; let isGroup = false; if (slackChannelID.charAt(0) === 'C') { slackResults = HTTP.get('https://slack.com/api/channels.info', { params: { token: this.slackBridge.apiToken, channel: slackChannelID } }); } else if (slackChannelID.charAt(0) === 'G') { slackResults = HTTP.get('https://slack.com/api/groups.info', { params: { token: this.slackBridge.apiToken, channel: slackChannelID } }); isGroup = true; } if (slackResults && slackResults.data && slackResults.data.ok === true) { const rocketChannelData = isGroup ? slackResults.data.group : slackResults.data.channel; const existingRocketRoom = RocketChat.models.Rooms.findOneByName(rocketChannelData.name); // If the room exists, make sure we have its id in importIds if (existingRocketRoom || rocketChannelData.is_general) { rocketChannelData.rocketId = rocketChannelData.is_general ? 'GENERAL' : existingRocketRoom._id; RocketChat.models.Rooms.addImportIds(rocketChannelData.rocketId, rocketChannelData.id); } else { const rocketUsers = []; for (const member of rocketChannelData.members) { if (member !== rocketChannelData.creator) { const rocketUser = this.findUser(member) || this.addUser(member); if (rocketUser && rocketUser.username) { rocketUsers.push(rocketUser.username); } } } const rocketUserCreator = rocketChannelData.creator ? this.findUser(rocketChannelData.creator) || this.addUser(rocketChannelData.creator) : null; if (!rocketUserCreator) { logger.rocket.error('Could not fetch room creator information', rocketChannelData.creator); return; } try { const rocketChannel = RocketChat.createRoom(isGroup ? 'p' : 'c', rocketChannelData.name, rocketUserCreator.username, rocketUsers); rocketChannelData.rocketId = rocketChannel.rid; } catch (e) { if (!hasRetried) { logger.rocket.debug('Error adding channel from Slack. Will retry in 1s.', e.message); // If first time trying to create channel fails, could be because of multiple messages received at the same time. Try again once after 1s. Meteor._sleepForMs(1000); return this.findChannel(slackChannelID) || this.addChannel(slackChannelID, true); } else { console.log(e.message); } } const roomUpdate = { ts: new Date(rocketChannelData.created * 1000), }; let lastSetTopic = 0; if (!_.isEmpty(rocketChannelData.topic && rocketChannelData.topic.value)) { roomUpdate.topic = rocketChannelData.topic.value; lastSetTopic = rocketChannelData.topic.last_set; } if (!_.isEmpty(rocketChannelData.purpose && rocketChannelData.purpose.value) && rocketChannelData.purpose.last_set > lastSetTopic) { roomUpdate.topic = rocketChannelData.purpose.value; } RocketChat.models.Rooms.addImportIds(rocketChannelData.rocketId, rocketChannelData.id); this.slack.addSlackChannel(rocketChannelData.rocketId, slackChannelID); } return RocketChat.models.Rooms.findOneById(rocketChannelData.rocketId); } logger.rocket.debug('Channel not added'); return; }
function(o) { return o.rsvp === 'yes' && o.user !== Meteor.userId(); });
notificationList.map((notify) => Meteor.call("notification/markOneAsRead", notify._id));
Meteor.methods({ addTask: function (text, A1, A2, A3, A4) { // Make sure the user is logged in before inserting a task if (! Meteor.userId()) { throw new Meteor.Error('not-authorized'); } Tasks.insert({ text: text, A1:A1, A2:A2, A3:A3, A4:A4, createdAt: new Date(), owner: Meteor.userId(), username: Meteor.user().username }); }, deleteTask: function (taskId) { var task = Tasks.findOne(taskId); if (task.private && task.owner !== Meteor.userId()) { // If the task is private, make sure only the owner can delete it throw new Meteor.Error('not-authorized'); } Tasks.remove(taskId); }, setChecked: function (taskId, setChecked) { var task = Tasks.findOne(taskId); if (task.private && task.owner !== Meteor.userId()) { // If the task is private, make sure only the owner can check it off throw new Meteor.Error('not-authorized'); } Tasks.update(taskId, { $set: { checked: setChecked} }); }, setChoice1: function (taskId, setToPrivate) { var task = Tasks.findOne(taskId); // Make sure only the task owner can make a task private if (task.owner !== Meteor.userId()) { throw new Meteor.Error('not-authorized'); } Tasks.update(taskId, { $set: { private: setToPrivate } }); }, setChoice2: function (taskId, setToPrivate) { var task = Tasks.findOne(taskId); // Make sure only the task owner can make a task private if (task.owner !== Meteor.userId()) { throw new Meteor.Error('not-authorized'); } Tasks.update(taskId, { $set: { choice2: setToPrivate } }); }, setChoice3: function (taskId, setToPrivate) { var task = Tasks.findOne(taskId); // Make sure only the task owner can make a task private if (task.owner !== Meteor.userId()) { throw new Meteor.Error('not-authorized'); } Tasks.update(taskId, { $set: { choice3: setToPrivate } }); }, setChoice4: function (taskId, setToPrivate) { var task = Tasks.findOne(taskId); // Make sure only the task owner can make a task private if (task.owner !== Meteor.userId()) { throw new Meteor.Error('not-authorized'); } Tasks.update(taskId, { $set: { choice4: setToPrivate } }); } });
const AddDocumentWithUserId = createContainer(() => { return { userId: Meteor.userId(), }; }, AddDocumentWithData);
import {CallPromiseMixin} from 'meteor/didericis:callpromise-mixin'; import {_} from 'meteor/erasaur:meteor-lodash'; import {moment} from 'meteor/momentjs:moment'; // Collection import {Company} from '../../../../core/imports/api/collections/company.js'; import {GroupBill} from '../../../imports/api/collections/groupBill'; // lib func import {correctFieldLabel} from '../../../imports/api/libs/correctFieldLabel'; export const groupBillReport = new ValidatedMethod({ name: 'pos.groupBillReport', mixins: [CallPromiseMixin], validate: null, run(params) { if (!this.isSimulation) { Meteor._sleepForMs(200); let selector = {}; let project = {}; let data = { title: {}, fields: [], displayFields: [], content: [{index: 'No Result'}], footer: {} }; let branch = []; let user = Meteor.users.findOne(Meteor.userId()); // console.log(user); // let date = _.trim(_.words(params.date, /[^To]+/g)); selector.status = {$in: ['active', 'closed']}; if(params.vendor && params.vendor != '') {
waitOn: function() { return [ Meteor.subscribe('userProfile', Meteor.userId()) ]; },
Meteor.methods({ unreadMessages(firstUnreadMessage, room) { const userId = Meteor.userId(); if (!userId) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'unreadMessages', }); } if (room) { const lastMessage = RocketChat.models.Messages.findVisibleByRoomId(room, { limit: 1, sort: { ts: -1 } }).fetch()[0]; if (lastMessage == null) { throw new Meteor.Error('error-action-not-allowed', 'Not allowed', { method: 'unreadMessages', action: 'Unread_messages', }); } return RocketChat.models.Subscriptions.setAsUnreadByRoomIdAndUserId(lastMessage.rid, userId, lastMessage.ts); } const originalMessage = RocketChat.models.Messages.findOneById(firstUnreadMessage._id, { fields: { u: 1, rid: 1, file: 1, ts: 1, }, }); if (originalMessage == null || userId === originalMessage.u._id) { throw new Meteor.Error('error-action-not-allowed', 'Not allowed', { method: 'unreadMessages', action: 'Unread_messages', }); } const lastSeen = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(originalMessage.rid, userId).ls; if (firstUnreadMessage.ts >= lastSeen) { return logger.connection.debug('Provided message is already marked as unread'); } logger.connection.debug(`Updating unread message of ${ originalMessage.ts } as the first unread`); return RocketChat.models.Subscriptions.setAsUnreadByRoomIdAndUserId(originalMessage.rid, userId, originalMessage.ts); }, });
Router.initPackageRoutes = (options) => { // make _initialized = false in case router is reinitialized Router._initialized = false; routerReadyDependency.changed(); Router.Reaction = options.reactionContext; Router.routes = []; const pkgs = Packages.find().fetch(); const prefix = Router.Reaction.getShopPrefix(); const routeDefinitions = []; // prefixing isnt necessary if we only have one shop // but we need to bypass the current // subscription to determine this. const shopSub = Meteor.subscribe("shopsCount"); Tracker.autorun(shopSubWaitFor => { if (shopSub.ready()) { shopSubWaitFor.stop(); // using tmeasday:publish-counts const shopCount = Counts.get("shops-count"); // Default layouts const indexLayout = ReactionLayout(options.indexRoute); const notFoundLayout = ReactionLayout({ template: "notFound" }); // Index route routeDefinitions.push({ route: "/", name: "index", options: { name: "index", ...options.indexRoute, component: indexLayout.component, structure: indexLayout.structure } }); // Not found route routeDefinitions.push({ route: "/not-found", name: "not-found", options: { name: "not-found", ...notFoundLayout.indexRoute, component: notFoundLayout.component, structure: notFoundLayout.structure } }); // get package registry route configurations for (const pkg of pkgs) { const newRoutes = []; // pkg registry if (pkg.registry && pkg.enabled) { const registry = Array.from(pkg.registry); for (const registryItem of registry) { // registryItems if (registryItem.route) { const { meta, route, permissions, template, layout, workflow } = registryItem; // get registry route name const name = getRegistryRouteName(pkg.name, registryItem); // define new route // we could allow the options to be passed in the registry if we need to be more flexible const reactionLayout = ReactionLayout({ template, workflow, layout, permissions }); const newRouteConfig = { route, name, options: { meta, name, template, layout, triggersEnter: Router.Hooks.get("onEnter", name), triggersExit: Router.Hooks.get("onExit", name), component: reactionLayout.component, structure: reactionLayout.structure } }; // push new routes newRoutes.push(newRouteConfig); } // end registryItems } // end package.registry // // add group and routes to routing table // for (const route of newRoutes) { // allow overriding of prefix in route definitions // define an "absolute" url by excluding "/" route.group = {}; if (route.route.substring(0, 1) !== "/") { route.route = "/" + route.route; route.group.prefix = ""; } else if (shopCount <= 1) { route.group.prefix = ""; } else { route.group.prefix = prefix; route.route = `${prefix}${route.route}`; } routeDefinitions.push(route); } } } // end package loop // Uniq-ify routes // Take all route definitions in the order that were received, and reverse it. // Routes defined later, like in the case of custom routes will then have a // higher precedence. Any duplicates after the first instance will be removed. // // TODO: In the future, sort by priority // TODO: Allow duplicated routes with a prefix / suffix / flag const uniqRoutes = uniqBy(routeDefinitions.reverse(), "route"); const reactRouterRoutes = uniqRoutes.map((route, index) => { return ( <Route key={`${route.name}-${index}`} path={route.route} exact={true} render={route.options.component} /> ); }); Router._initialized = true; Router.reactComponents = reactRouterRoutes; Router._routes = uniqRoutes; routerReadyDependency.changed(); } }); };
before(function () { this.timeout(10000); Meteor._sleepForMs(7000); });
import { Meteor } from 'meteor/meteor'; import { Apps } from '../imports/collections/apps'; Meteor.startup(() => { Apps._ensureIndex({ "app_name": "text" }); // publications Meteor.publish("singleApp", function(app_id) { let app = Apps.find({app_id : app_id}); return app; }); Meteor.publish('apps', function(options) { return Apps.find({}, options); }); Meteor.publish('appsByCategory', function(category, options) { return Apps.find({category : category}, options); }); Meteor.publish("search", function(app_name) { return Apps.find({ app_name : { $regex : ".*" + app_name + ".*"} }); }); });
expect(() => Meteor.call("accounts/addressBookUpdate")).to.throw;
import { i18next, Reaction } from "/client/api"; import { Accounts } from "/lib/collections"; import UpdateEmail from "../components/updateEmail"; const handlers = { handleUpdateEmail({ newEmail, oldEmail }, callback) { Meteor.call("accounts/validation/email", newEmail, false, (result, error) => { if (error.error) { Alerts.toast(i18next.t("accountsUI.error.invalidEmail", { err: error.reason }), "error"); return callback(); } Meteor.call("accounts/updateEmailAddress", newEmail, (err) => { if (err) { Alerts.toast(i18next.t("accountsUI.error.emailAlreadyExists", { err: err.message }), "error"); return callback(); } // Email changed, remove original email Meteor.call("accounts/removeEmailAddress", oldEmail, () => { Alerts.toast(i18next.t("accountsUI.info.emailUpdated"), "success"); return callback(); }); }); }); } }; const composer = (props, onData) => { const user = Accounts.findOne(Reaction.getUserId()); const email = user.emails.length > 0 ? user.emails[0].address : "";
expect(function () { return Meteor.call( "accounts/addressBookUpdate", () => { expect(true).to.be.true; } ); }).to.not.throw;
import {Meteor} from 'meteor/meteor'; import {check} from 'meteor/check'; import {Events} from '/imports/api/Events.js'; Meteor.methods({ 'events.add'(event) { check(event, Object); Events.insert( { name: event.name, description: event.description, date: event.date, createdAt: new Date(), counter: 0, }); }, });
expect(() => Meteor.call("accounts/addressBookRemove", null)).to.throw;
import '../imports/api/email'; import '../imports/api/messages'; import '../imports/api/needs'; import '../imports/api/offers'; import '../imports/api/phone_numbers'; import '../imports/api/services'; import '../imports/api/twilio'; import '../imports/api/users'; import '../imports/api/weather'; import '../imports/startup/simpl-schema-configuration.js'; Meteor.startup(() => { if (Meteor.settings.MAIL_URL) { process.env.MAIL_URL = Meteor.settings.MAIL_URL; } if (Meteor.settings.DARKSKY_KEY) { process.env.DARKSKY_KEY = Meteor.settings.DARKSKY_KEY; } if (Meteor.settings.TWILIO_NUMBER) { process.env.TWILIO_NUMBER = Meteor.settings.TWILIO_NUMBER; } if (Meteor.settings.TWILIO_ACCOUNT_SID) { process.env.TWILIO_ACCOUNT_SID = Meteor.settings.TWILIO_ACCOUNT_SID; } if (Meteor.settings.TWILIO_AUTH_TOKEN) { process.env.TWILIO_AUTH_TOKEN = Meteor.settings.TWILIO_AUTH_TOKEN; } });