debian-mirror-gitlab/app/controllers/snippets_controller.rb

52 lines
1.3 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2020-06-23 00:09:42 +05:30
class SnippetsController < Snippets::ApplicationController
2017-08-17 22:00:37 +05:30
include SnippetsActions
2018-03-17 18:26:18 +05:30
include PreviewMarkdown
2020-06-23 00:09:42 +05:30
include ToggleAwardEmoji
include SpammableActions
2018-10-15 14:42:47 +05:30
2021-01-03 14:25:43 +05:30
before_action :snippet, only: [:show, :edit, :raw, :toggle_award_emoji, :mark_as_spam]
2014-09-02 18:07:02 +05:30
2021-01-03 14:25:43 +05:30
before_action :authorize_create_snippet!, only: :new
2017-08-17 22:00:37 +05:30
before_action :authorize_read_snippet!, only: [:show, :raw]
2021-01-03 14:25:43 +05:30
before_action :authorize_update_snippet!, only: :edit
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
skip_before_action :authenticate_user!, only: [:index, :show, :raw]
2015-04-26 12:48:37 +05:30
2015-09-11 14:41:01 +05:30
layout 'snippets'
2014-09-02 18:07:02 +05:30
def index
2015-09-11 14:41:01 +05:30
if params[:username].present?
2018-12-13 13:39:08 +05:30
@user = UserFinder.new(params[:username]).find_by_username!
2015-09-11 14:41:01 +05:30
2020-07-28 23:09:34 +05:30
@snippets = SnippetsFinder.new(current_user, author: @user, scope: params[:scope], sort: sort_param)
2019-12-04 20:38:33 +05:30
.execute
.page(params[:page])
.inc_author
2021-04-17 20:07:23 +05:30
.inc_statistics
2019-12-04 20:38:33 +05:30
return if redirect_out_of_range(@snippets)
@noteable_meta_data = noteable_meta_data(@snippets, 'Snippet')
2015-09-11 14:41:01 +05:30
2015-09-25 12:07:36 +05:30
render 'index'
2014-09-02 18:07:02 +05:30
else
2015-09-25 12:07:36 +05:30
redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path)
2014-09-02 18:07:02 +05:30
end
end
def new
@snippet = PersonalSnippet.new
end
protected
2016-09-29 09:46:39 +05:30
alias_method :awardable, :snippet
2017-08-17 22:00:37 +05:30
alias_method :spammable, :snippet
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
def spammable_path
snippet_path(@snippet)
end
2014-09-02 18:07:02 +05:30
end