<commit_before># frozen_string_literal: true

module Dashboard
  class QuickStartController < ApplicationController
    include InputSanitizeHelper

    before_action :load_project, only: %i(create_task experiment_filter)
    before_action :load_experiment, only: :create_task
    before_action :check_task_create_permissions, only: :create_task

    def create_task
      my_module = CreateMyModuleService.new(current_user, current_team,
                                            project: @project || create_project_params,
                                            experiment: @experiment || create_experiment_params).call
      if my_module.errors.empty?
        render json: { my_module_path: protocols_my_module_path(my_module) }
      else
        render json: { errors: my_module.errors, error_object: my_module.class.name }, status: :unprocessable_entity
      end
    end

    def project_filter
      projects = current_team.projects.search(current_user, false, params[:query], 1, current_team)
                             .where('user_projects.role <= 1')
                             .select(:id, :name)
      projects = projects.map { |i| { value: i.id, label: escape_input(i.name) } }
      if (projects.map { |i| i[:label] }.exclude? params[:query]) && params[:query].present?
        projects = [{ value: 0, label: params[:query] }] + projects<commit_msg>Add user check to project filter in quick start widget<commit_after># frozen_string_literal: true

module Dashboard
  class QuickStartController < ApplicationController
    include InputSanitizeHelper

    before_action :load_project, only: %i(create_task experiment_filter)
    before_action :load_experiment, only: :create_task
    before_action :check_task_create_permissions, only: :create_task

    def create_task
      my_module = CreateMyModuleService.new(current_user, current_team,
                                            project: @project || create_project_params,
                                            experiment: @experiment || create_experiment_params).call
      if my_module.errors.empty?
        render json: { my_module_path: protocols_my_module_path(my_module) }
      else
        render json: { errors: my_module.errors, error_object: my_module.class.name }, status: :unprocessable_entity
      end
    end

    def project_filter
      projects = current_team.projects.search(current_user, false, params[:query], 1, current_team)
                             .where(user_projects: { user_id: current_user.id, role: %i(owner normal_user) })
                             .select(:id, :name)
      projects = projects.map { |i| { value: i.id, label: escape_input(i.name) } }
      if (projects.map { |i| i[:label] }.exclude? params[:query]) && params[:query].present?
        projects = [{ value: 0, label: params[:query] }] + projects
{'fraction_non_alphanumeric': 0.09471830985915493, 'fraction_numerical': 0.0017605633802816902, 'mean_word_length': 2.79305740987984, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1557078', 'n_tokens_mistral': 779, 'n_tokens_neox': 765, 'n_words': 178}