<commit_before>async       = require 'async'
KodingError = require '../../../error'

log = ->
  console.log '[handlers:memberremoved]', arguments...


checkOwnership = (machine, user) ->

  userId = user.getId()
  owner  = no

  for u in machine.users
    if u.owner and u.sudo and userId.equals u.id
      owner = yes
      break

  return owner


setOwnerOfStack = (stack, newOwner, oldOwner, group) ->

  newOwnerId = newOwner.getId()

  stack.unuseStackTemplate (err) ->
    log 'Failed to mark as unused stack:', err  if err
    stack.update {
      $set : {
        originId          : newOwnerId
        title             : "#{stack.getAt 'title'} (@#{oldOwner})"
        'config.oldOwner' : oldOwner
      }
    }, (err) ->
      if err
      then log 'Failed to change ownership of stack:', err
      else newOwner.sendNotification 'MachineListUpdated', { group }


updateStacks = ({ reason, stacks, oldOwner, requester, group }) ->
<commit_msg>server: send better event with member removal<commit_after>async       = require 'async'
KodingError = require '../../../error'

log = ->
  console.log '[handlers:memberremoved]', arguments...


checkOwnership = (machine, user) ->

  userId = user.getId()
  owner  = no

  for u in machine.users
    if u.owner and u.sudo and userId.equals u.id
      owner = yes
      break

  return owner


setOwnerOfStack = (stack, newOwner, oldOwner, group) ->

  newOwnerId = newOwner.getId()
  stackId = stack.getId()

  stack.unuseStackTemplate (err) ->
    log 'Failed to mark as unused stack:', err  if err
    stack.update {
      $set : {
        originId          : newOwnerId
        title             : "#{stack.getAt 'title'} (@#{oldOwner})"
        'config.oldOwner' : oldOwner
      }
    }, (err) ->
      if err
      then log 'Failed to change ownership of stack:', err
      else newOwner.sendNotification 'StackOwnerUpdated', { group, stackId }


updateStacks = ({ reason, stacks, oldOwner, requester, group }) ->

{'fraction_non_alphanumeric': 0.12664640324214793, 'fraction_numerical': 0.0, 'mean_word_length': 2.440766550522648, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4630407', 'n_tokens_mistral': 606, 'n_tokens_neox': 600, 'n_words': 177}