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

pulibrary / tigerdata-app / fbcd6d8c-b31b-4741-a97d-288a1eedfe72

11 Dec 2025 07:57PM UTC coverage: 91.227% (+3.7%) from 87.531%
fbcd6d8c-b31b-4741-a97d-288a1eedfe72

push

circleci

web-flow
Edit buttons for project request summary page (#2296)

<img width="1259" height="190" alt="image"
src="https://github.com/user-attachments/assets/c8702492-782e-4ca5-b1da-7e58ca5c3b00"
/>

<img width="1512" height="670" alt="Screenshot 2025-12-11 at 1 10 39 PM"
src="https://github.com/user-attachments/assets/cc29c366-1539-4f68-ae70-5b36de3c0392"
/>

Co-authored-by: Hector Correa <hector_correa@princeton.edu>

2974 of 3260 relevant lines covered (91.23%)

1227.56 hits per line

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

95.0
/app/operations/project_create.rb
1
# frozen_string_literal: true
2
class ProjectCreate < Dry::Operation
6✔
3
  class ProjectCreateError < StandardError; end
6✔
4

5
  def call(request:, approver:)
6✔
6
    project = step create_project_from_request(request)
552✔
7
    mediaflux_id = step persist_in_mediaflux(project, approver)
548✔
8
    step update_project_with_mediaflux_info(mediaflux_id:, project:)
540✔
9
    step persist_users_in_mediaflux(project, approver)
538✔
10
    step activate_project(project, approver)
538✔
11
  end
12

13
  private
6✔
14
    def create_project_from_request(request)
6✔
15
      # Create the project in the Rails database
16
      project_metadata_json = RequestProjectMetadata.convert(request)
552✔
17
      # Link the request to the project
18
      project = Project.create!({ metadata_json: project_metadata_json })
552✔
19
      request.project_id = project.id
550✔
20
      project.draft_doi
550✔
21
      project.save!
548✔
22

23
      # Return Success(attrs) or Failure(error)
24
      Success project
548✔
25
    rescue => ex
26
      Failure("Error creating the project: #{ex}")
4✔
27
    end
28

29
    def persist_in_mediaflux(project, current_user)
6✔
30
      # Create the project in Mediaflux
31
      mediaflux_request = Mediaflux::ProjectCreateServiceRequest.new(session_token: current_user.mediaflux_session, project: project)
554✔
32
      mediaflux_request.resolve
554✔
33

34
      mediaflux_id = mediaflux_request.mediaflux_id
546✔
35

36
      if mediaflux_id.to_i == 0
546✔
37
        debug_output = "Error saving project #{project.id} to Mediaflux: #{mediaflux_request.response_error}. Debug output: #{mediaflux_request.debug_output}"
6✔
38
        Rails.logger.error debug_output
6✔
39
        Failure debug_output
6✔
40
      else
41
        ProvenanceEvent.generate_approval_events(project: project, user: current_user, debug_output: mediaflux_request.debug_output.to_s)
540✔
42
        # Save the submission provenance
43
        # TODO:  Should we update the metadata_model or just the metadata hash directly?
44
        project.metadata_model.submission["approved_by"] = current_user.uid
540✔
45
        project.metadata_model.submission["approved_on"] = project.provenance_events.where(event_type: "Approved").first.created_at
540✔
46
        project.save!
540✔
47

48
        Success(mediaflux_id)
540✔
49
      end
50
    rescue EOFError => ex
51
      # Retry EOFErrors a few times
52
      if eof_error_handler
8✔
53
        Rails.logger.error "EOFError detected when saving project #{project.id} to Mediaflux, Details: #{ex.message}, retrying..."
6✔
54
        Honeybadger.notify "EOFError detected when saving project #{project.id} to Mediaflux, Details: #{ex.message}, retrying..."
6✔
55
        retry
6✔
56
      else
57
        Failure("Error saving project #{project.id} to Mediaflux: #{ex}. EOFError retry failed.")
2✔
58
      end
59
    rescue => ex
60
      # All other errors will just be returned as failures
61
      Failure("Error saving project #{project.id} to Mediaflux: #{ex}")
×
62
    end
63

64
    def update_project_with_mediaflux_info(mediaflux_id:, project:)
6✔
65
      project.mediaflux_id = mediaflux_id
540✔
66
      project.metadata_model.status = Project::APPROVED_STATUS
538✔
67
      project.save!
538✔
68
      Success(project)
538✔
69
    rescue => ex
70
      # TODO: It was saved in mediaflux, so maybe a retry here?  I don't want to destroy the project
71
      Failure("Setting the mediaflux id the project(#{project.id}) : #{ex}")
2✔
72
    end
73

74
    def persist_users_in_mediaflux(project, current_user)
6✔
75
      # Do nothing if there are no users to persist
76
      return Success(project) if (project.metadata_model.ro_users + project.metadata_model.rw_users).empty?
538✔
77

78
      # Add the data users to the project in Mediaflux
79
      add_users_request = Mediaflux::ProjectUserAddRequest.new(session_token: current_user.mediaflux_session, project: project)
54✔
80
      add_users_request.resolve
54✔
81

82
      if add_users_request.error?
54✔
83
        # TODO: what should we do with the project in this case?  It got all the way to mediaflux, but the users were not added
84
        Failure("Error adding users to mediaflux project #{project.mediaflux_id} #{add_users_request.response_error}")
×
85
      else
86
        user_debug = add_users_request.debug_output.to_s
54✔
87
        Rails.logger.debug { "Project #{project.id} users have been added to MediaFlux: #{user_debug}" }
108✔
88
        Success project
54✔
89
      end
90
    # TODO:  What kind of error are we expecting here?  This will capture the session errors, but maybe we should not be doing this.
91
    #        I could not figure out a way in tests to hit this error...
92
    rescue => ex
93
      Failure("Exception adding users to mediaflux project #{project.mediaflux_id}: #{ex}")
×
94
    end
95

96
    def activate_project(project, approver)
6✔
97
      project.activate(current_user: approver)
538✔
98
      Success(project)
536✔
99
    rescue => ex
100
      Failure("Error activate project #{project.id}: #{ex}")
2✔
101
    end
102

103
    def eof_error_handler
6✔
104
      @retry_count ||= 0
8✔
105
      @retry_count += 1
8✔
106
      # TODO: How do we fix EOF errors?  Just retrying for now.
107

108
      @retry_count < 3 # If the session is expired we should not have to retry more than once, but let's have a little wiggle room
8✔
109
    end
110

111
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

© 2026 Coveralls, Inc