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

pulibrary / tigerdata-app / 5148dbcc-2bd0-4e3f-a950-2ccd27825e51

03 Nov 2025 04:59PM UTC coverage: 57.025% (-34.4%) from 91.394%
5148dbcc-2bd0-4e3f-a950-2ccd27825e51

Pull #2128

circleci

hectorcorrea
Minor tweak
Pull Request #2128: Project Show page now displays metadata straight from Mediaflux

27 of 32 new or added lines in 5 files covered. (84.38%)

168 existing lines in 13 files now uncovered.

1932 of 3388 relevant lines covered (57.02%)

58.73 hits per line

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

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

6
  attr_reader :project, :project_metadata
1✔
7
  attr_reader :project_mf
1✔
8

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

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

31
  def title
1✔
32
    if @project_mf.nil?
9✔
UNCOV
33
      @project.title
×
34
    else
35
      @project_mf[:title]
9✔
36
    end
37
  end
38

39
  def description
1✔
40
    if @project_mf.nil?
2✔
UNCOV
41
      @project.metadata_model.description
×
42
    else
43
      @project_mf[:description]
2✔
44
    end
45
  end
46

47
  # @return [String] the XML for the project Document
48
  def to_xml
1✔
49
    xml_document.to_xml
2✔
50
  end
51

52
  # @return [Nokogiri::XML::Document] the XML Document for the Project
53
  def xml_document
1✔
54
    @xml_document ||= xml_presenter.document
2✔
55
  end
56

57
  def created
1✔
58
    @project.created_at.strftime("%b %e, %Y %l:%M %p")
1✔
59
  end
60

61
  def updated
1✔
62
    @project.updated_at.strftime("%b %e, %Y %l:%M %p")
1✔
63
  end
64

65
  def data_sponsor
1✔
66
    if @project_mf.nil?
2✔
NEW
67
      User.find_by(uid: @project.metadata["data_sponsor"])
×
68
    else
69
      User.find_by(uid: @project_mf[:data_sponsor])
2✔
70
    end
71
  end
72

73
  def data_manager
1✔
74
    if @project_mf.nil?
2✔
NEW
75
      User.find_by(uid: @project.metadata["data_manager"])
×
76
    else
77
      User.find_by(uid: @project_mf[:data_manager])
2✔
78
    end
79
  end
80

81
  def project_purpose
1✔
82
    if @project_mf.nil?
1✔
83
      project_metadata.project_purpose
×
84
    else
85
      @project_mf[:project_purpose]
1✔
86
    end
87
  end
88

89
  # used to hide the project root that is not visible to the end user
90
  def project_directory
1✔
91
    if @project.nil?
1✔
NEW
92
      project_metadata.project_directory.gsub(Mediaflux::Connection.hidden_root, "")
×
93
    else
94
      # This value comes from Mediaflux without the extra hidden root
95
      directory = @project_mf[:project_directory] || ""
1✔
96
      directory.start_with?("/") ? directory : "/" + directory
1✔
97
    end
98
  end
99

100
  def hpc
1✔
101
    @project_mf[:hpc] == true ? "Yes" : "No"
1✔
102
  end
103

104
  def globus
1✔
105
    @project_mf[:globus] == true ? "Yes" : "No"
1✔
106
  end
107

108
  def smb
1✔
109
    @project_mf[:smb] == true ? "Yes" : "No"
1✔
110
  end
111

112
  def number_of_files
1✔
113
    @project_mf[:number_of_files]
1✔
114
  end
115

116
  def departments
1✔
117
    @project_mf[:departments] || []
1✔
118
  end
119

120
  def project_id
1✔
121
    @project_mf[:project_id]
1✔
122
  end
123

124
  def storage_capacity(session_id: nil)
1✔
125
    return project_metadata.storage_capacity if session_id.nil?
1✔
126

127
    persisted = project.storage_capacity_raw(session_id: session_id)
1✔
128
    value = persisted.to_f
1✔
129

130
    value*default_capacity_divisor
1✔
131
  end
132

133
  def formatted_storage_capacity(session_id:)
1✔
134
    value = storage_capacity(session_id: session_id)
1✔
135
    format("%.3f", value)
1✔
136
  end
137

138
  def formatted_quota_percentage(session_id:)
1✔
139
    value = quota_percentage(session_id:)
1✔
140
    format("%.3f", value)
1✔
141
  end
142

143
  def quota_usage(session_id:)
1✔
144
    "#{project.storage_usage(session_id:)} out of #{project.storage_capacity(session_id:)} used"
1✔
145
  end
146

147
  def quota_percentage(session_id:)
1✔
148
    storage_capacity = project.storage_capacity_raw(session_id:)
2✔
149
    return 0 if storage_capacity.zero?
2✔
150

151
    storage_usage = project.storage_usage_raw(session_id:)
×
152
    (storage_usage.to_f / storage_capacity.to_f) * 100
×
153
  end
154

155
  def project_in_rails?
1✔
156
    project != nil
×
157
  end
158

159
  private
1✔
160

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

166
    def xml_presenter_args
1✔
167
      project
2✔
168
    end
169

170
    def xml_presenter
1✔
171
      @xml_presenter ||= self.class.xml_presenter_class.new(xml_presenter_args)
2✔
172
    end
173

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