diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/journal.rb | 10 | ||||
-rw-r--r-- | app/models/user_preference.rb | 11 |
2 files changed, 20 insertions, 1 deletions
diff --git a/app/models/journal.rb b/app/models/journal.rb index 3d1feb906..01d5debcd 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -60,6 +60,7 @@ class Journal < ActiveRecord::Base ) acts_as_mentionable :attributes => ['notes'] before_create :split_private_notes + before_create :add_watcher after_create_commit :send_notification scope :visible, (lambda do |*args| @@ -327,6 +328,15 @@ class Journal < ActiveRecord::Base true end + def add_watcher + if user && + user.allowed_to?(:add_issue_watchers, project) && + user.pref.auto_watch_on?('issue_contributed_to') && + !Watcher.any_watched?(Array.wrap(journalized), user) + journalized.set_watcher(user, true) + end + end + def send_notification if notify? && ( diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index a0fea2851..758736824 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -39,10 +39,12 @@ class UserPreference < ActiveRecord::Base 'history_default_tab', 'default_issue_query', 'default_project_query', - 'toolbar_language_options') + 'toolbar_language_options', + 'auto_watch_on') TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional'] DEFAULT_TOOLBAR_LANGUAGE_OPTIONS = %w[c cpp csharp css diff go groovy html java javascript objc perl php python r ruby sass scala shell sql swift xml yaml] + AUTO_WATCH_ON_OPTIONS = ['issue_contributed_to'] def initialize(attributes=nil, *args) super @@ -56,6 +58,9 @@ class UserPreference < ActiveRecord::Base unless attributes && attributes.key?(:no_self_notified) self.no_self_notified = Setting.default_users_no_self_notified end + unless attributes && attributes.key?(:auto_watch_on) + self.auto_watch_on = AUTO_WATCH_ON_OPTIONS + end end self.others ||= {} end @@ -124,6 +129,10 @@ class UserPreference < ActiveRecord::Base def default_project_query; self[:default_project_query] end def default_project_query=(value); self[:default_project_query]=value; end + def auto_watch_on; self[:auto_watch_on] || []; end + def auto_watch_on=(values); self[:auto_watch_on]=values; end + def auto_watch_on?(action); self.auto_watch_on.include?(action.to_s); end + # Returns the names of groups that are displayed on user's page # Example: # preferences.my_page_groups |