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

pulibrary / pdc_describe / 5b5d665b-3b84-43db-bb80-ce78bb0f4bf2

26 Apr 2024 01:46PM UTC coverage: 95.888% (-0.2%) from 96.054%
5b5d665b-3b84-43db-bb80-ce78bb0f4bf2

push

circleci

web-flow
Fixes and logs bad Work URLs in production (#1787)

* Temporary work-around to fix and troubleshoot bad Work URLs generated in some places

* Fixed typo

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

3265 of 3405 relevant lines covered (95.89%)

220.43 hits per line

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

93.33
/app/models/work_state_transition_notification.rb
1
# frozen_string_literal: true
2

3
# Connect with the curators of a work when an activity occurs
4
#
5
class WorkStateTransitionNotification
1✔
6
  attr_reader :group_administrators, :depositor, :to_state, :from_state, :group,
1✔
7
                :work_url, :notification, :users, :id, :current_user_id, :work_title
8

9
  def initialize(work, current_user_id)
1✔
10
    @to_state = work.aasm.to_state
162✔
11
    @from_state = work.aasm.from_state
162✔
12
    @depositor = work.created_by_user
162✔
13
    @group = work.group
162✔
14
    @group_administrators = group.administrators.to_a
162✔
15
    @work_url = Rails.application.routes.url_helpers.work_url(work)
162✔
16

17
    # Troubleshooting https://github.com/pulibrary/pdc_describe/issues/1783
18
    if @work_url.include?("/describe/describe/")
162✔
NEW
19
      Rails.logger.error("URL #{@work_url} included /describe/describe/ and was fixed. See https://github.com/pulibrary/pdc_describe/issues/1783")
×
NEW
20
      @work_url = @work_url.gsub("/describe/describe/", "/describe/")
×
21
    end
22

23
    @work_title = work.title
162✔
24
    @notification = notification_for_transition
162✔
25
    @id = work.id
162✔
26
    @current_user_id = current_user_id
162✔
27
  end
28

29
  def send
1✔
30
    return if notification.nil?
162✔
31

32
    WorkActivity.add_work_activity(id, notification, current_user_id, activity_type: WorkActivity::NOTIFICATION)
129✔
33
  end
34

35
    private
1✔
36

37
      def notification_for_transition
1✔
38
        case to_state
162✔
39
        when :awaiting_approval
40
          "#{user_tags} [#{work_title}](#{work_url}) is ready for review."
50✔
41
        when :draft
42
          "#{user_tags} [#{work_title}](#{work_url}) has been created."
49✔
43
        when :approved
44
          "#{user_tags} [#{work_title}](#{work_url}) has been approved."
30✔
45
        end
46
      end
47

48
      def user_tags
1✔
49
        @user_tags = begin
50
                      groups_users_for_tags = ["@#{group.code}"]
129✔
51
                      unless group_administrators.include?(depositor)
129✔
52
                        groups_users_for_tags << "@#{depositor.uid}"
81✔
53
                      end
54

55
                      groups_users_for_tags.join(", ")
129✔
56
                    end
57
      end
58
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