Skip to content

Commit

Permalink
Merge e7258a2 into 01bcea6
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Jan 14, 2020
2 parents 01bcea6 + e7258a2 commit a008b2b
Show file tree
Hide file tree
Showing 53 changed files with 1,428 additions and 443 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ config/settings/server.conf

dump.rdb

public/uploads/
public/uploads/**/*
public/tmp/
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ cache:
- directories
- '/home/travis/.rvm/'
bundler_args: --without production
before_install:
- sudo wget http://www.freetds.org/files/stable/freetds-1.1.6.tar.gz
- sudo tar -xzf freetds-1.1.6.tar.gz
- cd freetds-1.1.6
- sudo ./configure --prefix=/usr/local --with-tdsver=7.3
- sudo make
- sudo make install
- cd ..
before_script:
- mkdir -p tmp/Dataload/EndowRpt
- mkdir -p tmp/Dataload/BookplateMerge/Batches/Queue
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ gem 'has_scope'
gem 'tsv'
# Rails javascript runtime environment
gem 'therubyracer'
# To query an sqlserver instance (lobbytrack)
gem 'tiny_tds', '~> 2.1.2'

group :production do
gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.8'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ GEM
thread_safe (0.3.6)
tilt (2.0.10)
tins (1.21.1)
tiny_tds (2.1.2)
tsv (1.0.0)
tzinfo (1.2.6)
thread_safe (~> 0.1)
Expand Down Expand Up @@ -408,6 +409,7 @@ DEPENDENCIES
sul_styles
systemu
therubyracer
tiny_tds (~> 2.1.2)
tsv
uglifier
web-console
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,26 @@ is no Rails ORM on which to base an Ability.) Clicking the "Run" link will exec
already configured OCI8 connection gem (using the environment's database.yml connection details). If more jobs need to be
added in the future, just fill out a new section under the pl_sql_jobs section in the https://github.com/sul-dlss/shared_configs
repository and follow the instructions there for deploying to the application server.

## Lobbytrack Report

The lobbytrack database connection settings are kept in the Settings config file along with an array of IP addresses that
have firewall access to the lobbytrack database and can also use this webform. Inclusion of the client IP address here will
allow the Lobbytrack report menu item to appear for only clients with the IPs listed here:
```yml
# Lobbytrack settings
lobbytrack_host: '-----'
lobbytrack_user: '-----'
lobbytrack_password: '-----'
lobbytrack_db: '-----'
lobbytrack_port: -----
lobbytrack_ips: ['1.1.1.1', '2.2.2.2']
```

To work with LobbyTrack Reports in development you need to have your static IP address (`123.45.67.89` in the example below)
allowed through sul-lobbytrack.stanford.edu's firewall, and then start up the local development server bound to that same IP address:
```sh
$ REMOTE_USER=yourSUNet rails s -b 123.45.67.89
```

Then you would visit `123.45.67.89:3000` in your browser to view the locally running application.
7 changes: 7 additions & 0 deletions app/assets/javascripts/lobbytrack_reports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
jQuery(document).ready(function($) {
$('table').DataTable({
paging: false
});
});
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def display_name
end
helper_method :display_name

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
87 changes: 87 additions & 0 deletions app/controllers/lobbytrack_reports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Controller for lobbytrack report
class LobbytrackReportsController < ApplicationController
load_and_authorize_resource

def index
@lobbytrack_reports = LobbytrackReport.new
end

def visits
id = params[:lobbytrack_report][:visit_id]
begin
@lobbytrack_reports = LobbytrackReport.query_visits(id)
rescue TinyTds::Error => e
flash[:error] = e
end

return if @lobbytrack_reports&.any?

if Settings.lobbytrack_ips.include?(client_ip.to_s)
flash[:error] = 'You cannot access Lobbytrack from the current client IP address'
elsif id
flash[:warning] = "There is no attendance history for id #{id}"
end
redirect_to lobbytrack_reports_path
end

def checkins
id = params[:lobbytrack_report][:checkin_id]

begin
@lobbytrack_reports = LobbytrackReport.query_checkins(id)
rescue TinyTds::Error => e
flash[:error] = e
end

return if @lobbytrack_reports&.any?

if Settings.lobbytrack_ips.include?(client_ip.to_s)
flash[:error] = 'You cannot access Lobbytrack from the current client IP address'
elsif id
flash[:warning] = "There is no attendance history for id #{id}"
end
redirect_to lobbytrack_reports_path
end

def visit_dates
date1 = params[:lobbytrack_report][:visit_date1]
date2 = params[:lobbytrack_report][:visit_date2]
@dates = "#{date1} to #{date2}"

begin
@lobbytrack_reports = LobbytrackReport.query_visit_dates(date1, date2)
rescue TinyTds::Error => e
flash[:error] = e
end

return if @lobbytrack_reports&.any?

if Settings.lobbytrack_ips.include?(client_ip.to_s)
flash[:error] = 'You cannot access Lobbytrack from the current client IP address'
elsif @dates
flash[:warning] = "There is no attendance history between the dates #{@dates}"
end
redirect_to lobbytrack_reports_path
end

def checkin_dates
date1 = params[:lobbytrack_report][:checkin_date1]
date2 = params[:lobbytrack_report][:checkin_date2]
@dates = "#{date1} to #{date2}"

begin
@lobbytrack_reports = LobbytrackReport.query_checkin_dates(date1, date2)
rescue TinyTds::Error => e
flash[:error] = e
end

return if @lobbytrack_reports&.any?

if Settings.lobbytrack_ips.include?(client_ip.to_s)
flash[:error] = 'You cannot access Lobbytrack from the current client IP address'
elsif @dates
flash[:warning] = "There is no attendance history between the dates #{@dates}"
end
redirect_to lobbytrack_reports_path
end
end
3 changes: 2 additions & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def assign_staff_read_permission(current_user)

def assign_staff_manage_permission(current_user)
can :manage, AccessionNumberUpdate if /A|Y/.match?(current_user.accession_number)
can :manage, ManagementReport if /A|Y/.match?(current_user.mgt_rpts)
can :manage, EdiInvoice if /A|Y/.match?(current_user.edi_inv_manage)
can :manage, EdiErrorReport if /A|Y/.match?(current_user.edi_inv_manage)
can :manage, LobbytrackReport if /A|Y/.match? current_user.lobbytrack_report
can :manage, ManagementReport if /A|Y/.match?(current_user.mgt_rpts)
end

def assign_admin_permission(current_user)
Expand Down
53 changes: 53 additions & 0 deletions app/models/lobbytrack_report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Class to connect to Lobbytrack
class LobbytrackReport
include ActiveModel::Model

attr_accessor :visit_id, :checkin_id, :visit_date1, :visit_date2, :checkin_date1, :checkin_date2
require 'tiny_tds'

def self.client
TinyTds::Client.new username: Settings.lobbytrack_user, password: Settings.lobbytrack_password,
host: Settings.lobbytrack_host, port: Settings.lobbytrack_port,
database: Settings.lobbytrack_db, login_timeout: 5
end

def self.query_visits(visit_id)
client.active? ? client.execute(visits(visit_id)).each : client.close
end

def self.query_visit_dates(date1, date2)
client.active? ? client.execute(visits_for_dates(date1, date2)).each : client.close
end

def self.query_checkins(visit_id)
client.active? ? client.execute(checkins(visit_id)).each : client.close
end

def self.query_checkin_dates(date1, date2)
client.active? ? client.execute(checkins_for_dates(date1, date2)).each : client.close
end

def self.visits(id)
'SELECT CardHolderID, DateIn, ReportField1, ReportField2, LookupField1' \
' FROM Jolly.dbo.logAttendance' \
" WHERE CardHolderID = '#{id}'"
end

def self.visits_for_dates(date1, date2)
'SELECT CardHolderID, DateIn, ReportField1, ReportField2, LookupField1' \
' FROM Jolly.dbo.logAttendance' \
" WHERE DateIn between '#{date1} 00:00:00' and '#{date2} 23:59:59'"
end

def self.checkins(id)
'SELECT CardHolderID, DateOfEvent, ReportField1, ReportField2, LookupField1' \
' FROM Jolly.dbo.logPerson' \
" WHERE CardHolderID = '#{id}'"
end

def self.checkins_for_dates(date1, date2)
'SELECT CardHolderID, DateOfEvent, ReportField1, ReportField2, LookupField1' \
' FROM Jolly.dbo.logPerson' \
" WHERE DateOfEvent between '#{date1} 00:00:00' and '#{date2} 23:59:59'"
end
end
33 changes: 20 additions & 13 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,41 @@
<div class="access-error">
You do not have permissions to use other staff web forms.
</div>
<%= link_to "Login here", login_path(referrer: request.original_url) %>
<%= link_to 'Login here', login_path(referrer: request.original_url) %>
<% else %>
<h3>What would you like to do?</h3>
<% if can? :read, AccessionNumber %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4><%= link_to "Accession number generator", 'accession_number_updates' %></h4>
<h4><%= link_to 'Accession number generator', 'accession_number_updates' %></h4>
</div>
</div>
<% end %>
<% if can? :manage, BatchRecordUpdate %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4><%= link_to "Batch record updates", 'batch_record_updates' %></h4>
<h4><%= link_to 'Batch record updates', 'batch_record_updates' %></h4>
</div>
</div>
<% end %>
<% if can? :read, DigitalBookplatesBatch %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4><%= link_to "Digital bookplates", 'digital_bookplates_batches' %></h4>
<h4><%= link_to 'Digital bookplates', 'digital_bookplates_batches' %></h4>
</div>
</div>
<% end %>
<% if can? :read, EdiInvoice %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4><%= link_to "EDIFACT invoice management", edi_invoices_menu_path %></h4>
<h4><%= link_to 'EDIFACT invoice management', edi_invoices_menu_path %></h4>
</div>
</div>
<% end %>
<% if can? :read, Package %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4><%= link_to "Electronic resource package management", packages_url %></h4>
<h4><%= link_to 'Electronic resource package management', packages_url %></h4>
</div>
</div>
<% end %>
Expand All @@ -54,9 +54,9 @@
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<ul>
<li><%= link_to "Place batch request", new_sal3_batch_requests_batch_path %></li>
<li><%= link_to 'Place batch request', new_sal3_batch_requests_batch_path %></li>
<% if can? :read, Sal3BatchRequestsBatch %>
<li><%= link_to "Review batches", sal3_batch_requests_batches_path %></li>
<li><%= link_to 'Review batches', sal3_batch_requests_batches_path %></li>
<% end %>
</ul>
</div>
Expand All @@ -72,33 +72,40 @@
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">
<%= render template: "management_reports/index" %>
<%= render template: 'management_reports/index' %>
</div>
</div>
<% end %>
</div>
<% if can? :create, UserloadRerun %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4><%= link_to "Userload Rerun", new_userload_rerun_path %></h4>
<h4><%= link_to 'Userload Rerun', new_userload_rerun_path %></h4>
</div>
</div>
<% end %>
<% if can? :create, IlliadUserExport %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4><%= link_to "ILLiad User Export", new_illiad_user_export_path %></h4>
<h4><%= link_to 'ILLiad User Export', new_illiad_user_export_path %></h4>
</div>
</div>
<% end %>
<% if can? :manage, LobbytrackReport %>
<div class="panel panel-default">
<div class="panel-heading" role="tab">
<h4><%= link_to 'LobbyTrack Reports', lobbytrack_reports_path %></h4>
</div>
</div>
<% end %>
<% end %>
<% Settings.pl_sql_jobs.each_with_index do |(k,v),i| %>
<% if v.sunet_ids.include?(user_id) %>
<p></p>
<div class="panel panel-default">
<div class="panel-heading" role="tab">
<h4 class="link" role="button" data-toggle="collapse" href="#buttonCollapse<%=i%>" aria-expanded="false" aria-controls="buttonCollapse<%=i%>"><%= v.text %></h4>
<%= link_to "Run", pl_sql_job_create_path(command: v.command, confirm: v.confirm), id: "buttonCollapse#{i}", class: "collapse btn btn-md btn-default", style: "width:60px", "aria-labelledby" => "buttonCollapse#{i}" %>
<%= link_to 'Run', pl_sql_job_create_path(command: v.command, confirm: v.confirm), id: "buttonCollapse#{i}", class: "collapse btn btn-md btn-default", style: "width:60px", "aria-labelledby" => "buttonCollapse#{i}" %>
</div>
</div>
<% end %>
Expand All @@ -107,7 +114,7 @@
<p></p>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4><%= link_to "Ckey to Bibframe Conversion", new_ckey2bibframe_path %></h4>
<h4><%= link_to 'Ckey to Bibframe Conversion', new_ckey2bibframe_path %></h4>
</div>
</div>
<% end %>
Expand Down

0 comments on commit a008b2b

Please sign in to comment.