Class: SnippetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/snippets_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#redirect_back_or_default

Methods included from PageLayoutHelper

#blank_container, #container_class, #fluid_layout, #header_title, #nav, #page_card_attributes, #page_card_meta_tags, #page_description, #page_image, #page_title, #sidebar

Methods included from GitlabRoutingHelper

#activity_project_path, #edit_project_path, #edit_project_url, #issue_path, #issue_url, #merge_request_path, #merge_request_url, #milestone_path, #project_builds_path, #project_commits_path, #project_files_path, #project_path, #project_pipelines_path, #project_snippet_url, #project_url, #runner_path, #runners_path, #toggle_subscription_path

Methods included from Gitlab::GonHelper

#add_gon_variables

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Instance Method Details

#createObject


40
41
42
43
44
45
# File 'app/controllers/snippets_controller.rb', line 40

def create
  @snippet = CreateSnippetService.new(nil, current_user,
                                      snippet_params).execute

  respond_with @snippet.becomes(Snippet)
end

#destroyObject


59
60
61
62
63
64
65
# File 'app/controllers/snippets_controller.rb', line 59

def destroy
  return access_denied! unless can?(current_user, :admin_personal_snippet, @snippet)

  @snippet.destroy

  redirect_to snippets_path
end

#editObject


47
48
# File 'app/controllers/snippets_controller.rb', line 47

def edit
end

#indexObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/snippets_controller.rb', line 18

def index
  if params[:username].present?
    @user = User.find_by(username: params[:username])

    render_404 and return unless @user

    @snippets = SnippetsFinder.new.execute(current_user, {
      filter: :by_user,
      user: @user,
      scope: params[:scope] }).
    page(params[:page])

    render 'index'
  else
    redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path)
  end
end

#newObject


36
37
38
# File 'app/controllers/snippets_controller.rb', line 36

def new
  @snippet = PersonalSnippet.new
end

#rawObject


67
68
69
70
71
72
73
74
# File 'app/controllers/snippets_controller.rb', line 67

def raw
  send_data(
    @snippet.content,
    type: 'text/plain; charset=utf-8',
    disposition: 'inline',
    filename: @snippet.sanitized_file_name
  )
end

#showObject


56
57
# File 'app/controllers/snippets_controller.rb', line 56

def show
end

#updateObject


50
51
52
53
54
# File 'app/controllers/snippets_controller.rb', line 50

def update
  UpdateSnippetService.new(nil, current_user, @snippet,
                           snippet_params).execute
  respond_with @snippet.becomes(Snippet)
end