Commit 61c85332d2ab8545323a897724439526297c8899
Exists in
master
and in
4 other branches
Merge branch 'add_wiki_comments' of git://github.com/seeingidog/gitlabhq into se…
…eingidog-add_wiki_comments Conflicts: app/controllers/admin/mailer_controller.rb app/controllers/notes_controller.rb
Showing
10 changed files
with
117 additions
and
1 deletions
Show diff stats
app/assets/stylesheets/notes.scss
app/contexts/notes_load.rb
@@ -17,6 +17,8 @@ class NotesLoad < BaseContext | @@ -17,6 +17,8 @@ class NotesLoad < BaseContext | ||
17 | then project.issues.find(target_id).notes.inc_author.order("created_at DESC").limit(20) | 17 | then project.issues.find(target_id).notes.inc_author.order("created_at DESC").limit(20) |
18 | when "merge_request" | 18 | when "merge_request" |
19 | then project.merge_requests.find(target_id).notes.inc_author.order("created_at DESC").limit(20) | 19 | then project.merge_requests.find(target_id).notes.inc_author.order("created_at DESC").limit(20) |
20 | + when "wiki" | ||
21 | + then project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20] | ||
20 | end | 22 | end |
21 | 23 | ||
22 | @notes = if last_id | 24 | @notes = if last_id |
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
1 | +class Admin::MailerController < ApplicationController | ||
2 | + layout "admin" | ||
3 | + before_filter :authenticate_user! | ||
4 | + before_filter :authenticate_admin! | ||
5 | + | ||
6 | + def preview | ||
7 | + | ||
8 | + end | ||
9 | + | ||
10 | + def preview_note | ||
11 | + @note = Note.first | ||
12 | + @user = @note.author | ||
13 | + @project = @note.project | ||
14 | + case params[:type] | ||
15 | + when "Commit" then | ||
16 | + @commit = @project.commit | ||
17 | + render :file => 'notify/note_commit_email', :layout => 'notify' | ||
18 | + when "Issue" then | ||
19 | + @issue = Issue.first | ||
20 | + render :file => 'notify/note_issue_email', :layout => 'notify' | ||
21 | + when "Wiki" then | ||
22 | + render :file => 'notify/note_wiki_email', :layout => 'notify' | ||
23 | + else | ||
24 | + render :file => 'notify/note_wall_email', :layout => 'notify' | ||
25 | + end | ||
26 | + rescue | ||
27 | + render :text => "Preview not available" | ||
28 | + end | ||
29 | + | ||
30 | + def preview_user_new | ||
31 | + @user = User.first | ||
32 | + @password = "DHasJKDHAS!" | ||
33 | + | ||
34 | + render :file => 'notify/new_user_email', :layout => 'notify' | ||
35 | + rescue | ||
36 | + render :text => "Preview not available" | ||
37 | + end | ||
38 | + | ||
39 | + def preview_issue_new | ||
40 | + @issue = Issue.first | ||
41 | + @user = @issue.assignee | ||
42 | + @project = @issue.project | ||
43 | + render :file => 'notify/new_issue_email', :layout => 'notify' | ||
44 | + rescue | ||
45 | + render :text => "Preview not available" | ||
46 | + end | ||
47 | +end |
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 |