Commit 36efa2042cb94571957582c7bd4316a3559696e6
1 parent
652d28f5
Exists in
master
and in
4 other branches
Add comments to Wiki pages
Showing
10 changed files
with
72 additions
and
1 deletions
Show diff stats
app/assets/stylesheets/notes.scss
app/controllers/admin/mailer_controller.rb
@@ -18,6 +18,8 @@ class Admin::MailerController < ApplicationController | @@ -18,6 +18,8 @@ class Admin::MailerController < ApplicationController | ||
18 | when "Issue" then | 18 | when "Issue" then |
19 | @issue = Issue.first | 19 | @issue = Issue.first |
20 | render :file => 'notify/note_issue_email', :layout => 'notify' | 20 | render :file => 'notify/note_issue_email', :layout => 'notify' |
21 | + when "Wiki" then | ||
22 | + render :file => 'notify/note_wiki_email', :layout => 'notify' | ||
21 | else | 23 | else |
22 | render :file => 'notify/note_wall_email', :layout => 'notify' | 24 | render :file => 'notify/note_wall_email', :layout => 'notify' |
23 | end | 25 | end |
app/controllers/notes_controller.rb
@@ -51,6 +51,8 @@ class NotesController < ApplicationController | @@ -51,6 +51,8 @@ class NotesController < ApplicationController | ||
51 | then project.issues.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20) | 51 | then project.issues.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20) |
52 | when "merge_request" | 52 | when "merge_request" |
53 | then project.merge_requests.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20) | 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 | end | 56 | end |
55 | 57 | ||
56 | @notes = if params[:last_id] | 58 | @notes = if params[:last_id] |
app/controllers/wikis_controller.rb
@@ -17,6 +17,8 @@ class WikisController < ApplicationController | @@ -17,6 +17,8 @@ class WikisController < ApplicationController | ||
17 | return render_404 unless can?(current_user, :write_wiki, @project) | 17 | return render_404 unless can?(current_user, :write_wiki, @project) |
18 | end | 18 | end |
19 | 19 | ||
20 | + @note = @project.notes.new(:noteable => @wiki) | ||
21 | + | ||
20 | respond_to do |format| | 22 | respond_to do |format| |
21 | if @wiki | 23 | if @wiki |
22 | format.html | 24 | format.html |
app/mailers/notify.rb
@@ -46,6 +46,13 @@ class Notify < ActionMailer::Base | @@ -46,6 +46,13 @@ class Notify < ActionMailer::Base | ||
46 | mail(:to => recipient.email, :subject => "gitlab | note for issue #{@issue.id} | #{@note.project_name} ") | 46 | mail(:to => recipient.email, :subject => "gitlab | note for issue #{@issue.id} | #{@note.project_name} ") |
47 | end | 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 | def new_merge_request_email(merge_request_id) | 56 | def new_merge_request_email(merge_request_id) |
50 | @merge_request = MergeRequest.find(merge_request_id) | 57 | @merge_request = MergeRequest.find(merge_request_id) |
51 | mail(:to => @merge_request.assignee_email, :subject => "gitlab | new merge request | #{@merge_request.title} ") | 58 | mail(:to => @merge_request.assignee_email, :subject => "gitlab | new merge request | #{@merge_request.title} ") |
app/models/wiki.rb
1 | class Wiki < ActiveRecord::Base | 1 | class Wiki < ActiveRecord::Base |
2 | belongs_to :project | 2 | belongs_to :project |
3 | belongs_to :user | 3 | belongs_to :user |
4 | + has_many :notes, :as => :noteable, :dependent => :destroy | ||
4 | 5 | ||
5 | validates :content, :title, :user_id, :presence => true | 6 | validates :content, :title, :user_id, :presence => true |
6 | validates :title, :length => 1..250 | 7 | validates :title, :length => 1..250 |
app/observers/mailer_observer.rb
@@ -34,6 +34,7 @@ class MailerObserver < ActiveRecord::Observer | @@ -34,6 +34,7 @@ class MailerObserver < ActiveRecord::Observer | ||
34 | case note.noteable_type | 34 | case note.noteable_type |
35 | when "Commit"; Notify.note_commit_email(u.id, note.id).deliver | 35 | when "Commit"; Notify.note_commit_email(u.id, note.id).deliver |
36 | when "Issue"; Notify.note_issue_email(u.id, note.id).deliver | 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 | when "MergeRequest"; Notify.note_merge_request_email(u.id, note.id).deliver | 38 | when "MergeRequest"; Notify.note_merge_request_email(u.id, note.id).deliver |
38 | when "Snippet"; true | 39 | when "Snippet"; true |
39 | else | 40 | else |
@@ -0,0 +1,24 @@ | @@ -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,3 +15,5 @@ | ||
15 | - if can? current_user, :admin_wiki, @project | 15 | - if can? current_user, :admin_wiki, @project |
16 | = link_to project_wiki_path(@project, @wiki), :confirm => "Are you sure you want to delete this page?", :method => :delete do | 16 | = link_to project_wiki_path(@project, @wiki), :confirm => "Are you sure you want to delete this page?", :method => :delete do |
17 | Delete this page | 17 | Delete this page |
18 | + | ||
19 | +.wiki_notes#notes= render "notes/notes", :tid => @wiki.id, :tt => "wiki" |
@@ -0,0 +1,29 @@ | @@ -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 |