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

pulibrary / tigerdata-app / 863e578f-15a5-4c93-8357-08f855de0bbc

24 Nov 2025 02:23PM UTC coverage: 87.366% (-0.7%) from 88.064%
863e578f-15a5-4c93-8357-08f855de0bbc

Pull #2235

circleci

carolyncole
Do not redirect from home page when login is disabled
fixes #2188
Pull Request #2235: Do not redirect from home page when login is disabled

5 of 5 new or added lines in 2 files covered. (100.0%)

834 existing lines in 48 files now uncovered.

2773 of 3174 relevant lines covered (87.37%)

499.78 hits per line

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

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

5
  def call(request:, approver:)
4✔
6
    project = step create_project_from_request(request)
266✔
7
    mediaflux_id = step persist_in_mediaflux(project, approver)
264✔
8
    step update_project_with_mediaflux_info(mediaflux_id:, project:)
261✔
9
    step persist_users_in_mediaflux(project, approver)
260✔
10
    step activate_project(project, approver)
260✔
11
  end
12

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

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

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

34
      mediaflux_id = mediaflux_request.mediaflux_id
264✔
35

36
      if mediaflux_id.to_i == 0
264✔
UNCOV
37
        debug_output = "Error saving project #{project.id} to Mediaflux: #{mediaflux_request.response_error}. Debug output: #{mediaflux_request.debug_output}"
3✔
UNCOV
38
        Rails.logger.error debug_output
3✔
UNCOV
39
        Failure debug_output
3✔
40
      else
41
        ProvenanceEvent.generate_approval_events(project: project, user: current_user, debug_output: mediaflux_request.debug_output.to_s)
261✔
42
        Success(mediaflux_id)
261✔
43
      end
44
    # TODO:  What kind of error are we expecting here?  This will capture the session errors, but maybe we should not be doing this.
45
    #        I could not figure out a way in tests to hit this error...
46
    rescue => ex
47
      Failure("Error saving project #{project.id} to Mediaflux: #{ex}")
×
48
    end
49

50
    def update_project_with_mediaflux_info(mediaflux_id:, project:)
4✔
51
      project.mediaflux_id = mediaflux_id
261✔
52
      project.metadata_model.status = Project::APPROVED_STATUS
260✔
53
      project.save!
260✔
54
      Success(project)
260✔
55
    rescue => ex
56
      # TODO: It was saved in mediaflux, so maybe a retry here?  I don't want to destroy the project
UNCOV
57
      Failure("Setting the mediaflux id the project(#{project.id}) : #{ex}")
1✔
58
    end
59

60
    def persist_users_in_mediaflux(project, current_user)
4✔
61
      # Do nothing if there are no users to persist
62
      return Success(project) if (project.metadata_model.ro_users + project.metadata_model.rw_users).empty?
260✔
63

64
      # Add the data users to the project in Mediaflux
UNCOV
65
      add_users_request = Mediaflux::ProjectUserAddRequest.new(session_token: current_user.mediaflux_session, project: project)
34✔
UNCOV
66
      add_users_request.resolve
34✔
67

UNCOV
68
      if add_users_request.error?
34✔
69
        # TODO: what should we do with the project in this case?  It got all the way to mediaflux, but the users were not added
70
        Failure("Error adding users to mediaflux project #{project.mediaflux_id} #{add_users_request.response_error}")
×
71
      else
UNCOV
72
        user_debug = add_users_request.debug_output.to_s
34✔
UNCOV
73
        Rails.logger.debug { "Project #{project.id} users have been added to MediaFlux: #{user_debug}" }
68✔
UNCOV
74
        Success project
34✔
75
      end
76
    # TODO:  What kind of error are we expecting here?  This will capture the session errors, but maybe we should not be doing this.
77
    #        I could not figure out a way in tests to hit this error...
78
    rescue => ex
79
      Failure("Exception adding users to mediaflux project #{project.mediaflux_id}: #{ex}")
×
80
    end
81

82
    def activate_project(project, approver)
4✔
83
      project.activate(current_user: approver)
260✔
84
      Success(project)
259✔
85
    rescue => ex
UNCOV
86
      Failure("Error activate project #{project.id}: #{ex}")
1✔
87
    end
88
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