<commit_before>require 'will_paginate/array'

class WorkletsController < ApplicationController
  wrap_parameters :workfile
  include DataSourceAuth

  before_filter :authorize_show_worklet, :only => [:show, :image]
  before_filter :authorize_edit_worklet, :only => [:update, :destroy, :upload_image]

  def show

    if params[:connect].present?
      authorize_data_sources_access worklet
      worklet.attempt_data_source_connection
    end

    #log_workfile_opened_event(worklet, current_user)

    present worklet, :presenter_options => {:contents => true, :workfile_as_latest_version => true}
  end

  def create
 #   authorize! :can_edit_sub_objects, workspace

    merged_params = ActiveSupport::HashWithIndifferentAccess['file_name', params[:workfile][:file_name]]
    .merge(params[:workfile])
    .merge(:workspace => workspace, :owner => current_user, :content_type => 'worklet')
    .merge(:workflow_id => params[:workfile][:workflow_id])
    .merge(:state => 'completed')

    # merge_params should have content_type = 'worklet'
    workfile = Worklet.build_for(merged_params)<commit_msg>DEV-12881 - Opened image permissions for published touchpoints<commit_after>require 'will_paginate/array'

class WorkletsController < ApplicationController
  wrap_parameters :workfile
  include DataSourceAuth

  before_filter :authorize_show_worklet, :only => [:show]
  before_filter :authorize_edit_worklet, :only => [:update, :destroy, :upload_image]

  def show

    if params[:connect].present?
      authorize_data_sources_access worklet
      worklet.attempt_data_source_connection
    end

    #log_workfile_opened_event(worklet, current_user)

    present worklet, :presenter_options => {:contents => true, :workfile_as_latest_version => true}
  end

  def create
 #   authorize! :can_edit_sub_objects, workspace

    merged_params = ActiveSupport::HashWithIndifferentAccess['file_name', params[:workfile][:file_name]]
    .merge(params[:workfile])
    .merge(:workspace => workspace, :owner => current_user, :content_type => 'worklet')
    .merge(:workflow_id => params[:workfile][:workflow_id])
    .merge(:state => 'completed')

    # merge_params should have content_type = 'worklet'
    workfile = Worklet.build_for(merged_params)
{'fraction_non_alphanumeric': 0.10779510022271716, 'fraction_numerical': 0.0022271714922048997, 'mean_word_length': 5.472622478386167, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '1543880', 'n_tokens_mistral': 703, 'n_tokens_neox': 672, 'n_words': 132}