Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Merge 57d790f into 513968d
Browse files Browse the repository at this point in the history
  • Loading branch information
jessieay committed May 16, 2016
2 parents 513968d + 57d790f commit 6fe2f26
Show file tree
Hide file tree
Showing 27 changed files with 1,734 additions and 42 deletions.
30 changes: 30 additions & 0 deletions app/controllers/admin/auction_reports_controller.rb
@@ -0,0 +1,30 @@
class Admin::AuctionReportsController < ApplicationController
before_filter :require_admin

def show
@auction = Auction.find(params[:id])

respond_to do |format|
format.csv do
begin
response.headers['Content-Type'] = 'text/csv'
response.headers['Content-Disposition'] = "attachment"
send_data WinningBidderExport.new(@auction).export_csv,
filename: "winning_bidder_info_for_auction_#{@auction.id}.csv"
rescue WinningBidderExport::Error
redirect_to :back
flash[:error] = I18n.t('controllers.admin.auction_reports.show.error')
end
end
end
end

def csv_string
CSV.generate do |csv|
csv << [
"User ID",
"Test",
]
end
end
end
11 changes: 5 additions & 6 deletions app/controllers/application_controller.rb
Expand Up @@ -30,11 +30,6 @@ class ApplicationController < ActionController::Base
redirect_to login_path
end

rescue_from UnauthorizedError do |error|
message = error.message || "Unauthorized"
handle_error(message)
end

rescue_from 'UnauthorizedError::UserNotFound' do |error|
message = error.message || "User not found"
handle_error(message)
Expand All @@ -44,7 +39,7 @@ class ApplicationController < ActionController::Base

def authenticator
if @authenticator.nil?
@authenticator = if html_request?
@authenticator = if html_request? || csv_request?
WebAuthenticator.new(self)
elsif api_request?
ApiAuthenticator.new(self)
Expand All @@ -60,6 +55,10 @@ def html_request?
request.format.html?
end

def csv_request?
request.format == :csv
end

def api_request?
request.format.json?
end
Expand Down
17 changes: 17 additions & 0 deletions app/models/winning_bid.rb
@@ -0,0 +1,17 @@
class WinningBid
def initialize(auction)
@auction = auction
end

def find
auction_rules.winning_bid
end

private

attr_reader :auction

def auction_rules
RulesFactory.new(auction).create
end
end
110 changes: 110 additions & 0 deletions app/models/winning_bidder_export.rb
@@ -0,0 +1,110 @@
require 'csv'

class WinningBidderExport
class Error < StandardError; end

def initialize(auction)
@auction = auction
end

def export_csv
CSV.generate do |csv|
csv << [
"13GG Vendor Name",
"13JJ Vendor Address Line 1",
'13KK Vendor Address Line 2',
'13LL Vendor Address Line 3',
'13MM Vendor Address City',
'13NN Vendor Address State',
'13PP Vendor Zip Code',
'13QQ Vendor Country Code',
'13RR Vendor Phone Number',
'13SS Vendor Fax Number',
]
csv << [
legal_business_name,
address_line_1,
address_line_2,
address_line_3,
address_city,
address_state,
address_zip,
address_country,
phone,
fax,
]
end
end

private

attr_reader :auction

def legal_business_name
sam_data[:legalBusinessName]
end

def address_line_1
sam_address[:line1]
end

def address_line_2
sam_address[:line2] || nil
end

def address_line_3
sam_address[:line3] || nil
end

def address_city
sam_address[:city]
end

def address_state
sam_address[:stateorProvince]
end

def address_zip
sam_address[:zip] + zip_plus_4
end

def zip_plus_4
sam_address[:zipPlus4] || ''
end

def address_country
sam_address[:countryCode]
end

def phone
sam_data[:govtBusinessPoc][:usPhone]
end

def fax
sam_data[:govtBusinessPoc][:fax]
end

def sam_address
sam_data[:samAddress]
end

def sam_data
if get_duns_data['Code'] && get_duns_data['Code'] == 404
fail WinningBidderExport::Error
else
get_duns_data.deep_symbolize_keys[:sam_data][:registration]
end
end

def get_duns_data
@_get_duns_data ||= client.get_duns_info(duns: winning_bidder.duns_number)
end

def winning_bidder
WinningBid.new(auction).find.bidder
end

def client
@client ||= Samwise::Client.new(api_key: DataDotGovCredentials.api_key)
end
end
2 changes: 1 addition & 1 deletion app/serializers/auction_serializer.rb
Expand Up @@ -46,7 +46,7 @@ def find_winning_bid
if auction_status.available?
NullBid.new
else
RulesFactory.new(object).create.winning_bid
WinningBid.new(object).find
end
end

Expand Down
6 changes: 1 addition & 5 deletions app/services/losing_bidder_email_sender.rb
Expand Up @@ -30,10 +30,6 @@ def losing_bidders
end

