Commit 36efa2042cb94571957582c7bd4316a3559696e6

Authored by Ian Morgan
1 parent 652d28f5

Add comments to Wiki pages

app/assets/stylesheets/notes.scss
... ... @@ -14,7 +14,8 @@
14 14 border-bottom:1px solid #aaa;
15 15 }
16 16  
17   -.issue_notes {
  17 +.issue_notes,
  18 +.wiki_notes {
18 19 .note_content {
19 20 float:left;
20 21 width:400px;
... ...
app/controllers/admin/mailer_controller.rb
... ... @@ -18,6 +18,8 @@ class Admin::MailerController < ApplicationController
18 18 when "Issue" then
19 19 @issue = Issue.first
20 20 render :file => 'notify/note_issue_email', :layout => 'notify'
  21 + when "Wiki" then
  22 + render :file => 'notify/note_wiki_email', :layout => 'notify'
21 23 else
22 24 render :file => 'notify/note_wall_email', :layout => 'notify'
23 25 end
... ...
app/controllers/notes_controller.rb
... ... @@ -51,6 +51,8 @@ class NotesController < ApplicationController
51 51 then project.issues.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20)
52 52 when "merge_request"
53 53 then project.merge_requests.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20)
  54 + when "wiki"
  55 + then project.wikis.find(params[:target_id]).notes.order("created_at DESC").limit(20)
54 56 end
55 57  
56 58 @notes = if params[:last_id]
... ...
app/controllers/wikis_controller.rb
... ... @@ -17,6 +17,8 @@ class WikisController < ApplicationController
17 17 return render_404 unless can?(current_user, :write_wiki, @project)
18 18 end
19 19  
  20 + @note = @project.notes.new(:noteable => @wiki)
  21 +
20 22 respond_to do |format|
21 23 if @wiki
22 24 format.html
... ...
app/mailers/notify.rb
... ... @@ -46,6 +46,13 @@ class Notify < ActionMailer::Base
46 46 mail(:to => recipient.email, :subject => "gitlab | note for issue #{@issue.id} | #{@note.project_name} ")
47 47 end
48 48  
  49 + def note_wiki_email(recipient_id, note_id)
  50 + recipient = User.find(recipient_id)
  51 + @note = Note.find(note_id)
  52 + @wiki = @note.noteable
  53 + mail(:to => recipient.email, :subject => "gitlab | note for wiki | #{@note.project_name}")
  54 + end
  55 +
49 56 def new_merge_request_email(merge_request_id)
50 57 @merge_request = MergeRequest.find(merge_request_id)
51 58 mail(:to => @merge_request.assignee_email, :subject => "gitlab | new merge request | #{@merge_request.title} ")
... ...
app/models/wiki.rb
1 1 class Wiki < ActiveRecord::Base
2 2 belongs_to :project
3 3 belongs_to :user
  4 + has_many :notes, :as => :noteable, :dependent => :destroy
4 5  
5 6 validates :content, :title, :user_id, :presence => true
6 7 validates :title, :length => 1..250
... ...
app/observers/mailer_observer.rb
... ... @@ -34,6 +34,7 @@ class MailerObserver &lt; ActiveRecord::Observer
34 34 case note.noteable_type
35 35 when "Commit"; Notify.note_commit_email(u.id, note.id).deliver
36 36 when "Issue"; Notify.note_issue_email(u.id, note.id).deliver
  37 + when "Wiki"; Notify.note_wiki_email(u.id, note.id).deliver
37 38 when "MergeRequest"; Notify.note_merge_request_email(u.id, note.id).deliver
38 39 when "Snippet"; true
39 40 else
... ...
app/views/notify/note_wiki_email.html.haml 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +%td.content{:align => "left", :style => "font-family: Helvetica, Arial, sans-serif; padding: 20px 0 0;", :valign => "top", :width => "600"}
  2 + %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :style => "color: #717171; font: normal 11px Helvetica, Arial, sans-serif; margin: 0; padding: 0;", :width => "600"}
  3 + %tr
  4 + %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
  5 + %td{:align => "left", :style => "padding: 20px 0 0;"}
  6 + %h2{:style => "color:#646464 !important; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
  7 + New comment -
  8 + = link_to project_issue_url(@wiki.project, @wiki, :anchor => "note_#{@note.id}") do
  9 + = "Wiki ##{@wiki.title.to_s}"
  10 + %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
  11 + %tr
  12 + %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
  13 + %td{:style => "padding: 15px 0 15px;", :valign => "top"}
  14 + %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
  15 + %a{:href => "#", :style => "color: #0eb6ce; text-decoration: none;"} #{@note.author_name}
  16 + commented on Wiki page:
  17 + %br
  18 + %table{:border => "0", :cellpadding => "0", :cellspacing => "0", :width => "558"}
  19 + %tr
  20 + %td{:valign => "top"}
  21 + %div{ :style => "background:#f5f5f5; padding:20px;border:1px solid #ddd" }
  22 + = markdown(@note.note)
  23 + %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
  24 +
... ...
app/views/wikis/show.html.haml
... ... @@ -15,3 +15,5 @@
15 15 - if can? current_user, :admin_wiki, @project
16 16 = link_to project_wiki_path(@project, @wiki), :confirm => "Are you sure you want to delete this page?", :method => :delete do
17 17 Delete this page
  18 +
  19 +.wiki_notes#notes= render "notes/notes", :tid => @wiki.id, :tt => "wiki"
... ...
spec/requests/wikis_notes_spec.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "Wikis" do
  4 + let(:project) { Factory :project }
  5 +
  6 + before do
  7 + login_as :user
  8 + project.add_access(@user, :read, :write)
  9 + end
  10 +
  11 + describe "add new note", :js => true do
  12 + before do
  13 + visit project_wiki_path(project, :index)
  14 +
  15 + fill_in "Title", :with => 'Test title'
  16 + fill_in "Content", :with => '[link test](test)'
  17 + click_on "Save"
  18 +
  19 + page.should have_content("Test title")
  20 +
  21 + fill_in "note_note", :with => "Comment on wiki!"
  22 + click_button "Add Comment"
  23 + end
  24 +
  25 + it "should contain the new note" do
  26 + page.should have_content("Comment on wiki!")
  27 + end
  28 + end
  29 +end
... ...