Module: Workflow

Extended by:
ActiveSupport::Concern
Included in:
Edition
Defined in:
app/models/workflow.rb

Defined Under Namespace

Classes: CannotDeletePublishedPublication

Instance Method Summary collapse

Instance Method Details

#can_destroy?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'app/models/workflow.rb', line 127

def can_destroy?
  ! scheduled_for_publishing? && ! published? && ! archived?
end

#check_can_delete_and_notifyObject



131
132
133
# File 'app/models/workflow.rb', line 131

def check_can_delete_and_notify
  raise CannotDeletePublishedPublication unless can_destroy?
end

#denormalise_users!Object



118
119
120
121
122
123
124
125
# File 'app/models/workflow.rb', line 118

def denormalise_users!
  new_assignee = assigned_to.try(:name)
  set(assignee: new_assignee) unless new_assignee == assignee
  update_user_action("creator",   [Action::CREATE, Action::NEW_VERSION])
  update_user_action("publisher", [Action::PUBLISH])
  update_user_action("archiver",  [Action::ARCHIVE])
  self
end

#error_descriptionObject



155
156
157
# File 'app/models/workflow.rb', line 155

def error_description
  published? ? 'Published editions' : 'Editions scheduled for publishing'
end

#fact_checked?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'app/models/workflow.rb', line 108

def fact_checked?
  (self.actions.where(request_type: Action::APPROVE_FACT_CHECK).count > 0)
end

#important_noteObject



166
167
168
169
# File 'app/models/workflow.rb', line 166

def important_note
  action = actions.where(:request_type.in => [Action::IMPORTANT_NOTE, Action::IMPORTANT_NOTE_RESOLVED]).last
  action if action.try(:request_type) == Action::IMPORTANT_NOTE
end

#in_progress?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'app/models/workflow.rb', line 147

def in_progress?
  ! ["archived", "published"].include? self.state
end

#locked_for_edits?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'app/models/workflow.rb', line 151

def locked_for_edits?
  scheduled_for_publishing? || published?
end

#mark_as_rejectedObject



135
136
137
# File 'app/models/workflow.rb', line 135

def mark_as_rejected
  self.inc(rejected_count: 1)
end

#notify_siblings_of_new_editionObject



143
144
145
# File 'app/models/workflow.rb', line 143

def notify_siblings_of_new_edition
  siblings.update_all(sibling_in_progress: self.version_number)
end

#perform_event_without_validations(event) ⇒ Object



159
160
161
162
163
164
# File 'app/models/workflow.rb', line 159

def perform_event_without_validations(event)
  # http://rubydoc.info/github/pluginaweek/state_machine/StateMachine/Machine:event
  # pass false to transition state without performing state machine actions
  public_send(event, false)
  save(validate: false)
end

#previous_editionObject



139
140
141
# File 'app/models/workflow.rb', line 139

def previous_edition
  self.previous_published_edition || false
end

#status_textObject



112
113
114
115
116
# File 'app/models/workflow.rb', line 112

def status_text
  text = human_state_name.capitalize
  text += ' on ' + publish_at.strftime("%d/%m/%Y %H:%M") if scheduled_for_publishing?
  text
end