<commit_before>_ = require 'lodash'
kd = require 'kd'
jspath = require 'jspath'
Encoder = require 'htmlencode'

whoami = require 'app/util/whoami'
curryIn = require 'app/util/curryIn'
Tracker = require 'app/util/tracker'
actions = require 'app/flux/environment/actiontypes'
showError = require 'app/util/showError'

OutputView = require 'stacks/views/stacks/outputview'
ReadmeView = require 'stacks/views/stacks/readmeview'
ProvidersView = require 'stacks/views/stacks/providersview'
VariablesView = require 'stacks/views/stacks/variablesview'
{ yamlToJson } = require 'stacks/views/stacks/yamlutils'
CustomLinkView = require 'app/customlinkview'
providersParser = require 'stacks/views/stacks/providersparser'
StackTemplateView = require 'stacks/views/stacks/stacktemplateview'
CredentialListItem = require '../credentials/credentiallistitem'
requirementsParser = require 'stacks/views/stacks/requirementsparser'
updateStackTemplate = require 'stacks/views/stacks/updatestacktemplate'
addUserInputOptions = require 'stacks/views/stacks/adduserinputoptions'
updateCustomVariable = require 'stacks/views/stacks/updatecustomvariable'
parseTerraformOutput = require 'stacks/views/stacks/parseterraformoutput'
CredentialStatusView = require 'stacks/views/stacks/credentialstatusview'
generateStackTemplateTitle = require 'app/util/generateStackTemplateTitle'
StackTemplatePreviewModal = require 'stacks/views/stacks/stacktemplatepreviewmodal'
EnvironmentFlux = require 'app/flux/environment'
ContentModal = require 'app/components/contentModal'
createShareModal = require './createShareModal'
{ actions : HomeActions } = require 'home/flux'

module.exports = class StackEditorView extends kd.View

  constructor: (options = {}, data = {}) ->

    options.cssClass = kd.utils.curry 'StackEditorView', options.cssClass

    { stackTemplate } = data

    if stackTemplate
      unless selectedProvider = stackTemplate.selectedProvider
        for selectedProvider in stackTemplate.config.requiredProviders
          break  if selectedProvider in ['aws', 'vagrant']
      selectedProvider ?= (Object.keys stackTemplate.credentials ? { aws: yes }).first

    options.selectedProvider = selectedProvider ?= 'aws'

    super options, data

    @isMine = yes
    kd.singletons.groupsController.ready =>

      { groupsController } = kd.singletons
      @isMine = stackTemplate?.isMine() or groupsController.canEditGroup()

      unless @isMine
        @tabView.setClass 'StackEditorTabs isntMine'
        @warningView.show()
        @secondaryActions.hide()
        @saveButton.setClass 'isntMine'
        @inputTitle.setClass 'template-title isntMine'



    @setClass 'edit-mode'  if inEditMode = @getOption 'inEditMode'

    if stackTemplate?.title
      stackTemplate.title = Encoder.htmlDecode stackTemplate.title

    generatedStackTemplateTitle = generateStackTemplateTitle()

    title   = stackTemplate?.title or generatedStackTemplateTitle
    content = stackTemplate?.template?.content

    @createStackNameInput title

    stackEditorTabsCssClass = unless @isMine then 'StackEditorTabs isntMine' else 'StackEditorTabs'
<commit_msg>TMS-3228 'You must be an admin to edit this stack' message is displayed for a second when a member creates his own stack template. (#8470)<commit_after>_ = require 'lodash'
kd = require 'kd'
jspath = require 'jspath'
Encoder = require 'htmlencode'

whoami = require 'app/util/whoami'
curryIn = require 'app/util/curryIn'
Tracker = require 'app/util/tracker'
actions = require 'app/flux/environment/actiontypes'
showError = require 'app/util/showError'

OutputView = require 'stacks/views/stacks/outputview'
ReadmeView = require 'stacks/views/stacks/readmeview'
ProvidersView = require 'stacks/views/stacks/providersview'
VariablesView = require 'stacks/views/stacks/variablesview'
{ yamlToJson } = require 'stacks/views/stacks/yamlutils'
CustomLinkView = require 'app/customlinkview'
providersParser = require 'stacks/views/stacks/providersparser'
StackTemplateView = require 'stacks/views/stacks/stacktemplateview'
CredentialListItem = require '../credentials/credentiallistitem'
requirementsParser = require 'stacks/views/stacks/requirementsparser'
updateStackTemplate = require 'stacks/views/stacks/updatestacktemplate'
addUserInputOptions = require 'stacks/views/stacks/adduserinputoptions'
updateCustomVariable = require 'stacks/views/stacks/updatecustomvariable'
parseTerraformOutput = require 'stacks/views/stacks/parseterraformoutput'
CredentialStatusView = require 'stacks/views/stacks/credentialstatusview'
generateStackTemplateTitle = require 'app/util/generateStackTemplateTitle'
StackTemplatePreviewModal = require 'stacks/views/stacks/stacktemplatepreviewmodal'
EnvironmentFlux = require 'app/flux/environment'
ContentModal = require 'app/components/contentModal'
createShareModal = require './createShareModal'
{ actions : HomeActions } = require 'home/flux'

module.exports = class StackEditorView extends kd.View

  constructor: (options = {}, data = {}) ->

    options.cssClass = kd.utils.curry 'StackEditorView', options.cssClass

    { stackTemplate } = data

    if stackTemplate
      unless selectedProvider = stackTemplate.selectedProvider
        for selectedProvider in stackTemplate.config.requiredProviders
          break  if selectedProvider in ['aws', 'vagrant']
      selectedProvider ?= (Object.keys stackTemplate.credentials ? { aws: yes }).first

    options.selectedProvider = selectedProvider ?= 'aws'

    super options, data

    @isMine = yes
    kd.singletons.groupsController.ready =>

      { groupsController } = kd.singletons
      @isMine = stackTemplate?.isMine() or groupsController.canEditGroup()

      if not @isMine and stackTemplate
        @tabView.setClass 'StackEditorTabs isntMine'
        @warningView.show()
        @secondaryActions.hide()
        @saveButton.setClass 'isntMine'
        @inputTitle.setClass 'template-title isntMine'



    @setClass 'edit-mode'  if inEditMode = @getOption 'inEditMode'

    if stackTemplate?.title
      stackTemplate.title = Encoder.htmlDecode stackTemplate.title

    generatedStackTemplateTitle = generateStackTemplateTitle()

    title   = stackTemplate?.title or generatedStackTemplateTitle
    content = stackTemplate?.template?.content

    @createStackNameInput title

    stackEditorTabsCssClass = unless @isMine then 'StackEditorTabs isntMine' else 'StackEditorTabs'

{'fraction_non_alphanumeric': 0.09289617486338798, 'fraction_numerical': 0.001249024199843872, 'mean_word_length': 4.964618249534451, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2000960', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1803, 'n_words': 391}