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

pulibrary / pdc_describe / 9091a1ae-29be-458c-984a-339d213919c4

12 Dec 2024 07:41PM UTC coverage: 26.434% (-69.7%) from 96.113%
9091a1ae-29be-458c-984a-339d213919c4

Pull #2000

circleci

jrgriffiniii
Removing integration with ActiveStorage
Pull Request #2000: Bump actionpack from 7.2.1.1 to 7.2.2.1

945 of 3575 relevant lines covered (26.43%)

0.35 hits per line

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

4.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
×
10
  before_action :authenticate_user!
×
11

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

16
  private
×
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_aasm_error(aasm_error:, work:)
×
26
      message = aasm_error.message
×
27
      if work.errors.count > 0
×
28
        message = work.errors.to_a.join(", ")
×
29
      end
30
      message.chop! if message.last == "."
×
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:)
×
43
      no_error = false
×
44
      if current_user.blank? || !work.editable_by?(current_user)
×
45
        Honeybadger.notify(uneditable_message)
×
46
        redirect_to root_path, notice: I18n.t("works.uneditable.privs")
×
47
      elsif !work.editable_in_current_state?(current_user)
×
48
        Honeybadger.notify(current_state_message)
×
49
        redirect_to root_path, notice: I18n.t("works.uneditable.approved")
×
50
      else
51
        no_error = true
×
52
      end
53

54
      no_error
×
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
×
61
      # Do not allow a nil for the group id
62
      @params_group_id ||= begin
×
63
        group_id = params[:group_id]
×
64
        if group_id.blank?
×
65
          group_id = current_user.default_group.id
×
66
          Honeybadger.notify("We got a nil group as part of the parameters #{params} #{request}")
×
67
        end
68
        group_id
×
69
      end
70
    end
71

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

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

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

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

99
    def rescue_aasm_error
×
100
      yield
×
101
    rescue AASM::InvalidTransition => error
102
      message = message_from_aasm_error(aasm_error: error, work: @work)
×
103

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

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