Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Change Manager from Scholar
- Loading branch information
Showing
32 changed files
with
427 additions
and
6 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
23 changes: 23 additions & 0 deletions
23
app/controllers/concerns/scholar/works_controller_behavior.rb
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,23 @@ | ||
# frozen_string_literal: true | ||
# Generated via | ||
# `rails generate hyrax:work GenericWork` | ||
|
||
module Scholar | ||
module WorksControllerBehavior | ||
include ChangeManager::ChangeManagerHelper | ||
|
||
def create | ||
super | ||
# the to_s_u method must be implemented for every model | ||
editors = params.to_unsafe_hash[curation_concern.class.to_s_u][:permissions_attributes] | ||
queue_notifications_for_editors(editors) if editors | ||
end | ||
|
||
def update | ||
super | ||
# the to_s_u method must be implemented for every model | ||
editors = params.to_unsafe_hash[curation_concern.class.to_s_u][:permissions_attributes] | ||
queue_notifications_for_editors(editors) if editors | ||
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
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require Hyrax::Engine.root.join('app/controllers/hyrax/depositors_controller.rb') | ||
module Hyrax | ||
class DepositorsController < ApplicationController | ||
def destroy | ||
grantor = authorize_and_return_grantor | ||
grantee = ::User.from_url_component(params[:id]) | ||
send_removed_proxy_email(grantor, grantee) if grantor.can_receive_deposits_from.delete(grantee) | ||
head :ok | ||
end | ||
|
||
def send_granted_proxy_email(grantor, grantee) | ||
ChangeManager::EmailManager.queue_change(grantor, 'added_as_proxy', '', grantee) | ||
rescue NotImplementedError # needed for specs and development environments | ||
ChangeManager::EmailManager.skip_sidekiq_for_emails(grantor, 'added_as_proxy', '', grantee) | ||
end | ||
|
||
def send_removed_proxy_email(grantor, grantee) | ||
ChangeManager::EmailManager.queue_change(grantor, 'removed_as_proxy', '', grantee) | ||
rescue NotImplementedError # needed for specs and development environments | ||
ChangeManager::EmailManager.skip_sidekiq_for_emails(grantor, 'removed_as_proxy', '', grantee) | ||
end | ||
|
||
private | ||
|
||
def send_proxy_depositor_added_messages(grantor, grantee) | ||
message_to_grantee = "#{grantor.name} has assigned you as a proxy depositor" | ||
message_to_grantor = "You have assigned #{grantee.name} as a proxy depositor" | ||
::User.batch_user.send_message(grantor, message_to_grantor, "Proxy Depositor Added") | ||
::User.batch_user.send_message(grantee, message_to_grantee, "Proxy Depositor Added") | ||
send_granted_proxy_email(grantor, grantee) | ||
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
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
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,45 @@ | ||
# frozen_string_literal: true | ||
# helper for the WorksControllerBehavior class | ||
# cleaner to keep all change manager code in here | ||
module ChangeManager | ||
module ChangeManagerHelper | ||
def queue_notifications_for_editors(editors) | ||
editors.each do |editor_wrapper| | ||
editor = editor_wrapper[1] | ||
EmailManager.queue_change(curation_concern.depositor, 'added_as_editor', curation_concern.id, editor['name']) if new_editor? editor | ||
# uncomment this once the `Ldp::Gone` error is resolved | ||
# elsif removed_editor? editor | ||
# EmailManager.queue_change(curation_concern.depositor, 'removed_as_editor', curation_concern.id, editor[:name]) | ||
# end | ||
end | ||
rescue NotImplementedError | ||
editors.each do |editor_wrapper| | ||
editor = editor_wrapper[1] | ||
EmailManager.skip_sidekiq_for_emails(curation_concern.depositor, 'added_as_editor', curation_concern.id, editor['name']) if new_editor? editor | ||
# uncomment this once the `Ldp::Gone` error is resolved | ||
# elsif removed_editor? editor | ||
# EmailManager.skip_sidekiq_for_emails(curation_concern.depositor, 'removed_as_editor', curation_concern.id, editor['name']) | ||
# end | ||
end | ||
end | ||
|
||
private | ||
|
||
def new_editor?(editor) | ||
edit_access?(editor) && name_key?(editor) | ||
end | ||
|
||
# implement once Ldp::Gone error is resolved | ||
# def removed_editor?(_editor) | ||
# false | ||
# end | ||
|
||
def name_key?(hash) | ||
hash.key? 'name' | ||
end | ||
|
||
def edit_access?(hash) | ||
hash.key?('access') && hash['access'] == 'edit' | ||
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,12 @@ | ||
# frozen_string_literal: true | ||
require 'yaml' | ||
module ChangeManager | ||
class ProcessChangeJob < ActiveJob::Base | ||
queue_as :change | ||
|
||
def perform(change_id) | ||
config_file ||= YAML.load_file(Rails.root.join('config', 'change_manager_config.yml')) | ||
config_file['manager_class'].constantize.process_change(change_id) | ||
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
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,14 @@ | ||
# frozen_string_literal: true | ||
module ChangeManager | ||
module ComparisonConcern | ||
extend ActiveSupport::Concern | ||
|
||
def proxy_change? | ||
change_type == 'added_as_proxy' || change_type == 'removed_as_proxy' | ||
end | ||
|
||
def editor_change? | ||
change_type == 'added_as_editor' || change_type == 'removed_as_editor' | ||
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,51 @@ | ||
# frozen_string_literal: true | ||
module ChangeManager | ||
class EmailManager | ||
extend ChangeManager::Manager | ||
|
||
def self.queue_change(owner, change_type, context, target) | ||
change_id = Change.new_change(owner, change_type, context, target) | ||
ChangeManager::ProcessChangeJob.set(wait: 15.minutes).perform_later(change_id) | ||
end | ||
|
||
def self.skip_sidekiq_for_emails(owner, change_type, context, target) | ||
# Note: For some reason, it duplicates the items in the final email, but only when not using sidekiq | ||
change_id = Change.new_change(owner, change_type, context, target) | ||
process_change change_id | ||
end | ||
|
||
def self.process_change(change_id) | ||
change = Change.find change_id | ||
return if change.cancelled? | ||
verified_changes = process_changes_similar_to change | ||
notify_target_of verified_changes unless verified_changes.empty? | ||
true | ||
end | ||
|
||
def self.notify_target_of(changes) | ||
grouped_changes = group_changes(changes) | ||
if grouped_changes['proxies'] | ||
grouped_changes['proxies'].each(&:notify) if ChangeManager::ScholarNotificationMailer.notify_changes(grouped_changes['proxies']).deliver | ||
end | ||
|
||
return unless grouped_changes['editors'] | ||
grouped_changes['editors'].each(&:notify) if ChangeManager::ScholarNotificationMailer.notify_changes(grouped_changes['editors']).deliver | ||
end | ||
|
||
def self.group_changes(changes) | ||
proxy_changes = [] | ||
editor_changes = [] | ||
changes.each do |change| | ||
if change.proxy_change? | ||
proxy_changes << change | ||
elsif change.editor_change? | ||
editor_changes << change | ||
end | ||
end | ||
grouped_changes = {} | ||
grouped_changes['proxies'] = proxy_changes unless proxy_changes.empty? | ||
grouped_changes['editors'] = editor_changes unless editor_changes.empty? | ||
grouped_changes | ||
end | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
app/views/change_manager/scholar_notification_mailer/_editor_changes.html.erb
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,14 @@ | ||
<%= User.find_by_email(@changes.first.owner).name %> has added or removed you as an editor to the following works in Scholar@UC: | ||
|
||
<ul> | ||
<% @changes.each do |change| %> | ||
<% work_title = ActiveFedora::Base.find(change.context).title.first %> | ||
<% work_url = File.join(Rails.configuration.application_root_url, 'show', change.context) %> | ||
<li> | ||
<%= @change_types[change.change_type]['human_readable'] %> | ||
<%= link_to work_title, work_url %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
|
||
An editor can modify all metadata for a work and upload/delete files for a work. If you feel that this was made in error, please contact the <a href="mailto:scholar@uc.edu">Scholar@UC</a> team. |
3 changes: 3 additions & 0 deletions
3
app/views/change_manager/scholar_notification_mailer/_proxy_changes.html.erb
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,3 @@ | ||
<%= User.find_by_email(@changes.first.owner).name %> has <%= @change_types[@changes.first.change_type]['human_readable'] %> | ||
you as a proxy in Scholar@UC. A proxy can create and upload files on behalf of another user as well as edit, or delete those | ||
corresponding works and files. If you feel that this was made in error, <a href="mailto:scholar@uc.edu">Scholar@UC team</a>. |
12 changes: 12 additions & 0 deletions
12
app/views/change_manager/scholar_notification_mailer/notify_changes.html.erb
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 @@ | ||
<p>Dear <%= User.find_by_email(@changes.first.target).name %>:</p> | ||
|
||
<% if @changes.first.proxy_change? %> | ||
<%= render 'proxy_changes' %> | ||
<% elsif @changes.first.editor_change? %> | ||
<%= render 'editor_changes' %> | ||
<% end %> | ||
|
||
<p> | ||
Thanks, | ||
Scholar@UC | ||
</p> |
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 @@ | ||
manager_class: ChangeManager::EmailManager |
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,24 @@ | ||
added_as_proxy: | ||
print: proxy | ||
inverse: removed_as_proxy | ||
human_readable: added | ||
removed_as_proxy: | ||
print: proxy | ||
inverse: added_as_proxy | ||
human_readable: removed | ||
added_as_editor: | ||
print: editor | ||
inverse: removed_as_editor | ||
human_readable: Added as an editor to | ||
removed_as_editor: | ||
print: editor | ||
inverse: added_as_editor | ||
human_readable: Removed as an editor from | ||
embargo_set: | ||
print: embargo | ||
inverse: embargo_lifted | ||
human_readable: An embargo has been set | ||
embargo_lifted: | ||
print: Emboargo lifted | ||
inverse: embargo | ||
human_readable: An embargo has been lifted |
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,2 @@ | ||
# frozen_string_literal: true | ||
ChangeManager::Change.send :include, ChangeManager::ComparisonConcern |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ max_retries: 3 | |
- default | ||
- ingest | ||
- event | ||
- change |
13 changes: 13 additions & 0 deletions
13
db/migrate/20181001000000_create_change_manager_changes.rb
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,13 @@ | ||
class CreateChangeManagerChanges < ActiveRecord::Migration[5.1] | ||
def change | ||
create_table :change_manager_changes do |t| | ||
t.string :change_type | ||
t.boolean :cancelled | ||
t.datetime :notified | ||
t.string :owner | ||
t.string :target | ||
t.string :context | ||
t.timestamps | ||
end | ||
end | ||
end |
Oops, something went wrong.