<commit_before>class Institution < ActiveRecord::Base
  acts_as_paranoid

	mount_uploader :logo, LogoUploader

	has_ancestry
	has_many :users
	has_many :resource_templates
	has_many :requirements_templates
  has_many :resource_contexts
  
  has_many :statistics, foreign_key: "institution_id", 
                        class_name: "InstitutionStatistic"

	validates :full_name, presence: true

  def plans_by_state(state)
    #get all plans this institution and sub-institutions has in the state specified
    Plan.joins(:current_state, :requirements_template).
          where(:requirements_templates => { :institution_id => self.subtree_ids }).
          where(:plan_states => { :state => state})
  end

  def unique_plan_states
    #returns a list of the unique plan states that this institution and sub-institutions has
    Plan.joins(:current_state, :requirements_template).
        where(:requirements_templates => { :institution_id => self.subtree_ids }).
        select('plan_states.state').distinct.pluck(:state)
  end

  def requirements_templates_deep
    #gets the deep list of all requirements templates for this and all sub-institutions under it
    RequirementsTemplate.where(institution_id: self.subtree_ids)
  end

  def resource_templates_deep
    #gets the deep list of all resource templates for this and all sub-institutions under it
    ResourceTemplate.where(institution_id: self.subtree_ids)
  end
  
  def users_deep
    #gets the list of all users associated with this institution and sub-institutions
    User.where(institution_id: self.subtree_ids)
  end

  def non_admin_users
    User.includes(:authorizations).where(authorizations: {role_id: nil})
  end

  def users_in_role(role_name)<commit_msg>updated institution user assign roles list so that it includes all users<commit_after>class Institution < ActiveRecord::Base
  acts_as_paranoid

	mount_uploader :logo, LogoUploader

	has_ancestry
	has_many :users
	has_many :resource_templates
	has_many :requirements_templates
  has_many :resource_contexts
  
  has_many :statistics, foreign_key: "institution_id", 
                        class_name: "InstitutionStatistic"

	validates :full_name, presence: true

  def plans_by_state(state)
    #get all plans this institution and sub-institutions has in the state specified
    Plan.joins(:current_state, :requirements_template).
          where(:requirements_templates => { :institution_id => self.subtree_ids }).
          where(:plan_states => { :state => state})
  end

  def unique_plan_states
    #returns a list of the unique plan states that this institution and sub-institutions has
    Plan.joins(:current_state, :requirements_template).
        where(:requirements_templates => { :institution_id => self.subtree_ids }).
        select('plan_states.state').distinct.pluck(:state)
  end

  def requirements_templates_deep
    #gets the deep list of all requirements templates for this and all sub-institutions under it
    RequirementsTemplate.where(institution_id: self.subtree_ids)
  end

  def resource_templates_deep
    #gets the deep list of all resource templates for this and all sub-institutions under it
    ResourceTemplate.where(institution_id: self.subtree_ids)
  end
  
  def users_deep
    #gets the list of all users associated with this institution and sub-institutions
    User.where(institution_id: self.subtree_ids)
  end

  def non_admin_users
    self.users.includes(:authorizations).where(authorizations: {role_id: nil})
  end

  def users_in_role(role_name)
{'fraction_non_alphanumeric': 0.06958250497017893, 'fraction_numerical': 0.0, 'mean_word_length': 4.233283803863299, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '5253606', 'n_tokens_mistral': 1040, 'n_tokens_neox': 1010, 'n_words': 284}