Method: IssuableActions#update

Defined in:
app/controllers/concerns/issuable_actions.rb

#updateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/concerns/issuable_actions.rb', line 31

def update
  updated_issuable = update_service.execute(issuable)
  # NOTE: We only assign the instance variable on this line, and use the local variable
  # everywhere else in the method, to avoid having to add multiple `rubocop:disable` comments.
  @issuable = updated_issuable # rubocop:disable Gitlab/ModuleWithInstanceVariables

  # NOTE: This check for `is_a?(Spammable)` is necessary because not all
  # possible `issuable` types implement Spammable. Once they all implement Spammable,
  # this check can be removed.
  if updated_issuable.is_a?(Spammable)
    respond_to do |format|
      format.html do
        if updated_issuable.valid?
          # NOTE: This redirect is intentionally only performed in the case where the valid updated
          # issuable is a spammable, and intentionally is not performed below in the
          # valid non-spammable case. This preserves the legacy behavior of this action.
          redirect_to spammable_path
        else
          with_captcha_check_html_format(spammable: spammable) { render :edit }
        end
      end

      format.json do
        with_captcha_check_json_format(spammable: spammable) { render_entity_json }
      end
    end
  else
    respond_to do |format|
      format.html do
        render :edit
      end

      format.json do
        render_entity_json
      end
    end
  end
rescue ActiveRecord::StaleObjectError
  render_conflict_response
end