wiking_redmine30.patch
plugins/wiking/app/models/mention_observer.rb | ||
---|---|---|
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 |
plugins/wiking/app/models/wiki_macro.rb | ||
---|---|---|
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 |
plugins/wiking/config/routes.rb | ||
---|---|---|
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 | 21 |
delete('macros/:id', :to => 'macros#destroy') |
22 | 22 |
plugins/wiking/init.rb | ||
---|---|---|
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) |
plugins/wiking/lib/mention_observer.rb | ||
---|---|---|
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 |