<commit_before>require_dependency "storytime/application_controller"

module Storytime
  module Dashboard
    class UsersController < DashboardController
      before_action :load_users, only: :index
      before_action :load_user, only: [:edit, :update, :destroy]

      respond_to :json

      def index
        authorize @users
        respond_with @users
      end

      def new
        @user = Storytime.user_class.new
        @membership = @user.memberships.new
        authorize @user
        respond_with @user
      end

      def create
        @user = Storytime.user_class.new(user_params)
        authorize @user

        respond_with @user do |format|
          if @user.save
            load_users
            format.json { render :index }
          else
            format.json { render :new, status: :unprocessable_entity }
          end
        end
      end<commit_msg>Handle creation of membership with newly created user<commit_after>require_dependency "storytime/application_controller"

module Storytime
  module Dashboard
    class UsersController < DashboardController
      before_action :load_users, only: :index
      before_action :load_user, only: [:edit, :update, :destroy]

      respond_to :json

      def index
        authorize @users
        respond_with @users
      end

      def new
        @user = Storytime.user_class.new
        @membership = @user.memberships.new
        authorize @user
        respond_with @user
      end

      def create
        membership_attrs = params[:user].delete(:memberships_attributes)["0"]
        @user = Storytime.user_class.new(user_params)
        authorize @user

        respond_to do |format|
          if @user.save
            @user.memberships.create(storytime_role_id: membership_attrs[:storytime_role_id])
            load_users
            format.json { render :index }
          else
            format.json { render :new, status: :unprocessable_entity }
          end
        end
      end
{'fraction_non_alphanumeric': 0.06868686868686869, 'fraction_numerical': 0.000505050505050505, 'mean_word_length': 2.1900161030595813, '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': '5213359', 'n_tokens_mistral': 548, 'n_tokens_neox': 532, 'n_words': 137}