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

pulibrary / tigerdata-app / 8d70f2ab-acc5-4aab-b64b-743d66ddd2eb

29 Aug 2025 06:22PM UTC coverage: 87.983% (-0.1%) from 88.118%
8d70f2ab-acc5-4aab-b64b-743d66ddd2eb

Pull #1801

circleci

JaymeeH
Merge branch '1586-request-mailer' of https://github.com/pulibrary/tiger-data-app into 1586-request-mailer
Pull Request #1801: 1586 request mailer

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

1173 existing lines in 56 files now uncovered.

2482 of 2821 relevant lines covered (87.98%)

317.98 hits per line

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

85.22
/app/controllers/projects_controller.rb
1
# frozen_string_literal: true
2
class ProjectsController < ApplicationController
2✔
3

4
  before_action :set_breadcrumbs
2✔
5
  before_action :authenticate_user!
2✔
6

7
  def project_params
2✔
8
    params.dup
×
9
  end
10

11
  def details
2✔
UNCOV
12
    return if project.blank?
16✔
13

UNCOV
14
    add_breadcrumb(project.title, project_path)
15✔
UNCOV
15
    add_breadcrumb("Details")
15✔
16

UNCOV
17
    @departments = project.departments.join(", ")
15✔
UNCOV
18
    @project_metadata = project.metadata_model
15✔
19

UNCOV
20
    @data_sponsor = User.find_by(uid: @project_metadata.data_sponsor)
15✔
UNCOV
21
    @data_manager = User.find_by(uid: @project_metadata.data_manager)
15✔
22

UNCOV
23
    read_only_uids = @project_metadata.ro_users
15✔
UNCOV
24
    data_read_only_users = read_only_uids.map { |uid| ReadOnlyUser.find_by(uid:) }.reject(&:blank?)
20✔
25

UNCOV
26
    read_write_uids = @project_metadata.rw_users
15✔
UNCOV
27
    data_read_write_users = read_write_uids.map { |uid| User.find_by(uid:) }.reject(&:blank?)
20✔
28

UNCOV
29
    unsorted_data_users = data_read_only_users + data_read_write_users
15✔
UNCOV
30
    sorted_data_users = unsorted_data_users.sort_by { |u| u.family_name || u.uid }
25✔
UNCOV
31
    @data_users = sorted_data_users.uniq { |u| u.uid }
25✔
UNCOV
32
    user_model_names = @data_users.map(&:display_name_safe)
15✔
UNCOV
33
    @data_user_names = user_model_names.join(", ")
15✔
34

UNCOV
35
    @provenance_events = project.provenance_events.where.not(event_type: ProvenanceEvent::STATUS_UPDATE_EVENT_TYPE)
15✔
36

UNCOV
37
    @project_eligible_to_edit = true if project.status == Project::APPROVED_STATUS && eligible_editor?
15✔
38

UNCOV
39
    @project_metadata = @project.metadata
15✔
UNCOV
40
    @project_id = @project_metadata[:project_id] || {}
15✔
UNCOV
41
    @storage_capacity = @project_metadata[:storage_capacity]
15✔
UNCOV
42
    @size = @storage_capacity[:size]
15✔
UNCOV
43
    @unit = @storage_capacity[:unit]
15✔
44

UNCOV
45
    @requested_size = @size[:requested]
15✔
UNCOV
46
    @requested_unit = @unit[:requested]
15✔
47

UNCOV
48
    @approved_size = @size[:approved]
15✔
UNCOV
49
    @approved_unit = @unit[:approved]
15✔
50

UNCOV
51
    @storage_expectations = @project_metadata[:storage_performance_expectations]
15✔
UNCOV
52
    @requested_storage_expectations = @storage_expectations[:requested]
15✔
UNCOV
53
    @approved_storage_expectations = @storage_expectations[:approved]
15✔
54

UNCOV
55
    @project_purpose = @project_metadata[:project_purpose]
15✔
56

57

UNCOV
58
    @project_session = "details"
15✔
59

UNCOV
60
    respond_to do |format|
15✔
UNCOV
61
      format.html do
15✔
UNCOV
62
        @project = ProjectShowPresenter.new(project)
12✔
63
      end
UNCOV
64
      format.json do
15✔
UNCOV
65
        render json: project.to_json
2✔
66
      end
UNCOV
67
      format.xml do
15✔
UNCOV
68
        render xml: project.to_xml
1✔
69
      end
70
    end
71
  end
72

73
  def index
2✔
74
    if current_user.eligible_sysadmin?
5✔
UNCOV
75
      @projects = Project.all
1✔
76
    else
77
      flash[:alert] = I18n.t(:access_denied)
4✔
78
      redirect_to dashboard_path
4✔
79
    end
80
  end
