<commit_before>module Api
  module V20170715
    class CoreApiController < ApiController
      include PermissionHelper

      def tasks_tree
        teams_json = []
        current_user.teams.find_each do |tm|
          team = tm.as_json(only: %i(name description))
          team['team_id'] = tm.id.to_s
          projects = []
          tm.projects.find_each do |pr|
            project = pr.as_json(only: %i(name visibility archived))
            project['project_id'] = pr.id.to_s
            experiments = []
            pr.experiments.find_each do |exp|
              experiment = exp.as_json(only: %i(name description archived))
              experiment['experiment_id'] = exp.id.to_s
              tasks = []
              exp.my_modules.find_each do |tk|
                task = tk.as_json(only: %i(name description archived))
                task['task_id'] = tk.id.to_s
                tasks << task
              end
              experiment['tasks'] = tasks
              experiments << experiment
            end
            project['experiments'] = experiments
            projects << project
          end
          team['projects'] = projects
          teams_json << team
        end
        render json: teams_json, status: :ok
      end

      def task_samples
        task = MyModule.find_by_id(params[:task_id])
        return render json: {}, status: :not_found unless task
        return render json: {}, status: :forbidden unless can_view_module(task)
        samples = task.samples
        samples_json = []<commit_msg>Add editable field to task in tasks tree API call [GIOT-44]<commit_after>module Api
  module V20170715
    class CoreApiController < ApiController
      include PermissionHelper

      def tasks_tree
        teams_json = []
        current_user.teams.find_each do |tm|
          team = tm.as_json(only: %i(name description))
          team['team_id'] = tm.id.to_s
          projects = []
          tm.projects.find_each do |pr|
            project = pr.as_json(only: %i(name visibility archived))
            project['project_id'] = pr.id.to_s
            experiments = []
            pr.experiments.find_each do |exp|
              experiment = exp.as_json(only: %i(name description archived))
              experiment['experiment_id'] = exp.id.to_s
              tasks = []
              exp.my_modules.find_each do |tk|
                task = tk.as_json(only: %i(name description archived))
                task['task_id'] = tk.id.to_s
                task['editable'] = can_edit_module(tk)
                tasks << task
              end
              experiment['tasks'] = tasks
              experiments << experiment
            end
            project['experiments'] = experiments
            projects << project
          end
          team['projects'] = projects
          teams_json << team
        end
        render json: teams_json, status: :ok
      end

      def task_samples
        task = MyModule.find_by_id(params[:task_id])
        return render json: {}, status: :not_found unless task
        return render json: {}, status: :forbidden unless can_view_module(task)
        samples = task.samples
        samples_json = []
{'fraction_non_alphanumeric': 0.09407337723424271, 'fraction_numerical': 0.005644402634054563, 'mean_word_length': 1.800702370500439, 'pattern_counts': {'":': 0, '<': 21, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '367218', 'n_tokens_mistral': 880, 'n_tokens_neox': 879, 'n_words': 210}