-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split up
Hyrax::ContainedInWorksBehavior
In discussion, it was decided that it was better to break this out into separate modules.
- Loading branch information
Showing
7 changed files
with
93 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
## | ||
# A module of form behaviours for depositors and depositor agreements. | ||
module DepositAgreementBehavior | ||
def self.included(descendant) | ||
descendant.property :depositor | ||
|
||
descendant.property :agreement_accepted, virtual: true, default: false, prepopulator: proc { |_opts| self.agreement_accepted = !model.new_record } | ||
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,49 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
## | ||
# A module of form behaviours for embargoes, leases, and resulting | ||
# visibilities. | ||
module LeaseabilityBehavior | ||
def self.included(descendant) # rubocop:disable Metrics/AbcSize | ||
descendant.property :visibility, default: VisibilityIntention::PRIVATE, populator: :visibility_populator | ||
|
||
descendant.property :embargo, form: Hyrax::Forms::Embargo, populator: :embargo_populator | ||
descendant.property :lease, form: Hyrax::Forms::Lease, populator: :lease_populator | ||
|
||
# virtual properties for embargo/lease; | ||
descendant.property :embargo_release_date, virtual: true, prepopulator: proc { |_opts| self.embargo_release_date = model.embargo&.embargo_release_date } | ||
descendant.property :visibility_after_embargo, virtual: true, prepopulator: proc { |_opts| self.visibility_after_embargo = model.embargo&.visibility_after_embargo } | ||
descendant.property :visibility_during_embargo, virtual: true, prepopulator: proc { |_opts| self.visibility_during_embargo = model.embargo&.visibility_during_embargo } | ||
|
||
descendant.property :lease_expiration_date, virtual: true, prepopulator: proc { |_opts| self.lease_expiration_date = model.lease&.lease_expiration_date } | ||
descendant.property :visibility_after_lease, virtual: true, prepopulator: proc { |_opts| self.visibility_after_lease = model.lease&.visibility_after_lease } | ||
descendant.property :visibility_during_lease, virtual: true, prepopulator: proc { |_opts| self.visibility_during_lease = model.lease&.visibility_during_lease } | ||
end | ||
|
||
def embargo_populator(**) | ||
self.embargo = Hyrax::EmbargoManager.embargo_for(resource: model) | ||
end | ||
|
||
def lease_populator(**) | ||
self.lease = Hyrax::LeaseManager.lease_for(resource: model) | ||
end | ||
|
||
def visibility_populator(fragment:, doc:, **) | ||
case fragment | ||
when "embargo" | ||
self.visibility = doc['visibility_during_embargo'] | ||
|
||
doc['embargo'] = doc.slice('visibility_after_embargo', | ||
'visibility_during_embargo', | ||
'embargo_release_date') | ||
when "lease" | ||
self.visibility = doc['visibility_during_lease'] | ||
doc['lease'] = doc.slice('visibility_after_lease', | ||
'visibility_during_lease', | ||
'lease_expiration_date') | ||
else | ||
self.visibility = fragment | ||
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,20 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
## | ||
# A module of form behaviours for populating permissions. | ||
module PermissionBehavior | ||
def self.included(descendant) | ||
descendant.collection(:permissions, | ||
virtual: true, | ||
default: [], | ||
form: Hyrax::Forms::Permission, | ||
populator: :permission_populator, | ||
prepopulator: proc { |_opts| self.permissions = Hyrax::AccessControl.for(resource: model).permissions }) | ||
end | ||
|
||
# https://trailblazer.to/2.1/docs/reform.html#reform-populators-populator-collections | ||
def permission_populator(collection:, index:, **) | ||
Hyrax::Forms::Permission.new(collection[index]) | ||
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