• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

curationexperts / laevigata / 0d10b93f-7d12-4108-bfd7-303659b33b6c

18 Jun 2025 03:38AM UTC coverage: 97.41% (-0.001%) from 97.411%
0d10b93f-7d12-4108-bfd7-303659b33b6c

Pull #2464

circleci

mark-dce
Disable embargo expiration notifications

Per discussions with SCO, they wish to reduce administrative overhead
by eliminating embargo expiration notifications.

We still need to process actual embargo expirations to change the
corresponding ETDs from a restricted to open status.

Therefore, this change leaves the schedule and service code in place
and simply comments out the calls to notification processing so that
we still get nightly expiration processing.
Pull Request #2464: Disable embargo expiration notifications

4 of 4 new or added lines in 1 file covered. (100.0%)

43 existing lines in 7 files now uncovered.

2821 of 2896 relevant lines covered (97.41%)

52.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/app/controllers/hyrax/etds_controller.rb
1
# Generated via
2
#  `rails generate hyrax:work Etd`
3
require 'input_sanitizer'
4✔
4

5
module Hyrax
4✔
6
  class EtdsController < ApplicationController
4✔
7
    # Adds Hyrax behaviors to the controller.
8
    include Hyrax::WorksControllerBehavior
4✔
9
    include Hyrax::BreadcrumbsForWorks
4✔
10
    self.curation_concern_type = Etd
4✔
11
    self.show_presenter = EtdPresenter
4✔
12

13
    # Overriding `Hyrax::WorksControllerBehavior`, which wants to use the
14
    # 'dashboard' theme for all but the show view. Always use the theme instead.
15
    with_themed_layout nil
4✔
16

17
    def create
4✔
18
      sanitize_input(params)
9✔
19
      apply_file_metadata(params)
9✔
20
      if params['etd'].fetch('ipe_id', false)
9✔
21
        create_with_response_for_form
7✔
22
      else
23
        super
2✔
24
      end
25
    end
26

27
    def after_create_response
4✔
28
      delete_ipe_record
3✔
29
      super
3✔
30
    end
31

32
    ##
33
    # Our file set visibility behavior is somewhat different from Hyrax's
34
    # default behavior. When we update work visibility or permissions, we
35
    # want to ensure that the FileSets are given permissions congruent with
36
    # the embargo settings. We do this by setting the FileSet visibility using
37
    # `FileSetActor` directly, inline.
38
    #
39
    # We can afford to run this inline, because we don't expect works with
40
    # dozens or hundreds of FileSets.
41
    #
42
    # Overriding this method avoids redirects to confirmation pages when
43
    # updating the visibility and permissions of a work.
44
    def after_update_response
4✔
UNCOV
45
      enforce_file_visibility(curation_concern)
2✔
46

UNCOV
47
      respond_to do |wants|
2✔
UNCOV
48
        wants.html { redirect_to [main_app, curation_concern], notice: "Work \"#{curation_concern}\" successfully updated." }
4✔
UNCOV
49
        wants.json { render :show, status: :ok, location: polymorphic_path([main_app, curation_concern]) }
2✔
50
      end
51
    end
52

53
    # So that the next time a student wants to create
54
    # a new ETD, they won't have the old values from
55
    # their old ETD hanging around in the form.
56
    def delete_ipe_record
4✔
57
      return unless params['etd']['ipe_id']
3✔
58
      return unless InProgressEtd.exists? params['etd']['ipe_id']
1✔
59
      ipe = InProgressEtd.find params['etd']['ipe_id']
1✔
60
      ipe.destroy
1✔
61
    end
62

63
    def update
4✔
64
      sanitize_input(params)
8✔
65
      apply_file_metadata(params)
8✔
66

67
      if params['request_from_form'] == 'true'
8✔
68
        curation_concern.committee_chair = nil
6✔
69
        curation_concern.committee_members = nil
6✔
70
        update_with_response_for_form
6✔
71
      else
UNCOV
72
        super
2✔
73
      end
74
    end
75

76
    def update_with_response_for_form
4✔
77
      if actor.update(actor_environment)
6✔
78
        path = main_app.hyrax_etd_path(curation_concern)
5✔
79
        render json: { redirectPath: path }, status: :ok
5✔
80
      else
81
        render json: { errors: 'ERROR: Unable to save the ETD' }, status: 422
1✔
82
        # TODO: render json: { errors: curation_concern.errors.messages }, status: 422
83
      end
84
    end
85

86
    # we return unprocessable entity for Etd-creation errors
87

88
    # a record without school and department params will cause a Runtime error during the creation of an admin set
89

90
    # if any other StandardErrors occur, we want to catch them, log them and display a friendly message to the user
91

