<commit_before>namespace :blank do

  desc "Install Blank Application"
	task :install => :environment do
    p "Installing required gems"
    Rake::Task['gems:install'].invoke
    p "Creating Database"
		Rake::Task['db:create'].invoke
    p "Migrating"
		Rake::Task['db:migrate'].invoke
    p "Setting Up Default Settings"
		Rake::Task['blank:pump'].invoke
    p "Setting Other Settings"
    Rake::Task['blank:init'].invoke
    p "Starting Delayed_Job"
    system("ruby script/delayed_job start")
    p "Creating Cron Schedules"
    system("whenever --update-crontab blank -s environment=#{RAILS_ENV}")
    Rake::Task['blank:xapian_rebuild'].invoke
    p "Installed Blank Application Sucessfully."
	end

	desc "Initializing Blank Engine"
	task :init => :environment do
		system("rake captcha:generate COUNT=10")
		#Rake::Task['captcha:generate'].invoke
	end

	desc "Initializing Blank Engine"
	task :update => :environment do
		Rake::Task['gems:install'].invoke
		Rake::Task['db:migrate'].invoke
		Rake::Task['blank:xapian_rebuild'].invoke
	end

	desc "Building Xapian indexes"
	task :xapian_rebuild => :environment do
		p "Building Xapian indexes"
		system("rake xapian:rebuild_index models='#{ITEMS.map{ |e| e.camelize }.join(' ')} User #{CONTAINERS.map{ |e| e.camelize }.join(' ')}' RAILS_ENV=#{RAILS_ENV}")
		p "Done"
	end

  desc "Create Basic Settings for BLANK"
  task(:pump => :environment) do
    Rake::Task['blank:drop_rights'].invoke
    Rake::Task['blank:create_permissions'].invoke
    Rake::Task['blank:create_roles'].invoke
    Rake::Task['blank:create_users'].invoke
    Rake::Task['blank:create_workspaces'].invoke
    Rake::Task['blank:css'].invoke
    p "Populate database with test data y/n"
    if STDIN.gets.chomp == 'y'
      Rake::Task['db:populate'].invoke
    end
  end

	desc "From drop to pump"
	task(:pumper => :environment) do
		Rake::Task['db:drop'].invoke
		Rake::Task['db:create'].invoke
		Rake::Task['db:migrate'].invoke
		Rake::Task['blank:pump'].invoke
	end

	### Pump subtasks

  desc "Drop Roles & Permissions"
  task(:drop_rights => :environment) do
    ActiveRecord::Base.establish_connection
    # Drop All Pervious Roles & Permissions;
    sql =["TRUNCATE table roles;",
      "TRUNCATE table permissions;",
      "TRUNCATE table permissions_roles;",
      "TRUNCATE table elements;"
    ]
    for i in sql
      query=<<-SQL
        #{i}
      SQL
      ActiveRecord::Base.connection.execute(query)
    end
  end

  desc "Loading Roles"
  task(:create_roles => :environment) do
    p "Loading Roles ..."
    Role.create(:name =>'superadmin', :description => 'SuperAdministration', :type_role =>'system')
    Role.create(:name =>'admin', :description => 'Administration', :type_role =>'system')
    Role.create(:name =>'user', :description => 'User', :type_role =>'system')
    Role.create(:name =>'co_admin', :description => 'Container Administrator', :type_role =>'container')
    Role.create(:name =>'moderator', :description => 'Container Moderator', :type_role =>'container')
    Role.create(:name =>'writer', :description => 'Container Writer', :type_role =>'container')
    Role.create(:name =>'reader', :description => 'Container Reader', :type_role =>'container')
    p "Done"
    p "Assigning Permissions to Roles ..."

    @role_admin=Role.find_by_name("admin")
    @role_user=Role.find_by_name("user")
    @role_ws=Role.find_by_name("co_admin")
    @role_mod=Role.find_by_name("moderator")
    @role_red=Role.find_by_name("reader")
    @role_wri=Role.find_by_name("writer")
    # Permissions for SUPERADMIN
    # don't care, checked directly with the role
    
    # Permissions for ADMIN
    Permission.find(:all).each do |p|
      @role_admin.permissions << p
    end
    
    CONTAINERS.each do |container|
      # Permissions for USER ROLES
      @role_user.permissions << Permission.find_by_name("#{container}_new")
      # Permissions for CONTAINERS ROLES
      Permission.find(:all, :conditions => "name LIKE '#{container}%' AND type_permission='container'").each do |p|
        @role_ws.permissions << p
        @role_mod.permissions << p if p.name != "#{container}_destroy"
      end
      @role_red.permissions << Permission.find(:all, :conditions =>{:name => "#{container}_show"})
      @role_wri.permissions << Permission.find(:all, :conditions =>{:name => "#{container}_show"})
      @admin_ws = Permission.create(:name => "#{container}_administrate", :type_permission => 'container') unless Permission.exists?(:name => "#{container}_administrate", :type_permission => 'container')
      if @admin_ws
        @role_admin.permissions << @admin_ws
        @role_ws.permissions << @admin_ws
        @role_mod.permissions << @admin_ws
      end
    end
    ITEMS.each do |item|
      ['new', 'edit', 'index', 'show', 'destroy','comment','rate'].each do |action|
        Permission.find(:all, :conditions =>{:name => item + '_' + action}).each do |p|
          #@role_user.permissions << p<commit_msg>#1099 adding tag to default rights, others are ok<commit_after>namespace :blank do

  desc "Install Blank Application"
	task :install => :environment do
    p "Installing required gems"
    Rake::Task['gems:install'].invoke
    p "Creating Database"
		Rake::Task['db:create'].invoke
    p "Migrating"
		Rake::Task['db:migrate'].invoke
    p "Setting Up Default Settings"
		Rake::Task['blank:pump'].invoke
    p "Setting Other Settings"
    Rake::Task['blank:init'].invoke
    p "Starting Delayed_Job"
    system("ruby script/delayed_job start")
    p "Creating Cron Schedules"
    system("whenever --update-crontab blank -s environment=#{RAILS_ENV}")
    Rake::Task['blank:xapian_rebuild'].invoke
    p "Installed Blank Application Sucessfully."
	end

	desc "Initializing Blank Engine"
	task :init => :environment do
		system("rake captcha:generate COUNT=10")
		#Rake::Task['captcha:generate'].invoke
	end

	desc "Initializing Blank Engine"
	task :update => :environment do
		Rake::Task['gems:install'].invoke
		Rake::Task['db:migrate'].invoke
		Rake::Task['blank:xapian_rebuild'].invoke
	end

	desc "Building Xapian indexes"
	task :xapian_rebuild => :environment do
		p "Building Xapian indexes"
		system("rake xapian:rebuild_index models='#{ITEMS.map{ |e| e.camelize }.join(' ')} User #{CONTAINERS.map{ |e| e.camelize }.join(' ')}' RAILS_ENV=#{RAILS_ENV}")
		p "Done"
	end

  desc "Create Basic Settings for BLANK"
  task(:pump => :environment) do
    Rake::Task['blank:drop_rights'].invoke
    Rake::Task['blank:create_permissions'].invoke
    Rake::Task['blank:create_roles'].invoke
    Rake::Task['blank:create_users'].invoke
    Rake::Task['blank:create_workspaces'].invoke
    Rake::Task['blank:css'].invoke
    p "Populate database with test data y/n"
    if STDIN.gets.chomp == 'y'
      Rake::Task['db:populate'].invoke
    end
  end

	desc "From drop to pump"
	task(:pumper => :environment) do
		Rake::Task['db:drop'].invoke
		Rake::Task['db:create'].invoke
		Rake::Task['db:migrate'].invoke
		Rake::Task['blank:pump'].invoke
	end

	### Pump subtasks

  desc "Drop Roles & Permissions"
  task(:drop_rights => :environment) do
    ActiveRecord::Base.establish_connection
    # Drop All Pervious Roles & Permissions;
    sql =["TRUNCATE table roles;",
      "TRUNCATE table permissions;",
      "TRUNCATE table permissions_roles;",
      "TRUNCATE table elements;"
    ]
    for i in sql
      query=<<-SQL
        #{i}
      SQL
      ActiveRecord::Base.connection.execute(query)
    end
  end

  desc "Loading Roles"
  task(:create_roles => :environment) do
    p "Loading Roles ..."
    Role.create(:name =>'superadmin', :description => 'SuperAdministration', :type_role =>'system')
    Role.create(:name =>'admin', :description => 'Administration', :type_role =>'system')
    Role.create(:name =>'user', :description => 'User', :type_role =>'system')
    Role.create(:name =>'co_admin', :description => 'Container Administrator', :type_role =>'container')
    Role.create(:name =>'moderator', :description => 'Container Moderator', :type_role =>'container')
    Role.create(:name =>'writer', :description => 'Container Writer', :type_role =>'container')
    Role.create(:name =>'reader', :description => 'Container Reader', :type_role =>'container')
    p "Done"
    p "Assigning Permissions to Roles ..."

    @role_admin=Role.find_by_name("admin")
    @role_user=Role.find_by_name("user")
    @role_ws=Role.find_by_name("co_admin")
    @role_mod=Role.find_by_name("moderator")
    @role_red=Role.find_by_name("reader")
    @role_wri=Role.find_by_name("writer")
    # Permissions for SUPERADMIN
    # don't care, checked directly with the role
    
    # Permissions for ADMIN
    Permission.find(:all).each do |p|
      @role_admin.permissions << p
    end
    
    CONTAINERS.each do |container|
      # Permissions for USER ROLES
      @role_user.permissions << Permission.find_by_name("#{container}_new")
      # Permissions for CONTAINERS ROLES
      Permission.find(:all, :conditions => "name LIKE '#{container}%' AND type_permission='container'").each do |p|
        @role_ws.permissions << p
        @role_mod.permissions << p if p.name != "#{container}_destroy"
      end
      @role_red.permissions << Permission.find(:all, :conditions =>{:name => "#{container}_show"})
      @role_wri.permissions << Permission.find(:all, :conditions =>{:name => "#{container}_show"})
      @admin_ws = Permission.create(:name => "#{container}_administrate", :type_permission => 'container') unless Permission.exists?(:name => "#{container}_administrate", :type_permission => 'container')
      if @admin_ws
        @role_admin.permissions << @admin_ws
        @role_ws.permissions << @admin_ws
        @role_mod.permissions << @admin_ws
      end
    end
    ITEMS.each do |item|
      ['new', 'edit', 'index', 'show', 'destroy','comment','rate','tag'].each do |action|
        Permission.find(:all, :conditions =>{:name => item + '_' + action}).each do |p|
          #@role_user.permissions << p
{'fraction_non_alphanumeric': 0.15660112359550563, 'fraction_numerical': 0.0008025682182985554, 'mean_word_length': 4.16796267496112, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 83, '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': '6498382', 'n_tokens_mistral': 3338, 'n_tokens_neox': 3191, 'n_words': 713}