 # shared meteor methods
+require_admin = (func) ->
+  -> func.apply(@, arguments) if Houston._user_is_admin @userId
 
 Houston.methods = (collection, raw_methods) ->
   collection_name = collection.name or collection._name or collection


  methods = {}
  for func_name, func of raw_methods
    methods[Houston._custom_method_name(collection_name, func_name)] = func

  Meteor.methods methods

Houston._setup_collection_methods = (collection) ->
  name = collection._name
  methods = {}
  methods[Houston._houstonize "#{name}_insert"] = (doc) ->
    check doc, Object
    return unless Houston._user_is_admin @userId
    collection.insert(doc)

  methods[Houston._houstonize "#{name}_update"] = (id, update_dict) ->
    check id, Match.Any
    check update_dict, Object
    return unless Houston._user_is_admin @userId
    if collection.findOne(id)
      collection.update(id, update_dict)
    else


    "#{collection._name} #{id} saved successfully"

  methods[Houston._houstonize "#{name}_delete"] = require_admin (id) ->
    check id, Match.Any
    if collection.findOne(id)
      collection.remove(id)
    else
