<commit_before>module Invitations
end

class SubdomainController < ApplicationController
  respond_to :json
  skip_before_action :verify_authenticity_token, :only => :update_images_hack
  include Invitations

  def index 
    ActsAsTenant.without_tenant do 
      subdomains = Subdomain.where('name != "homepage"').map {|s| {:id => s.id, :name => s.name, :customizations => s.customizations, :activity => s.proposals.count > 1 || s.opinions.published.count > 1 || s.points.published.count > 0}}
      render :json => [{
        key: '/subdomains',
        subs: subdomains
      }]
    end
  end


  def create
    permitted = permit('create subdomain')
    if permitted < 0
      if params[:sso_domain]
        # redirect to IdP for authentication
        initiate_saml_auth(params[:sso_domain])
        return
      else 
        raise PermissionDenied.new permitted
      end
    end

    errors = []

    # force it to come from consider.it
    if current_subdomain.name != 'homepage'
      errors.push 'You can only create subdomains from https://consider.it'
    end

    # make sure this user hasn't been spam-creating subdomains...
    subs_for_user = Subdomain.where("roles like '%\"/user/#{current_user.id}\"%'").where("created_at >= :week", {:week => 1.week.ago})
    if subs_for_user.count > 25
      errors.push "You have created too many subdomains in the past week."
    end

    # TODO: sanitize / make sure has url-able characters
    subdomain = params[:subdomain]<commit_msg>super admins have no forum creation limits<commit_after>module Invitations
end

class SubdomainController < ApplicationController
  respond_to :json
  skip_before_action :verify_authenticity_token, :only => :update_images_hack
  include Invitations

  def index 
    ActsAsTenant.without_tenant do 
      subdomains = Subdomain.where('name != "homepage"').map {|s| {:id => s.id, :name => s.name, :customizations => s.customizations, :activity => s.proposals.count > 1 || s.opinions.published.count > 1 || s.points.published.count > 0}}
      render :json => [{
        key: '/subdomains',
        subs: subdomains
      }]
    end
  end


  def create
    permitted = permit('create subdomain')
    if permitted < 0
      if params[:sso_domain]
        # redirect to IdP for authentication
        initiate_saml_auth(params[:sso_domain])
        return
      else 
        raise PermissionDenied.new permitted
      end
    end

    errors = []

    # force it to come from consider.it
    if current_subdomain.name != 'homepage'
      errors.push 'You can only create subdomains from https://consider.it'
    end

    # make sure this user hasn't been spam-creating subdomains...
    if !current_user.super_admin
      subs_for_user = Subdomain.where("roles like '%\"/user/#{current_user.id}\"%'").where("created_at >= :week", {:week => 1.week.ago})
      if subs_for_user.count > 25
        errors.push "You have created too many subdomains in the past week."
      end
    end 

    # TODO: sanitize / make sure has url-able characters
    subdomain = params[:subdomain]
{'fraction_non_alphanumeric': 0.10759700032605152, 'fraction_numerical': 0.004564721225953701, 'mean_word_length': 2.9638242894056845, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 2, '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': '1203890', 'n_tokens_mistral': 960, 'n_tokens_neox': 904, 'n_words': 256}