<commit_before>debug                = (require 'debug') 'cc'
globals              = require 'globals'
Promise              = require 'bluebird'
Encoder              = require 'htmlencode'

kd                   = require 'kd'
KDController         = kd.Controller

nick                 = require 'app/util/nick'
FSHelper             = require 'app/util/fs/fshelper'
showError            = require 'app/util/showError'
showNotification     = require 'app/util/showNotification'
isLoggedIn           = require 'app/util/isLoggedIn'
isGroupDisabled      = require 'app/util/isGroupDisabled'
actions              = require 'app/flux/environment/actions'

remote               = require '../remote'
KiteCache            = require '../kite/kitecache'
ComputeStateChecker  = require './computestatechecker'
ComputeEventListener = require './computeeventlistener'
ComputeController_UI = require './computecontroller.ui'
ManagedKiteChecker   = require './managed/managedkitechecker'
envDataProvider      = require 'app/userenvironmentdataprovider'
Tracker              = require 'app/util/tracker'
getGroup             = require 'app/util/getGroup'
createShareModal     = require 'stack-editor/editor/createShareModal'
ContentModal         = require 'app/components/contentModal'
runMiddlewares       = require 'app/util/runMiddlewares'
SidebarFlux          = require 'app/flux/sidebar'
whoami               = require 'app/util/whoami'
ComputeStorage       = require './computestorage'
IDERoutes            = require 'ide/routes'

TestMachineMiddleware = require './middlewares/testmachine'


{ actions : HomeActions } = require 'home/flux'
require './config'


module.exports = class ComputeController extends KDController


  PROVIDERS  = globals.config.providers._getSupportedProviders()
  @Error     = {
    'TimeoutError', 'KiteError', 'NotSupported'
    Pending: '107', NotVerified: '500'
  }

  @getMiddlewares = ->
    return [
      TestMachineMiddleware.ComputeController
    ]

  constructor: ->

    super

    { mainController, groupsController, router } = kd.singletons

    @ui = ComputeController_UI
    @storage = new ComputeStorage

    @_trials = {}

    mainController.ready =>

      @bindPaymentEvents()

      @on 'StackAdminMessageDeleted', @bound 'handleStackAdminMessageDeleted'

      groupsController.on 'StackTemplateChanged', (event) => @checkGroupStacks event?.contents
      groupsController.on 'StackAdminMessageCreated', @bound 'handleStackAdminMessageCreated'
      groupsController.on 'SharedStackTemplateAccessLevel', @bound 'sharedStackTemplateAccessLevel'

      @eventListener      = new ComputeEventListener
      @managedKiteChecker = new ManagedKiteChecker
      @stateChecker       = new ComputeStateChecker { @storage }
      @stateChecker.start()

      @createDefaultStack()

      @appStorage = kd.singletons.appStorageController.storage 'Compute', '0.0.1'

      debug 'now ready'
      @emit 'ready'

      @checkGroupStackRevisions()
      @checkGroupStacks()

      if groupsController.canEditGroup()
        @checkMachinePermissions()

      @checkMachines()


  # ComputeController internal helpers
  #

  getKloud: ->

    kd.singletons.kontrol.getKite
      name         : 'kloud'<commit_msg>compute/ctrl: cheeck permissions after disabled stack update<commit_after>debug                = (require 'debug') 'cc'
globals              = require 'globals'
Promise              = require 'bluebird'
Encoder              = require 'htmlencode'

kd                   = require 'kd'
KDController         = kd.Controller

nick                 = require 'app/util/nick'
FSHelper             = require 'app/util/fs/fshelper'
showError            = require 'app/util/showError'
showNotification     = require 'app/util/showNotification'
isLoggedIn           = require 'app/util/isLoggedIn'
isGroupDisabled      = require 'app/util/isGroupDisabled'
actions              = require 'app/flux/environment/actions'

remote               = require '../remote'
KiteCache            = require '../kite/kitecache'
ComputeStateChecker  = require './computestatechecker'
ComputeEventListener = require './computeeventlistener'
ComputeController_UI = require './computecontroller.ui'
ManagedKiteChecker   = require './managed/managedkitechecker'
envDataProvider      = require 'app/userenvironmentdataprovider'
Tracker              = require 'app/util/tracker'
getGroup             = require 'app/util/getGroup'
createShareModal     = require 'stack-editor/editor/createShareModal'
ContentModal         = require 'app/components/contentModal'
runMiddlewares       = require 'app/util/runMiddlewares'
SidebarFlux          = require 'app/flux/sidebar'
whoami               = require 'app/util/whoami'
ComputeStorage       = require './computestorage'
IDERoutes            = require 'ide/routes'

TestMachineMiddleware = require './middlewares/testmachine'


{ actions : HomeActions } = require 'home/flux'
require './config'


module.exports = class ComputeController extends KDController


  PROVIDERS  = globals.config.providers._getSupportedProviders()
  @Error     = {
    'TimeoutError', 'KiteError', 'NotSupported'
    Pending: '107', NotVerified: '500'
  }

  @getMiddlewares = ->
    return [
      TestMachineMiddleware.ComputeController
    ]

  constructor: ->

    super

    { mainController, groupsController, router
      appStorageController, notificationController } = kd.singletons

    @ui = ComputeController_UI
    @storage = new ComputeStorage

    @_trials = {}

    mainController.ready =>

      @bindPaymentEvents()

      @on 'StackAdminMessageDeleted', @bound 'handleStackAdminMessageDeleted'

      groupsController.on 'StackTemplateChanged', (event) => @checkGroupStacks event?.contents
      groupsController.on 'StackAdminMessageCreated', @bound 'handleStackAdminMessageCreated'
      groupsController.on 'SharedStackTemplateAccessLevel', @bound 'sharedStackTemplateAccessLevel'

      @eventListener      = new ComputeEventListener
      @managedKiteChecker = new ManagedKiteChecker
      @stateChecker       = new ComputeStateChecker { @storage }
      @stateChecker.start()

      @createDefaultStack()

      @appStorage = kd.singletons.appStorageController.storage 'Compute', '0.0.1'

      debug 'now ready'
      @emit 'ready'

      @checkGroupStackRevisions()
      @checkGroupStacks()

      kd.singletons.notificationController.on 'DisabledUserStackAdded', (data) =>
        debug 'disabled user stack added', data
        if groupsController.canEditGroup()
          @checkMachinePermissions()

      if groupsController.canEditGroup()
        @checkMachinePermissions()

      @checkMachines()


  # ComputeController internal helpers
  #

  getKloud: ->

    kd.singletons.kontrol.getKite
      name         : 'kloud'
{'fraction_non_alphanumeric': 0.0946483856700575, 'fraction_numerical': 0.0026536930561698365, 'mean_word_length': 2.9396051103368177, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '5824452', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1821, 'n_words': 377}