0001-Per-role-visibility-settings-for-project-custom-fiel.patch

Marius BALTEANU, 2019-08-19 22:17

Download (4.5 KB)

View differences:

app/models/project.rb
870 870
    end
871 871
  end
872 872

  
873
  def visible_custom_field_values(user = nil)
874
    user ||= User.current
875
    custom_field_values.select do |value|
876
      value.custom_field.visible_by?(project, user)
877
    end
878
  end
879

  
873 880
  private
874 881

  
875 882
  def update_inherited_members
app/models/project_custom_field.rb
22 22
    :label_project_plural
23 23
  end
24 24

  
25
  def visible_by?(project, user=User.current)
26
    super || (roles & user.roles_for_project(project)).present?
27
  end
28

  
25 29
  def visibility_by_project_condition(project_key=nil, user=User.current, id_column=nil)
26 30
    project_key ||= "#{Project.table_name}.id"
27 31
    super(project_key, user, id_column)
app/views/custom_fields/_form.html.erb
34 34
  <div class="box tabular">
35 35
    <p><%= f.check_box :is_required %></p>
36 36

  
37
    <% if %w(UserCustomField ProjectCustomField).include?(@custom_field.class.name) %>
37
    <% if %w(UserCustomField).include?(@custom_field.class.name) %>
38 38
      <p><%= f.check_box :visible %></p>
39 39
    <% end %>
40 40

  
......
53 53
    <%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
54 54
  </div>
55 55

  
56
  <% if %w(IssueCustomField TimeEntryCustomField).include?(@custom_field.class.name) %>
56
  <% if %w(IssueCustomField TimeEntryCustomField ProjectCustomField).include?(@custom_field.class.name) %>
57 57
    <%= render :partial => 'visibility_by_role_selector', :locals => { :f => f } %>
58 58
  <% end %>
59 59

  
app/views/projects/_form.html.erb
25 25

  
26 26
<%= wikitoolbar_for 'project_description' %>
27 27

  
28
<% @project.custom_field_values.each do |value| %>
28
<% @project.visible_custom_field_values.each do |value| %>
29 29
  <p><%= custom_field_tag_with_label :project, value %></p>
30 30
<% end %>
31 31
<%= call_hook(:view_projects_form, :project => @project, :form => f) %>
test/functional/custom_fields_controller_test.rb
126 126
    end
127 127
  end
128 128

  
129
  def test_new_project_custom_field
130
    get :new, :params => {
131
        :type => 'ProjectCustomField'
132
      }
133
    assert_response :success
134

  
135
    assert_select 'form#custom_field_form' do
136
      assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' do
137
        assert_select 'option[value=user]', :text => 'User'
138
        assert_select 'option[value=version]', :text => 'Version'
139
      end
140

  
141
      # Visibility
142
      assert_select 'input[type=radio][name=?]', 'custom_field[visible]', 2
143
      assert_select 'input[type=checkbox][name=?]', 'custom_field[role_ids][]', 3
144

  
145
      assert_select 'input[type=hidden][name=type][value=ProjectCustomField]'
146
    end
147
  end
148

  
129 149
  def test_new_time_entry_custom_field_should_not_show_trackers_and_projects
130 150
    get :new, :params => {
131 151
        :type => 'TimeEntryCustomField'
test/functional/projects_controller_test.rb
726 726
    assert_select 'a#tab-activities'
727 727
  end
728 728

  
729
  def test_settings_should_not_display_custom_fields_not_visible_for_user
730
    @request.session[:user_id] = 2
731

  
732
    ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
733
    get :settings, :params => {
734
        :id => 'ecookbook'
735
      }
736
    assert_response :success
737

  
738
    assert_select 'select#project_custom_field_values_3', :count => 0
739
  end
740

  
729 741
  def test_update
730 742
    @request.session[:user_id] = 2 # manager
731 743
    post :update, :params => {