enable-to-setting-auto-watch-by-account.patch

Takenori TAKAKI, 2019-03-07 01:44

Download (6.63 KB)

View differences:

app/helpers/users_helper.rb
33 33
    [[l(:label_font_default), '']] + UserPreference::TEXTAREA_FONT_OPTIONS.map {|o| [l("label_font_#{o}"), o]}
34 34
  end
35 35

  
36
  def auto_watch_on_options
37
    UserPreference::AUTO_WATCH_ON_OPTIONS.map {|o| [l("label_auto_watch_on_#{o}"), o]}.to_h
38
  end
39

  
36 40
  def change_status_link(user)
37 41
    url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
38 42

  
app/models/journal.rb
42 42
                                            " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')").distinct
43 43

  
44 44
  before_create :split_private_notes
45
  before_create :add_watcher
45 46
  after_create_commit :send_notification
46 47

  
47 48
  scope :visible, lambda {|*args|
......
301 302
    true
302 303
  end
303 304

  
305
  def add_watcher
306
    if user.allowed_to?(:add_issue_watchers, project) &&
307
        user.pref.auto_watch_on?('add_note') &&
308
        Watcher.any_watched?(Array.wrap(journalized), user) == false
309
      journalized.set_watcher(user, true)
310
    end
311
  end
312

  
304 313
  def send_notification
305 314
    if notify? && (Setting.notified_events.include?('issue_updated') ||
306 315
        (Setting.notified_events.include?('issue_note_added') && notes.present?) ||
app/models/user_preference.rb
30 30
    'comments_sorting',
31 31
    'warn_on_leaving_unsaved',
32 32
    'no_self_notified',
33
    'textarea_font'
33
    'textarea_font',
34
    'auto_watch_on'
34 35

  
35 36
  TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional']
37
  AUTO_WATCH_ON_OPTIONS = ['add_note']
36 38

  
37 39
  def initialize(attributes=nil, *args)
38 40
    super
......
46 48
      unless attributes && attributes.key?(:no_self_notified)
47 49
        self.no_self_notified = true
48 50
      end
51
      unless attributes && attributes.key?(:auto_watch_on)
52
        self.auto_watch_on = AUTO_WATCH_ON_OPTIONS
53
      end
49 54
    end
50 55
    self.others ||= {}
51 56
  end
......
88 93
  def textarea_font; self[:textarea_font] end
89 94
  def textarea_font=(value); self[:textarea_font]=value; end
90 95

  
96
  def auto_watch_on; self[:auto_watch_on] || []; end
97
  def auto_watch_on=(values); self[:auto_watch_on]=values; end
98
  def auto_watch_on?(action); self.auto_watch_on.include?(action.to_s); end
99

  
91 100
  # Returns the names of groups that are displayed on user's page
92 101
  # Example:
93 102
  #   preferences.my_page_groups
app/views/my/account.html.erb
44 44
  <%= render :partial => 'users/mail_notifications' %>
45 45
</fieldset>
46 46

  
47
<fieldset class="box tabular">
48
  <legend><%=l(:label_auto_watch_on)%></legend>
49
  <%= render :partial => 'users/auto_watch_on' %>
50
</fieldset>
51

  
47 52
<fieldset class="box tabular">
48 53
  <legend><%=l(:label_preferences)%></legend>
49 54
  <%= render :partial => 'users/preferences' %>
app/views/users/_auto_watch_on.html.erb
1
<%= labelled_fields_for :pref, @user.pref do |pref_fields| %>
2
  <%= pref_fields.collection_check_boxes :auto_watch_on, auto_watch_on_options, :last, :first, :checked => @user.pref.auto_watch_on do |b| %>
3
    <p><%= b.label %><%= b.check_box %></p>
4
  <% end %>
5
<% end %>
app/views/users/_form.html.erb
46 46
  <%= render :partial => 'users/mail_notifications' %>
47 47
</fieldset>
48 48

  
49
<fieldset class="box tabular">
50
  <legend><%=l(:label_auto_watch_on)%></legend>
51
  <%= render :partial => 'users/auto_watch_on' %>
52
</fieldset>
53

  
49 54
<fieldset class="box tabular">
50 55
  <legend><%=l(:label_preferences)%></legend>
51 56
  <%= render :partial => 'users/preferences' %>
config/locales/en.yml
910 910
  label_downloads_abbr: D/L
911 911
  label_optional_description: Optional description
912 912
  label_add_another_file: Add another file
913
  label_auto_watch_on: Auto watch
914
  label_auto_watch_on_add_note: Issues I added notes
913 915
  label_preferences: Preferences
914 916
  label_chronological_order: In chronological order
915 917
  label_reverse_chronological_order: In reverse chronological order
test/unit/journal_test.rb
118 118
    end
119 119
  end
120 120

  
121
  def test_create_should_add_wacher
122
    user = User.first
123
    user.pref.auto_watch_on=['add_note']
124
    user.save
125
    journal = Journal.new(:journalized => Issue.first, :notes => 'notes', :user => user)
126

  
127
    assert_difference 'Watcher.count', 1 do
128
      assert_equal true, journal.save
129
    end
130
  end
131

  
132
  def test_create_should_not_add_watcher
133
    user = User.first
134
    user.pref.auto_watch_on=[]
135
    user.save
136
    journal = Journal.new(:journalized => Issue.first, :notes => 'notes', :user => user)
137

  
138
    assert_no_difference 'Watcher.count' do
139
      assert_equal true, journal.save
140
    end
141
  end
142

  
121 143
  def test_visible_scope_for_anonymous
122 144
    # Anonymous user should see issues of public projects only
123 145
    journals = Journal.visible(User.anonymous).to_a
test/unit/user_preference_test.rb
48 48
    assert_equal true, preference.no_self_notified
49 49
  end
50 50

  
51
  def test_auto_watch_on_should_default_to_setting
52
    preference = UserPreference.new
53
    assert_equal ['add_note'], preference.auto_watch_on
54
  end
55

  
51 56
  def test_create
52 57
    user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
53 58
    user.login = "newuser"