    Deps.autorun () ->
       userId = Meteor.userId()
       Meteor.subscribe 'allData', userId
+      Meteor.subscribe 'allJobs', userId
       $.cookie 'X-Auth-Token', Accounts._storedLoginToken()
 
    #####################

if Meteor.isServer

   myJobs.setLogStream process.stdout
   myJobs.allow
      manager: (userId, method, params) -> return userId?
      jobRerun: (userId, method, params) -> return userId?

   Meteor.startup () ->

      myJobs.startJobs()

      Meteor.publish 'allJobs', () ->
         myJobs.find({})

      # Only publish files owned by this userId, and ignore temp file chunks used by resumable
      Meteor.publish 'allData', (clientUserId) ->

         # This prevents a race condition on the client between Meteor.userId() and subscriptions to this publish
         # See: https://stackoverflow.com/questions/24445404/how-to-prevent-a-client-reactive-race-between-meteor-userid-and-a-subscription/24460877#24460877
         if this.userId is clientUserId


      # Don't allow users to modify the user docs
      Meteor.users.deny({update: () -> true })

      # Only allow job owners to manage or rerun jobs
      myJobs.allow
         manager: (userId, method, params) ->
            ids = params[0]
            unless typeof ids is 'object' and ids instanceof Array
               ids = [ ids ]
            numIds = ids.length
            numMatches = myJobs.find({ _id: { $in: ids }, 'data.owner': userId }).count()
            return numMatches is numIds

         jobRerun: (userId, method, params) ->
            id = params[0]
            numMatches = myJobs.find({ _id: id, 'data.owner': userId }).count()
            return numMatches is 1

      # Allow rules for security. Without these, no writes would be allowed by default
      myData.allow
