Commit 61c85332d2ab8545323a897724439526297c8899

Authored by randx
2 parents 5133541f 04a85f45

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
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/contexts/notes_load.rb
... ... @@ -17,6 +17,8 @@ class NotesLoad < BaseContext
17 17 then project.issues.find(target_id).notes.inc_author.order("created_at DESC").limit(20)
18 18 when "merge_request"
19 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 22 end
21 23  
22 24 @notes = if last_id
... ...
app/controllers/admin/mailer_controller.rb 0 → 100644
... ... @@ -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 &lt; 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 &lt; 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
... ...