Class: Projects::SnippetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/projects/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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Projects::ApplicationController

Instance Method Details

#createObject


31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/projects/snippets_controller.rb', line 31

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

  if @snippet.valid?
    respond_with(@snippet,
                 location: namespace_project_snippet_path(@project.namespace,
                                                          @project, @snippet))
  else
    render :new
  end
end

#destroyObject


61
62
63
64
65
66
67
# File 'app/controllers/projects/snippets_controller.rb', line 61

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

  @snippet.destroy

  redirect_to namespace_project_snippets_path(@project.namespace, @project)
end

#editObject


44
45
# File 'app/controllers/projects/snippets_controller.rb', line 44

def edit
end

#indexObject


19
20
21
22
23
24
25
# File 'app/controllers/projects/snippets_controller.rb', line 19

def index
  @snippets = SnippetsFinder.new.execute(current_user, {
    filter: :by_project,
    project: @project
  })
  @snippets = @snippets.page(params[:page])
end

#newObject


27
28
29
# File 'app/controllers/projects/snippets_controller.rb', line 27

def new
  @snippet = @noteable = @project.snippets.build
end

#rawObject


69
70
71
72
73
74
75
76
# File 'app/controllers/projects/snippets_controller.rb', line 69

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

#showObject


55
56
57
58
59
# File 'app/controllers/projects/snippets_controller.rb', line 55

def show
  @note = @project.notes.new(noteable: @snippet)
  @notes = @snippet.notes.fresh
  @noteable = @snippet
end

#updateObject


47
48
49
50
51
52
53
# File 'app/controllers/projects/snippets_controller.rb', line 47

def update
  UpdateSnippetService.new(project, current_user, @snippet,
                           snippet_params).execute
  respond_with(@snippet,
               location: namespace_project_snippet_path(@project.namespace,
                                                        @project, @snippet))
end