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

pulibrary / pdc_describe / cace366a-ffad-45f1-9b60-678e607fa527

14 May 2024 02:21PM UTC coverage: 60.862% (-35.0%) from 95.908%
cace366a-ffad-45f1-9b60-678e607fa527

push

circleci

jrgriffiniii
wip

1 of 3 new or added lines in 2 files covered. (33.33%)

1194 existing lines in 57 files now uncovered.

2076 of 3411 relevant lines covered (60.86%)

22.71 hits per line

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

60.0
/app/controllers/application_controller.rb
1
# frozen_string_literal: true
2
class ApplicationController < ActionController::Base
1✔
3
  # This is necessary only for localhost development, with storage configured for the filesystem,
4
  # but it shouldn't cause problems in other environments that use S3.
5
  # Including this concern lets the disk service generate URLs using
6
  # the same host, protocol, and port as the current request.
7
  include ActiveStorage::SetCurrent
1✔
8

9
  protect_from_forgery with: :exception
1✔
10
  before_action :authenticate_user!
1✔
11

12
  def new_session_path(_scope)
1✔
13
    new_user_session_path
×
14
  end
15

16
  private
1✔
17

18
    # Take all the errors from the exception and the work and combine them into a single error message that can be shown to the user
19
    #
20
    # @param [AASM::InvalidTransition] aasm_error Error thrown by trying to transition states
21
    # @param [Work] work The work that had the issue
22
    #
23
    # @return [String] a combined error message for the work and transition error
24
    #
25
    def message_from_assm_error(aasm_error:, work:)
1✔
UNCOV
26
      message = aasm_error.message
×
UNCOV
27
      if work.errors.count > 0
×
UNCOV
28
        message = work.errors.to_a.join(", ")
×
29
      end
UNCOV
30
      message.chop! if message.last == "."
×
UNCOV
31
      message
×
32
    end
33

34
    # Validates that the current user can modify the work
35
    #
36
    # @params [Work] work the work to be modifed
37
    # @params [String] uneditable_message message to send to honey bandger about the work not being editable by the user
38
    # @params [String] current_state_message message to send to honey bandger about the work not being editable in the current state
39
    #
40
    # @returns false if an error occured
41
    #
42
    def validate_modification_permissions(work:, uneditable_message:, current_state_message:)
1✔
43
      no_error = false
30✔
44
      if current_user.blank? || !work.editable_by?(current_user)
30✔
UNCOV
45
        Honeybadger.notify(uneditable_message)
×
UNCOV
46
        redirect_to root_path, notice: I18n.t("works.uneditable.privs")
×
47
      elsif !work.editable_in_current_state?(current_user)
30✔
48
        Honeybadger.notify(current_state_message)
1✔
49
        redirect_to root_path, notice: I18n.t("works.uneditable.approved")
1✔
50
      else
51
        no_error = true
29✔
52
      end
53

54
      no_error
30✔
55
    end
56

57
    # returns either the group sent in by the user in group_id
58
    #   OR the default group for the user
59
    #
60
    def params_group_id
1✔
61
      # Do not allow a nil for the group id
62
      @params_group_id ||= begin
11✔
63
        group_id = params[:group_id]
11✔
64
        if group_id.blank?
11✔
UNCOV
65
          group_id = current_user.default_group.id
×
UNCOV
66
          Honeybadger.notify("We got a nil group as part of the parameters #{params} #{request}")
×
67
        end
68
        group_id
11✔
69
      end
70
    end
71

72
    # parses the embargo date from the parameters and parses into a Date object
73
    def embargo_date
1✔
74
      embargo_date_param = params["embargo-date"]
10✔
75
      return nil if embargo_date_param.blank?
10✔
76

UNCOV
77
      Date.parse(embargo_date_param)
×
78
    rescue Date::Error
UNCOV
79
      message = "Failed to parse the embargo date #{embargo_date_param} for Work #{@work.id}"
×
UNCOV
80
      Rails.logger.error(message)
×
UNCOV
81
      Honeybadger.notify(message)
×
UNCOV
82
      nil
×
83
    end
84

85
    # parameters utilize to update the work converted from the user's parameters
86
    def update_params
1✔
87
      {
88
        group_id: params_group_id,
10✔
89
        embargo_date:,
90
        resource: FormToResourceService.convert(params, @work)
91
      }
92
    end
93

94
    def prepare_decorators_for_work_form(work)
1✔
95
      @work_decorator = WorkDecorator.new(work, current_user)
3✔
96
      @form_resource_decorator = FormResourceDecorator.new(work, current_user)
3✔
97
    end
98

99
    def rescue_aasm_error
1✔
100
      yield
2✔
101
    rescue AASM::InvalidTransition => error
UNCOV
102
      message = message_from_assm_error(aasm_error: error, work: @work)
×
103

UNCOV
104
      Honeybadger.notify("Invalid #{@work.current_transition}: #{error.message} errors: #{message}")
×
UNCOV
105
      transition_error_message = "We apologize, the following errors were encountered: #{message}. Please contact the PDC Describe administrators for any assistance."
×
UNCOV
106
      @errors = [transition_error_message]
×
107

UNCOV
108
      redirect_aasm_error(transition_error_message)
×
109
    end
110
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