Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Remove Scoap3 specific code
Browse files Browse the repository at this point in the history
closes #310

Also modifies redirect of successful knip.
  • Loading branch information
JPrevost committed Aug 12, 2015
1 parent 0111c69 commit 37cde5e
Show file tree
Hide file tree
Showing 50 changed files with 154 additions and 123 deletions.
28 changes: 23 additions & 5 deletions README.md
@@ -1,10 +1,9 @@
SCOAP3 TopicHub
TopicHub
=================================
This web application allows users to discover, subscribe to, and obtain automatic delivery of
aggregations of article content repositories.

This is a web application to allow users to discover, subscribe to,
and obtain automatic delivery of, aggregations of article content from the SCOAP3 repository.

[![Build Status](https://travis-ci.org/MITLibraries/scoap3hub.svg?branch=master)](https://travis-ci.org/MITLibraries/scoap3hub) [![Coverage Status](https://coveralls.io/repos/MITLibraries/scoap3hub/badge.svg?branch=master)](https://coveralls.io/r/MITLibraries/scoap3hub?branch=master)
[![Build Status](https://travis-ci.org/MITLibraries/topichub.svg?branch=master)](https://travis-ci.org/MITLibraries/topichub) [![Coverage Status](https://coveralls.io/repos/MITLibraries/topichub/badge.svg?branch=master)](https://coveralls.io/r/MITLibraries/topichub?branch=master)

Authentication
=====
Expand All @@ -18,3 +17,22 @@ OAuth provider will be required. `AUTH_CALLBACK_URL` should be whatever domain y
running this app on plus `/_oauth-callback`. You will need to configure that on your
OAuth provider site as well. For development `http://localhost:9000/_oauth-callback`
(or similar) should also be set with the provider.

**A full list of settings and some examples can been seen in app/conf/authentication.conf.**

Authorization
=====
Explicit roles `sysadmin` and `analyst` can manually be assigned in the `hub_user` table. All other
roles are implicit so don't need to be defined.

Branding
=====
Three Environment Variables control the branding experience.
1. `SITE_NAME`: controls the overall branded sitename and defaults to "TopicHub"
2. `SITE_DESCRIPTION`: allows for a description of the site to be configured for the home page.
Html is allowed.
3. `SITE_BASE_URL`: This is used in generated emails to provide links back to the site.
Use the protocol and FQDN for your site. Defaults to "http://example.com" so if you get emails
with that in them you'll want to check this value.

**Developers should access those values using the HubUtils wrapper methods for consistency.**
7 changes: 4 additions & 3 deletions app/controllers/Application.scala
Expand Up @@ -297,7 +297,8 @@ object Application extends Controller with Security {
Harvest.findById(hid).map( harvest => {
if (harvest.publisher.get.userId == identity.id) {
harvester ! (oid, coll, harvest, force)
Ok(views.html.harvest.index("pulled: " + oid))
Redirect(routes.Application.index).flashing(
"success" -> s"pulled: ${oid}")
} else {
Unauthorized(views.html.static.trouble("You are not authorized"))
}
Expand Down Expand Up @@ -926,7 +927,7 @@ object Application extends Controller with Security {
val subscriber = Subscriber.findById(value).get
subscriber.linkUser(identity.id)
val adminEmails = subscriber.adminList.map {user => user.email}.mkString(",")
val subject = "SCOAP3Hub Request to Join Subscriber"
val subject = s"${HubUtils.siteName} Request to Join Subscriber"
val msg = views.txt.email.subscriber_join_request(subscriber, identity).body
Emailer.subscriberEmails(adminEmails, subject, msg)
Ok(views.html.subscriber.request())
Expand All @@ -941,7 +942,7 @@ object Application extends Controller with Security {

def subscriberResolveUser(id: Int, userid: Int, res: String) = isAuthenticated { identity => implicit request =>
val sub = Subscriber.findById(id).get
val subject = s"SCOAP3Hub Request to Join Subscriber ${res}"
val subject = s"${HubUtils.siteName} Request to Join Subscriber ${res}"
val user = User.findById(userid).get
val msg = views.txt.email.subscriber_resolve(sub, res).body

Expand Down
17 changes: 17 additions & 0 deletions app/models/HubUtils.scala
Expand Up @@ -80,4 +80,21 @@ object HubUtils {
val uncovered = allItems - covered
List(("Covered", covered), ("Uncovered", uncovered))
}

def siteName = {
current.configuration.getString("brand.name").getOrElse("TopicHub")
}

def replyEmail = {
current.configuration.getString("brand.reply_email").getOrElse("noreply@example.com")
}

def baseUrl = {
current.configuration.getString("brand.site_url").getOrElse("http://example.com")
}

def siteDescription = {
current.configuration.getString("brand.site_description").getOrElse(
"Add a description in conf/brand.conf or by setting the SITE_DESCRIPTION Environement Variable")
}
}
18 changes: 12 additions & 6 deletions app/services/email.scala
Expand Up @@ -9,6 +9,7 @@ import java.net.URLEncoder._
import play.api._
import play.api.libs.ws._
import play.api.Play.current
import models.HubUtils

/** Service for email delivery
* TODO: refactor for real plug-in modularity, this contains
Expand All @@ -29,20 +30,25 @@ trait EmailService {
val adminEmail = Play.configuration.getString("hub.admin.email").get

def notify(to: String, subject: String, msg: String) {
val props = Map("to" -> munge(to), "from" -> "noreply@scoap3hub.org",
"subject" -> subject, "text" -> msg)
val props = Map("to" -> munge(to),
"from" -> HubUtils.replyEmail,
"subject" -> subject,
"text" -> msg)
send(props)
}

def feedback(from: String, msg: String, reply: Boolean) = {
val props = Map("to" -> munge(adminEmail), "from" -> from,
"subject" -> "SCOAP3Hub Feedback", "text" -> msg)
val props = Map("to" -> munge(adminEmail),
"from" -> from,
"subject" -> s"${HubUtils.siteName} Feedback",
"text" -> msg)
send(if (reply) props + ("h:Reply-To" -> from) else props)
}

def subscriberEmails(to: String, subject: String, msg: String) = {
val props = Map("to" -> munge(to), "from" -> "noreply@scoap3hub.org",
"sender" -> "noreply@scoap3hub.org",
val props = Map("to" -> munge(to),
"from" -> HubUtils.replyEmail,
"sender" -> HubUtils.replyEmail,
"subject" -> subject,
"text" -> msg)
send(props)
Expand Down
4 changes: 2 additions & 2 deletions app/views/collection/index.scala.html
Expand Up @@ -18,8 +18,8 @@
</div>
<div class="col-md-8">
<div class="jumbotron">
<h2>Collections in SCOAP<sup>3</sup></h2>
<p>SCOAP content is organized by the journal in which each article appears. Browse the journal collections at left.</p>
<h2>Collections in @HubUtils.siteName</h2>
<p>Content is organized by the collection in which each item appears. Browse the collections at left.</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/cull/create.scala.html
Expand Up @@ -24,7 +24,7 @@ <h2>Define a content cull (removal)</h2>
@inputText(cullForm("notify_url"),
'class -> "form-control",
'_label -> "Notify URL",
'_help -> "ex. mailto:admin@repo.scoap3.org")
'_help -> "ex. mailto:admin@repo.example.org")

@inputDate(cullForm("start"),
'class -> "form-control",
Expand Down
2 changes: 1 addition & 1 deletion app/views/email/abort_harvest.scala.txt
Expand Up @@ -7,7 +7,7 @@ An error occurred starting the following harvest:

Harvest: @harvest.name
Publisher: @harvest.publisher.get.name
Link to Harvest: http://scoap3.topichub.org/harvest/@harvest.id
Link to Harvest: @HubUtils.baseUrl/harvest/@harvest.id

Exception text:
@exception
2 changes: 1 addition & 1 deletion app/views/email/item_notify.scala.txt
Expand Up @@ -4,7 +4,7 @@
*****************************************************************************@
@(item: Item)

Now available on Scoap3Hub:
Now available on @HubUtils.siteName:

Title: @item.metadataValue("title")
Authors: @item.metadataValues("author").mkString(";")
2 changes: 1 addition & 1 deletion app/views/email/item_removed.scala.txt
Expand Up @@ -4,7 +4,7 @@
*****************************************************************************@
@(item: Item)

The following item is no longer available from Scoap3Hub:
The following item is no longer available from @HubUtils.siteName:

Title: @item.metadataValue("title")
Authors: @item.metadataValues("author").mkString(";")
2 changes: 1 addition & 1 deletion app/views/email/subscriber_resolve.scala.txt
Expand Up @@ -6,5 +6,5 @@

Your request to join Subscriber Group: @subscriber.name has been @resolution.

You may visit SCOAP3Hub at:
You may visit @HubUtils.siteName at:
@routes.Application.index.absoluteURL()
2 changes: 1 addition & 1 deletion app/views/email/sword_transfer_failure.scala.txt
Expand Up @@ -12,7 +12,7 @@ Channel:
Subscriber:
@Subscriber.findById(trans.subscriberId).get.name

Link to Item: http://scoap3.topichub.org/item/@item.id
Link to Item: @HubUtils.baseUrl/item/@item.id

Exception text:
@error
2 changes: 1 addition & 1 deletion app/views/email/unhandled_collections.scala.txt
Expand Up @@ -7,7 +7,7 @@ The following collections were not handled during a Harvest:

Harvest: @harvest.name
Publisher: @harvest.publisher.get.name
Link to Harvest: http://scoap3.topichub.org/harvest/@harvest.id
Link to Harvest: @HubUtils.baseUrl/harvest/@harvest.id

Unhandled Collections:
@collection.map {c =>
Expand Down
7 changes: 0 additions & 7 deletions app/views/harvest/index.scala.html

This file was deleted.

4 changes: 2 additions & 2 deletions app/views/layout/main.scala.html
@@ -1,5 +1,5 @@
@*****************************************************************************
* Main HTML template for SCOAP3 TopicHub pages. Included by all pages *
* Main HTML template for TopicHub pages. Included by all pages *
* Copyright (c) 2015 MIT Libraries *
*****************************************************************************@
@(title: String)(content: Html)(implicit request: play.api.mvc.RequestHeader)
Expand Down Expand Up @@ -36,7 +36,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="@routes.Application.index">SCOAP<sup>3</sup> TopicHub</a>
<a class="navbar-brand" href="@routes.Application.index">@HubUtils.siteName</a>
</div>
<div class="navbar-collapse collapse" id="th-navbar-collapse">
<ul class="nav navbar-nav">
Expand Down
3 changes: 1 addition & 2 deletions app/views/login/index.scala.html
@@ -1,6 +1,5 @@
@(loginText: String, externalAuthUrl: String)(implicit request: play.api.mvc.RequestHeader)

@layout.main("Login to SCOAP3 - TopicHub") {
@layout.main(s"Login to ${HubUtils.siteName}") {
<h2>Not Yet Authenticated</h2>
<a id="openid" class="btn btn-primary" href="/_external-oauth?requestUri=@helper.urlEncode(externalAuthUrl)">
@loginText
Expand Down
2 changes: 1 addition & 1 deletion app/views/static/about.scala.html
Expand Up @@ -14,5 +14,5 @@ <h2>About TopicHub</h2>
<li>In application web pages, metadata is expressed using the <a href="http://schema.org">Schema.org</a> vocabulary.</li>
<li>Topics identified by the hub are syndicated as <a href="http://www.atomenabled.org">Atom</a> feeds containing items.</li>
</ul>
<p>TopicHub is built upon an open-source, Apache 2 licensed platform available on <a href="https://github.com/MITLibraries/scoap3hub">GitHub</a>.</p>
<p>TopicHub is built upon an open-source, Apache 2 licensed platform available on <a href="https://github.com/MITLibraries/topichub">GitHub</a>.</p>
}
2 changes: 1 addition & 1 deletion app/views/static/feedback.scala.html
Expand Up @@ -10,7 +10,7 @@

<h2>We'd love to hear from you!</h2>

<p>Thanks for helping make SCOAP3 TopicHub a more valuable service!</p>
<p>Thanks for helping make @HubUtils.siteName a more valuable service!</p>

@form(routes.Application.takeFeedback, 'class -> "form-horizontal") {
<span id="helpBlock" class="help-block">* Denotes Required Element</span>
Expand Down
11 changes: 3 additions & 8 deletions app/views/static/home.scala.html
@@ -1,10 +1,9 @@
@*****************************************************************************
* Front page for SCOAP3-bound topichub, also providing entry point for *
* topic browsing *
* Front page for topichub, also providing entry point for topic browsing *
* Copyright (c) 2015 MIT Libraries *
*****************************************************************************@
@(schemes: List[Scheme])(implicit request: play.api.mvc.RequestHeader)
@layout.main("SCOAP3 - TopicHub") {
@layout.main(s"${HubUtils.siteName}") {
<div class="container-fluid">
<div class="row-fluid">
<div class="col-md-4">
Expand All @@ -25,11 +24,7 @@ <h3>Schemes</h3>
</div>
<div class="col-md-8">
<div class="jumbotron">
<h2>Welcome to SCOAP<sup>3</sup> TopicHub!</h2>
<p>SCOAP<sup>3</sup> (Sponsoring Consortium for Open Access Publishing in Particle Physics) is a <a href="http://cern.ch">CERN</a>-managed service to deliver High-Energy Physics articles as open access. Visit them <a href="http://repo.scoap3.org">here</a>.</p>
<p>The hub analyzes each article in the SCOAP<sup>3</sup> repository to extract <em>topics</em>. A topic is an identifier or term belonging to a standard vocabulary or name-space, known as its <em>scheme</em>.
Relative to this scheme, the topic identifies, describes, characterizes or classifies the article. Topics help organize articles into groups that are of interest to subscribers:
all articles in a particular journal, everything written by a certain author, etc. Find the topics (or articles) you want by <a href="@routes.Search.index">searching</a>, or explore topics within a scheme by clicking on one of the scheme browse links at the left.</p>
@Html(HubUtils.siteDescription)
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/static/sandbox.scala.html
Expand Up @@ -18,7 +18,7 @@
'class -> "form-control")
@inputText(sbForm("resourceUrl"),
'_label -> "* Resource URL",
'_help -> "ex: http://repo.scoap3.org/record/10405/export/xm?ln=en",
'_help -> "ex: http://repo.example.org/record/10405/export/xm?ln=en",
'size -> 50,
'class -> "form-control")

Expand Down
4 changes: 0 additions & 4 deletions app/views/static/workbench.scala.html
Expand Up @@ -25,12 +25,8 @@ <h3>Tools</h3>
<a id="sidenav_cformats" href="@routes.Application.contentFormats" class="list-group-item">Content Formats</a>
<a id="sidenav_cprofiles" href="@routes.Application.contentProfiles" class="list-group-item">Content Profiles</a>
<a id="sidenav_rmaps" href="@routes.Application.resourceMaps" class="list-group-item">Resource Maps</a>
@* next choice specific to a UI bound, like SCOAP3, to a single publisher: need a place to set it up *@
@* In the multi-publisher case, this link is at the top level *@
<a id="sidenav_publishers" href="@routes.Application.publishers" class="list-group-item">Publishers</a>
@* likewise, next choice would top-level if open to all subscribers *@
<a id="sidenav_subscribers" href="@routes.Application.subscribers" class="list-group-item">Subscribers</a>
@* this will be moved to subscriber-based links when multiple subscribers allowed *@
<a id="sidenav_plans" href="@routes.Application.newPlan(1)" class="list-group-item">Plans</a>
@*<a href="@routes.Application.pkgmaps" class="list-group-item">Packages</a>*@
<a id="sidenav_sandbox" href="@routes.Application.sandbox" class="list-group-item">Sandbox</a>
Expand Down
8 changes: 4 additions & 4 deletions app/workers/Conveyor.scala
Expand Up @@ -15,7 +15,7 @@ import play.api.libs.ws._
import play.api.mvc._
import play.api.http.HeaderNames._

import models.{Agent, Channel, Hold, Interest, Item, Plan, Scheme, Subscriber,
import models.{Agent, Channel, Hold, HubUtils, Interest, Item, Plan, Scheme, Subscriber,
Subscription, Topic, TopicPick, Transfer, User}
import services.Emailer

Expand All @@ -34,7 +34,7 @@ class ConveyorWorker extends Actor {
case (item: Item, subscr: Subscriber) => Conveyor.transferItem(item, subscr)
case (hold: Hold, accept: Boolean) => Conveyor.resolveHold(hold, accept)
case (pick: TopicPick, accept: Boolean) => Conveyor.resolvePick(pick, accept)
case _ => Logger.error("Unhandle Case in ConveryWorker#receive")
case _ => Logger.error("Unhandled Case in ConveryWorker#receive")
}
}

Expand Down Expand Up @@ -257,7 +257,7 @@ object Conveyor {

def sendSwordFailureEmail(addresses: String, msg: String) = {
Logger.info(msg)
Emailer.notify(addresses, "SCOAP3Hub: failure of sword delivery detected", msg)
Emailer.notify(addresses, s"${HubUtils.siteName}: failure of sword delivery detected", msg)
Transfer.delete(trans.id)
}

Expand All @@ -279,6 +279,6 @@ object Conveyor {
val text = views.txt.email.item_notify(item)
val topic = sub.topic
Emailer.notify(sub.subscriber.contact,
"Scoap3Hub Alert - new in " + topic.tag + ":" + topic.name, text.body)
s"${HubUtils.siteName} Alert - new in ${topic.tag}: ${topic.name}", text.body)
}
}
4 changes: 2 additions & 2 deletions app/workers/Harvester.scala
Expand Up @@ -90,7 +90,7 @@ class Harvester {
val sysadminEmails = User.allByRole("sysadmin").map(x => x.email).mkString(",")
val msg = views.txt.email.unhandled_collections(harvest, collections).body
Logger.warn(msg)
Emailer.notify(sysadminEmails, "SCOAP3Hub: An unhandled collection was detected", msg)
Emailer.notify(sysadminEmails, s"${HubUtils.siteName}: An unhandled collection was detected", msg)
}

def handleOaiError(errorText: String, errorCode: String) = {
Expand Down Expand Up @@ -131,7 +131,7 @@ class Harvester {
val sysadminEmails = User.allByRole("sysadmin").map(x => x.email).mkString(",")
val msg = views.txt.email.abort_harvest(harvest, exception).body
Logger.error(msg)
Emailer.notify(sysadminEmails, "SCOAP3Hub: An error occurred starting a Harvest", msg)
Emailer.notify(sysadminEmails, s"${HubUtils.siteName} An error occurred starting a Harvest", msg)
}

// OAI-PMH date filters are inclusive on both ends (from and until),
Expand Down
2 changes: 1 addition & 1 deletion app/workers/Reaper.scala
Expand Up @@ -72,7 +72,7 @@ object Reaper {
if (notifyUrl.isDefined && notifyUrl.get.startsWith("mailto:")) {
val recip = notifyUrl.get.substring(7)
val msg = views.txt.email.item_removed(item)
Emailer.notify(recip, "Item Removed from SCOAP3Hub", msg.body)
Emailer.notify(recip, s"Item Removed from ${HubUtils.siteName}", msg.body)
}
// Finally delete item itself
Item.delete(item.id)
Expand Down
6 changes: 6 additions & 0 deletions conf/application.conf
Expand Up @@ -69,3 +69,9 @@ include "authentication"
# keys allowed to start non-authenticated harvests
auth.harvest.key = ""
auth.harvest.key = ${?HARVEST_KEY}

# Branding changes should be made using Environment Variables
# Developers should access values via the HubUtils model rather than directly.
brand.name=${?SITE_NAME}
brand.site_description=${?SITE_DESCRIPTION}
brand.base_url=${?SITE_BASE_URL}
2 changes: 1 addition & 1 deletion test/ApplicationSpec.scala
Expand Up @@ -29,7 +29,7 @@ class ApplicationSpec extends Specification {

status(home) must equalTo(OK)
contentType(home) must beSome.which(_ == "text/html")
contentAsString(home) must contain ("Welcome to SCOAP")
contentAsString(home) must contain ("Add a description in conf/brand.conf")
}

"display a login screen" in new WithApplication(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
Expand Down

0 comments on commit 37cde5e

Please sign in to comment.