This repository has been archived by the owner on Jan 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from ualbertalib/special-report-form
Special report form
- Loading branch information
Showing
24 changed files
with
483 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Hydranorth | ||
module Forms | ||
class CstrBatchEditForm < CstrEditForm | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Hydranorth | ||
module Forms | ||
class CstrEditForm < CstrPresenter | ||
include HydraEditor::Form | ||
self.required_fields = [:title, :creator, :subject, :license, :trid, :language] | ||
|
||
# This is required so that fields_for will draw a nested form. | ||
# See ActionView::Helpers#nested_attributes_association? | ||
# https://github.com/rails/rails/blob/a04c0619617118433db6e01b67d5d082eaaa0189/actionview/lib/action_view/helpers/form_helper.rb#L1890 | ||
def permissions_attributes= attributes | ||
model.permissions_attributes= attributes | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Hydranorth | ||
module Forms | ||
class SerBatchEditForm < SerEditForm | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Hydranorth | ||
module Forms | ||
class SerEditForm < SerPresenter | ||
include HydraEditor::Form | ||
self.required_fields = [:title, :creator, :subject, :license, :ser, :language] | ||
|
||
# This is required so that fields_for will draw a nested form. | ||
# See ActionView::Helpers#nested_attributes_association? | ||
# https://github.com/rails/rails/blob/a04c0619617118433db6e01b67d5d082eaaa0189/actionview/lib/action_view/helpers/form_helper.rb#L1890 | ||
def permissions_attributes= attributes | ||
model.permissions_attributes= attributes | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
class BatchUpdateJob | ||
include Hydra::PermissionsQuery | ||
include Sufia::Messages | ||
|
||
def queue_name | ||
:batch_update | ||
end | ||
|
||
attr_accessor :login, :title, :trid, :ser, :file_attributes, :batch_id, :visibility, :saved, :denied | ||
|
||
def initialize(login, batch_id, title, trid, ser, file_attributes, visibility) | ||
self.login = login | ||
self.title = title || {} | ||
if trid.present? | ||
self.trid = trid | ||
elsif ser.present? | ||
self.ser = ser | ||
end | ||
self.file_attributes = file_attributes | ||
self.visibility = visibility | ||
self.batch_id = batch_id | ||
self.saved = [] | ||
self.denied = [] | ||
end | ||
|
||
def run | ||
batch = Batch.find_or_create(self.batch_id) | ||
user = User.find_by_user_key(self.login) | ||
batch.generic_files.each do |gf| | ||
update_file(gf, user) | ||
end | ||
|
||
batch.update(status: ["Complete"]) | ||
|
||
if denied.empty? | ||
send_user_success_message(user, batch) unless saved.empty? | ||
else | ||
send_user_failure_message(user, batch) | ||
end | ||
end | ||
|
||
def update_file(gf, user) | ||
unless user.can? :edit, gf | ||
ActiveFedora::Base.logger.error "User #{user.user_key} DENIED access to #{gf.id}!" | ||
denied << gf | ||
return | ||
end | ||
gf.title = title[gf.id] if title[gf.id] | ||
gf.attributes = file_attributes | ||
if (trid.present? && trid[gf.id]) | ||
gf.trid = trid[gf.id] | ||
elsif (ser.present? && ser[gf.id]) | ||
gf.ser = ser[gf.id] | ||
end | ||
gf.visibility= visibility | ||
save_tries = 0 | ||
begin | ||
gf.save! | ||
rescue RSolr::Error::Http => error | ||
save_tries += 1 | ||
ActiveFedora::Base.logger.warn "BatchUpdateJob caught RSOLR error on #{gf.id}: #{error.inspect}" | ||
# fail for good if the tries is greater than 3 | ||
raise error if save_tries >=3 | ||
sleep 0.01 | ||
retry | ||
end # | ||
Sufia.queue.push(ContentUpdateEventJob.new(gf.id, login)) | ||
saved << gf | ||
end | ||
|
||
def send_user_success_message user, batch | ||
message = saved.count > 1 ? multiple_success(batch.id, saved) : single_success(batch.id, saved.first) | ||
User.batchuser.send_message(user, message, success_subject, sanitize_text = false) | ||
end | ||
|
||
def send_user_failure_message user, batch | ||
message = denied.count > 1 ? multiple_failure(batch.id, denied) : single_failure(batch.id, denied.first) | ||
User.batchuser.send_message(user, message, failure_subject, sanitize_text = false) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Hydranorth | ||
class CstrPresenter < GenericFilePresenter | ||
include Hydra::Presenter | ||
self.model_class = ::GenericFile | ||
# Terms is the list of fields displayed by app/views/generic_files/_show_descriptions.html.erb | ||
self.terms = [:resource_type, :title, :trid, :creator, :contributor, :description, :date_created, :license, :subject, :spatial, :temporal, :is_version_of, :source, :related_url, :language] | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Hydranorth | ||
class SerPresenter < GenericFilePresenter | ||
include Hydra::Presenter | ||
self.model_class = ::GenericFile | ||
# Terms is the list of fields displayed by app/views/generic_files/_show_descriptions.html.erb | ||
self.terms = [:resource_type, :title, :ser, :creator, :contributor, :description, :date_created, :license, :subject, :spatial, :temporal, :is_version_of, :source, :related_url, :language] | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= form_for(@generic_file, url: sufia.generic_files_path, html: { multipart: true, id: 'fileupload' }) do |f| %> | ||
<% unless current_user.can_make_deposits_for.empty? %> | ||
<div class="controls"> | ||
<%= label_tag :on_behalf_of, 'On Behalf of' %> | ||
<%= select_tag :on_behalf_of, options_for_select(current_user.can_make_deposits_for), prompt: "Yourself" %> | ||
</div> | ||
<% end %> | ||
<div class="well"> | ||
<%= render partial: 'generic_files/upload/special_reports' %> | ||
<%= render partial: 'generic_files/upload/form_fields' %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="controls"> | ||
<%= label_tag :special_reports, 'Uploading Special Reports?' %> | ||
<%= radio_button_tag :resource_type, 'Computing Science Technical Report' %> | ||
<%= label_tag :resource_type, 'Computing Science Technical Report' %> | ||
<%= radio_button_tag :resource_type, 'Structural Engineering Report' %> | ||
<%= label_tag :resource_type, 'Structural Engineering Report' %> | ||
<%= button_tag "Clear", class: 'btn btn-warning cancel reset-special-reports', id: 'reset-special-reports', name: "reset-special-reports", onclick: "confirmation_needed = false;", type: :reset %> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% if (@form[:resource_type].include? Sufia.config.special_reports['cstr']) || (@form[:resource_type].include? Sufia.config.special_reports['ser']) %> | ||
<% else %> | ||
|
||
<%= f.input :resource_type, as: :select_with_help, collection: Sufia.config.resource_types, | ||
input_html: { class: 'form-control', multiple: true } %> | ||
<% end %> |
Oops, something went wrong.