<commit_before>class WebsitesController < ApplicationController
  before_filter :admin_required
  before_filter :find_website, :only => [:edit, :update, :destroy]
  
  def index
    @websites = Website.find(:all, :order => :name)
  end
  
  def new
    @website = Website.new
  end
  
  def edit
  end
  
  def create
    @website = Website.new(params[:website])

    if @website.save
      Page.bootstrap @website

      create_latest_news
      
      flash[:notice] = "Successfully added new website."
      redirect_to :action => "index"
    else
      render :action => "new"
    end
  end

  def update
    if @website.update_attributes(params[:website])
      flash[:notice] = 'Website saved.'
      redirect_to websites_path
    else
      render :action => 'edit'
    end
  end
  
  def destroy
    @website.destroy
    flash[:notice] = "Website deleted."
    redirect_to :action => "index"
  end
  
  protected
  
  def find_website
    @website = Website.find(params[:id])
  end

  def create_latest_news
    # create latest news forum and link it as the website's blog
    latest_news = Forum.new
    latest_news.name = 'Latest News'
    latest_news.website_id = @website.id
    latest_news.locked = true
    latest_news.save
    @website.blog_id = latest_news.id
    @website.save
    
    # create a vapid placeholder topic to introduce the new website
    topic = Topic.new
    topic.topic = 'New Website Launched'
    topic.posts_count = 1
    topic.forum_id = latest_news.id
    topic.views = 1
    topic.last_post_at = Time.now
    topic.save

    post = Post.new
    post.topic_id = topic.id
    post.content = 'The new website for ' + @website.name +
      ' is now complete. We hope you find it useful and easy to use.'<commit_msg>Allow managers to update their website settings<commit_after>class WebsitesController < ApplicationController
  before_filter :admin_required, :except => [:edit, :update]
  before_filter :find_website, :only => [:edit, :update, :destroy]
  before_filter :permission_check, :only => [:edit, :update]

  def index
    @websites = Website.find(:all, :order => :name)
  end
  
  def new
    @website = Website.new
  end
  
  def edit
  end
  
  def create
    @website = Website.new(params[:website])

    if @website.save
      Page.bootstrap @website

      create_latest_news
      
      flash[:notice] = "Successfully added new website."
      redirect_to :action => "index"
    else
      render :action => "new"
    end
  end

  def update
    if @website.update_attributes(params[:website])
      flash[:notice] = 'Website saved.'
      redirect_to edit_website_path(@website)
    else
      render :action => 'edit'
    end
  end
  
  def destroy
    @website.destroy
    flash[:notice] = "Website deleted."
    redirect_to :action => "index"
  end
  
  protected

  def permission_check
    admin_or_manager_required
    return if admin?
    if manager? && @w.id != @website.id
      flash[:notice] = 'You do not manage this website.'
      redirect_to :controller => 'sessions', :action => 'new'
    end
  end

  def find_website
    @website = Website.find(params[:id])
  end

  def create_latest_news
    # create latest news forum and link it as the website's blog
    latest_news = Forum.new
    latest_news.name = 'Latest News'
    latest_news.website_id = @website.id
    latest_news.locked = true
    latest_news.save
    @website.blog_id = latest_news.id
    @website.save
    
    # create a vapid placeholder topic to introduce the new website
    topic = Topic.new
    topic.topic = 'New Website Launched'
    topic.posts_count = 1
    topic.forum_id = latest_news.id
    topic.views = 1
    topic.last_post_at = Time.now
    topic.save

    post = Post.new
    post.topic_id = topic.id
    post.content = 'The new website for ' + @website.name +
      ' is now complete. We hope you find it useful and easy to use.'
{'fraction_non_alphanumeric': 0.09366958311888832, 'fraction_numerical': 0.001029336078229542, 'mean_word_length': 2.7447013487475913, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '806954', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1191, 'n_words': 345}