Project

General

Profile

Feature #9432 » 0001-Allow-the-default-value-of-the-private-field-to-be-c.patch

Go MAEDA, 2023-04-15 08:51

View differences:

app/controllers/issues_controller.rb
624 624

  
625 625
    if @issue.project
626 626
      @issue.tracker ||= @issue.allowed_target_trackers.first
627
      @issue.is_private ||= @issue.tracker&.private_by_default?
627 628
      if @issue.tracker.nil?
628 629
        if @issue.project.trackers.any?
629 630
          # None of the project trackers is allowed to the user
app/models/tracker.rb
74 74
    'name',
75 75
    'default_status_id',
76 76
    'is_in_roadmap',
77
    'private_by_default',
77 78
    'core_fields',
78 79
    'position',
79 80
    'custom_field_ids',
app/views/trackers/_form.html.erb
10 10
        :include_blank => @tracker.default_status.nil?,
11 11
        :required => true %>
12 12
</p>
13
<p><%= f.check_box :private_by_default %></p>
13 14
<p><%= f.check_box :is_in_roadmap %></p>
14 15
<p><%= f.text_area :description, :rows => 4 %></p>
15 16
<p>
config/locales/en.yml
319 319
  field_is_public: Public
320 320
  field_parent: Subproject of
321 321
  field_is_in_roadmap: Issues displayed in roadmap
322
  field_private_by_default: Private by default
322 323
  field_login: Login
323 324
  field_mail_notification: Email notifications
324 325
  field_admin: Administrator
db/migrate/20230414071513_add_private_by_default_to_trackers.rb
1
class AddPrivateByDefaultToTrackers < ActiveRecord::Migration[6.1]
2
  def change
3
    add_column :trackers, :private_by_default, :boolean, default: false, null: false, after: :default_status_id
4
  end
5
end
test/functional/issues_controller_test.rb
5634 5634
    assert_equal [], issue.watcher_user_ids
5635 5635
  end
5636 5636

  
5637
  def test_create_should_respect_private_by_default_per_tracker_setting
5638
    @request.session[:user_id] = 2
5639
    tracker = Tracker.find(1)
5640

  
5641
    post_issue = -> do
5642
      post(
5643
        :create,
5644
        params: {
5645
          project_id: 1,
5646
          issue: {tracker_id: tracker.id, status_id: '1', subject: '_'}
5647
        }
5648
      )
5649
    end
5650

  
5651
    tracker.update_attribute(:private_by_default, true)
5652
    assert_difference 'Issue.count' do
5653
      post_issue.call
5654
    end
5655
    issue = Issue.order('id DESC').first
5656
    assert issue.is_private?
5657

  
5658
    tracker.update_attribute(:private_by_default, false)
5659
    assert_difference 'Issue.count' do
5660
      post_issue.call
5661
    end
5662
    issue = Issue.order('id DESC').first
5663
    assert_not issue.is_private?
5664
  end
5665

  
5637 5666
  def test_get_edit
5638 5667
    @request.session[:user_id] = 2
5639 5668
    get(:edit, :params => {:id => 1})
test/integration/api_test/issues_test.rb
753 753
    assert_response 422
754 754
  end
755 755

  
756
  test "POST /issues.json should respect the private_by_default per tracker setting" do
757
    tracker = Tracker.find(1)
758
    tracker.update_attribute(:private_by_default, true)
759
    issue = new_record(Issue) do
760
      post(
761
        '/issues.json',
762
        :params => {:issue => {:project_id => 1, :tracker_id => 1, :subject => 'API'}},
763
        :headers => credentials('jsmith'))
764
    end
765
    assert issue.is_private?
766

  
767
    tracker.update_attribute(:private_by_default, false)
768
    issue = new_record(Issue) do
769
      post(
770
        '/issues.json',
771
        :params => {:issue => {:project_id => 1, :tracker_id => 1, :subject => 'API'}},
772
        :headers => credentials('jsmith'))
773
    end
774
    assert_not issue.is_private?
775
  end
776

  
756 777
  test "PUT /issues/:id.xml" do
757 778
    assert_difference('Journal.count') do
758 779
      put(
(7-7/7)