• 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

90.0
/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
3✔
11
    @from_state = work.aasm.from_state
3✔
12
    @depositor = work.created_by_user
3✔
13
    @group = work.group
3✔
14
    @group_administrators = group.administrators.to_a
3✔
15
    @work_url = Rails.application.routes.url_helpers.work_url(work)
3✔
16

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

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

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

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

35
    private
1✔
36

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

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

55
                      groups_users_for_tags.join(", ")
3✔
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