I'm looking for a part-time remote job.

Hire me


I'm the author of:

Mastering Redmine is a comprehensive guide with tips, tricks and best practices, and an easy-to-learn structure.

Check the book's project or

Buy the book

Social pages of the book:

By buying this book you also donate to Redmine (see this page).


Follow me:

wiking-redmine-3.2.patch

Patch - Rob Spearman, 10 Jan 2016 17:33

Download (5.76 KB)

View differences:

CREDITS (working copy)
9 9
 o Timothy Miller for the "More" icon
10 10
 o Yusuke Kamiyamane for the "Success" and "Failure" icons
11 11
 o Ki Won Kim for Korean translation
12
 o Massimo Rossello & Rob Spearman for patches for Redmine 3 / Rails 4
app/controllers/macros_controller.rb (working copy)
6 6
    before_filter :find_macro, :only => [ :edit, :update, :destroy ]
7 7

  
8 8
    def index
9
        @macros = WikiMacro.all(:order => :name)
9
      @macros = WikiMacro.all.sort_by(&:name)
10 10
    end
11 11

  
12 12
    def new
......
14 14
    end
15 15

  
16 16
    def create
17
        @macro = WikiMacro.new(params[:wiki_macro])
17
        @macro = WikiMacro.new(user_params)
18 18
        if request.post? && @macro.save
19 19
            flash[:notice] = l(:notice_successful_create)
20 20
            @macro.register!
......
24 24
        end
25 25
    end
26 26

  
27
    def user_params
28
      params.require(:wiki_macro).permit(:name, :description, :content, :commit)
29
    end
30

  
27 31
    def edit
28 32
    end
29 33

  
30 34
    def update
31
        if request.put?
35
        if request.put? or request.patch?
32 36
            old_name = @macro.name
33
            @macro.attributes = params[:wiki_macro]
37
            @macro.attributes = user_params
34 38
            name_changed = @macro.name_changed?
35 39
            desc_changed = @macro.description_changed?
36 40
            if @macro.save
app/models/mention_observer.rb (working copy)
1
class MentionObserver < ActiveRecord::Observer
2

  
3
    def after_create(mention)
4
        if Setting.notified_events.include?('user_mentioned') &&
5
           %w(all only_my_events only_owner).include?(mention.mentioned.mail_notification) &&
6
           mention.title.present? && mention.url.present? && mention.created_on > 1.day.ago &&
7
           (!mention.mentioning.respond_to?(:visible?) || mention.mentioning.visible?(mention.mentioned))
8
            if Rails::VERSION::MAJOR < 3
9
                Mailer.deliver_mention(mention)
10
            else
11
                Mailer.mention(mention).deliver
12
            end
13
        end
14
    rescue Exception => exception
15
        Rails.logger.error exception.message
16
    end
17

  
18
end
app/models/wiki_macro.rb (working copy)
7 7

  
8 8
    validates_presence_of :name, :description, :content
9 9
    validates_length_of :name, :in => 1..NAME_MAX_LENGTH
10
    validates_format_of :name, :with => %r{^[a-z0-9_]+$}
10
    validates_format_of :name, :with => %r{\A[a-z0-9_]+\z}
11 11

  
12 12
    validate :validate_name
13 13

  
config/routes.rb (working copy)
12 12

  
13 13
else
14 14

  
15
    match('mentions/:id',    :to => 'mentions#index')
16
    match('macros',          :to => 'macros#index')
17
    match('macros/new',      :to => 'macros#new')
15
    get('mentions/:id',      :to => 'mentions#index')
16
    get('macros',            :to => 'macros#index')
17
    get('macros/new',        :to => 'macros#new')
18 18
    post('macros/create',    :to => 'macros#create')
19
    match('macros/:id/edit', :to => 'macros#edit')
19
    get('macros/:id/edit',   :to => 'macros#edit')
20 20
    put('macros/:id',        :to => 'macros#update')
21
    patch('macros/:id',        :to => 'macros#update')
21 22
    delete('macros/:id',     :to => 'macros#destroy')
22 23

  
23 24
end
init.rb (working copy)
4 4

  
5 5
Rails.logger.info 'Starting WikiNG Plugin for Redmine'
6 6

  
7
ActiveRecord::Base.observers << :mention_observer
8 7

  
9 8
Rails.configuration.to_prepare do
9
    unless ActiveRecord::Base.included_modules.include?(MentionObserver)
10
      ActiveRecord::Base.send(:include, MentionObserver)
11
    end
10 12
    unless Redmine::WikiFormatting::Textile::Formatter.included_modules.include?(WikingFormatterPatch)
11
        Redmine::WikiFormatting::Textile::Formatter.send(:include, WikingFormatterPatch)
13
      Redmine::WikiFormatting::Textile::Formatter.send(:include, WikingFormatterPatch)
12 14
    end
13 15
    unless Redmine::WikiFormatting::Textile::Helper.included_modules.include?(WikingWikiHelperPatch)
14 16
        Redmine::WikiFormatting::Textile::Helper.send(:include, WikingWikiHelperPatch)
lib/mention_observer.rb (working copy)
1
module MentionObserver
2

  
3
  def self.included(base)
4
    base.send(:include, InstanceMethods)
5
    base.instance_eval do
6
      unloadable
7
      after_create :handle_mention
8
    end
9

  
10
  end
11

  
12
  module InstanceMethods
13

  
14
    def handle_mention
15
      mention = self
16
      if Setting.notified_events.include?('user_mentioned') &&
17
          %w(all only_my_events only_owner).include?(mention.mentioned.mail_notification) &&
18
          mention.title.present? && mention.url.present? && mention.created_on > 1.day.ago &&
19
          (!mention.mentioning.respond_to?(:visible?) || mention.mentioning.visible?(mention.mentioned))
20
        if Rails::VERSION::MAJOR < 3
21
          Mailer.deliver_mention(mention)
22
        else
23
          Mailer.mention(mention).deliver
24
        end
25
      end
26
    rescue Exception => exception
27
      Rails.logger.error exception.message
28
    end
29

  
30
  end
31
end
32

  
Terms of use | Privacy policy