81

82
  def show
2✔
83

84
    return if project.blank?
37✔
85
    add_breadcrumb(project.title, project_path)
33✔
86
    add_breadcrumb("Contents")
33✔
87

88
    @latest_completed_download = current_user.user_requests.where(project_id: @project.id, state: "completed").order(:completion_time).last
33✔
89
    @storage_usage = project.storage_usage(session_id: current_user.mediaflux_session)
33✔
90
    @storage_capacity = project.storage_capacity(session_id: current_user.mediaflux_session)
29✔
91

92
    @num_files = project.asset_count(session_id: current_user.mediaflux_session)
29✔
93

94
    @file_list = project.file_list(session_id: current_user.mediaflux_session, size: 100)
29✔
95
    @files = @file_list[:files]
29✔
96
    @files.sort_by!(&:path)
29✔
97
    @project = ProjectShowPresenter.new(project)
29✔
98

99
    @project_session = "content"
29✔
100
    respond_to do |format|
29✔
101
      format.html { render }
53✔
102
      format.xml { render xml: @project.to_xml }
34✔
103
    end
104
  end
105

106
  # GET "projects/:id/:id-mf"
107
  #
108
  # This action is used to render the mediaflux metadata for a project.
109
  def show_mediaflux
2✔
UNCOV
110
    project_id = params[:id]
3✔
UNCOV
111
    project = Project.find(project_id)
3✔
UNCOV
112
    if project.mediaflux_id == 0
2✔
113
      flash[:alert] = "Project has not been created in Mediaflux"
×
114
      redirect_to project_path(project_id)
×
115
    else
UNCOV
116
      respond_to do |format|
2✔
UNCOV
117
        format.xml do
2✔
UNCOV
118
          render xml: project.mediaflux_meta_xml(user: current_user)
2✔
119
        end
120
      end
121
    end
122
  rescue => ex
UNCOV
123
    Rails.logger.error "Error getting MediaFlux XML for project #{project_id}, user #{current_user.uid}: #{ex.message}"
1✔
UNCOV
124
    flash[:alert] = "Error fetching Mediaflux XML for this project"
1✔
UNCOV
125
    redirect_to project_path(project_id)
1✔
126
  end
127

128
  def project_job_service
2✔
UNCOV
129
    @project_job_service ||= ProjectJobService.new(project:)
2✔
130
  end
131

132
  def list_contents
2✔
UNCOV
133
    return if project.blank?
3✔
134

UNCOV
135
    project_job_service.list_contents_job(user: current_user)
2✔
136

137
    json_response = {
UNCOV
138
      message: "File list for \"#{project.title}\" is being generated in the background. A link to the downloadable file list will be available in the \"Recent Activity\" section of your dashboard when it is available. You may safely navigate away from this page or close this tab."
2✔
139
    }
UNCOV
140
    render json: json_response
2✔
141
  rescue => ex
142
    message = "Error producing document list (project id: #{project&.id}): #{ex.message}"
×
143
    Rails.logger.error(message)
×
144
    Honeybadger.notify(message)
×
145
    render json: { message: "Document list could not be generated." }
×
146
  end
147

148
  def file_list_download
2✔
149
    job_id = params[:job_id]
×
150
    user_request = FileInventoryRequest.where(job_id:job_id).first
×
151
    if user_request.nil?
×
152
      # TODO: handle error
153
      redirect_to "/"
×
154
    else
155
      filename = user_request.output_file
×
156
      send_data File.read(filename), type: "text/plain", filename: "filelist.csv", disposition: "attachment"
×
157
    end
158
  end
159

160
  private
2✔
161

162
    def build_new_project
2✔
163
      @project ||= Project.new
×
164
    end
165

166
    def project
2✔
167
      @project ||= begin
332✔
168
        project = Project.find(params[:id])
54✔
169
        if project.user_has_access?(user: current_user)
54✔
170
          project
48✔
171
        else
UNCOV
172
          flash[:alert] = I18n.t(:access_denied)
6✔
UNCOV
173
          redirect_to dashboard_path
6✔
UNCOV
174
          nil
6✔
175
        end
176
      end
177
    end
178

179
    def eligible_editor?
2✔
UNCOV
180
      return true if current_user.eligible_sponsor? or current_user.eligible_manager?
10✔
181
    end
182

183
    def shared_file_location(filename)
2✔
184
      raise "Shared location is not configured" if Rails.configuration.mediaflux["shared_files_location"].blank?
×
185
      location = Pathname.new(Rails.configuration.mediaflux["shared_files_location"])
×
186
      location.join(filename).to_s
×
187
    end
188

189
    def set_breadcrumbs
2✔
190
      add_breadcrumb("Dashboard",dashboard_path)
69✔
191
    end
192
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