Skip to content

Commit

Permalink
Merging / fixing conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Collier committed Nov 30, 2016
2 parents 872a4de + 156a22e commit 24b0c79
Show file tree
Hide file tree
Showing 49 changed files with 900 additions and 197 deletions.
3 changes: 1 addition & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RSpec/NamedSubject:
Enabled: false

RSpec/ExampleLength:
Max: 7
Max: 7
Exclude:
- 'spec/controllers/api/items_controller_spec.rb'
- 'spec/controllers/authorities_controller_spec.rb'
Expand Down Expand Up @@ -113,4 +113,3 @@ RSpec/AnyInstance:
- 'spec/presenters/sufia/work_usage_spec.rb'
- 'spec/presenters/sufia/file_usage_spec.rb'
- 'spec/services/sufia/repository_audit_service_spec.rb'

15 changes: 0 additions & 15 deletions app/actors/sufia/grant_edit_to_depositor_actor.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/assets/javascripts/sufia.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
//= require almond
//= require sufia/admin/admin_set_controls
//= require sufia/admin/admin_set/participants
//= require sufia/admin/admin_set/visibility
//= require sufia/save_work
//= require sufia/permissions
//= require sufia/notifications
Expand Down
134 changes: 134 additions & 0 deletions app/assets/javascripts/sufia/admin/admin_set/visibility.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
export default class {
constructor(element) {
this.element = element
}

setup() {
// Watch for changes to "release_period" radio inputs
let releasePeriodInput = this.element.find("input[type='radio'][name$='[release_period]']")
$(releasePeriodInput).on('change', () => { this.releasePeriodSelected() })
this.releasePeriodSelected()

// Watch for changes to "release_varies" radio inputs
let releaseVariesInput = this.element.find("input[type='radio'][name$='[release_varies]']")
$(releaseVariesInput).on('change', () => { this.releaseVariesSelected() })
this.releaseVariesSelected()
}

// Based on the "release_period" radio selected, enable/disable other options
releasePeriodSelected() {
let selected = this.element.find("input[type='radio'][name$='[release_period]']:checked")

switch(selected.val()) {
// If "No Delay" (now) selected
case "now":
this.disableReleaseVariesOptions()
this.disableReleaseFixedDate()
this.enableVisibilityRestricted()
break;

// If "Varies" ("") selected
case "":
this.enableReleaseVariesRadio()
this.disableReleaseFixedDate()
this.disableVisibilityRestricted()
// Also check if a release "Varies" sub-option previously selected
this.releaseVariesSelected()
break;

// If "Fixed" selected
case "fixed":
this.disableReleaseVariesOptions()
this.enableReleaseFixedDate()
this.disableVisibilityRestricted()
break;

// Nothing selected
default:
this.disableReleaseVariesOptions()
this.disableReleaseFixedDate()
this.disableVisibilityRestricted()
}
}

// Based on the "release_varies" radio selected, enable/disable other options
releaseVariesSelected() {
let selected = this.element.find("input[type='radio'][name$='[release_varies]']:checked")

switch(selected.val()) {
// If before specific date selected
case "before":
this.enableReleaseVariesDate();
this.disableReleaseVariesSelect();
break;

// If embargo option selected
case "embargo":
this.disableReleaseVariesDate();
this.enableReleaseVariesSelect();
break;

// Nothing selected
default:
this.disableReleaseVariesDate();
this.disableReleaseVariesSelect();
}
}

// Disable ALL sub-options under "Varies"
disableReleaseVariesOptions() {
this.disableReleaseVariesRadio()
this.disableReleaseVariesSelect()
this.disableReleaseVariesDate()
}

// Disable all radio inputs under the release "Varies" option
disableReleaseVariesRadio() {
this.element.find("#release-varies input[type='radio'][name$='[release_varies]']").prop("disabled", true)
}

// Enable all radio inputs under the release "Varies" option
enableReleaseVariesRadio() {
this.element.find("#release-varies input[type='radio'][name$='[release_varies]']").prop("disabled", false)
}

// Disable selectbox next to release "Varies" embargo option
disableReleaseVariesSelect() {
this.element.find("#release-varies select[name$='[release_embargo]']").prop("disabled", true)
}

// Enable selectbox next to release "Varies" embargo option
enableReleaseVariesSelect() {
this.element.find("#release-varies select[name$='[release_embargo]']").prop("disabled", false)
}

// Disable date input field next to release "Varies" before option
disableReleaseVariesDate() {
this.element.find("#release-varies input[type='date'][name$='[release_date]']").prop("disabled", true)
}

// Enable date input field next to release "Varies" before option
enableReleaseVariesDate() {
this.element.find("#release-varies input[type='date'][name$='[release_date]']").prop("disabled", false)
}

// Disable date input field next to release "Fixed" option
disableReleaseFixedDate() {
this.element.find("#release-fixed input[type='date'][name$='[release_date]']").prop("disabled", true)
}

// Enable date input field next to release "Fixed" option
enableReleaseFixedDate() {
this.element.find("#release-fixed input[type='date'][name$='[release_date]']").prop("disabled", false)
}

// Disable visibility "Restricted" option (not valid for embargoes)
disableVisibilityRestricted() {
this.element.find("input[type='radio'][name$='[visibility]'][value='restricted']").prop("disabled", true)
}

// Enable visibility "Restricted" option
enableVisibilityRestricted() {
this.element.find("input[type='radio'][name$='[visibility]'][value='restricted']").prop("disabled", false)
}
}
4 changes: 4 additions & 0 deletions app/assets/javascripts/sufia/admin/admin_set_controls.es6
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ export default class {
let Participants = require('sufia/admin/admin_set/participants');
let participants = new Participants(elem.find('#participants'))
participants.setup();

let Visibility = require('sufia/admin/admin_set/visibility');
let visibilityTab = new Visibility(elem.find('#visibility'));
visibilityTab.setup();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def add_breadcrumb_for_controller
end

def _prefixes
# This allows us to use the templates in curation_concerns/base
# This allows us to use the templates in curation_concerns/base, while prefering
# our local paths. Thus we are unable to just override `self.local_prefixes`
@_prefixes ||= super + ['curation_concerns/base']
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Sufia
module DenyAccessOverrideBehavior
# Overriding the default behavior from Hydra::Core::ContorllerBehavior
# Overriding the default behavior from Hydra::Core::ControllerBehavior
def deny_access(exception)
if current_user && current_user.persisted?
redirect_to root_path, alert: exception.message
Expand Down
19 changes: 5 additions & 14 deletions app/controllers/concerns/sufia/file_sets_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ module FileSetsControllerBehavior
include Sufia::Breadcrumbs

included do
include Blacklight::Configurable

with_themed_layout '1_column'

copy_blacklight_config_from(CatalogController)

# actions: index, create, new, edit, show, update,
# destroy, permissions, citation, stats

# prepend this hook so that it comes before load_and_authorize
prepend_before_action :authenticate_user!, except: [:show, :citation, :stats]
before_action :build_breadcrumbs, only: [:show, :edit, :stats]
Expand Down Expand Up @@ -44,12 +35,12 @@ def add_breadcrumb_for_action
end
end

protected
# This allows us to use the templates in curation_concerns/file_sets
def self.local_prefixes
['curation_concerns/file_sets']
end

def _prefixes
# This allows us to use the templates in curation_concerns/file_sets
@_prefixes ||= ['curation_concerns/file_sets'] + super
end
protected

def initialize_edit_form
@version_list = version_list
Expand Down
25 changes: 18 additions & 7 deletions app/controllers/concerns/sufia/users_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ module Sufia::UsersControllerBehavior
end

def index
query = params[:uq].blank? ? nil : "%" + params[:uq].downcase + "%"
base = User.where(*base_query)
unless query.blank?
base = base.where("#{Devise.authentication_keys.first} like lower(?) OR display_name like lower(?)", query, query)
end
@users = base.references(:trophies).order(sort_value).page(params[:page]).per(10)

@users = search(params[:uq])
respond_to do |format|
format.html
format.json { render json: @users.to_json }
Expand Down Expand Up @@ -68,6 +62,23 @@ def notifications_number

protected

# TODO: this should move to a service.
# Returns a list of users excluding the system users and guest_users
# @param query [String] the query string
def search(query)
clause = query.blank? ? nil : "%" + query.downcase + "%"
base = User.where(*base_query)
unless clause.blank?
base = base.where("#{Devise.authentication_keys.first} like lower(?) OR display_name like lower(?)", clause, clause)
end
base.where("#{Devise.authentication_keys.first} not in (?)",
[User.batch_user_key, User.audit_user_key])
.where(guest: false)
.references(:trophies)
.order(sort_value)
.page(params[:page]).per(10)
end

def user_params
params.require(:user).permit(:avatar, :facebook_handle, :twitter_handle,
:googleplus_handle, :linkedin_handle, :remove_avatar, :orcid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def load_template_for_admin_set

def update_params
params.require(:sufia_permission_template)
.permit(:visibility, :workflow_name, access_grants_attributes: [:access, :agent_id, :agent_type, :id])
.permit(:release_date, :release_period, :release_varies, :release_embargo, :visibility,
access_grants_attributes: [:access, :agent_id, :agent_type, :id])
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/sufia/trophies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ def toggle_trophy
t = current_user.trophies.where(work_id: work_id).first
if t
t.destroy
return false if t.persisted?
else
t = current_user.trophies.create(work_id: work_id)
return false unless t.persisted?
end
render json: t
end
Expand Down
66 changes: 65 additions & 1 deletion app/forms/sufia/forms/permission_template_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ class PermissionTemplateForm
include HydraEditor::Form
self.model_class = PermissionTemplate
self.terms = []
delegate :access_grants, :access_grants_attributes=, :visibility, to: :model
delegate :access_grants, :access_grants_attributes=, :release_date, :release_period, :visibility, to: :model

# Stores which radio button under release "Varies" option is selected
attr_accessor :release_varies
# Selected release embargo timeframe (if any) under release "Varies" option
attr_accessor :release_embargo

# Visibility options for permission templates
def visibility_options
Expand All @@ -16,9 +21,29 @@ def visibility_options
[Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE, I18n.t('.restricted', scope: i18n_prefix)]]
end

# Embargo / release period options
def embargo_options
i18n_prefix = "sufia.admin.admin_sets.form_visibility.release.varies.embargo"
[[Sufia::PermissionTemplate::RELEASE_TEXT_VALUE_6_MONTHS, I18n.t('.6mos', scope: i18n_prefix)],
[Sufia::PermissionTemplate::RELEASE_TEXT_VALUE_1_YEAR, I18n.t('.1yr', scope: i18n_prefix)],
[Sufia::PermissionTemplate::RELEASE_TEXT_VALUE_2_YEARS, I18n.t('.2yrs', scope: i18n_prefix)],
[Sufia::PermissionTemplate::RELEASE_TEXT_VALUE_3_YEARS, I18n.t('.3yrs', scope: i18n_prefix)]]
end

def initialize(model)
# This is a temporary way to make sure all new PermissionTemplates have
# a workflow assigned to them. Ultimately we want to expose workflows in
# the UI and have users choose a workflow for their PermissionTemplate.
model.workflow_name = 'one_step_mediated_deposit'
super(model)
# Ensure proper form options selected, based on model
select_release_varies_option(model)
end

def update(attributes)
manage_grants = grants_as_collection(attributes).select { |x| x[:access] == 'manage' }
grant_admin_set_access(manage_grants) if manage_grants.present?
update_release_attributes(attributes)
model.update(attributes)
end

Expand Down Expand Up @@ -46,6 +71,45 @@ def grant_admin_set_access(manage_grants)
admin_set.edit_groups = manage_grants.select { |x| x[:agent_type] == 'group' }.map { |x| x[:agent_id] }
admin_set.save!
end

# In form, select appropriate radio button under Release "Varies" option based on saved permission_template
def select_release_varies_option(permission_template)
# Ignore 'no_delay' or 'fixed' values, as they are separate options
return if permission_template.release_no_delay? || permission_template.release_fixed?

# If release_period BEFORE a specified date, then 'before' option under "varies" was selected
if permission_template.release_before_date?
@release_varies = Sufia::PermissionTemplate::RELEASE_TEXT_VALUE_BEFORE_DATE
# If embargo specified, then 'embargo' option under "varies" was selected and embargo period selected
elsif permission_template.release_embargo?
# If release_period is some other value, it is specifying an embargo period (e.g. 6mos, 1yr, etc)
@release_varies = Sufia::PermissionTemplate::RELEASE_TEXT_VALUE_EMBARGO
@release_embargo = permission_template.release_period
end
end

# Update attributes based on release options selected (if any).
def update_release_attributes(attributes)
# If 'varies' before date option selected, then set release_period='before' and save release_date as-is
if attributes[:release_varies] == Sufia::PermissionTemplate::RELEASE_TEXT_VALUE_BEFORE_DATE
attributes[:release_period] = Sufia::PermissionTemplate::RELEASE_TEXT_VALUE_BEFORE_DATE
# Else if 'varies' + embargo selected, save embargo as the release_period
elsif attributes[:release_varies] == Sufia::PermissionTemplate::RELEASE_TEXT_VALUE_EMBARGO && attributes[:release_embargo]
attributes[:release_period] = attributes[:release_embargo]
# In an embargo, the release_date should be unspecified as it is based on deposit date
attributes[:release_date] = nil
end

# If release is "no delay", a release_date should never be allowed/specified
if attributes[:release_period] == Sufia::PermissionTemplate::RELEASE_TEXT_VALUE_NO_DELAY
attributes[:release_date] = nil
end

# Remove release_varies and release_embargo from attributes
# These form fields are only used (above) to update release_period
attributes.delete(:release_varies)
attributes.delete(:release_embargo)
end
end
end
end
5 changes: 0 additions & 5 deletions app/helpers/sufia/citations_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ def export_as_chicago_citation(work)
Sufia::CitationsBehaviors::Formatters::ChicagoFormatter.new(self).format(work)
end

# MIME: 'application/x-endnote-refer'
def export_as_endnote(work)
Sufia::CitationsBehaviors::Formatters::EndnoteFormatter.new(self).format(work)
end

def export_as_mla_citation(work)
Sufia::CitationsBehaviors::Formatters::MlaFormatter.new(self).format(work)
end
Expand Down

0 comments on commit 24b0c79

Please sign in to comment.