Commit 8470d70da67355c9c009e4401746b1d5410af2e3
1 parent
1e689bfb
Exists in
master
and in
4 other branches
notes controller refactored
Showing
1 changed file
with
23 additions
and
28 deletions
Show diff stats
app/controllers/notes_controller.rb
| ... | ... | @@ -10,22 +10,8 @@ class NotesController < ApplicationController |
| 10 | 10 | respond_to :js |
| 11 | 11 | |
| 12 | 12 | def index |
| 13 | - @notes = case params[:target_type] | |
| 14 | - when "commit" | |
| 15 | - then project.commit_notes(project.commit((params[:target_id]))).fresh.limit(20) | |
| 16 | - when "snippet" | |
| 17 | - then project.snippets.find(params[:target_id]).notes | |
| 18 | - when "wall" | |
| 19 | - then project.common_notes.order("created_at DESC").fresh.limit(10) | |
| 20 | - when "issue" | |
| 21 | - then project.issues.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20) | |
| 22 | - when "merge_request" | |
| 23 | - then project.merge_requests.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20) | |
| 24 | - end | |
| 25 | - | |
| 26 | - respond_to do |format| | |
| 27 | - format.js { respond_with_notes } | |
| 28 | - end | |
| 13 | + notes | |
| 14 | + respond_with(@notes) | |
| 29 | 15 | end |
| 30 | 16 | |
| 31 | 17 | def create |
| ... | ... | @@ -43,9 +29,7 @@ class NotesController < ApplicationController |
| 43 | 29 | |
| 44 | 30 | def destroy |
| 45 | 31 | @note = @project.notes.find(params[:id]) |
| 46 | - | |
| 47 | 32 | return access_denied! unless can?(current_user, :admin_note, @note) |
| 48 | - | |
| 49 | 33 | @note.destroy |
| 50 | 34 | |
| 51 | 35 | respond_to do |format| |
| ... | ... | @@ -55,15 +39,26 @@ class NotesController < ApplicationController |
| 55 | 39 | |
| 56 | 40 | protected |
| 57 | 41 | |
| 58 | - def respond_with_notes | |
| 59 | - if params[:last_id] && params[:first_id] | |
| 60 | - @notes = @notes.where("id >= ?", params[:first_id]) | |
| 61 | - elsif params[:last_id] | |
| 62 | - @notes = @notes.where("id > ?", params[:last_id]) | |
| 63 | - elsif params[:first_id] | |
| 64 | - @notes = @notes.where("id < ?", params[:first_id]) | |
| 65 | - else | |
| 66 | - nil | |
| 67 | - end | |
| 42 | + def notes | |
| 43 | + @notes = case params[:target_type] | |
| 44 | + when "commit" | |
| 45 | + then project.commit_notes(project.commit((params[:target_id]))).fresh.limit(20) | |
| 46 | + when "snippet" | |
| 47 | + then project.snippets.find(params[:target_id]).notes | |
| 48 | + when "wall" | |
| 49 | + then project.common_notes.order("created_at DESC").fresh.limit(10) | |
| 50 | + when "issue" | |
| 51 | + then project.issues.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20) | |
| 52 | + when "merge_request" | |
| 53 | + then project.merge_requests.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20) | |
| 54 | + end | |
| 55 | + | |
| 56 | + @notes = if params[:last_id] | |
| 57 | + @notes.where("id > ?", params[:last_id]) | |
| 58 | + elsif params[:first_id] | |
| 59 | + @notes.where("id < ?", params[:first_id]) | |
| 60 | + else | |
| 61 | + @notes | |
| 62 | + end | |
| 68 | 63 | end |
| 69 | 64 | end | ... | ... |