Project

General

Profile

Feature #38238 » 38238.patch

Felix Schäfer, 2023-02-03 02:00

View differences:

app/models/issue.rb
before_validation :default_assign, on: :create
before_validation :clear_disabled_fields
before_create :add_auto_watcher
before_save :close_duplicates, :update_done_ratio_from_issue_status,
:force_updated_on_change, :update_closed_on
after_save do |issue|
......
end
end
def add_auto_watcher
if author &&
author.allowed_to?(:add_issue_watchers, project) &&
author.pref.auto_watch_on?('issue_created') &&
!Watcher.any_watched?(Array.wrap(self), author)
self.set_watcher(author, true)
end
end
def send_notification
if notify? && Setting.notified_events.include?('issue_added')
Mailer.deliver_issue_add(self)
app/models/user_preference.rb
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']
AUTO_WATCH_ON_OPTIONS = %w[issue_created issue_contributed_to]
def initialize(attributes=nil, *args)
super
config/locales/en.yml
label_optional_description: Optional description
label_add_another_file: Add another file
label_auto_watch_on: Auto watch
label_auto_watch_on_issue_created: Issues I created
label_auto_watch_on_issue_contributed_to: Issues I contributed to
label_preferences: Preferences
label_chronological_order: In chronological order
db/migrate/20230126213739_add_issue_created_to_auto_watch_on_user_preferences.rb
class AddIssueCreatedToAutoWatchOnUserPreferences < ActiveRecord::Migration[6.1]
def up
UserPreference.find_each do |pref|
if pref.auto_watch_on?('issue_contributed_to')
pref.auto_watch_on << 'issue_created'
pref.save
end
end
end
end
test/unit/issue_test.rb
assert_equal [5], issue2.filter_projects_scope('').ids.sort
end
def test_create_should_add_watcher
user = User.first
user.pref.auto_watch_on=['issue_created']
user.pref.save
issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => user.id, :subject => 'test_create_should_add_watcher')
assert_difference 'Watcher.count', 1 do
assert_equal true, issue.save
end
end
def test_create_should_not_add_watcher
user = User.first
user.pref.auto_watch_on=[]
user.pref.save
issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => user.id, :subject => 'test_create_should_not_add_watcher')
assert_no_difference 'Watcher.count' do
assert_equal true, issue.save
end
end
def test_like_should_escape_query
issue = Issue.generate!(:subject => "asdf")
r = Issue.like('as_f')
test/unit/user_preference_test.rb
def test_auto_watch_on_should_default_to_setting
preference = UserPreference.new
assert_equal ['issue_contributed_to'], preference.auto_watch_on
assert_equal %w[issue_created issue_contributed_to], preference.auto_watch_on
end
def test_create
(1-1/4)