diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-11-17 20:27:16 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-11-18 01:01:53 +0800 |
commit | 9ac0c76b78cd04b2505924f003dd720a0f155959 (patch) | |
tree | 67af1f0be0b9d6b5fc42b27c5afe5516e2c7574c /app/controllers/concerns/notes_actions.rb | |
parent | 0af35d7e30e373b885bfddb30b14718d72d75ab0 (diff) | |
download | gitlab-ce-9ac0c76b78cd04b2505924f003dd720a0f155959.tar.gz |
Use StrongMemoize and enable/disable cops properly
Diffstat (limited to 'app/controllers/concerns/notes_actions.rb')
-rw-r--r-- | app/controllers/concerns/notes_actions.rb | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/app/controllers/concerns/notes_actions.rb b/app/controllers/concerns/notes_actions.rb index be153d9fdbd..e6ef1f6f5e4 100644 --- a/app/controllers/concerns/notes_actions.rb +++ b/app/controllers/concerns/notes_actions.rb @@ -1,6 +1,6 @@ -# rubocop:disable Cop/ModuleWithInstanceVariables module NotesActions include RendersNotes + include Gitlab::Utils::StrongMemoize extend ActiveSupport::Concern included do @@ -31,6 +31,7 @@ module NotesActions render json: notes_json end + # rubocop:disable Cop/ModuleWithInstanceVariables def create create_params = note_params.merge( merge_request_diff_head_sha: params[:merge_request_diff_head_sha], @@ -48,7 +49,9 @@ module NotesActions format.html { redirect_back_or_default } end end + # rubocop:enable Cop/ModuleWithInstanceVariables + # rubocop:disable Cop/ModuleWithInstanceVariables def update @note = Notes::UpdateService.new(project, current_user, note_params).execute(note) @@ -61,6 +64,7 @@ module NotesActions format.html { redirect_back_or_default } end end + # rubocop:enable Cop/ModuleWithInstanceVariables def destroy if note.editable? @@ -139,7 +143,7 @@ module NotesActions end else template = "discussions/_diff_discussion" - @fresh_discussion = true + @fresh_discussion = true # rubocop:disable Cop/ModuleWithInstanceVariables locals = { discussions: [discussion], on_image: on_image } end @@ -192,7 +196,7 @@ module NotesActions end def noteable - @noteable ||= notes_finder.target || @note&.noteable + @noteable ||= notes_finder.target || @note&.noteable # rubocop:disable Cop/ModuleWithInstanceVariables end def require_noteable! @@ -212,20 +216,21 @@ module NotesActions end def note_project - return @note_project if defined?(@note_project) - return nil unless project + strong_memoize(:note_project) do + return nil unless project - note_project_id = params[:note_project_id] + note_project_id = params[:note_project_id] - @note_project = - if note_project_id.present? - Project.find(note_project_id) - else - project - end + the_project = + if note_project_id.present? + Project.find(note_project_id) + else + project + end - return access_denied! unless can?(current_user, :create_note, @note_project) + return access_denied! unless can?(current_user, :create_note, the_project) - @note_project + the_project + end end end |