Skip to content

Commit

Permalink
Merge branch 'master' into collections-sprint
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle committed Sep 22, 2017
2 parents 9728c73 + 5f79711 commit eaff720
Show file tree
Hide file tree
Showing 24 changed files with 186 additions and 30 deletions.
32 changes: 32 additions & 0 deletions .rubocop_fixme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,35 @@ RSpec/AnyInstance:
- 'spec/services/hyrax/workflow/sipity_actions_generator_spec.rb'
- 'spec/services/hyrax/workflow/state_machine_generator_spec.rb'
- 'spec/services/hyrax/workflow/workflow_permissions_generator_spec.rb'

# Offense count: 51
RSpec/ExpectInHook:
Enabled: false

# Offense count: 31
RSpec/LetBeforeExamples:
Exclude:
- 'spec/forms/hyrax/forms/collection_form_spec.rb'
- 'spec/presenters/hyrax/collection_presenter_spec.rb'
- 'spec/presenters/hyrax/trophy_presenter_spec.rb'
- 'spec/services/hyrax/query_service_spec.rb'
- 'spec/services/hyrax/workflow/action_taken_service_spec.rb'
- 'spec/services/hyrax/workflow/notification_service_spec.rb'

# Offense count: 27
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: and_return, block
RSpec/ReturnFromStub:
Exclude:
- 'spec/controllers/hyrax/api/items_controller_spec.rb'
- 'spec/controllers/hyrax/file_sets_controller_spec.rb'
- 'spec/lib/hyrax/arkivo/create_subscription_job_spec.rb'
- 'spec/models/file_set_spec.rb'
- 'spec/presenters/hyrax/admin_set_options_presenter_spec.rb'
- 'spec/routing/api_route_spec.rb'
- 'spec/views/_user_util_links.html.erb_spec.rb'
- 'spec/views/hyrax/base/_attributes.html.erb_spec.rb'
- 'spec/views/hyrax/base/_form.html.erb_spec.rb'
- 'spec/views/hyrax/base/file_manager.html.erb_spec.rb'
- 'spec/views/hyrax/dashboard/profiles/edit.html.erb_spec.rb'
- 'spec/views/hyrax/users/_user_info.html.erb_spec.rb'
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The Samvera community is here to help. Please see our [support guide](./.github/
# Getting started

This document contains instructions specific to setting up an app with __Hyrax
v2.0.0.beta2__. If you are looking for instructions on installing a different
v2.0.0.beta3__. If you are looking for instructions on installing a different
version, be sure to select the appropriate branch or tag from the drop-down
menu above.

Expand Down Expand Up @@ -160,7 +160,7 @@ NOTE: The steps need to be done in order to create a new Hyrax based app.
Generate a new Rails application using the template.

```
rails _5.0.5_ new my_app -m https://raw.githubusercontent.com/samvera/hyrax/v2.0.0.beta2/template.rb
rails _5.0.5_ new my_app -m https://raw.githubusercontent.com/samvera/hyrax/v2.0.0.beta3/template.rb
```

Generating a new Rails application using Hyrax's template above takes cares of a number of steps for you, including:
Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/hyrax/app.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ Hyrax = {

// ActionCable for user notifications. This is displayed in the navbar.
notifications: function() {
// Do not create a consumer if user is not logged in
if ($("meta[name='current-user']").length === 0)
return;
<% if Hyrax.config.realtime_notifications? %>
var consumer = ActionCable.createConsumer("<%= Hyrax::Engine.routes.url_helpers.notifications_endpoint_path %>");
consumer.subscriptions.create("Hyrax::NotificationsChannel", {
connected: function(data) {
Expand All @@ -114,6 +118,7 @@ Hyrax = {
new Notification($('.notify-number')).update(data.notifications_count, data.notifications_label);
}
});
<% end %>
},

// Search for a user to transfer a work to
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions app/controllers/hyrax/citations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class CitationsController < ApplicationController
include Breadcrumbs
include SingularSubresourceController

layout :decide_layout
before_action :build_breadcrumbs, only: [:work, :file]

def work
Expand All @@ -24,5 +25,16 @@ def file
def show_presenter
WorkShowPresenter
end

def decide_layout
case action_name
when 'work', 'file'
theme
else
# Not currently used in this controller, but left here to
# support dashboard-based work views which are ticketed
'dashboard'
end
end
end
end
2 changes: 2 additions & 0 deletions app/jobs/stream_notifications_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class StreamNotificationsJob < Hyrax::ApplicationJob
def perform(users)
# Do not use the ActionCable machinery if the feature is disabled
return unless Hyrax.config.realtime_notifications?
Array.wrap(users).each do |user|
mailbox = UserMailbox.new(user)
Hyrax::NotificationsChannel.broadcast_to(user,
Expand Down
2 changes: 1 addition & 1 deletion app/services/hyrax/curation_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CurationConcern
# is used. Once it is used, it becomes immutable.
# @return [ActionDispatch::MiddlewareStack]
def self.actor_factory
Hyrax::DefaultMiddlewareStack.build_stack
@actor_factory ||= Hyrax::DefaultMiddlewareStack.build_stack
end

# A consumer of this method can inject a different factory
Expand Down
7 changes: 6 additions & 1 deletion app/views/layouts/_head_tag_content.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<%= csrf_meta_tag %>
<meta charset="utf-8" />

<%# Only display meta tag, which enables creation of the ActionCable
consumer, when realtime notifications are enabled and the user is
signed in %>
<% if Hyrax.config.realtime_notifications? && signed_in? %>
<%= tag :meta, name: 'current-user', data: { user_key: current_user.user_key } %>
<% end %>
<!-- added for use on small devices like phones -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="resourcesync" href="<%= hyrax.capability_list_url %>"/>
Expand Down
8 changes: 5 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@
delete 'delete_all'
end
end
namespace :notifications do
# WebSocket for notifications
mount ActionCable.server => 'endpoint', as: :endpoint
if Hyrax.config.realtime_notifications?
namespace :notifications do
# WebSocket for notifications
mount ActionCable.server => 'endpoint', as: :endpoint
end
end

# User profile
Expand Down
22 changes: 17 additions & 5 deletions hyrax.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ EOF
spec.add_dependency 'blacklight-gallery', '~> 0.7'
spec.add_dependency 'tinymce-rails', '~> 4.1'
spec.add_dependency 'font-awesome-rails', '~> 4.2'
spec.add_dependency 'select2-rails', '~> 3.5.9'
spec.add_dependency 'json-schema' # for Arkivio
spec.add_dependency 'select2-rails', '~> 3.5'
spec.add_dependency 'json-schema' # for Arkivo
spec.add_dependency 'nest', '~> 2.0'
spec.add_dependency 'mailboxer', '~> 0.12'
spec.add_dependency 'carrierwave', '~> 1.0'
Expand All @@ -51,18 +51,20 @@ EOF
spec.add_dependency 'legato', '~> 0.3'
spec.add_dependency 'posix-spawn'
spec.add_dependency 'jquery-ui-rails', '~> 5.0'
spec.add_dependency 'redis-namespace', '~> 1.5.2'
spec.add_dependency 'redis-namespace', '~> 1.5'
# Pin more tightly because 0.x gems are potentially unstable
spec.add_dependency 'flot-rails', '~> 0.0.6'
spec.add_dependency 'almond-rails', '~> 0.1'
spec.add_dependency 'qa', '~> 1.0' # questioning_authority
spec.add_dependency 'flipflop', '~> 2.3'
spec.add_dependency 'jquery-datatables-rails', '~> 3.4.0'
spec.add_dependency 'jquery-datatables-rails', '~> 3.4'
spec.add_dependency 'rdf-rdfxml' # controlled vocabulary importer
spec.add_dependency 'clipboard-rails', '~> 1.5'
spec.add_dependency 'rails_autolink', '~> 1.1'
spec.add_dependency 'active_fedora-noid', '~> 2.0', '>= 2.0.2'
spec.add_dependency 'awesome_nested_set', '~> 3.1'
spec.add_dependency 'breadcrumbs_on_rails', '~> 3.0'
# Pin more tightly because 0.x gems are potentially unstable
spec.add_dependency 'kaminari_route_prefix', '~> 0.1.1'
spec.add_dependency 'power_converter', '~> 0.1', '>= 0.1.2'
spec.add_dependency 'dry-validation', '~> 0.9'
Expand All @@ -89,8 +91,18 @@ EOF
spec.add_development_dependency "factory_girl_rails", '~> 4.4'
spec.add_development_dependency "equivalent-xml", '~> 0.5'
spec.add_development_dependency "jasmine", '~> 2.3'
# Pin rubocop and rubocop-rspec tightly. Minor-level version bumps
# in these gems cause Rubocop violations, and those violations cause
# continuous integration builds to fail, and those failures prevent
# us from merging pull requests. As a community, we have decided
# that it is not reasonable to manage style violations to be dealt
# with in a pull request *unless* said pull request's intent is to
# bring the codebase in further alignment with community style
# conventions. This allows us to take a managed approach to code
# style -- we choose to update style when we wish, not when a
# minor-level version bump in a dependency comes out.
spec.add_development_dependency 'rubocop', '~> 0.49.1'
spec.add_development_dependency 'rubocop-rspec', '~> 1.15.0'
spec.add_development_dependency 'rubocop-rspec', '~> 1.16.0'
spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
spec.add_development_dependency 'rails-controller-testing', '~> 0'
spec.add_development_dependency 'webmock'
Expand Down
3 changes: 3 additions & 0 deletions lib/generators/hyrax/templates/config/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
# of Zotero-managed research items.
# config.arkivo_api = false

# Stream realtime notifications to users in the browser
# config.realtime_notifications = true

# Location autocomplete uses geonames to search for named regions
# Username for connecting to geonames
# config.geonames_username = ''
Expand Down
16 changes: 16 additions & 0 deletions lib/hyrax/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ def arkivo_api?
@arkivo_api ||= false
end

# rubocop:disable Metrics/LineLength
attr_writer :realtime_notifications
def realtime_notifications?
# Coerce @realtime_notifications to false if server software
# does not support WebSockets, and warn the user that we are
# overriding the value in their config unless it's already
# flipped to false
if ENV.fetch('SERVER_SOFTWARE', '').match(/Apache.*Phusion_Passenger/).present?
Rails.logger.warn('Cannot enable realtime notifications atop Passenger + Apache. Coercing `Hyrax.config.realtime_notifications` to `false`. Set this value to `false` in config/initializers/hyrax.rb to stop seeing this warning.') unless @realtime_notifications == false
@realtime_notifications = false
end
return @realtime_notifications unless @realtime_notifications.nil?
@realtime_notifications = true
end
# rubocop:enable Metrics/LineLength

def geonames_username=(username)
Qa::Authorities::Geonames.username = username
end
Expand Down
2 changes: 1 addition & 1 deletion lib/hyrax/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Hyrax
VERSION = '2.0.0.beta2'.freeze
VERSION = '2.0.0.beta3'.freeze
end
6 changes: 0 additions & 6 deletions solr/config/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,6 @@
-->
<uniqueKey>id</uniqueKey>

<!-- field for the QueryParser to use when an explicit fieldname is absent -->
<!-- <defaultSearchField>text</defaultSearchField> -->

<!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
<solrQueryParser defaultOperator="OR"/>

<!-- copyField commands copy one field to another at the time a document
is added to the index. It's used either to index the same field differently,
or to add multiple fields to the same field for easier/faster searching. -->
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/hyrax/citations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
expect(controller).to receive(:add_breadcrumb).with('My Dashboard', Hyrax::Engine.routes.url_helpers.dashboard_path(locale: 'en'))
get :work, params: { id: work }
expect(response).to be_successful
expect(response).to render_template('layouts/hyrax')
expect(assigns(:presenter)).to be_kind_of Hyrax::WorkShowPresenter
end
end
Expand Down Expand Up @@ -41,6 +42,7 @@
expect(controller).to receive(:add_breadcrumb).with('My Dashboard', Hyrax::Engine.routes.url_helpers.dashboard_path(locale: 'en'))
get :file, params: { id: file_set }
expect(response).to be_successful
expect(response).to render_template('layouts/hyrax')
expect(assigns(:presenter)).to be_kind_of Hyrax::FileSetPresenter
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/jobs/stream_notifications_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
RSpec.describe StreamNotificationsJob do
let(:realtime_notifications) { true }

before do
allow(Hyrax.config).to receive(:realtime_notifications?).and_return(realtime_notifications)
end

describe '#perform' do
context 'with zero users' do
let(:users) { nil }
Expand All @@ -25,6 +31,15 @@
notifications_label: "You've got mail!")
described_class.perform_now(users)
end

context 'when realtime notifications feature is disabled' do
let(:realtime_notifications) { false }

it 'does not broadcast' do
expect(Hyrax::NotificationsChannel).not_to receive(:broadcast_to)
described_class.perform_now(users)
end
end
end
end
end
2 changes: 2 additions & 0 deletions spec/lib/hyrax/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
it { is_expected.to respond_to(:permission_levels) }
it { is_expected.to respond_to(:permission_options) }
it { is_expected.to respond_to(:persistent_hostpath) }
it { is_expected.to respond_to(:realtime_notifications?) }
it { is_expected.to respond_to(:realtime_notifications=) }
it { is_expected.to respond_to(:redis_namespace) }
it { is_expected.to respond_to(:subject_prefix) }
it { is_expected.to respond_to(:translate_id_to_uri) }
Expand Down
8 changes: 8 additions & 0 deletions spec/services/hyrax/curation_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@

it { is_expected.to be_kind_of Hyrax::Actors::TransactionalRequest }
end

describe ".actor_factory" do
subject { described_class.actor_factory }

it "returns same ActionDispatch::MiddlewareStack instance" do
is_expected.to eq described_class.actor_factory
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def main_app
Hyrax.config.enable_noids = false
end

config.before :each do |example|
config.before do |example|
if example.metadata[:type] == :feature && Capybara.current_driver != :rack_test
DatabaseCleaner.strategy = :truncation
else
Expand Down
6 changes: 3 additions & 3 deletions spec/tasks/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

it "creates a file" do
run_task "hyrax:user:list_emails"
expect(File.exist?("user_emails.txt")).to be_truthy
expect(File).to exist("user_emails.txt")
expect(IO.read("user_emails.txt")).to include(user1.email, user2.email)
File.delete("user_emails.txt")
end

it "creates a file I give it" do
run_task "hyrax:user:list_emails", "abc123.txt"
expect(File.exist?("user_emails.txt")).not_to be_truthy
expect(File.exist?("abc123.txt")).to be_truthy
expect(File).not_to exist("user_emails.txt")
expect(File).to exist("abc123.txt")
expect(IO.read("abc123.txt")).to include(user1.email, user2.email)
File.delete("abc123.txt")
end
Expand Down
1 change: 1 addition & 0 deletions spec/views/hyrax/base/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
allow(controller).to receive(:current_user).and_return(depositor)
allow(User).to receive(:find_by_user_key).and_return(depositor.user_key)
allow(view).to receive(:blacklight_config).and_return(Blacklight::Configuration.new)
allow(view).to receive(:signed_in?)
allow(view).to receive(:on_the_dashboard?).and_return(false)
stub_template 'hyrax/base/_metadata.html.erb' => ''
stub_template 'hyrax/base/_relationships.html.erb' => ''
Expand Down
Loading

0 comments on commit eaff720

Please sign in to comment.