def winning_bid
auction_rules.winning_bid
end

def auction_rules
RulesFactory.new(auction).create
WinningBid.new(auction).find
end
end
2 changes: 2 additions & 0 deletions app/views/admin/auctions/show.html.erb
@@ -1,5 +1,7 @@
<h1><%= @auction.title %></h1>

<%= link_to I18n.t('admin.auctions.show.winner_report'), admin_auction_report_path(@auction, format: :csv) %>

<div class='usa-width-one-whole'>
<div class='usa-width-one-sixth'>
<% if @auction.available? %>
Expand Down
22 changes: 0 additions & 22 deletions config/application.rb
Expand Up @@ -9,35 +9,13 @@
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Micropurchase
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
config.time_zone = "Etc/UTC"

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true

config.active_job.queue_adapter = :delayed_job

# Don't automatically generate factories for now
config.generators do |g|
g.factory_girl false
end
config.assets.precompile += %w( *-bundle.js )

config.middleware.insert_before 0, "Rack::Cors" do
Expand Down
8 changes: 8 additions & 0 deletions config/locales/en.yml
Expand Up @@ -23,6 +23,9 @@ en:
auctions:
create:
success: "Auction created successfully"
auction_reports:
show:
error: "Registration not found for winning bidder DUNS number"
mailers:
auction_mailer:
losing_bidder_notification:
Expand All @@ -34,3 +37,8 @@ en:
sign_off: "Sincerely,"
from: "The 18f Micropurchase team"
subject: "18f Micropurchase Auction Status"

admin:
auctions:
show:
winner_report: "Generate a CSV Report"
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -28,6 +28,7 @@
namespace :admin do
resources :auctions
resources :users, only: [:index, :edit, :update, :show]
resources :auction_reports, only: [:show]
end

get '/auth/:provider/callback', to: 'authentications#create'
Expand Down
28 changes: 28 additions & 0 deletions features/admin_auctions.feature
Expand Up @@ -52,3 +52,31 @@ Feature: Using the Admin Auctions panel

When I click on the auction's title
Then I should see new content on the page

Scenario: I get a CSV file containing Sam.gov data for the winning vendor
Given I am an administrator
And I sign in
And there is a closed auction
And the winning bidder has a valid DUNS number
When I visit the admin auction page for that auction
And I click on the link to generate a winning bidder CSV report
Then the file should contain the following data from Sam.gov:
"""
13GG Vendor Name,
13JJ Vendor Address Line 1,
13KK Vendor Address Line 2,
13LL Vendor Address Line 3,
13MM Vendor Address City,
13NN Vendor Address State,
13PP Vendor Zip Code,
13QQ Vendor Country Code,
13RR Vendor Phone Number,
13SS Vendor Fax Number,
Sudol, Brendan,
4301 N Henderson Rd Apt 408,
Arlington,
VA,
222032511,
USA,
5404218332,
"""
17 changes: 16 additions & 1 deletion features/step_definitions/admin_auctions_steps.rb
Expand Up @@ -2,8 +2,16 @@
visit admin_auctions_path
end

When(/^I visit the admin auction page for that auction$/) do
visit admin_auction_path(@auction)
end

When(/^I visit the admin edit page for that auction$/) do
visit "/admin/auctions/#{@auction.id}/edit"
visit edit_admin_auction_path(@auction)
end

When(/^I click on the link to generate a winning bidder CSV report$/) do
click_on(I18n.t('admin.auctions.show.winner_report'))
end

When(/^I select the result as accepted$/) do
Expand All @@ -27,6 +35,13 @@
expect(page).to have_content(@auction.cap_proposal_url)
end

Then(/^the file should contain the following data from Sam\.gov:$/) do |content|
expect(page.response_headers["Content-Disposition"]).to include("attachment")
content.split(',').each do |info|
expect(page.source).to include(info.strip)
end
end

Then(/^I will not see a warning I must be an admin$/) do
expect(page).to_not have_text('must be an admin')
end
Expand Down
9 changes: 7 additions & 2 deletions features/step_definitions/auction_steps.rb
Expand Up @@ -35,11 +35,16 @@
end

When(/^I visit the auction page$/) do
visit "/auctions/#{@auction.id}"
visit auction_path(@auction)
end

When(/^I visit the unpublished auction$/) do
visit "/auctions/#{@unpublished_auction.id}"
visit auction_path(@unpublished_auction)
end

When(/^the winning bidder has a valid DUNS number$/) do
winning_bid = RulesFactory.new(@auction).create.winning_bid
winning_bid.bidder.update(duns_number: FakeSamApi::VALID_DUNS)
end

Then(/^I should see the winning bid for the auction$/) do
Expand Down

0 comments on commit 6fe2f26

Please sign in to comment.