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