-{ Module } = require 'jraphical'
+{ Module }     = require 'jraphical'
+{ revive }     = require './computeutils'
 
 module.exports = class JMachine extends Module
 
-  { ObjectId } = require 'bongo'
+  { ObjectId, signature } = require 'bongo'
+
+  @trait __dirname, '../../traits/protected'
+  {permit} = require '../group/permissionset'
+
+  @share()
 
   @set
 

    sharedEvents        :
      static            : [ ]
      instance          : [ ]

    schema              :


        default         : "not-initialized"

      meta              : Object


  @one$: permit 'list machines',

    success: revive

      shouldReviveClient   : yes
      shouldReviveProvider : no

    , (client, machineId, callback)->

      { r: { group, user } } = client

      selector =
        _id      : machineId
        users    : $elemMatch: id: user.getId()
        groups   : $elemMatch: id: group.getId()

      JMachine.one selector, (err, machine)->
        callback err, machine
