Skip to content
Anton Argirov edited this page Jun 23, 2015 · 19 revisions

Workflows

Error trapping

Here is a basic workflow rule that should be the last enabled one. It is used to provide a generic message in addition to the specific errors raised by the various workflows.

# = before_save = #
raise WorkflowError, 'Errors found. Please contact the Admin for assistance as required.' unless errors.blank?

Watchers

# Add authors/updaters to Watchers
#
# Sets: Watcher

# = before_save = #
if subject.present?
	self.add_watcher(User.current) unless watched_by?(User.current)
end

Creating subtask if the issue's status has changed.

# = before_save = #
@need_create = status_id_changed? && !new_record?
# = after_save = #
if @need_create
  issue = Issue.create!(
    :author => User.current,
    :project => project,
    :tracker => tracker,
    :assigned_to => author,
    :parent_issue_id => id,
    :subject => "Subtask",
    :description => "Description")
end

Methods

IssueCustomValue

# returns icf.value if visible, else nil
def visible_custom_value(icf)
	visible_custom_field_values(User.current)\
		.find { |cfv| cfv.custom_field == icf }
end

# returns icf.value if editable, else nil
def editable_custom_value(icf)
	editable_custom_field_values(User.current)
	.find { |cfv| cfv.custom_field == icf }
end

Clone this wiki locally