2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-16 11:08:32 -04:00
|
|
|
class Projects::SnippetsController < Projects::Snippets::ApplicationController
|
2021-07-22 14:08:29 -04:00
|
|
|
extend ::Gitlab::Utils::Override
|
2020-06-16 11:08:32 -04:00
|
|
|
include SnippetsActions
|
2016-09-04 04:51:12 -04:00
|
|
|
include ToggleAwardEmoji
|
2021-08-11 02:10:02 -04:00
|
|
|
include SpammableActions::AkismetMarkAsSpamAction
|
2018-02-06 08:33:18 -05:00
|
|
|
|
2017-06-20 07:13:04 -04:00
|
|
|
before_action :check_snippets_available!
|
2020-06-16 11:08:32 -04:00
|
|
|
|
2020-10-12 11:08:32 -04:00
|
|
|
before_action :snippet, only: [:show, :edit, :raw, :toggle_award_emoji, :mark_as_spam]
|
2013-03-23 14:14:37 -04:00
|
|
|
|
2020-10-12 11:08:32 -04:00
|
|
|
before_action :authorize_create_snippet!, only: :new
|
|
|
|
before_action :authorize_read_snippet!, except: [:new, :index]
|
|
|
|
before_action :authorize_update_snippet!, only: :edit
|
2013-03-23 14:14:37 -04:00
|
|
|
|
2021-04-21 11:09:35 -04:00
|
|
|
before_action only: [:show] do
|
|
|
|
push_frontend_feature_flag(:improved_emoji_picker, @project, default_enabled: :yaml)
|
|
|
|
end
|
|
|
|
|
2013-03-23 14:14:37 -04:00
|
|
|
def index
|
2020-06-22 08:08:47 -04:00
|
|
|
@snippet_counts = ::Snippets::CountService
|
2020-02-05 04:08:43 -05:00
|
|
|
.new(current_user, project: @project)
|
|
|
|
.execute
|
|
|
|
|
2020-07-10 14:09:45 -04:00
|
|
|
@snippets = SnippetsFinder.new(current_user, project: @project, scope: params[:scope], sort: sort_param)
|
2019-09-02 07:12:20 -04:00
|
|
|
.execute
|
|
|
|
.page(params[:page])
|
|
|
|
.inc_author
|
2021-03-15 20:09:44 -04:00
|
|
|
.inc_statistics
|
2019-09-02 07:12:20 -04:00
|
|
|
|
2019-09-03 13:45:00 -04:00
|
|
|
return if redirect_out_of_range(@snippets)
|
2019-09-02 07:12:20 -04:00
|
|
|
|
|
|
|
@noteable_meta_data = noteable_meta_data(@snippets, 'Snippet')
|
2013-03-23 14:14:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2016-01-15 05:29:53 -05:00
|
|
|
@snippet = @noteable = @project.snippets.build
|
2013-03-23 14:14:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2016-09-04 04:51:12 -04:00
|
|
|
alias_method :awardable, :snippet
|
2017-02-01 13:15:59 -05:00
|
|
|
alias_method :spammable, :snippet
|
2013-03-23 14:14:37 -04:00
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
def spammable_path
|
|
|
|
project_snippet_path(@project, @snippet)
|
|
|
|
end
|
2021-07-22 14:08:29 -04:00
|
|
|
|
|
|
|
override :snippet_find_params
|
|
|
|
def snippet_find_params
|
|
|
|
super.merge(project_id: project.id)
|
|
|
|
end
|
2013-03-23 14:14:37 -04:00
|
|
|
end
|