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

pulibrary / tigerdata-app / e7a92392-be4c-4214-89f9-e70084a3165f

03 Nov 2025 06:52PM UTC coverage: 46.881% (-44.5%) from 91.394%
e7a92392-be4c-4214-89f9-e70084a3165f

Pull #2128

circleci

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

35 of 61 new or added lines in 6 files covered. (57.38%)

764 existing lines in 37 files now uncovered.

1646 of 3511 relevant lines covered (46.88%)

69.44 hits per line

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

52.75
/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)
4✔
22
      @project_mf = project
×
23
      @project = rails_project(@project_mf)
×
24
    else
25
      @project = project
4✔
26
      @project_mf = project.mediaflux_metadata(session_id: current_user.mediaflux_session) if current_user.present?
4✔
27
    end
28
    @project_metadata = @project&.metadata_model
4✔
29
  end
30

31
  def title
1✔
32
    @project_mf[:title]
2✔
33
  end
34

35
  def description
1✔
NEW
36
    @project_mf[:description]
×
37
  end
38

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

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

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

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

57
  def data_sponsor
1✔
NEW
58
    User.find_by(uid: @project_mf[:data_sponsor])
×
59
  end
60

61
  def data_manager
1✔
NEW
62
    User.find_by(uid: @project_mf[:data_manager])
×
63
  end
64

65
  def data_read_only_users
1✔
NEW
66
    @project_mf[:ro_users].map { |uid| ReadOnlyUser.find_by(uid:) }
×
67
  end
68

69
  def data_read_write_users
1✔
NEW
70
    @project_mf[:rw_users].map { |uid| User.find_by(uid:) }
×
71
  end
72

73
  def data_users
1✔
NEW
74
    unsorted_data_users = data_read_only_users + data_read_write_users
×
NEW
75
    sorted_data_users = unsorted_data_users.sort_by { |u| u.family_name || u.uid }
×
NEW
76
    sorted_data_users.uniq { |u| u.uid }
×
77
  end
78

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

84
  def project_purpose
1✔
NEW
85
    @project_mf[:project_purpose]
×
86
  end
87

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

95
  def hpc
1✔
NEW
96
    @project_mf[:hpc] == true ? "Yes" : "No"
×
97
  end
98

99
  def globus
1✔
NEW
100
    @project_mf[:globus] == true ? "Yes" : "No"
×
101
  end
102

103
  def smb
1✔
NEW
104
    @project_mf[:smb] == true ? "Yes" : "No"
×
105
  end
106

107
  def number_of_files
1✔
NEW
108
    @project_mf[:number_of_files]
×
109
  end
110

111
  def departments
1✔
NEW
112
    @project_mf[:departments] || []
×
113
  end
114

115
  def project_id
1✔
NEW
116
    @project_mf[:project_id]
×
117
  end
118

119
  def storage_capacity(session_id: nil)
1✔
UNCOV
120
    return project_metadata.storage_capacity if session_id.nil?
×
121

UNCOV
122
    persisted = project.storage_capacity_raw(session_id: session_id)
×
UNCOV
123
    value = persisted.to_f
×
124

UNCOV
125
    value*default_capacity_divisor
×
126
  end
127

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

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

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

142
  def quota_percentage(session_id:)
1✔
UNCOV
143
    storage_capacity = project.storage_capacity_raw(session_id:)
×
UNCOV
144
    return 0 if storage_capacity.zero?
×
145

146
    storage_usage = project.storage_usage_raw(session_id:)
×
147
    (storage_usage.to_f / storage_capacity.to_f) * 100
×
148
  end
149

150
  def project_in_rails?
1✔
151
    project != nil
×
152
  end
153

154
  private
1✔
155

156
    # Capacity is in bytes
157
    def default_capacity_divisor
1✔
UNCOV
158
      1.0/(1000.0**3)
×
159
    end
160

161
    def xml_presenter_args
1✔
162
      project
2✔
163
    end
164

165
    def xml_presenter
1✔
166
      @xml_presenter ||= self.class.xml_presenter_class.new(xml_presenter_args)
2✔
167
    end
168

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