-
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.
Delete PermissionTemplate when destroying a Hyrax::AdministrativeSet …
…or Hyrax collection (#6917) Co-authored-by: David Moles <dmoles@dmoles.net>
- Loading branch information
Showing
6 changed files
with
106 additions
and
10 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
30 changes: 30 additions & 0 deletions
30
lib/hyrax/transactions/steps/delete_permission_template.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,30 @@ | ||
# frozen_string_literal: true | ||
require 'dry/monads' | ||
|
||
module Hyrax | ||
module Transactions | ||
module Steps | ||
## | ||
# Deletes the Hyrax::PermissionTemplate for a resource. | ||
# If no PermissionTemplate associated with that resource is found, succeeds. | ||
# | ||
# @see https://dry-rb.org/gems/dry-monads/1.0/result/ | ||
class DeletePermissionTemplate | ||
include Dry::Monads[:result] | ||
|
||
## | ||
# @param [Valkyrie::Resource] obj | ||
# | ||
# @return [Dry::Monads::Result] | ||
def call(obj) | ||
permission_template = Hyrax::PermissionTemplate.find_by(source_id: obj.id) | ||
return Success(obj) if permission_template.nil? | ||
|
||
permission_template.destroy || (return Failure[:failed_to_delete_permission_template, permission_template]) | ||
|
||
Success(obj) | ||
end | ||
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
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