Class: WorkStateTransitionNotification

Inherits:
Object
  • Object
show all
Defined in:
app/models/work_state_transition_notification.rb

Overview

Connect with the curators of a work when an activity occurs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work, current_user_id) ⇒ WorkStateTransitionNotification

Returns a new instance of WorkStateTransitionNotification.

Raises:

  • (NotImplementedError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/work_state_transition_notification.rb', line 9

def initialize(work, current_user_id)
  @to_state = work.aasm.to_state
  @from_state = work.aasm.from_state
  @depositor = work.created_by_user
  @group = work.group
  @group_administrators = group.administrators.to_a
  @work_url = Rails.application.routes.url_helpers.work_url(work)

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

  @work_title = work.title
  @notification = notification_for_transition
  @id = work.id

  raise(NotImplementedError, "Invalid user ID provided.") if current_user_id.nil?
  @current_user_id = current_user_id
end

Instance Attribute Details

#current_user_idObject (readonly)

Returns the value of attribute current_user_id.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def current_user_id
  @current_user_id
end

#depositorObject (readonly)

Returns the value of attribute depositor.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def depositor
  @depositor
end

#from_stateObject (readonly)

Returns the value of attribute from_state.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def from_state
  @from_state
end

#groupObject (readonly)

Returns the value of attribute group.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def group
  @group
end

#group_administratorsObject (readonly)

Returns the value of attribute group_administrators.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def group_administrators
  @group_administrators
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def id
  @id
end

#notificationObject (readonly)

Returns the value of attribute notification.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def notification
  @notification
end

#to_stateObject (readonly)

Returns the value of attribute to_state.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def to_state
  @to_state
end

#usersObject (readonly)

Returns the value of attribute users.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def users
  @users
end

#work_titleObject (readonly)

Returns the value of attribute work_title.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def work_title
  @work_title
end

#work_urlObject (readonly)

Returns the value of attribute work_url.



6
7
8
# File 'app/models/work_state_transition_notification.rb', line 6

def work_url
  @work_url
end

Instance Method Details

#sendObject



31
32
33
34
35
# File 'app/models/work_state_transition_notification.rb', line 31

def send
  return if notification.nil?

  WorkActivity.add_work_activity(id, notification, current_user_id, activity_type: WorkActivity::NOTIFICATION)
end