<commit_before>import schema from './schema.js';
import { createCollection, getDefaultResolvers } from 'meteor/vulcan:core';
import { extractVersionsFromSemver } from '../../editor/utils'
import { addUniversalFields } from '../../collectionUtils'

export const Revisions = createCollection({
  collectionName: 'Revisions',
  typeName: 'Revision',
  schema,
  resolvers: getDefaultResolvers('Revisions'),
  // mutations: getDefaultMutations('Revisions'),
});
addUniversalFields({collection: Revisions})

// Note, since we want to make sure checkAccess is a performant function, we can only check the 
// userId of the current revision for ownership. If the userId of the document the revision is on,
// and the revision itself differ (e.g. because an admin has made the edit, or a coauthor), then
// we will hide those revisions unless they are marked as post-1.0.0 releases. This is not ideal, but
// seems acceptable
Revisions.checkAccess = function (user, revision) {
  if ((user && user._id) === revision.userId) return true
  if (user.isAdmin) return true
  const { major } = extractVersionsFromSemver(revision.version)
  return major > 0
}

export default Revisions;<commit_msg>admins and sunshines can access draft-revisions<commit_after>import schema from './schema.js';
import { createCollection, getDefaultResolvers } from 'meteor/vulcan:core';
import { extractVersionsFromSemver } from '../../editor/utils'
import { addUniversalFields } from '../../collectionUtils'
import Users from 'meteor/vulcan:users';

export const Revisions = createCollection({
  collectionName: 'Revisions',
  typeName: 'Revision',
  schema,
  resolvers: getDefaultResolvers('Revisions'),
  // mutations: getDefaultMutations('Revisions'),
});
addUniversalFields({collection: Revisions})

// Note, since we want to make sure checkAccess is a performant function, we can only check the 
// userId of the current revision for ownership. If the userId of the document the revision is on,
// and the revision itself differ (e.g. because an admin has made the edit, or a coauthor), then
// we will hide those revisions unless they are marked as post-1.0.0 releases. This is not ideal, but
// seems acceptable
Revisions.checkAccess = function (user, revision) {
  if ((user && user._id) === revision.userId) return true
  if (Users.canDo(user, 'posts.view.all')) return true
  const { major } = extractVersionsFromSemver(revision.version)
  return major > 0
}

export default Revisions;
{'fraction_non_alphanumeric': 0.1075487012987013, 'fraction_numerical': 0.003246753246753247, 'mean_word_length': 4.666666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6034252', 'n_tokens_mistral': 688, 'n_tokens_neox': 677, 'n_words': 259}