• 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

0.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
×
6
  attr_reader :group_administrators, :depositor, :to_state, :from_state, :group,
×
7
                :work_url, :notification, :users, :id, :current_user_id, :work_title
×
8

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

17
    # Troubleshooting https://github.com/pulibrary/pdc_describe/issues/1783
18
    if @work_url.include?("/describe/describe/")
×
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
×
24
    @notification = notification_for_transition
×
25
    @id = work.id
×
26

27
    raise(NotImplementedError, "Invalid user ID provided.") if current_user_id.nil?
×
28
    @current_user_id = current_user_id
×
29
  end
×
30

31
  def send
×
32
    return if notification.nil?
×
33

34
    WorkActivity.add_work_activity(id, notification, current_user_id, activity_type: WorkActivity::NOTIFICATION)
×
35
  end
×
36

37
    private
×
38

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

50
      def user_tags
×
51
        @user_tags = begin
×
52
                      groups_users_for_tags = ["@#{group.code}"]
×
53
                      unless group_administrators.include?(depositor)
×
54
                        groups_users_for_tags << "@#{depositor.uid}"
×
55
                      end
×
56

57
                      groups_users_for_tags.join(", ")
×
58
                    end
×
59
      end
×
60
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