<commit_before>module Alchemy
  module Admin
    class UsersController < ResourcesController

      before_filter :set_roles_and_genders, except: [:index, :destroy]

      handles_sortable_columns do |c|
        c.default_sort_value = :login
      end

      def index
        if !params[:query].blank?
          users = User.where([
           "login LIKE ? OR email LIKE ? OR firstname LIKE ? OR lastname LIKE ?",
           "%#{params[:query]}%",
           "%#{params[:query]}%",
           "%#{params[:query]}%",
           "%#{params[:query]}%"
         ])
        else
          users = User.all
        end
        @users = users.page(params[:page] || 1).per(per_page_value_for_screen_size).order(sort_order)
      end

      def create
        @user = User.create(user_params)
        render_errors_or_redirect(
          @user,
          admin_users_path,
          _t("User created", :name => @user.name)
        )
      end

      def update
        # User is fetched via before filter
        if params[:user][:password].present?
          @user.update_attributes(user_params)
        else
          @user.update_without_password(user_params)
        end
        render_errors_or_redirect(
          @user,
          admin_users_path,
          _t("User updated", :name => @user.name)
        )
      end

      def destroy
        # User is fetched via before filter
        name = @user.name
        if @user.destroy
          flash[:notice] = _t("User deleted", :name => name)
        end
        @redirect_url = admin_users_path
        render :action => :redirect
      end

    private

      def set_roles_and_genders
        @user_roles = User::ROLES.map { |role| [User.human_rolename(role), role] }
        @user_genders = User.genders_for_select
      end

      def user_params
        params.require(:user).permit(*secure_attributes)
      end

      def secure_attributes
        if can?(:update_role, Alchemy::User)
          User::PERMITTED_ATTRIBUTES + [{roles: []}]
        else
          User::PERMITTED_ATTRIBUTES
        end
      end

    end
  end
end
<commit_msg>Set User#send_credentials checkbox to checked in Admin::Users#new<commit_after>module Alchemy
  module Admin
    class UsersController < ResourcesController

      before_filter :set_roles_and_genders, except: [:index, :destroy]

      handles_sortable_columns do |c|
        c.default_sort_value = :login
      end

      def index
        if !params[:query].blank?
          users = User.where([
           "login LIKE ? OR email LIKE ? OR firstname LIKE ? OR lastname LIKE ?",
           "%#{params[:query]}%",
           "%#{params[:query]}%",
           "%#{params[:query]}%",
           "%#{params[:query]}%"
         ])
        else
          users = User.all
        end
        @users = users.page(params[:page] || 1).per(per_page_value_for_screen_size).order(sort_order)
      end

      def new
        @user = User.new(send_credentials: true)
      end

      def create
        @user = User.create(user_params)
        render_errors_or_redirect(
          @user,
          admin_users_path,
          _t("User created", :name => @user.name)
        )
      end

      def update
        # User is fetched via before filter
        if params[:user][:password].present?
          @user.update_attributes(user_params)
        else
          @user.update_without_password(user_params)
        end
        render_errors_or_redirect(
          @user,
          admin_users_path,
          _t("User updated", :name => @user.name)
        )
      end

      def destroy
        # User is fetched via before filter
        name = @user.name
        if @user.destroy
          flash[:notice] = _t("User deleted", :name => name)
        end
        @redirect_url = admin_users_path
        render :action => :redirect
      end

    private

      def set_roles_and_genders
        @user_roles = User::ROLES.map { |role| [User.human_rolename(role), role] }
        @user_genders = User.genders_for_select
      end

      def user_params
        params.require(:user).permit(*secure_attributes)
      end

      def secure_attributes
        if can?(:update_role, Alchemy::User)
          User::PERMITTED_ATTRIBUTES + [{roles: []}]
        else
          User::PERMITTED_ATTRIBUTES
        end
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.10314523589269195, 'fraction_numerical': 0.00046253469010175765, 'mean_word_length': 1.9542349726775956, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '128356', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1280, 'n_words': 280}