2018-09-14 05:42:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-16 15:08:32 +00:00
|
|
|
class SnippetsController < Snippets::ApplicationController
|
2017-02-06 15:04:00 +00:00
|
|
|
include SnippetsActions
|
2017-10-11 09:03:19 +00:00
|
|
|
include PreviewMarkdown
|
2020-06-16 15:08:32 +00:00
|
|
|
include ToggleAwardEmoji
|
2021-08-11 06:10:02 +00:00
|
|
|
include SpammableActions::AkismetMarkAsSpamAction
|
2018-02-06 13:33:18 +00:00
|
|
|
|
2020-10-12 15:08:32 +00:00
|
|
|
before_action :snippet, only: [:show, :edit, :raw, :toggle_award_emoji, :mark_as_spam]
|
2011-10-16 21:07:10 +00:00
|
|
|
|
2020-10-12 15:08:32 +00:00
|
|
|
before_action :authorize_create_snippet!, only: :new
|
2017-04-30 17:15:20 +00:00
|
|
|
before_action :authorize_read_snippet!, only: [:show, :raw]
|
2020-10-12 15:08:32 +00:00
|
|
|
before_action :authorize_update_snippet!, only: :edit
|
2011-10-16 21:07:10 +00:00
|
|
|
|
2017-04-30 17:15:20 +00:00
|
|
|
skip_before_action :authenticate_user!, only: [:index, :show, :raw]
|
2014-10-08 13:44:25 +00:00
|
|
|
|
2015-05-01 08:39:11 +00:00
|
|
|
layout 'snippets'
|
2011-10-16 21:07:10 +00:00
|
|
|
|
2016-05-08 08:27:33 +00:00
|
|
|
def index
|
|
|
|
if params[:username].present?
|
2018-10-18 09:06:44 +00:00
|
|
|
@user = UserFinder.new(params[:username]).find_by_username!
|
2016-05-08 08:27:33 +00:00
|
|
|
|
2020-07-10 18:09:45 +00:00
|
|
|
@snippets = SnippetsFinder.new(current_user, author: @user, 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')
|
2016-05-08 08:27:33 +00:00
|
|
|
|
|
|
|
render 'index'
|
|
|
|
else
|
|
|
|
redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-26 13:46:25 +00:00
|
|
|
def new
|
2013-03-25 16:32:10 +00:00
|
|
|
@snippet = PersonalSnippet.new
|
2011-10-16 21:07:10 +00:00
|
|
|
end
|
|
|
|
|
2011-12-15 21:57:46 +00:00
|
|
|
protected
|
2012-06-12 18:41:46 +00:00
|
|
|
|
2016-06-03 09:44:04 +00:00
|
|
|
alias_method :awardable, :snippet
|
2017-02-01 18:15:59 +00:00
|
|
|
alias_method :spammable, :snippet
|
2011-12-15 21:57:46 +00:00
|
|
|
|
2017-06-29 17:06:35 +00:00
|
|
|
def spammable_path
|
|
|
|
snippet_path(@snippet)
|
|
|
|
end
|
2011-10-16 21:07:10 +00:00
|
|
|
end
|