Skip to content

Commit

Permalink
Testing of Quepid8 Functions (#1222)
Browse files Browse the repository at this point in the history
* Smarter handling of HTTPS versus HTTP links.

Return to HTTPS from HTTP when we are not in the core app.

* relative link to fit under context path

* language cleanup

* prevent error being thrown

* Update the ERD

* Another relative path

* lint
  • Loading branch information
epugh authored Feb 11, 2025
1 parent b2e0ea8 commit ce63a94
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 52 deletions.
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ SOLID_CABLE_POLLING=0.1.seconds
# This makes Quepid run only on SSL, including all interactions
# with search engines on SSL. If FORCE_SSL is false, then Quepid will switch
# between http and https based on the url of the search engine for the main
# /case page.
# /case page. Browsers prevent Quepid in HTTPS mode from accessing HTTP search engines,
# so in that case you need to set this to false.
FORCE_SSL=false

# The main application can be run in either HTTP or HTTPS mode. THis sets it to prefer
# HTTPS mode.
PREFER_SSL=false

# This makes Quepid show detailed error messages in the UI instead of a generic 500 page,
# useful while testing a deployment in Production.
QUEPID_CONSIDER_ALL_REQUESTS_LOCAL=false
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/components/judgements/_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h3 class="modal-title">Judgements</h3>
You have not created any Books of Judgements yet, so go ahead and create a new Book!
</p>

<a class="btn btn-primary btn-lg" ng-href="{{ctrl.createBookLink()}}" target="_self">
<a class="btn btn-primary btn-lg" ng-href="{{ctrl.createNewBookLink()}}" target="_self">
<i class="bi bi-plus-lg"></i>
Create a book
</a>
Expand Down Expand Up @@ -104,7 +104,7 @@ <h3 class="modal-title">Judgements</h3>
</div>

<div class="modal-footer">
<a class="btn btn-primary pull-left" ng-href="{{ctrl.createBookLink()}}" target="_self" ng-disabled="processingPrompt.inProgress">
<a class="btn btn-primary pull-left" ng-href="{{ctrl.createNewBookLink()}}" target="_self" ng-disabled="processingPrompt.inProgress">
<i class="glyphicon glyphicon-plus" style="color: #FFF"></i>
Create a book
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ angular.module('QuepidApp')
$location.path('/teams');
};

