<commit_before># Scaffolding generated by Casein v5.1.1.5

module Casein
  class OrdersController < Casein::CaseinController
  
    ## optional filters for defining usage according to Casein::AdminUser access_levels
    # before_filter :needs_admin, :except => [:action1, :action2]
    # before_filter :needs_admin_or_current_user, :only => [:action1, :action2]
  
    def index
      @casein_page_title = t('menu.orders')
      if current_user.is_admin?
  		  @orders = Order.posted(params[:posted]).order(:cancelled, status: :desc, created_at: :desc)
      else
        @orders = Order.where(casein_admin_user: current_user).active.order(created_at: :desc)
      end

      @orders = @orders.order(sort_order(:created_at)).paginate :page => params[:page]

      session[:return_to] = request.url
    end
  
    def show
      @casein_page_title = t('action.view_order')
      @order = Order.find params[:id]
    end
  
    def new
      @casein_page_title = t('action.create_order')
    	@order = Order.new
      @order.casein_admin_user = current_user
    end

    def create
      @order = Order.new order_params
      @order.casein_admin_user_id = order_params[:casein_admin_user_id] || current_user.id
      @order.status = @order.status ? @order.status : Order::STATUS.first
    
      if @order.save
        flash[:notice] = t('message.create_order_success')
        redirect_to casein_orders_path
      else
        flash.now[:warning] = t('message.create_order_fail')
        render :action => :new
      end
    end
  
    def update
      @casein_page_title = t('action.view_order')
      
      @order = Order.find params[:id]
    
      if @order.update_attributes order_params

        flash[:notice] = t('message.update_order_success')
        redirect_to casein_orders_path
      else
        flash.now[:warning] = t('message.update_order_fail')
        render :action => :show
      end
    end<commit_msg>limit agent to update order user; forbit agent to destroy order<commit_after># Scaffolding generated by Casein v5.1.1.5

module Casein
  class OrdersController < Casein::CaseinController
  
    ## optional filters for defining usage according to Casein::AdminUser access_levels
    before_filter :needs_admin, :only => [:destroy]
    # before_filter :needs_admin_or_current_user, :only => [:action1, :action2]
  
    def index
      @casein_page_title = t('menu.orders')
      if current_user.is_admin?
  		  @orders = Order.posted(params[:posted]).order(:cancelled, status: :desc, created_at: :desc)
      else
        @orders = Order.where(casein_admin_user: current_user).active.order(created_at: :desc)
      end

      @orders = @orders.order(sort_order(:created_at)).paginate :page => params[:page]

      session[:return_to] = request.url
    end
  
    def show
      @casein_page_title = t('action.view_order')
      @order = Order.find params[:id]
    end
  
    def new
      @casein_page_title = t('action.create_order')
    	@order = Order.new
      @order.casein_admin_user = current_user
    end

    def create
      @order = Order.new order_params

      if current_user.is_admin?
        @order.casein_admin_user_id = order_params[:casein_admin_user_id] || current_user.id
      else
        @order.casein_admin_user = current_user
      end
      
      @order.status = @order.status ? @order.status : Order::STATUS.first
    
      if @order.save
        flash[:notice] = t('message.create_order_success')
        redirect_to casein_orders_path
      else
        flash.now[:warning] = t('message.create_order_fail')
        render :action => :new
      end
    end
  
    def update
      @casein_page_title = t('action.view_order')
      
      @order = Order.find params[:id]
    
      if @order.update_attributes order_params

        flash[:notice] = t('message.update_order_success')
        redirect_to casein_orders_path
      else
        flash.now[:warning] = t('message.update_order_fail')
        render :action => :show
      end
    end
{'fraction_non_alphanumeric': 0.10538172715894868, 'fraction_numerical': 0.003504380475594493, 'mean_word_length': 2.90234375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3214620', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1254, 'n_words': 254}