92
    def create_with_response_for_form
4✔
93
      if actor.create(actor_environment)
7✔
94
        after_create_response
1✔
95
      else
96
        render json: { errors: curation_concern.errors.messages }, status: 422
3✔
97
      end
98
    rescue StandardError => error
99
      Rails.logger.error("Create from IPE error: #{error}, current_user: #{current_user}")
3✔
100
      Honeybadger.notify(error, error_message: "current_user = #{current_user} #{error.message}")
3✔
101
      render json: { errors: error.to_s }, status: 422
3✔
102
    end
103

104
    # Override from Hyrax:app/controllers/concerns/hyrax/curation_concern_controller.rb
105
    # Hyrax default behavior is that a user cannot see their own work if the document
106
    # is "suppressed", which means Hyrax::Workflow::ActivateObject has not been called.
107
    # In Emory's case, they do not want the object activated until the student has
108
    # graduated. That means we need to override the default behavior.
109
    def document_not_found!
4✔
110
      doc = ::SolrDocument.find(params[:id])
6✔
111
      # Render the document if the current_user == the depositor of the document
112
      return doc if current_user && current_user.user_key == doc["depositor_ssim"].first
6✔
113
      raise WorkflowAuthorizationException if doc.suppressed?
6✔
114
      raise CanCan::AccessDenied.new(nil, :show)
1✔
115
    end
116

117
    # Any fields coming in through tinymce are likely to be full of ms word
118
    # type markup that we don't want. Sanitize it.
119
    def sanitize_input(params)
4✔
120
      params["etd"]["abstract"] = ::InputSanitizer.sanitize(params["etd"]["abstract"]) if params["etd"]["abstract"]
19✔
121
      params["etd"]["table_of_contents"] = ::InputSanitizer.sanitize(params["etd"]["table_of_contents"]) if params["etd"]["table_of_contents"]
19✔
122
    end
123

124
    # Take supplemental file metadata and write it to the appropriate UploadedFile
125
    # @param [ActionController::Parameters] params
126
    # @return [ActionController::Parameters] params
127
    def apply_file_metadata(params)
4✔
128
      uploaded_file_ids = params["uploaded_files"]
18✔
129
      return if uploaded_file_ids.nil?
18✔
130
      uploaded_file_ids.each do |uploaded_file_id|
4✔
131
        uploaded_file = ::Hyrax::UploadedFile.find(uploaded_file_id)
6✔
132
        next if uploaded_file.pcdm_use == "primary"
6✔
133
        apply_metadata_to_uploaded_file(uploaded_file, params)
3✔
134
      end
135
      params["etd"].delete("supplemental_file_metadata")
4✔
136
      params # return the params after processing, for ease of testing
4✔
137
    end
138

139
    private
4✔
140

141
      def must_update_file_visibility?(work)
4✔
UNCOV
142
        work.file_sets.present? &&
2✔
UNCOV
143
          (permissions_changed? || work.visibility_changed?)
2✔
144
      end
145

146
      def enforce_file_visibility(work)
4✔
UNCOV
147
        return unless must_update_file_visibility?(work)
2✔
148

149
        visibility_attrs =
UNCOV
150
          FileSetVisibilityAttributeBuilder
2✔
151
            .new(work: work)
152
            .build
153

UNCOV
154
        work.file_sets.each do |fs|
2✔
UNCOV
155
          Hyrax::Actors::FileSetActor
2✔
156
            .new(fs, current_user)
157
            .update_metadata(visibility_attrs)
158
        end
159
      end
160

161
      def apply_metadata_to_uploaded_file(uploaded_file, params)
4✔
162
        supplemental_file_metadata = get_supplemental_file_metadata(uploaded_file, params)
3✔
163

164
        uploaded_file.title = supplemental_file_metadata["title"]
3✔
165
        uploaded_file.description = supplemental_file_metadata["description"]
3✔
166
        uploaded_file.file_type = supplemental_file_metadata["file_type"]
3✔
167
        uploaded_file.pcdm_use = ::FileSet::SUPPLEMENTAL
3✔
168
        uploaded_file.save
3✔
169
      end
170

171
      def get_supplemental_file_metadata(uploaded_file, params)
4✔
172
        filename = get_filename_for_uploaded_file(uploaded_file)
3✔
173
        supplemental_file_metadata = params["etd"]["supplemental_file_metadata"]&.values || {}
3✔
174
        supplemental_file_metadata.find { |a| a["filename"].tr(' ', '_') == filename.tr(' ', '_') } || {}
7✔
175
      end
176

177
      def get_filename_for_uploaded_file(uploaded_file)
4✔
178
        File.basename(uploaded_file.file.file.file)
3✔
179
      end
180
  end
181
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc