<commit_before>module Kiitos
  module Admin
    class KiitosController < ApplicationController
      before_filter :kiitos, only: [:create, :index]
      before_filter :is_admin?

      def index
        @kiito = Kiito.new
      end

      def create
        @kiito = Kiito.new kiito_params
        if @kiito.save
          redirect_to action: :index
        else
          render :index
        end
      end

      def edit
        @kiito = Kiito.find(params[:id])
      end

      def update
        @kiito = Kiito.find(params[:id])
        if @kiito.update kiito_params
          redirect_to action: :edit
        else
          render :edit
        end
      end

      def destroy
        @user = Kiitos::Kiito.find(params[:id]).destroy
        render json: @user
      end

      private

      def kiitos
        @kiitos = Kiito.all
      end

      def kiito_params
        params.require(:kiito).permit(
          :title,
          :kiitos_category_id,
          :description,
          :image,
          :state
        )
      end

      def is_admin?
        unless Kiitos::UserQuery.is_admin?(kiitos_current_user)
          render json: { message: "Error 403, you don't have permissions for this operation" },
            status: 403
        end<commit_msg>Refactor kiitos_controller - Create before_filter find_kiito for only edit and update actions<commit_after>module Kiitos
  module Admin
    class KiitosController < ApplicationController
      before_filter :kiitos, only: [:create, :index]
      before_filter :find_kiito, only: [:edit, :update]
      before_filter :is_admin?

      def index
        @kiito = Kiito.new
      end

      def create
        @kiito = Kiito.new kiito_params
        if @kiito.save
          redirect_to action: :index
        else
          render :index
        end
      end

      def edit
      end

      def update
        if @kiito.update kiito_params
          redirect_to action: :edit
        else
          render :edit
        end
      end

      def destroy
        @user = Kiitos::Kiito.find(params[:id]).destroy
        render json: @user
      end

      private

      def find_kiito
        @kiito = Kiito.find(params[:id])
      end

      def kiitos
        @kiitos = Kiito.all
      end

      def kiito_params
        params.require(:kiito).permit(
          :title,
          :kiitos_category_id,
          :description,
          :image,
          :state
        )
      end

      def is_admin?
        unless Kiitos::UserQuery.is_admin?(kiitos_current_user)
          render json: { message: "Error 403, you don't have permissions for this operation" },
            status: 403
        end
{'fraction_non_alphanumeric': 0.07161604799400074, 'fraction_numerical': 0.0044994375703037125, 'mean_word_length': 1.657370517928287, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3100739', 'n_tokens_mistral': 787, 'n_tokens_neox': 753, 'n_words': 207}