<commit_before>/**
 * TODO - this is setting createdBy, not owner.
 * The comment below, and the name of this file/function is confusing to me
 * Ensure that the 'owner' property of an Object is set upon creation.
 */
module.exports = function OwnerPolicy (req, res, next) {
  //sails.log('OwnerPolicy()');
  if (!req.user || !req.user.id) {
    req.logout();
    return res.send(500, new Error('req.user is not set'));
  }

  /*
  sails.log('OwnerPolicy user', req.user);
  sails.log('OwnerPolicy method', req.method);
  sails.log('OwnerPolicy req.body', req.body);
  */

  if (req.options.modelDefinition.autoCreatedBy === false) {
    // sails.log('OwnerPolicy hasOwnershipPolicy: false');
    return next();
  }

  if ('POST' == req.method) {
    //req.body || (req.body = { });
    req.body.createdBy = req.user.id;
  }

  //sails.log('OwnerPolicy req.model', req.model);
  next();
};<commit_msg>changed owner policy to create owner attribute when new records are created. This fixes the owner relation permission problem<commit_after>/**
 * TODO - this is setting createdBy, not owner.
 * The comment below, and the name of this file/function is confusing to me
 * Ensure that the 'owner' property of an Object is set upon creation.
 */
module.exports = function OwnerPolicy (req, res, next) {
  //sails.log('OwnerPolicy()');
  if (!req.user || !req.user.id) {
    req.logout();
    return res.send(500, new Error('req.user is not set'));
  }

  /*
  sails.log('OwnerPolicy user', req.user);
  sails.log('OwnerPolicy method', req.method);
  sails.log('OwnerPolicy req.body', req.body);
  */

  if (req.options.modelDefinition.autoCreatedBy === false) {
    // sails.log('OwnerPolicy hasOwnershipPolicy: false');
    return next();
  }

  if ('POST' == req.method) {
    //req.body || (req.body = { });
    req.body.createdBy = req.user.id;
    req.body.owner = req.user.id;
  }

  //sails.log('OwnerPolicy req.model', req.model);
  next();
};
{'fraction_non_alphanumeric': 0.16273100616016428, 'fraction_numerical': 0.003080082135523614, 'mean_word_length': 3.360178970917226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5870832', 'n_tokens_mistral': 641, 'n_tokens_neox': 625, 'n_words': 178}