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

pulibrary / tigerdata-app / f38a196c-60ac-4f70-afff-acf5f2a3dd33

09 Nov 2025 02:49PM UTC coverage: 77.281% (-14.0%) from 91.243%
f38a196c-60ac-4f70-afff-acf5f2a3dd33

Pull #2170

circleci

bess
Test that the Review and Submit step of the wizard has a Submit button
Pull Request #2170: Test that the Review and Submit step of the wizard has a Submit button

2490 of 3222 relevant lines covered (77.28%)

276.23 hits per line

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

97.85
/app/presenters/project_show_presenter.rb
1
# frozen_string_literal: true
2
class ProjectShowPresenter
3✔
3
  delegate "id", "in_mediaflux?", "mediaflux_id", "status", to: :project
3✔
4
  delegate "project_id", "storage_performance_expectations", to: :project_metadata
3✔
5

6
  attr_reader :project, :project_metadata
3✔
7

8
  # @return [Class] The presenter class for building XML Documents from Projects
9
  def self.xml_presenter_class
3✔
10
    ProjectXmlPresenter
4✔
11
  end
12

13
  # While we are transitioning to fetching the data straight from Mediaflux `project` can be
14
  # an ActiveRecord Project model (when used from the Project show page) or a Hash with the
15
  # data from Mediaflux (when used from the Dashboard).
16
  # This branching can be refactored (elimitated?) once we implement ticket
17
  # https://github.com/pulibrary/tigerdata-app/issues/2039 and the project data will always
18
  # come from Mediaflux.
19
  def initialize(project, current_user)
3✔
20
    if project.is_a?(Hash)
143✔
21
      @project_mf = project
97✔
22
      @project = rails_project(@project_mf)
97✔
23
    else
24
      @project = project
46✔
25
      @project_mf = project.mediaflux_metadata(session_id: current_user.mediaflux_session) if current_user.present?
46✔
26
    end
27
    @project_metadata = @project&.metadata_model
139✔
28
  end
29

30
  def title
3✔
31
    @project_mf[:title]
11✔
32
  end
33

34
  def description
3✔
35
    @project_mf[:description]
4✔
36
  end
37

38
  # @return [String] the XML for the project Document
39
  def to_xml
3✔
40
    xml_document.to_xml
3✔
41
  end
42

43
  # @return [Nokogiri::XML::Document] the XML Document for the Project
44
  def xml_document
3✔
45
    @xml_document ||= xml_presenter.document
4✔
46
  end
47

48
  def created
3✔
49
    @project.created_at.strftime("%b %e, %Y %l:%M %p")
1✔
50
  end
51

52
  def updated
3✔
53
    @project.updated_at.strftime("%b %e, %Y %l:%M %p")
1✔
54
  end
55

56
  def data_sponsor
3✔
57
    User.find_by(uid: @project_mf[:data_sponsor])
22✔
58
  end
59

60
  def data_manager
3✔
61
    User.find_by(uid: @project_mf[:data_manager])
13✔
62
  end
63

64
  def data_read_only_users
3✔
65
    (@project_mf[:ro_users] || []).map { |uid| ReadOnlyUser.find_by(uid:) }.compact
10✔
66
  end
67

68
  def data_read_write_users
3✔
69
    (@project_mf[:rw_users] || []).map { |uid| User.find_by(uid:) }.compact
10✔
70
  end
71

72
  def data_users
3✔
73
    unsorted_data_users = data_read_only_users + data_read_write_users
7✔
74
    sorted_data_users = unsorted_data_users.sort_by { |u| u.family_name || u.uid }
13✔
75
    sorted_data_users.uniq { |u| u.uid }
13✔
76
  end
77

78
  def data_user_names
3✔
79
    user_model_names = data_users.map(&:display_name_safe)
×
80
    user_model_names.join(", ")
×
81
  end
82

83
  def project_purpose
3✔
84
    @project_mf[:project_purpose]
3✔
85
  end
86

87
  # used to hide the project root that is not visible to the end user
88
  def project_directory
3✔
89
    # This value comes from Mediaflux without the extra hidden root
90
    directory = @project_mf[:project_directory] || ""
3✔
91
    directory.start_with?("/") ? directory : "/" + directory
3✔
92
  end
93

94
  def hpc
3✔
95
    @project_mf[:hpc] == true ? "Yes" : "No"
1✔
96
  end
97

98
  def globus
3✔
99
    @project_mf[:globus] == true ? "Yes" : "No"
1✔
100
  end
101

102
  def smb
3✔
103
    @project_mf[:smb] == true ? "Yes" : "No"
1✔
104
  end
105

106
  def number_of_files
3✔
107
    @project_mf[:number_of_files]
1✔
108
  end
109

110
  def departments
3✔
111
    @project_mf[:departments] || []
2✔
112
  end
113

114
  def project_id
3✔
115
    @project_mf[:project_id]
3✔
116
  end
117

118
  def storage_capacity(session_id: nil)
3✔
119
    return project_metadata.storage_capacity if session_id.nil?
3✔
120

121
    persisted = project.storage_capacity_raw(session_id: session_id)
1✔
122
    value = persisted.to_f
1✔
123

124
    value*default_capacity_divisor
1✔
125
  end
126

127
  def formatted_storage_capacity(session_id:)
3✔
128
    value = storage_capacity(session_id: session_id)
1✔
129
    format("%.3f", value)
1✔
130
  end
131

132
  def formatted_quota_percentage(session_id:)
3✔
133
    value = quota_percentage(session_id:)
1✔
134
    format("%.3f", value)
1✔
135
  end
136

137
  def quota_usage(session_id:)
3✔
138
    "#{project.storage_usage(session_id:)} out of #{project.storage_capacity(session_id:)} used"
1✔
139
  end
140

141
  def quota_percentage(session_id:)
3✔
142
    storage_capacity = project.storage_capacity_raw(session_id:)
2✔
143
    return 0 if storage_capacity.zero?
2✔
144

145
    storage_usage = project.storage_usage_raw(session_id:)
2✔
146
    (storage_usage.to_f / storage_capacity.to_f) * 100
2✔
147
  end
148

149
  def user_has_access?(user:)
3✔
150
    return true if user.eligible_sysadmin?
16✔
151
    data_sponsor.uid == user.uid || data_manager.uid == user.uid || data_users.map(&:uid).include?(user.uid)
16✔
152
  end
153

154
  def project_in_rails?
3✔
155
    project != nil
97✔
156
  end
157

158
  private
3✔
159

160
    # Capacity is in bytes
161
    def default_capacity_divisor
3✔
162
      1.0/(1000.0**3)
1✔
163
    end
164

165
    def xml_presenter_args
3✔
166
      project
4✔
167
    end
168

169
    def xml_presenter
3✔
170
      @xml_presenter ||= self.class.xml_presenter_class.new(xml_presenter_args)
4✔
171
    end
172

173
    def rails_project(project_mf)
3✔
174
      database_record = Project.where(mediaflux_id:project_mf[:mediaflux_id]).first
97✔
175
      if database_record.nil?
97✔
176
        Rails.logger.warn("Mediaflux project with ID #{project_mf[:mediaflux_id]} is not in the Rails database (title: #{project_mf[:title]})")
87✔
177
        Honeybadger.notify("Mediaflux project with ID #{project_mf[:mediaflux_id]} is not in the Rails database (title: #{project_mf[:title]})")
87✔
178
      end
179
      database_record
97✔
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