<commit_before>class AssignmentSubmission < ActiveRecord::Base
  attr_accessible :assignment_id, :comment, :feedback, :group_id, :attachment, :link, :submittable_id, :submittable_type
  
  include Canable::Ables 
  #userstamps! # adds creator and updater 
  
  
  #has_attached_file :attachment
  
  belongs_to :submittable, :polymorphic => :true
  belongs_to :assignment
  has_one :grade
  accepts_nested_attributes_for :grade
  
  scope :ungraded
  
  validates_presence_of :assignment_id, :submittable_id, :submittable_type
  
  
  scope :for_submittable, ->(submittable) { where(:submittable_id => submittable.id, :submittable_type => submittable.class) }
  
  #Canable permissions
  def updatable_by?(user)
    creator == user
  end
  
  def destroyable_by?(user)
    updatable_by?(user)
  end
  
  def viewable_by?(user)
    submittable_id == user.id
  end
  
  #Grading status
  def status
    if grade
      "Graded"
    else<commit_msg>Fixed team canable for assignment submissions<commit_after>class AssignmentSubmission < ActiveRecord::Base
  attr_accessible :assignment_id, :comment, :feedback, :group_id, :attachment, :link, :submittable_id, :submittable_type
  
  include Canable::Ables 
  #userstamps! # adds creator and updater 
  
  
  #has_attached_file :attachment
  
  belongs_to :submittable, :polymorphic => :true
  belongs_to :assignment
  has_one :grade
  accepts_nested_attributes_for :grade
  
  scope :ungraded
  
  validates_presence_of :assignment_id, :submittable_id, :submittable_type
  
  
  scope :for_submittable, ->(submittable) { where(:submittable_id => submittable.id, :submittable_type => submittable.class) }
  
  #Canable permissions
  def updatable_by?(user)
    creator == user
  end
  
  def destroyable_by?(user)
    updatable_by?(user)
  end
  
  def viewable_by?(user)
    if assignment.is_individual?
      submittable_id == user.id 
    elsif assignment.has_teams?
      submittable_id == user.teams.first.id 
    elsif assignment.has_groups?
      submittable_id == user.groups.first.id 
    end
  end
  
  #Grading status
  def status
    if grade
      "Graded"
    else
{'fraction_non_alphanumeric': 0.08576814326107446, 'fraction_numerical': 0.0, 'mean_word_length': 3.948717948717949, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '955100', 'n_tokens_mistral': 751, 'n_tokens_neox': 748, 'n_words': 151}