Skip to content

Commit

Permalink
Merge f4c8cee into d294908
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Sep 7, 2018
2 parents d294908 + f4c8cee commit 902381b
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 50 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ group :production do
gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
gem 'ruby-oci8'
gem 'ruby-plsql'
# To query an sqlserver instance (lobbytrack)
gem 'tiny_tds'
end

gem 'therubyracer'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ GEM
thread_safe (0.3.6)
tilt (2.0.8)
tins (1.16.3)
tiny_tds (2.1.2)
tsv (1.0.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
Expand Down Expand Up @@ -344,6 +345,7 @@ DEPENDENCIES
sul_styles
systemu
therubyracer
tiny_tds
tsv
uglifier
web-console (~> 2.0)
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def user_id
end
helper_method :user_id

def client_ip
request.env['HTTP_CLIENT_IP'] || ENV['HTTP_CLIENT_IP']
end
helper_method :client_ip

def webauth_user?
current_user.present? && user_id.present?
end
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/lobbytrack_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Controller for lobbytrack report
class LobbytrackController < ApplicationController
def show
@lobbytrack = LobbyTrack.query(params[:id])
return if @lobbytrack.any?
if Settings.lobbytrack_ips.include?(client_ip.to_s)
flash[:error] = 'You cannot access Lobbytrack from the current client IP address'
else
flash[:warning] = "There is no attendance history for id #{params[:id]}"
end
redirect_to root_path
end
end
20 changes: 20 additions & 0 deletions app/models/lobby_track.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Class to connect to LobbyTraclk
class LobbyTrack
include ActiveModel::Model

require 'tiny_tds'

@client = TinyTds::Client.new username: Settings.lobbytrack_user, password: Settings.lobbytrack_password,
host: Settings.lobbytrack_host, port: Settings.lobbytrack_port,
database: Settings.lobbytrack_db

def self.query(id)
@client.active? ? @client.execute(sql(id)).each : @client.close
end

def self.sql(id)
'SELECT CardHolderID, DateIn, ReportField1, ReportField2, LookupField1' \
' FROM Jolly.dbo.logAttendance' \
" WHERE CardHolderID = '#{id}'"
end
end
12 changes: 12 additions & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@
</div>
<% end %>
</div>
<% if Settings.lobbytrack_ips.include?(request.remote_ip) %>
<div class="panel panel-default">
<div class="panel-heading" role="tab">
<h4 class="link" role="button" data-toggle="collapse" href="#buttonCollapseLT" aria-expanded="false" aria-controls="buttonCollapseLT">LobbyTrack visitor report</h4>
<div id='buttonCollapseLT' class='collapse' aria-labelledby='buttonCollapseLT'>
<%= label_tag 'Enter visitor ID:' %>
<%= text_field_tag('lobbytrack_id') %>
<%= link_to 'Go', '#', :onclick => "window.location.href='/lobbytrack/' + $('#lobbytrack_id').val();", class: 'btn btn-md btn-default' %>
</div>
</div>
</div>
<% end %>
<% if can? :create, UserloadRerun %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
Expand Down
21 changes: 21 additions & 0 deletions app/views/lobbytrack/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="home-page-section">
<h2>Visitor attendance report</h2>
<h4>
<p>ID: <%= @lobbytrack.first.values[0] %></p>
<p>Name: <%= @lobbytrack.first.values[2] %> <%= @lobbytrack.first.values[3] %></p>
<p>Email: <%= @lobbytrack.first.values[4] %></p>
</h4>
<p>
<h4>Visits:</h4>
</p>
<div>
<% @lobbytrack.each_with_index do |row, index| %>
<ul>
<li><%= index %>: <%= row.values[1] ? row.values[1].strftime('%F %R') : '' %></li>
</ul>
<% end %>
</div>
</div>
<div class="btn-group">
<%= main_menu_button %>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
get 'edi_lins/update_barcode' => 'edi_lins#update_barcode'
get 'edi_lins/show/:barcode_num' => 'edi_lins#show'

get 'lobbytrack/:id' => 'lobbytrack#show'
get 'management_reports' => 'management_reports#index'

get 'by_location' => 'accession_number_updates#by_location'
Expand Down
1 change: 1 addition & 0 deletions config/settings/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ symphony_cgi_url: 'https://example.com'
symphony_dataload_endowrpt: 'tmp/Dataload/EndowRpt'
symphony_config_digital_bookplates: 'spec/fixtures/files/symp_dor.txt'
symphony_dataload_digital_bookplates: 'tmp/Dataload/BookplateMerge/Batches/Queue'
lobbytrack_ips: ['171.1.1.1', '171.67.138.83']
# PL/SQL jobs
pl_sql_jobs:
circ_stats_job:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLobbytrackToAuthorizedUser < ActiveRecord::Migration
def change
add_column :authorized_user, :lobbytrack, :string
end
end
53 changes: 3 additions & 50 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180830220045) do
ActiveRecord::Schema.define(version: 20180905171401) do

create_table "authorized_user", force: :cascade do |t|
t.string "user_id"
Expand All @@ -37,7 +37,7 @@
t.string "digital_bookplates"
t.string "edi_inv_manage"
t.string "edi_inv_view"
t.string "package_manage"
t.string "lobbytrack"
end

create_table "catnums", force: :cascade do |t|
Expand Down Expand Up @@ -356,6 +356,7 @@
t.datetime "last_action_date"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "bc_file_obj"
end

create_table "sal3_batch_requests_bcs", force: :cascade do |t|
Expand Down Expand Up @@ -481,52 +482,4 @@
t.datetime "updated_at", null: false
end

create_table "url_exclusions", force: :cascade do |t|
t.string "url_substring"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "vnd_packages", primary_key: "record_id", force: :cascade do |t|
t.string "package_id"
t.string "package_name"
t.string "package_status"
t.string "data_pickup_type"
t.string "afs_path"
t.string "ftp_server"
t.string "ftp_user"
t.string "ftp_password"
t.string "ftp_directory"
t.string "ftp_file_prefix"
t.string "ftp_list_type"
t.string "package_url"
t.datetime "date_entered"
t.string "vendor_name"
t.string "holding_code"
t.string "comments"
t.datetime "date_modified"
t.string "put_file_loc"
t.string "afs_search_string"
t.string "url_field"
t.string "vendor_id_read"
t.string "vendor_id_write"
t.string "access_note"
t.string "export_note"
t.string "junktag_file"
t.string "encoding_level"
t.string "vnd_catcode"
t.string "match_opts"
t.string "proc_type"
t.string "update_040"
t.string "rpt_mail"
t.string "access_urls_plats"
t.string "date_cat"
t.string "export_auth"
t.string "preprocess_modify_script"
t.string "preprocess_split_script"
t.string "preprocess_put_script"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

end
18 changes: 18 additions & 0 deletions spec/controllers/lobbytrack_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'rails_helper'

RSpec.describe LobbytrackController, type: :controller do
describe 'get#show', type: :lobbytrack do
before do
stub_current_user(FactoryBot.create(:authorized_user))
end
it 'returns the array of data if the id exists' do
get :show, id: '1104840'
expect(response).to render_template 'show'
end
it 'returns to the home page if the id does not exist' do
get :show, id: '123'
expect(flash).to be_present
expect(response).to redirect_to root_path
end
end
end
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
end

config.include ApplicationHelper

config.filter_run_excluding :type => 'lobbytrack' unless Settings.lobbytrack_ips.include?(ENV['HTTP_CLIENT_IP'].to_s)

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
Expand Down

0 comments on commit 902381b

Please sign in to comment.