debian-mirror-gitlab/app/controllers/snippets/notes_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class Snippets::NotesController < ApplicationController
include NotesActions
include ToggleAwardEmoji
skip_before_action :authenticate_user!, only: [:index]
2019-07-07 11:18:12 +05:30
before_action :authorize_read_snippet!, only: [:show, :index]
before_action :authorize_create_note!, only: [:create]
2017-08-17 22:00:37 +05:30
2023-03-04 22:38:38 +05:30
feature_category :source_code_management
2021-01-03 14:25:43 +05:30
2017-08-17 22:00:37 +05:30
private
def note
2018-11-18 11:00:15 +05:30
@note ||= snippet.notes.inc_relations_for_view.find(params[:id])
2017-08-17 22:00:37 +05:30
end
alias_method :awardable, :note
def project
nil
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
def snippet
2021-03-11 19:13:27 +05:30
@snippet ||= PersonalSnippet.find_by(id: params[:snippet_id])
2017-08-17 22:00:37 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-03-17 18:26:18 +05:30
alias_method :noteable, :snippet
2017-08-17 22:00:37 +05:30
def finder_params
2019-10-12 21:52:04 +05:30
params.merge(last_fetched_at: last_fetched_at, target_id: snippet.id, target_type: 'personal_snippet').tap do |merged_params|
merged_params[:project] = project if respond_to?(:project)
end
2017-08-17 22:00:37 +05:30
end
def authorize_read_snippet!
2020-03-13 15:44:24 +05:30
return render_404 unless can?(current_user, :read_snippet, snippet)
2017-08-17 22:00:37 +05:30
end
2019-07-07 11:18:12 +05:30
def authorize_create_note!
access_denied! unless can?(current_user, :create_note, noteable)
end
2017-08-17 22:00:37 +05:30
end