 
 exports.removeMediator = (urn) ->
   # Must be admin
-  if authorisation.inGroup('admin', @authenticated) is false
-    utils.logAndSetResponse this, 'forbidden', "User #{@authenticated.email} is not an admin, API access to removeMediator denied.", 'info'
+  if not authorisation.inGroup 'admin', this.authenticated
+    utils.logAndSetResponse this, 'forbidden', "User #{this.authenticated.email} is not an admin, API access to removeMediator denied.", 'info'
     return
 
-  urn = unescape (urn)
+  urn = unescape urn
 
   try
     yield Mediator.findOneAndRemove({ urn: urn }).exec()
-    @body = "Mediator with urn #{urn} has been successfully removed by #{@authenticated.email}"
-    logger.info "Mediator with urn #{urn} has been successfully removed by #{@authenticated.email}"
+    this.body = "Mediator with urn #{urn} has been successfully removed by #{this.authenticated.email}"
+    logger.info "Mediator with urn #{urn} has been successfully removed by #{this.authenticated.email}"
   catch err
     utils.logAndSetResponse this, 'internal server error', "Could not remove Mediator by urn  {urn} via the API: #{err}", 'error'
      yield Q.ninvoke(new Mediator(mediator), 'save')
      if mediator.defaultChannelConfig
        yield saveDefaultChannelConfig(mediator.defaultChannelConfig);
    @status = 'created'
    logger.info "User #{@authenticated.email} created mediator with urn #{mediator.urn}"
  catch err
    if err.name == 'ValidationError'
      utils.logAndSetResponse this, 'bad request', "Could not add Mediator via the API: #{err}", 'error'


exports.getMediator = (mediatorURN) ->
  # Must be admin
  if not authorisation.inGroup 'admin', this.authenticated
    utils.logAndSetResponse this, 'forbidden', "User #{this.authenticated.email} is not an admin, API access to getMediator denied.", 'info'
    return

  urn = unescape mediatorURN

  try
    result = yield Mediator.findOne({ "urn": urn }).exec()
    if result == null
      this.status = 'not found'
    else
      this.body = result
  catch err
    logAndSetResponse this, 'internal server error', "Could not fetch mediator using UUID {urn} via the API: #{err}", 'error'