ctrl.createBookLink = function() {
ctrl.createNewBookLink = function() {
const teamIds = ctrl.share.acase.teams.map(function(team) {
return `&team_ids[]=${team.id}`;
});
Expand Down
13 changes: 1 addition & 12 deletions app/assets/javascripts/components/new_case/new_case.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
<button
type="button"
class="btn btn-success btn-block"
ng-click="ctrl.newCase()"
ng-if="!isRailsGoingToAngular()"
ng-click="ctrl.newCase()"
>
<i class="bi bi-plus-lg"></i>
{{ ctrl.buttonText }}
</button>

<a
class="btn btn-success btn-block"
href="/cases?new=true"
ng-if="isRailsGoingToAngular()"
target="_self"
>
<i class="bi bi-plus-lg"></i>
{{ ctrl.buttonText }}
</a>
18 changes: 10 additions & 8 deletions app/assets/javascripts/controllers/headerCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ angular.module('QuepidApp')
bookSvc,
caseTryNavSvc
) {
$rootScope.isRailsGoingToAngular = isRailsGoingToAngular;

$scope.headerScope = {};
$scope.headerScope.dropdownCases = [];
Expand All @@ -28,6 +27,7 @@ angular.module('QuepidApp')
$scope.theCase = null;

$scope.headerScope.goToCase = goToCase;
$scope.headerScope.createNewBookLink = createNewBookLink;
$scope.headerScope.createBookLink = createBookLink;


Expand Down Expand Up @@ -60,23 +60,25 @@ angular.module('QuepidApp')
$event.preventDefault();
caseTryNavSvc.navigateTo({'caseNo': aCase.caseNo, 'tryNo': aCase.lastTry});
}

function isRailsGoingToAngular() {
return !( angular.isDefined($route.current) && angular.isDefined($route.current.$$route) );
}

$scope.$on('caseSelected', function() {
$scope.theCase = caseSvc.getSelectedCase();
});

function createBookLink() {
let bookLink = 'books/new';

function createBookLink(book) {
let bookLink = caseTryNavSvc.getQuepidRootUrl() + '/books/' + book.id;
bookLink = caseTryNavSvc.createMainApplicationLink(bookLink);
return bookLink;
}
function createNewBookLink() {
let bookLink = caseTryNavSvc.getQuepidRootUrl() + '/books/new';
if ($scope.theCase){
const teamIds = $scope.theCase.teams.map(function(team) {
return `&team_ids[]=${team.id}`;
});
bookLink = `${bookLink}?book[scorer_id]=${$scope.theCase.scorerId}${teamIds}&origin_case_id=${$scope.theCase.caseNo}`;
}
bookLink = caseTryNavSvc.createMainApplicationLink(bookLink);
return bookLink;
}
}
Expand Down
14 changes: 12 additions & 2 deletions app/assets/javascripts/services/caseTryNavSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// What did I do here, like implement a router on top of my router!?!?
angular.module('QuepidApp')
.service('caseTryNavSvc', [
'$location', '$timeout',
function caseTryNavSvc($location, $timeout) {
'configurationSvc','$location', '$timeout',
function caseTryNavSvc(configurationSvc, $location, $timeout) {
var caseNo = 0;
var tryNo = 0;

Expand Down Expand Up @@ -76,6 +76,14 @@ angular.module('QuepidApp')
return tryNo;
};

this.createMainApplicationLink = function (url) {
if (configurationSvc.preferSSL() && !url.startsWith('https')) {
url = url.replace(':3000', '');
url = url.replace('http', 'https');
}
return url;
};

// If Quepid is running on HTTPS, like on Heroku, then it needs to switch
// to HTTP in order to make calls to a Solr that is running in HTTP as well, otherwise
// you get this "Mixed Content", which browsers block as a security issue.
Expand Down Expand Up @@ -122,6 +130,8 @@ angular.module('QuepidApp')
return [quepidUrlToSwitchTo, protocolToSwitchTo];
};



this.appendQueryParams = function (quepidUrl, params) {
let seperator = '?';
if (quepidUrl.includes('?')) {
Expand Down
9 changes: 9 additions & 0 deletions app/assets/javascripts/services/configurationSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ angular.module('UtilitiesModule')
function ConfigurationSvc() {
var communalScorersOnly;
var queryListSortable;
var preferSSL;

this.setCommunalScorersOnly = function(val) {
communalScorersOnly = JSON.parse(val);
Expand All @@ -21,5 +22,13 @@ angular.module('UtilitiesModule')
this.isQueryListSortable = function() {
return queryListSortable;
};

this.setPreferSSL= function (val) {
preferSSL = JSON.parse(val);
};

this.preferSSL = function() {
return preferSSL;
};
}
]);
4 changes: 2 additions & 2 deletions app/assets/templates/views/teams/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<h2>Team: {{ currentTeam.name }}</h2>

<div class="pull-right">
<a ng-href='/teams'>
<a ng-href='teams'>
<i class="bi bi-arrow-left" aria-hidden="true"></i>
Back to list
</a>
Expand Down Expand Up @@ -81,7 +81,7 @@ <h3>Members</h3>
<div class="row">
<div class='col-md-4'>
<span class="bi bi-robot"></span>
<a type="button" ng-href="/teams/{{currentTeam.id}}/ai_judges/new" target="_self" >
<a type="button" ng-href="teams/{{currentTeam.id}}/ai_judges/new" target="_self" >
Create AI Judge
</a>
</div>
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,9 @@ def get_protocol_from_url url
Rails.logger.error("Invalid URL for search endpoint: #{url} - Error: #{e.message}")
nil
end

def determine_prefer_ssl
Rails.configuration.prefer_ssl ? 'https' : 'http'
end
end
# rubocop:enable Metrics/ModuleLength
6 changes: 3 additions & 3 deletions app/views/books/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@
<div class="form-check">
<%= form.check_box :delete_populate_file, class: 'form-check-input', checked: false, disabled: !@book.populate_file.attached? %>
<%= form.label :delete_populate_file, "Delete Populate File", class: 'form-check-label' %>
<div class="form-text">If enabled you have a associated file. Check this to delete it.</div>
<div class="form-text">If enabled you have an associated file. Check this to delete it.</div>
</div>
</div>
<div class="mb-3">
<div class="form-check">
<%= form.check_box :delete_import_file, class: 'form-check-input', checked: false, disabled: !@book.import_file.attached? %>
<%= form.label :delete_import_file, "Delete Import File", class: 'form-check-label' %>
<div class="form-text">If enabled you have a associated file. Check this to delete it.</div>
<div class="form-text">If enabled you have an associated file. Check this to delete it.</div>
</div>
</div>
<div class="mb-3">
<div class="form-check">
<%= form.check_box :delete_export_file, class: 'form-check-input', checked: false, disabled: !@book.export_file.attached? %>
<%= form.label :delete_export_file, "Delete Export File", class: 'form-check-label' %>
<div class="form-text">If enabled you have a associated file. Check this to delete it.</div>
<div class="form-text">If enabled you have an associated file. Check this to delete it.</div>
</div>
</div>
<% end %>
Expand Down
36 changes: 17 additions & 19 deletions app/views/layouts/_header_core_app.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<header id="header" class="navbar-inverse navbar-secondary clearfix">
<div class="container container-home">
<div class="navbar-header">
<%= link_to root_path, class: "navbar-brand", target: "_self" do %>
<%= link_to root_url(protocol: determine_prefer_ssl), class: "navbar-brand", target: "_self" do %>
Quepid
<span class="hover"><%= image_tag 'tagline-sm.png', title: "Give your queries some love" %></span>
<% end %>
Expand All @@ -22,13 +22,11 @@
</li>

<li ng-repeat="case in headerScope.dropdownCases | limitTo:5 track by $index">
<a href="#" class="dropdown-link" ng-click="headerScope.goToCase($event, case)" ng-if="!isRailsGoingToAngular()">{{ case.caseName }}</a>

<a ng-href="{{'/case/' + case.caseNo + '/try/' + case.lastTry}}" class="dropdown-link" ng-if="isRailsGoingToAngular()" target="_self">{{ case.caseName }}</a>
<a href="#" class="dropdown-link" ng-click="headerScope.goToCase($event, case)">{{ case.caseName }}</a>
</li>

<li class="actions">
<a href="cases" class="btn btn-default btn-block" ng-attr-target="{{ isRailsGoingToAngular() ? '_self' : undefined }}">
<a href="cases" class="btn btn-default btn-block">
View all cases
<small class="text-muted">
({{ headerScope.casesCount }} active)
Expand All @@ -53,7 +51,7 @@
</li>

<li ng-repeat="book in headerScope.dropdownBooks | limitTo:5 track by $index">
<a ng-href="books/{{book.id}}" target="_self" class="dropdown-link">{{ book.name }}</a>
<a ng-href="{{headerScope.createBookLink(book)}}" target="_self" class="dropdown-link">{{ book.name }}</a>
</li>

<li class="actions">
Expand All @@ -66,7 +64,7 @@

<a
class="btn btn-success btn-block"
ng-href="{{headerScope.createBookLink()}}"
ng-href="{{headerScope.createNewBookLink()}}"
target="_self"
>
<i class="bi bi-plus-lg"></i>
Expand All @@ -77,8 +75,8 @@
</li>
<!-- End book selector -->

<li><a ng-attr-target="{{ isRailsGoingToAngular() ? '_self' : undefined }}" href="teams">Teams</a></li>
<li><a ng-attr-target="{{ isRailsGoingToAngular() ? '_self' : undefined }}" href="scorers">Scorers</a></li>
<li><a href="teams">Teams</a></li>
<li><a href="scorers">Scorers</a></li>
<li><a ng-attr-target="_blank" href="notebooks/lab/index.html">Notebooks</a></li>
</ul>

Expand All @@ -92,18 +90,18 @@
</a>

<ul class="dropdown-menu dropdown-content" uib-dropdown-menu>
<li><%= link_to 'My profile', profile_path, class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'Log out', logout_path, class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'My profile', profile_url(protocol: determine_prefer_ssl), class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'Log out', logout_url(protocol: determine_prefer_ssl), class: 'dropdown-link', target: '_self' %></li>
<li role="separator" class=""></li>
<li><%= link_to 'Judgements', books_path, class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'API Docs', apipie_apipie_path, class: 'dropdown-item', target: '_self' %></li>
<li><%= link_to 'Judgements', books_url(protocol: determine_prefer_ssl), class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'API Docs', apipie_apipie_url(protocol: determine_prefer_ssl), class: 'dropdown-item', target: '_self' %></li>
<% if current_user.administrator? %>
<li role="separator" class=""></li>
<li><%= link_to 'Admin Home', admin_path, class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'Users', admin_users_path, class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'Quepid Scorers', admin_communal_scorers_path, class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'Announcements', admin_announcements_path, class: 'dropdown-item', target: '_self' %></li>
<li><%= link_to 'Job Manager', mission_control_jobs_path, class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'Admin Home', admin_url(protocol: determine_prefer_ssl), class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'Users', admin_users_url(protocol: determine_prefer_ssl), class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'Quepid Scorers', admin_communal_scorers_url(protocol: determine_prefer_ssl), class: 'dropdown-link', target: '_self' %></li>
<li><%= link_to 'Announcements', admin_announcements_url(protocol: determine_prefer_ssl), class: 'dropdown-item', target: '_self' %></li>
<li><%= link_to 'Job Manager', mission_control_jobs_url(protocol: determine_prefer_ssl), class: 'dropdown-link', target: '_self' %></li>
<% end %>
</ul>
</li> <!-- End account management -->
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/core.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
function(bootstrapSvc, configurationSvc) {
configurationSvc.setCommunalScorersOnly('<%= Rails.application.config.communal_scorers_only %>');
configurationSvc.setQueryListSortable('<%= Rails.application.config.query_list_sortable %>');
configurationSvc.setPreferSSL('<%= Rails.application.config.prefer_ssl %>');

bootstrapSvc.run();
}
Expand Down
7 changes: 7 additions & 0 deletions config/initializers/customize_quepid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
#
Rails.application.config.quepid_version = ENV.fetch('QUEPID_VERSION', 'UNKNOWN')

# == Prefer HTTPS Connection
# If you need to access a search endpoint using http instead of https, then Quepid needs to flip
# back and forth between those protocols. However, the rest of the app can run in https mode, and
# this is what controls creating those connections in https.
#
Rails.application.config.prefer_ssl = bool.deserialize(ENV.fetch('PREFER_SSL', false))

# == Quepid Default Scorer
# New users to Quepid need to have a recommended scorer to use, which they can then
# override to their own preferred scorer, either one of the defaults shipped with Quepid
Expand Down
Binary file modified docs/erd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/operating_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ server {
```
QUEPID_DOMAIN=https://localhost # Set this to the domain visible to the user
FORCE_SSL=true # Enable this to use https only connections
PREFER_SSL=true # Enable this to have URLs for the main application (not the core case app) be in https mode.
```

> ⚠️ Setting `FORCE_SSL=true` will prevent you from testing search engines
> that are not TLS enabled (`https`)!
> that are not TLS enabled (`https`)! You typically want either FORCE_SSL or PREFER_SSL.
## Setting up a Context Path

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace :assets do
puts "Unpacking Jupyterlite into #{destination}"
system "tar -xzf #{notebooks_gz} --directory #{destination}"

File.delete(notebooks_gz)
FileUtils.rm_f(notebooks_gz)
end

# Hook into existing assets:precompile task
Expand Down

0 comments on commit ce63a94

Please sign in to comment.