<commit_before>class Design::PlatformsController < Base::PlatformsController
  before_filter :find_assembly_and_platform

  swagger_controller :platforms, 'Design Platform Management'

  swagger_api :index do
    summary 'Fetches all platforms in the design of assembly.'
    notes 'This fetches all platforms from design including new platforms from open release.'
    param_org_name
    param_parent_ci_id :assembly
    response :unauthorized
  end

  def index
    @platforms = Cms::DjRelation.all(:params => {:ciId              => @assembly.ciId,
                                                 :direction         => 'from',
                                                 :relationShortName => 'ComposedOf',
                                                 :targetClassName   => 'catalog.Platform'}).map(&:toCi)
    render :json => @platforms
  end

  def show
    respond_to do |format|
      format.html do
        build_component_groups
        build_linkable_platform_map

        @policy_compliance = Cms::Ci.violates_policies(@components, false, true) if Settings.check_policy_compliance

        @release = Cms::Release.latest(:nsPath => assembly_ns_path(@assembly))
        @rfcs = @release.releaseState == 'open' ? Transistor.design_platform_rfcs(@platform.ciId) : {}


        unless @platform.rfcAction == 'add'
          @pack_version    = Cms::Ci.first(:params => {:nsPath      => "/public/#{@platform.ciAttributes.source}/packs/#{@platform.ciAttributes.pack}",
                                                       :ciClassName => 'mgmt.Version',
                                                       :ciName      => @platform.ciAttributes.version})
          @platform_detail = Cms::CiDetail.find(@platform.ciId)
        end

        render(:action => :show)
      end

      format.json do
        @platform.links_to = Cms::DjRelation.all(:params => {:ciId              => @platform.ciId,
                                                             :direction         => 'from',
                                                             :relationShortName => 'LinksTo',
                                                             :includeToCi       => true}).map { |r| r.toCi.ciName } if @platform
        render_json_ci_response(true, @platform)
      end
    end
  end


  def new
    @platform = Cms::DjCi.build({:nsPath      => assembly_ns_path(@assembly),
                                 :ciClassName => 'catalog.Platform'},
                                {:owner => {}})

    respond_to do |format|
      format.html do
        build_linkable_platform_map
        render :action => :new
      end

      format.json { render_json_ci_response(true, @platform) }
    end
  end

  def create
    platform_hash = params[:cms_dj_ci].merge(:nsPath => assembly_ns_path(@assembly), :ciClassName => 'catalog.Platform')
    attrs = platform_hash[:ciAttributes]
    attrs[:major_version] = 1
    attrs[:description] ||= ''
    attr_props = platform_hash.delete(:ciAttrProps)

    @platform = Cms::DjCi.build(platform_hash, attr_props)
    pack_ver = locate_pack_version_for_platform(@platform)

    if pack_ver.blank?
      @platform.errors.add(:base, 'Pack not found.')
    elsif pack_ver.ciAttributes.enabled == 'false'
      @platform.errors.add(:base, 'Pack is disabled.')
    else
      @platform = Transistor.create_platform(@assembly.ciId, @platform)
    end
    ok = @platform.errors.blank?

    save_platform_links if ok

    respond_to do |format|
      format.html do
        if ok
          show
        else
          flash.now[:alert] = 'Failed to create platform.'
          setup_linkable_platform_map
          render :action => :new
        end
      end

      format.json { render_json_ci_response(ok, @platform) }
    end
  end

  def edit
    respond_to do |format|
      format.json { render_json_ci_response(true, @platform) }<commit_msg>Fixed a problem with creating a platform for packs with restricted visibility.<commit_after>class Design::PlatformsController < Base::PlatformsController
  before_filter :find_assembly_and_platform

  swagger_controller :platforms, 'Design Platform Management'

  swagger_api :index do
    summary 'Fetches all platforms in the design of assembly.'
    notes 'This fetches all platforms from design including new platforms from open release.'
    param_org_name
    param_parent_ci_id :assembly
    response :unauthorized
  end

  def index
    @platforms = Cms::DjRelation.all(:params => {:ciId              => @assembly.ciId,
                                                 :direction         => 'from',
                                                 :relationShortName => 'ComposedOf',
                                                 :targetClassName   => 'catalog.Platform'}).map(&:toCi)
    render :json => @platforms
  end

  def show
    respond_to do |format|
      format.html do
        build_component_groups
        build_linkable_platform_map

        @policy_compliance = Cms::Ci.violates_policies(@components, false, true) if Settings.check_policy_compliance

        @release = Cms::Release.latest(:nsPath => assembly_ns_path(@assembly))
        @rfcs = @release.releaseState == 'open' ? Transistor.design_platform_rfcs(@platform.ciId) : {}


        unless @platform.rfcAction == 'add'
          @pack_version    = Cms::Ci.first(:params => {:nsPath      => "/public/#{@platform.ciAttributes.source}/packs/#{@platform.ciAttributes.pack}",
                                                       :ciClassName => 'mgmt.Version',
                                                       :ciName      => @platform.ciAttributes.version})
          @platform_detail = Cms::CiDetail.find(@platform.ciId)
        end

        render(:action => :show)
      end

      format.json do
        @platform.links_to = Cms::DjRelation.all(:params => {:ciId              => @platform.ciId,
                                                             :direction         => 'from',
                                                             :relationShortName => 'LinksTo',
                                                             :includeToCi       => true}).map { |r| r.toCi.ciName } if @platform
        render_json_ci_response(true, @platform)
      end
    end
  end


  def new
    @platform = Cms::DjCi.build({:nsPath      => assembly_ns_path(@assembly),
                                 :ciClassName => 'catalog.Platform'},
                                {:owner => {}})

    respond_to do |format|
      format.html do
        build_linkable_platform_map
        render :action => :new
      end

      format.json { render_json_ci_response(true, @platform) }
    end
  end

  def create
    platform_hash = params[:cms_dj_ci].merge(:nsPath => assembly_ns_path(@assembly), :ciClassName => 'catalog.Platform')
    attrs = platform_hash[:ciAttributes]
    attrs[:major_version] = 1
    attrs[:description] ||= ''
    attr_props = platform_hash.delete(:ciAttrProps)

    @platform = Cms::DjCi.build(platform_hash, attr_props)
    pack_ver = locate_pack_version_for_platform(@platform)

    if pack_ver.blank?
      @platform.errors.add(:base, 'Pack not found.')
    elsif pack_ver.ciAttributes.enabled == 'false'
      visibility = pack_ver.altNs.attributes[Catalog::PacksController::ORG_VISIBILITY_ALT_NS_TAG]
      @platform.errors.add(:base, 'Pack is disabled.') unless visibility.present? && visibility.include?(organization_ns_path)
    end

    @platform = Transistor.create_platform(@assembly.ciId, @platform) if @platform.errors.blank?
    ok = @platform.errors.blank?

    save_platform_links if ok

    respond_to do |format|
      format.html do
        if ok
          show
        else
          flash.now[:alert] = 'Failed to create platform.'
          setup_linkable_platform_map
          render :action => :new
        end
      end

      format.json { render_json_ci_response(ok, @platform) }
    end
  end

  def edit
    respond_to do |format|
      format.json { render_json_ci_response(true, @platform) }
{'fraction_non_alphanumeric': 0.10136986301369863, 'fraction_numerical': 0.00024906600249066, 'mean_word_length': 1.9877232142857142, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '125495', 'n_tokens_mistral': 2185, 'n_tokens_neox': 2097, 'n_words': 447}