Project

General

Profile

Feature #23997 » 0001-Per-role-visibility-settings-for-project-custom-fiel.patch

Marius BĂLTEANU, 2019-08-12 23:48

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
57 57
<% when "ProjectCustomField" %>
58 58
    <div class="box tabular">
59 59
      <p><%= f.check_box :is_required %></p>
60
      <p><%= f.check_box :visible %></p>
61 60
      <% if @custom_field.format.searchable_supported %>
62 61
      <p><%= f.check_box :searchable %></p>
63 62
      <% end %>
......
65 64
      <p><%= f.check_box :is_filter %></p>
66 65
      <% end %>
67 66
    </div>
67
    <%= render :partial => 'visibility_by_role_selector' %>
68 68

  
69 69
<% when "VersionCustomField" %>
70 70
    <div class="box tabular">
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) %>
app/views/projects/show.html.erb
132 132
	<ul class="subprojects">
133 133
	  <% @subprojects.each do |project| %>
134 134
	  <li><%= link_to(project.name, project_path(project), :class => project.css_classes).html_safe %></li>
135
	  <% end %> 
135
	  <% end %>
136 136
    </ul>
137 137
  </div>
138 138
  <% end %>
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 => {
(3-3/4)