Project

General

Profile

Feature #4347 » enable-to-setting-auto-watch-by-account.patch

Takenori TAKAKI, 2019-03-07 01:44

View differences:

app/helpers/users_helper.rb
[[l(:label_font_default), '']] + UserPreference::TEXTAREA_FONT_OPTIONS.map {|o| [l("label_font_#{o}"), o]}
end
def auto_watch_on_options
UserPreference::AUTO_WATCH_ON_OPTIONS.map {|o| [l("label_auto_watch_on_#{o}"), o]}.to_h
end
def change_status_link(user)
url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
app/models/journal.rb
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')").distinct
before_create :split_private_notes
before_create :add_watcher
after_create_commit :send_notification
scope :visible, lambda {|*args|
......
true
end
def add_watcher
if user.allowed_to?(:add_issue_watchers, project) &&
user.pref.auto_watch_on?('add_note') &&
Watcher.any_watched?(Array.wrap(journalized), user) == false
journalized.set_watcher(user, true)
end
end
def send_notification
if notify? && (Setting.notified_events.include?('issue_updated') ||
(Setting.notified_events.include?('issue_note_added') && notes.present?) ||
app/models/user_preference.rb
'comments_sorting',
'warn_on_leaving_unsaved',
'no_self_notified',
'textarea_font'
'textarea_font',
'auto_watch_on'
TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional']
AUTO_WATCH_ON_OPTIONS = ['add_note']
def initialize(attributes=nil, *args)
super
......
unless attributes && attributes.key?(:no_self_notified)
self.no_self_notified = true
end
unless attributes && attributes.key?(:auto_watch_on)
self.auto_watch_on = AUTO_WATCH_ON_OPTIONS
end
end
self.others ||= {}
end
......
def textarea_font; self[:textarea_font] end
def textarea_font=(value); self[:textarea_font]=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
app/views/my/account.html.erb
<%= render :partial => 'users/mail_notifications' %>
</fieldset>
<fieldset class="box tabular">
<legend><%=l(:label_auto_watch_on)%></legend>
<%= render :partial => 'users/auto_watch_on' %>
</fieldset>
<fieldset class="box tabular">
<legend><%=l(:label_preferences)%></legend>
<%= render :partial => 'users/preferences' %>
app/views/users/_auto_watch_on.html.erb
<%= labelled_fields_for :pref, @user.pref do |pref_fields| %>
<%= pref_fields.collection_check_boxes :auto_watch_on, auto_watch_on_options, :last, :first, :checked => @user.pref.auto_watch_on do |b| %>
<p><%= b.label %><%= b.check_box %></p>
<% end %>
<% end %>
app/views/users/_form.html.erb
<%= render :partial => 'users/mail_notifications' %>
</fieldset>
<fieldset class="box tabular">
<legend><%=l(:label_auto_watch_on)%></legend>
<%= render :partial => 'users/auto_watch_on' %>
</fieldset>
<fieldset class="box tabular">
<legend><%=l(:label_preferences)%></legend>
<%= render :partial => 'users/preferences' %>
config/locales/en.yml
label_downloads_abbr: D/L
label_optional_description: Optional description
label_add_another_file: Add another file
label_auto_watch_on: Auto watch
label_auto_watch_on_add_note: Issues I added notes
label_preferences: Preferences
label_chronological_order: In chronological order
label_reverse_chronological_order: In reverse chronological order
test/unit/journal_test.rb
end
end
def test_create_should_add_wacher
user = User.first
user.pref.auto_watch_on=['add_note']
user.save
journal = Journal.new(:journalized => Issue.first, :notes => 'notes', :user => user)
assert_difference 'Watcher.count', 1 do
assert_equal true, journal.save
end
end
def test_create_should_not_add_watcher
user = User.first
user.pref.auto_watch_on=[]
user.save
journal = Journal.new(:journalized => Issue.first, :notes => 'notes', :user => user)
assert_no_difference 'Watcher.count' do
assert_equal true, journal.save
end
end
def test_visible_scope_for_anonymous
# Anonymous user should see issues of public projects only
journals = Journal.visible(User.anonymous).to_a
test/unit/user_preference_test.rb
assert_equal true, preference.no_self_notified
end
def test_auto_watch_on_should_default_to_setting
preference = UserPreference.new
assert_equal ['add_note'], preference.auto_watch_on
end
def test_create
user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
user.login = "newuser"
(3-3/5)