<commit_before>// Tickets Publications

Meteor.smartPublish("allActiveTickets", function() {
  // Note the smartPublish: we use this to return multiple
  // cursors of the same collection.
  var activeQueues = Queues.find({"status": {$nin: ["done", "cancelled"]}}).fetch();
  var activeTickets = [];

  _.each(activeQueues, function(queue) {
    var queueId = queue._id;
    var isTA = false;
    if(this.userId)
      isTA = authorized.ta(this.userId, queue.course);

    var tickets = Tickets.find({
      queueId: queueId,
      status: {$in: ["open", "missing"]}
    }, {
      fields: {
        question: isTA,
        notify: isTA,
        ta: isTA,
        flag: isTA,
        "notify.email": false,
        "notify.phone": false,
        "notify.carrier": false
      }
    });

    activeTickets.push(tickets);
  });

  return activeTickets;
});

Meteor.publish("activeTickets", function(queueId) {
  var queue = Queues.findOne({_id: queueId});
  if(!queue) return;

  // Hide fields for non-TAs
  var projection = {
    "fields": {
      "notify.email": false,
      "notify.phone": false,
      "notify.carrier": false
    }
  };

  var isTA = false;
  if(this.userId) {
    isTA = authorized.ta(this.userId, queue.course);
  }

  if(!isTA) {
    _.extend(projection["fields"], {
      question: false,
      notify: false,
      ta: false,
      flag: false
    });
  }

  return Tickets.find({
    queueId: queueId,
    status: {$in: ["open", "missing"]}
  }, projection);
});

Meteor.publish("allTicketsInRange", function(course, startTime, endTime) {
  var startTime = startTime || 0,
      endTime = endTime || Date.now();

  var courseObject = Courses.findOne({name: course});
  if(!courseObject) return;

  if(!authorized.hta(this.userId, course))
    throw new Meteor.Error("not-allowed");

  return Tickets.find({
    course: course,
    createdAt: {$gte: startTime, $lte: endTime}
  }, {
    "notify.email": false,
    "notify.phone": false,
    "notify.carrier": false
  });
})<commit_msg>Fix allActiveTickets publication with 'ended' status<commit_after>// Tickets Publications

Meteor.smartPublish("allActiveTickets", function() {
  // Note the smartPublish: we use this to return multiple
  // cursors of the same collection.
  var activeQueues = Queues.find({"status": {$nin: ["ended", "cancelled"]}}).fetch();
  var activeTickets = [];

  _.each(activeQueues, function(queue) {
    var queueId = queue._id;
    var isTA = false;
    if(this.userId)
      isTA = authorized.ta(this.userId, queue.course);

    var tickets = Tickets.find({
      queueId: queueId,
      status: {$in: ["open", "missing"]}
    }, {
      fields: {
        question: isTA,
        notify: isTA,
        ta: isTA,
        flag: isTA,
        "notify.email": false,
        "notify.phone": false,
        "notify.carrier": false
      }
    });

    activeTickets.push(tickets);
  });

  return activeTickets;
});

Meteor.publish("activeTickets", function(queueId) {
  var queue = Queues.findOne({_id: queueId});
  if(!queue) return;

  // Hide fields for non-TAs
  var projection = {
    "fields": {
      "notify.email": false,
      "notify.phone": false,
      "notify.carrier": false
    }
  };

  var isTA = false;
  if(this.userId) {
    isTA = authorized.ta(this.userId, queue.course);
  }

  if(!isTA) {
    _.extend(projection["fields"], {
      question: false,
      notify: false,
      ta: false,
      flag: false
    });
  }

  return Tickets.find({
    queueId: queueId,
    status: {$in: ["open", "missing"]}
  }, projection);
});

Meteor.publish("allTicketsInRange", function(course, startTime, endTime) {
  var startTime = startTime || 0,
      endTime = endTime || Date.now();

  var courseObject = Courses.findOne({name: course});
  if(!courseObject) return;

  if(!authorized.hta(this.userId, course))
    throw new Meteor.Error("not-allowed");

  return Tickets.find({
    course: course,
    createdAt: {$gte: startTime, $lte: endTime}
  }, {
    "notify.email": false,
    "notify.phone": false,
    "notify.carrier": false
  });
})
{'fraction_non_alphanumeric': 0.15805022156573117, 'fraction_numerical': 0.0004923682914820286, 'mean_word_length': 2.8769083969465647, 'pattern_counts': {'":': 22, '<': 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': '4918744', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1330, 'n_words': 305}