<commit_before>require 'confluence_lib/confluence_interface.rb'
class Wiki < ActiveRecord::Base
  belongs_to :project

  #TODO: remove the wiki_pages table
  has_many :wiki_pages, :dependent => :destroy
  
  CONFLUENCE_INTERNAL_PATH = 'wiki/display/'
  CONFLUENCE_INTERNAL_URL = CONFLUENCE_URL + '/' + CONFLUENCE_INTERNAL_PATH
  
  def before_save
    self.external_url = '' if use_internal?
  end
  
  def after_create
    #self.wiki_pages << WikiPage.create(:slug => 'Downloads', 
    # :body => 'Use this page to provide links to any downloads you wish to provide.')
  end
  
  def before_destroy
    return true unless exists_internally?  
    
    conf_inter = ConfluenceInterface.new
    conf_inter.login
    conf_inter.remove_space(self.project.shortname)   
    conf_inter.logout
  end
  
  def is_active?
    use_internal? or not external_url.blank?
  end
  
  def internal_url
    CONFLUENCE_INTERNAL_URL + "#{self.project.shortname}/Home"
  end  
  
  def exists_internally?
    conf_inter = ConfluenceInterface.new
    conf_inter.login
    exist = conf_inter.space_exists?(self.project.shortname)
    conf_inter.logout
    exist
  end
  
  def create_internal
    return true if not use_internal? or exists_internally?

    confluence_interface = ConfluenceInterface.new
    confluence_interface.login
    confluence_interface.create_space(self.project.shortname, 
                   self.project.name,self.project.name + " Confluence Space",
                   CONFLUENCE_INTERNAL_URL,
                   self.project.is_private?)
    confluence_interface.logout
  end

  def url
    use_internal? ? internal_url : external_url
  end
  
  def get_latest_activity
    conf_inter = ConfluenceInterface.new
    conf_inter.login
    latest_act = conf_inter.get_latest_for_space(self.project.shortname)
    conf_inter.logout
    latest_act
  end

  def make_private
    reset_permissions(true)
  end
  
  def make_public
    reset_permissions(false)
  end
  
  def reset_permissions(reset_to_private)
    confluence_interface = ConfluenceInterface.new
    confluence_interface.login
    confluence_interface.reset_space_perm(project.shortname, reset_to__private)
    confluence_interface.logout
  end  
end<commit_msg>added code to inactivate a project<commit_after>require 'confluence_lib/confluence_interface.rb'
class Wiki < ActiveRecord::Base
  belongs_to :project

  #TODO: remove the wiki_pages table
  has_many :wiki_pages, :dependent => :destroy
  
  CONFLUENCE_INTERNAL_PATH = 'wiki/display/'
  CONFLUENCE_INTERNAL_URL = CONFLUENCE_URL + '/' + CONFLUENCE_INTERNAL_PATH
  
  def before_save
    self.external_url = '' if use_internal?
  end
  
  def after_create
    #self.wiki_pages << WikiPage.create(:slug => 'Downloads', 
    # :body => 'Use this page to provide links to any downloads you wish to provide.')
  end
  
  def before_destroy
    return true unless exists_internally?  
    
    conf_inter = ConfluenceInterface.new
    conf_inter.login
    conf_inter.remove_space(self.project.shortname)   
    conf_inter.logout
  end
  
  def is_active?
    use_internal? or not external_url.blank?
  end
  
  def internal_url
    CONFLUENCE_INTERNAL_URL + "#{self.project.shortname}/Home"
  end  
  
  def exists_internally?
    conf_inter = ConfluenceInterface.new
    conf_inter.login
    exist = conf_inter.space_exists?(self.project.shortname)
    conf_inter.logout
    exist
  end
  
  def create_internal
    return true if not use_internal? or exists_internally?

    confluence_interface = ConfluenceInterface.new
    confluence_interface.login
    confluence_interface.create_space(self.project.shortname, 
                   self.project.name,self.project.name + " Confluence Space",
                   CONFLUENCE_INTERNAL_URL,
                   self.project.is_private?)
    confluence_interface.logout
  end

  def url
    use_internal? ? internal_url : external_url
  end
  
  def get_latest_activity
    conf_inter = ConfluenceInterface.new
    conf_inter.login
    latest_act = conf_inter.get_latest_for_space(self.project.shortname)
    conf_inter.logout
    latest_act
  end

  def make_private
    reset_permissions(true)
  end
  
  def make_public
    reset_permissions(false)
  end
  
  def reset_permissions(reset_to_private)
    confluence_interface = ConfluenceInterface.new
    confluence_interface.login
    confluence_interface.reset_space_perm(project.shortname, reset_to_private)
    confluence_interface.logout
  end  
end
{'fraction_non_alphanumeric': 0.06395348837209303, 'fraction_numerical': 0.0, 'mean_word_length': 3.4199604743083003, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4467263', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1412, 'n_words': 274}