app/controllers/users_controller.rb
# TODO - creation of staff users needs to be made generic - it is currently tied to Unity system and campus LDAP
creation of staff users needs to be made generic - it is currently tied to Unity system and campus LDAP
creation of staff users needs to be made generic - it is currently tied to Unity system and campus LDAP
def create
    params[:user][:user_role_id] ||= UserRole.lowest.id
    if !current_user.can_assign_role?(params[:user][:user_role_id])
      role = UserRole.find(params[:user][:user_role_id])
      render json: { error: { detail: "Forbidden: This operation is only available to users with role '#{ role.name }'.", status: 403 } }, status: 403
      return
    else
      @user = User.find_by_email(params[:user][:email])
      if @user
        raise CircaExceptions::BadRequest, "User with email #{params[:user][:email]} already exists."
      else
        params[:user][:password] ||= SecureRandom.hex(8)
        if params[:user][:agreement_confirmed]
          params[:user][:agreement_confirmed_at] = Time.now
        end
        @user = User.create!(user_params)
        update_notes
        render json: SerializeUser.call(@user)
        return
      end
    end
  end
def create params [ :user ] [ :user_role_id ] ||= UserRole . lowest . id if ! current_user . can_assign_role? ( params [ :user ] [ :user_role_id ] ) role = UserRole . find ( params [ :user ] [ :user_role_id ] ) render json : { error : { detail : "Forbidden: This operation is only available to users with role '#{ role.name }'." , status : 403 } } , status : 403 return else @user = User . find_by_email ( params [ :user ] [ :email ] ) if @user raise CircaExceptions :: BadRequest , "User with email #{params[:user][:email]} already exists." else params [ :user ] [ :password ] ||= SecureRandom . hex ( 8 ) if params [ :user ] [ :agreement_confirmed ] params [ :user ] [ :agreement_confirmed_at ] = Time . now end @user = User . create! ( user_params ) update_notes render json : SerializeUser . call ( @user ) return end end end
TODO - creation of staff users needs to be made generic - it is currently tied to Unity system and campus LDAP
TODO - creation of staff users needs to be made generic - it is currently tied to Unity system and campus LDAP