Class: Projects::NotesController

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

#award_toggleObject


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/projects/notes_controller.rb', line 59

def award_toggle
  noteable = if note_params[:noteable_type] == "issue"
               project.issues.find(note_params[:noteable_id])
             else
               project.merge_requests.find(note_params[:noteable_id])
             end

  data = {
    author: current_user,
    is_award: true,
    note: note_params[:note].delete(":")
  }

  note = noteable.notes.find_by(data)

  if note
    note.destroy
  else
    Notes::CreateService.new(project, current_user, note_params).execute
  end

  render json: { ok: true }
end

#createObject


22
23
24
25
26
27
28
29
# File 'app/controllers/projects/notes_controller.rb', line 22

def create
  @note = Notes::CreateService.new(project, current_user, note_params).execute

  respond_to do |format|
    format.json { render json: note_json(@note) }
    format.html { redirect_back_or_default }
  end
end

#delete_attachmentObject


50
51
52
53
54
55
56
57
# File 'app/controllers/projects/notes_controller.rb', line 50

def delete_attachment
  note.remove_attachment!
  note.update_attribute(:attachment, nil)

  respond_to do |format|
    format.js { render nothing: true }
  end
end

#destroyObject


40
41
42
43
44
45
46
47
48
# File 'app/controllers/projects/notes_controller.rb', line 40

def destroy
  if note.editable?
    Notes::DeleteService.new(project, current_user).execute(note)
  end

  respond_to do |format|
    format.js { render nothing: true }
  end
end

#indexObject


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/projects/notes_controller.rb', line 8

def index
  current_fetched_at = Time.now.to_i

  notes_json = { notes: [], last_fetched_at: current_fetched_at }

  @notes.each do |note|
    next if note.cross_reference_not_visible_for?(current_user)

    notes_json[:notes] << note_json(note)
  end

  render json: notes_json
end

#updateObject


31
32
33
34
35
36
37
38
# File 'app/controllers/projects/notes_controller.rb', line 31

def update
  @note = Notes::UpdateService.new(project, current_user, note_params).execute(note)

  respond_to do |format|
    format.json { render json: note_json(@note) }
    format.html { redirect_back_or_default }
  end
end