<commit_before>require_dependency "application_controller"

class LightweightActivitiesController < ApplicationController
  before_filter :set_activity, :except => [:index, :new, :create]
  before_filter :set_session_key, :only => [:summary, :show]

  def index
    if can? :manage, LightweightActivity
      @activities = LightweightActivity.all
    elsif current_user.present?
      @activities = LightweightActivity.my(current_user) + LightweightActivity.public
    else
      @activities ||= LightweightActivity.public
    end
  end

  def show
    authorize! :read, @activity
    @run.increment_run_count!
    # TODO check logged in status, and auth if not logged in
    url = activity_page_path(@activity, @run.last_page)
    if current_user.nil?
      session[:auth_return_url] = url
      redirect_to user_omniauth_authorize_path(:concord_portal)
    else
      redirect_to url
    end
  end

  def new
    @activity = LightweightActivity.new()
    authorize! :create, @activity
  end

  def create
    @activity = LightweightActivity.create(params[:lightweight_activity])
    authorize! :create, @activity
    @activity.user = current_user
    @activity.changed_by = current_user
    if @activity.save
      flash[:notice] = "Lightweight Activity #{@activity.name} was created."
      redirect_to edit_activity_path(@activity)
    else
      flash[:warning] = "There was a problem creating the new Lightweight Activity."
      render :new
    end
  end<commit_msg>Only auto-login if we launch from a remote source<commit_after>require_dependency "application_controller"

class LightweightActivitiesController < ApplicationController
  before_filter :set_activity, :except => [:index, :new, :create]
  before_filter :set_session_key, :only => [:summary, :show]

  def index
    if can? :manage, LightweightActivity
      @activities = LightweightActivity.all
    elsif current_user.present?
      @activities = LightweightActivity.my(current_user) + LightweightActivity.public
    else
      @activities ||= LightweightActivity.public
    end
  end

  def show
    authorize! :read, @activity
    @run.increment_run_count!
    # check logged in status, and auth if not logged in and we were launched remotely
    url = activity_page_path(@activity, @run.last_page)
    if current_user.nil? && params[:domain] && params[:externalId]
      session[:auth_return_url] = url
      redirect_to user_omniauth_authorize_path(:concord_portal)
    else
      redirect_to url
    end
  end

  def new
    @activity = LightweightActivity.new()
    authorize! :create, @activity
  end

  def create
    @activity = LightweightActivity.create(params[:lightweight_activity])
    authorize! :create, @activity
    @activity.user = current_user
    @activity.changed_by = current_user
    if @activity.save
      flash[:notice] = "Lightweight Activity #{@activity.name} was created."
      redirect_to edit_activity_path(@activity)
    else
      flash[:warning] = "There was a problem creating the new Lightweight Activity."
      render :new
    end
  end
{'fraction_non_alphanumeric': 0.08560183666775992, 'fraction_numerical': 0.0, 'mean_word_length': 3.856687898089172, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1456293', 'n_tokens_mistral': 885, 'n_tokens_neox': 871, 'n_words': 231}