<commit_before>class ItemsController < ApplicationController
  before_action:find_item, only: [:show, :edit, :update, :destroy]
  
  def index
    if user_signed_in?
      @items = Item.where(:user_id => current_user.id).order("created_at DESC")
    end
  end
  
  def show
    
  end
    
  def new
    @item = current_user.items.build
  end
  
  def create
    @item =  current_user.items.build( item_params )
    if @item.save
      redirect_to items_path
    else
      render 'new'
    end
  end
  
  def edit
    
  end
  
  def update
    if @item.update( item_params )
      redirect_to item_path(@item)
    else
      render 'edit'
    end
  end
  
  def destroy
    @item.destroy
    redirect_to items_path
  end
    
  private
    def item_params
      params.require(:item).permit(:title, :description)
    end
    
    def find_item
      @item = Item.find(params[:id])
    end
end<commit_msg>Added security measure to prevent users from editing other users ideas<commit_after>class ItemsController < ApplicationController
  before_action :own_item, only: [:show, :edit, :update, :destroy]
  before_action:find_item, only: [:show, :edit, :update, :destroy]
  
    def index
    if user_signed_in?
      @items = Item.where(:user_id => current_user.id).order("created_at DESC")
    end
  end
  
  def show
    
  end
    
  def new
    @item = current_user.items.build
  end
  
  def create
    @item =  current_user.items.build( item_params )
    if @item.save
      redirect_to items_path
    else
      render 'new'
    end
  end
  
  def edit
    
  end
  
  def update
    if @item.update( item_params )
      redirect_to item_path(@item)
    else
      render 'edit'
    end
  end
  
  def destroy
    @item.destroy
    redirect_to items_path
  end
    
  private
    def item_params
      params.require(:item).permit(:title, :description)
    end
    
    def find_item
      @item = Item.find(params[:id])
    end
    
    def own_item 
      unless current_user == @item.user
         flash[:alert] = "You cannot view this item."
         redirect_to root_path
      end
    end  
end
{'fraction_non_alphanumeric': 0.0811965811965812, 'fraction_numerical': 0.0, 'mean_word_length': 2.297339593114241, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6419960', 'n_tokens_mistral': 701, 'n_tokens_neox': 697, 'n_words': 180}