<commit_before>desc 'Set up initial permissions for journey stuff'
task :journey_perms => [:sync_permissions, :create_roles, :create_admin_user] do
  guest = Role.find_by_name(UserEngine.config(:guest_role_name))
  user = Role.find_by_name(UserEngine.config(:user_role_name))
  
  ['index', 'answer', 'validate_answers', 'resume', 'save_session', 'save_answers'].each do |action|
    p = Permission.find_by_controller_and_action('questionnaire', action)
    if not guest.permissions.include? p
      guest.permissions << p
    end
    if not user.permissions.include? p
      user.permissions << p
    end
  end

  p = Permission.find_by_controller_and_action('analyze', 'rss')
  if not guest.permissions.include? p
    guest.permissions << p
  end
  if not user.permissions.include? p
    user.permissions << p
  end
  
  synopsis_perms = SynopsisController.new.action_method_names.collect do |action|
    Permission.find_by_controller_and_action('synopsis', action)
  end
  Role.find_all.each do |role|
    synopsis_perms.each do |perm|
      if not role.permissions.include? perm
        role.permissions << perm
      end
    end
    role.save
  end

  raise "Couldn't save guest role!" if !guest.save
  raise "Couldn't save user role!" if !user.save
  
  if Role.find_by_name('Editor') == nil
    puts "Creating Editor role"
    editor = Role.new
    editor.name = 'Editor'
    editor.description = "GMs and their minions."
  else
    editor = Role.find_by_name('Editor')
  end
  
  perms = []
  perms += Permission.find_all_by_controller('questionnaire') 
  perms += Permission.find_all_by_controller('jqml') 
  perms += Permission.find_all_by_controller('analyze')
  perms += Permission.find_all_by_controller('writing')
  perms.each do |perm|
    if not editor.permissions.include? perm
      editor.permissions << perm
    end
  end
  raise "Couldn't save editor role!" if !editor.save
end
    
task :bootstrap => [:journey_perms]<commit_msg>rip out permissions rake task<commit_after>
{'fraction_non_alphanumeric': 0.10631895687061184, 'fraction_numerical': 0.0, 'mean_word_length': 3.901719901719902, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, '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': '5863497', 'n_tokens_mistral': 664, 'n_tokens_neox': 650, 'n_words': 153}