2016-12-12 10:24:34 +09:00
|
|
|
|
// import { Callbacks } from 'meteor/nova:core';
|
2016-12-09 09:11:20 +01:00
|
|
|
|
// import Telescope from 'meteor/nova:lib';
|
|
|
|
|
// import Users from './collection.js';
|
|
|
|
|
//
|
|
|
|
|
// /*
|
|
|
|
|
// var completeUserProfile = function (userId, modifier, user) {
|
|
|
|
|
//
|
|
|
|
|
// Users.update(userId, modifier);
|
|
|
|
|
//
|
2016-12-12 10:24:34 +09:00
|
|
|
|
// Callbacks.runAsync("users.profileCompleted.async", Users.findOne(userId));
|
2016-12-09 09:11:20 +01:00
|
|
|
|
//
|
|
|
|
|
// return Users.findOne(userId);
|
|
|
|
|
//
|
|
|
|
|
// };
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// Users.methods = {};
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * @summary Edit a user in the database
|
|
|
|
|
// * @param {string} userId – the ID of the user being edited
|
|
|
|
|
// * @param {Object} modifier – the modifier object
|
|
|
|
|
// * @param {Object} user - the current user object
|
|
|
|
|
// */
|
|
|
|
|
// Users.methods.edit = (userId, modifier, user) => {
|
|
|
|
|
//
|
|
|
|
|
// if (typeof user === "undefined") {
|
|
|
|
|
// user = Users.findOne(userId);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // ------------------------------ Callbacks ------------------------------ //
|
|
|
|
|
//
|
2016-12-12 10:24:34 +09:00
|
|
|
|
// modifier = Callbacks.run("users.edit.sync", modifier, user);
|
2016-12-09 09:11:20 +01:00
|
|
|
|
//
|
|
|
|
|
// // ------------------------------ Update ------------------------------ //
|
|
|
|
|
//
|
|
|
|
|
// Users.update(userId, modifier);
|
|
|
|
|
//
|
|
|
|
|
// // ------------------------------ Callbacks ------------------------------ //
|
|
|
|
|
//
|
2016-12-12 10:24:34 +09:00
|
|
|
|
// Callbacks.runAsync("users.edit.async", Users.findOne(userId), user);
|
2016-12-09 09:11:20 +01:00
|
|
|
|
//
|
|
|
|
|
// // ------------------------------ After Update ------------------------------ //
|
|
|
|
|
// return Users.findOne(userId);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Users.methods.setSetting = (userId, settingName, value) => {
|
|
|
|
|
// // all users settings should begin with the prexi __: user.__setting namespace, so add "__" if needed
|
|
|
|
|
// var field = settingName.slice(0,2) === "__" ? settingName : "__" + settingName;
|
|
|
|
|
//
|
|
|
|
|
// var modifier = {$set: {}};
|
|
|
|
|
// modifier.$set[field] = value;
|
|
|
|
|
//
|
|
|
|
|
// Users.update(userId, modifier);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Users.methods.addGroup = (userId, groupName) => {
|
|
|
|
|
// Users.update(userId, {$push: {"__groups": groupName}});
|
|
|
|
|
// };
|
|
|
|
|
//
|
|
|
|
|
// Users.methods.removeGroup = (userId, groupName) => {
|
|
|
|
|
// Users.update(userId, {$pull: {"__groups": groupName}});
|
|
|
|
|
// };
|
|
|
|
|
//
|
|
|
|
|
// Meteor.methods({
|
|
|
|
|
// 'users.edit'(userId, modifier) {
|
|
|
|
|
//
|
|
|
|
|
// // checking might be redundant because SimpleSchema already enforces the schema, but you never know
|
|
|
|
|
// check(modifier, Match.OneOf({$set: Users.simpleSchema()}, {$unset: Object}, {$set: Users.simpleSchema(), $unset: Object}));
|
|
|
|
|
// check(userId, String);
|
|
|
|
|
//
|
|
|
|
|
// var currentUser = Meteor.user(),
|
|
|
|
|
// user = Users.findOne(userId),
|
|
|
|
|
// schema = Users.simpleSchema()._schema;
|
|
|
|
|
//
|
|
|
|
|
// // ------------------------------ Checks ------------------------------ //
|
|
|
|
|
//
|
|
|
|
|
// // check that user can edit document
|
|
|
|
|
// if (!user || !Users.canEdit(currentUser, user)) {
|
|
|
|
|
// throw new Meteor.Error(601, 'sorry_you_cannot_edit_this_user');
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // go over each field and throw an error if it's not editable
|
|
|
|
|
// // loop over each operation ($set, $unset, etc.)
|
|
|
|
|
// _.each(modifier, function (operation) {
|
|
|
|
|
// // loop over each property being operated on
|
|
|
|
|
// _.keys(operation).forEach(function (fieldName) {
|
|
|
|
|
//
|
|
|
|
|
// var field = schema[fieldName];
|
|
|
|
|
// if (!Users.canEditField(currentUser, field, user)) {
|
|
|
|
|
// throw new Meteor.Error("disallowed_property", 'disallowed_property_detected' + ": " + fieldName);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// });
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// return Users.methods.edit(userId, modifier, user);
|
|
|
|
|
//
|
|
|
|
|
// },
|
|
|
|
|
//
|
|
|
|
|
// 'users.remove'(userId, options) {
|
|
|
|
|
//
|
|
|
|
|
// // do the user which to delete his account or another user?
|
|
|
|
|
// const actionType = this.userId === userId ? "own" : "all";
|
|
|
|
|
//
|
|
|
|
|
// if (Users.canDo(Meteor.user(), `users.remove.${actionType}`)) {
|
|
|
|
|
//
|
|
|
|
|
// const user = Users.findOne(userId);
|
|
|
|
|
//
|
|
|
|
|
// Users.remove(userId);
|
|
|
|
|
//
|
2016-12-12 10:24:34 +09:00
|
|
|
|
// Callbacks.runAsync("users.remove.async", user, options);
|
2016-12-09 09:11:20 +01:00
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// },
|
|
|
|
|
//
|
|
|
|
|
// 'users.setSetting'(userId, settingName, value) {
|
|
|
|
|
//
|
|
|
|
|
// check(userId, String);
|
|
|
|
|
// check(settingName, String);
|
|
|
|
|
// check(value, Match.OneOf(String, Number, Boolean));
|
|
|
|
|
//
|
|
|
|
|
// var currentUser = Meteor.user(),
|
|
|
|
|
// user = Users.findOne(userId);
|
|
|
|
|
//
|
|
|
|
|
// // check that user can edit document
|
|
|
|
|
// if (!user || !Users.canEdit(currentUser, user)) {
|
|
|
|
|
// throw new Meteor.Error(601, 'sorry_you_cannot_edit_this_user');
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Users.methods.setSetting(userId, settingName, value);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// });
|