<commit_before>require 'builder'

class Workshop < ActiveRecord::Base
  include SocialStream::Models::Object
  has_many :workshop_activities

  has_attached_file :banner, styles: { large: "1280x100#" }, default_url: "/assets/logos/original/defaul_workshop_banner.png"
  validates_attachment_content_type :banner, content_type: /\Aimage\/.*\Z/
  
  after_destroy :destroy_workshop_activities

  define_index do
    activity_object_index
    has draft
  end

  validates_inclusion_of :draft, :in => [true, false]

  def thumbnail_url
    self.getAvatarUrl || "/assets/logos/original/defaul_workshop.png"
  end

  def hasAssignments
    self.workshop_activities.select{|workshop_activity| workshop_activity.wa_type=="WaAssignment"}.length > 0
  end

  def contributions
    self.workshop_activities.select{|workshop_activity| workshop_activity.wa_type=="WaAssignment"}.map{|workshop_activity| workshop_activity.object.contributions}.flatten.uniq
  end

  def afterPublish
    #Check if post_activity is public. If not, make it public and update the created_at param.
    post_activity = self.post_activity
    unless post_activity.nil? or post_activity.public?
      #Update the created_at param.
      post_activity.created_at = Time.now
      #Make it public
      post_activity.relation_ids = [Relation::Public.instance.id]<commit_msg>Do not allow Workshops without title<commit_after>require 'builder'

class Workshop < ActiveRecord::Base
  include SocialStream::Models::Object
  has_many :workshop_activities

  has_attached_file :banner, styles: { large: "1280x100#" }, default_url: "/assets/logos/original/defaul_workshop_banner.png"
  validates_attachment_content_type :banner, content_type: /\Aimage\/.*\Z/
  
  after_destroy :destroy_workshop_activities

  define_index do
    activity_object_index
    has draft
  end

  validates_presence_of :title, allow_blank: false
  validates_inclusion_of :draft, :in => [true, false]

  def thumbnail_url
    self.getAvatarUrl || "/assets/logos/original/defaul_workshop.png"
  end

  def hasAssignments
    self.workshop_activities.select{|workshop_activity| workshop_activity.wa_type=="WaAssignment"}.length > 0
  end

  def contributions
    self.workshop_activities.select{|workshop_activity| workshop_activity.wa_type=="WaAssignment"}.map{|workshop_activity| workshop_activity.object.contributions}.flatten.uniq
  end

  def afterPublish
    #Check if post_activity is public. If not, make it public and update the created_at param.
    post_activity = self.post_activity
    unless post_activity.nil? or post_activity.public?
      #Update the created_at param.
      post_activity.created_at = Time.now
      #Make it public
      post_activity.relation_ids = [Relation::Public.instance.id]
{'fraction_non_alphanumeric': 0.08709912536443148, 'fraction_numerical': 0.0058309037900874635, 'mean_word_length': 4.815677966101695, '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': '2720845', 'n_tokens_mistral': 887, 'n_tokens_neox': 846, 'n_words': 176}