Index: app/helpers/issues_helper.rb =================================================================== --- app/helpers/issues_helper.rb (revision 10764) +++ app/helpers/issues_helper.rb (working copy) @@ -146,12 +146,13 @@ end def render_custom_fields_rows(issue) - return if issue.custom_field_values.empty? + local_viewablecf=issue.viewable_custom_field_values + return if local_viewablecf.empty? ordered_values = [] - half = (issue.custom_field_values.size / 2.0).ceil + half = (local_viewablecf.size / 2.0).ceil half.times do |i| - ordered_values << issue.custom_field_values[i] - ordered_values << issue.custom_field_values[i + half] + ordered_values << local_viewablecf[i] + ordered_values << local_viewablecf[i + half] end s = "\n" n = 0 @@ -221,6 +222,7 @@ strings = [] values_by_field = {} details.each do |detail| + unless detail.journal.issue.hidden_attribute?(detail.prop_key) if detail.property == 'cf' field_id = detail.prop_key field = CustomField.find_by_id(field_id) @@ -237,7 +239,9 @@ end strings << show_detail(detail, no_html, options) end + end values_by_field.each do |field_id, changes| + unless detail.journal.issue.hidden_attribute?(detail.prop_key) detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) if changes[:added].any? detail.value = changes[:added] @@ -246,6 +250,7 @@ detail.old_value = changes[:deleted] strings << show_detail(detail, no_html, options) end + end end strings end @@ -381,6 +386,10 @@ # csv lines issues.each do |issue| col_values = columns.collect do |column| + hidden_fields = issue.hidden_attribute_names.map {|field| field.sub(/_id$/, '')} + if hidden_fields.include?(column.is_a?(QueryCustomFieldColumn) ? column.custom_field.id.to_s : column.name.to_s) + "" + else s = if column.is_a?(QueryCustomFieldColumn) cv = issue.custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id} show_value(cv) @@ -398,6 +407,7 @@ end s.to_s end + end csv << [ issue.id.to_s ] + col_values.collect {|c| Redmine::CodesetUtil.from_utf8(c.to_s, encoding) } + (options[:description] ? [Redmine::CodesetUtil.from_utf8(issue.description, encoding)] : []) end Index: app/models/issue.rb =================================================================== --- app/models/issue.rb (revision 10764) +++ app/models/issue.rb (working copy) @@ -446,6 +446,14 @@ end end + # Returns the custom_field_values that can be viewed by the given user + # For now: just exclude Fix Info and RNs, as it is printed seperately below description. + def viewable_custom_field_values(user=nil) + custom_field_values.reject do |value| + hidden_attribute_names(user).include?(value.custom_field_id.to_s) + end + end + # Returns the names of attributes that are read-only for user or the current user # For users with multiple roles, the read-only fields are the intersection of # read-only fields of each role @@ -455,9 +463,14 @@ # issue.read_only_attribute_names # => ['due_date', '2'] # issue.read_only_attribute_names(user) # => [] def read_only_attribute_names(user=nil) - workflow_rule_by_attribute(user).reject {|attr, rule| rule != 'readonly'}.keys + workflow_rule_by_attribute(user).reject {|attr, rule| rule != 'readonly' and rule != 'hidden'}.keys end + # Same as above, but for hidden fields + def hidden_attribute_names(user=nil) + workflow_rule_by_attribute(user).reject {|attr, rule| rule != 'hidden'}.keys + end + # Returns the names of required attributes for user or the current user # For users with multiple roles, the required fields are the intersection of # required fields of each role @@ -475,6 +488,16 @@ required_attribute_names(user).include?(name.to_s) end + # Returns true if the attribute should be hidden for user + def hidden_attribute?(name, user=nil) + logger.info("For " + name.to_s + ", It will return " + hidden_attribute_names(user).include?(name.to_s).to_s ) +# hidden_attribute_names(user).each do |n| +# logger.info(n.to_s) +# end + hidden_attribute_names(user).include?(name.to_s) + end + + # Returns a hash of the workflow rule by attribute for the given user # # Examples: Index: app/models/project.rb =================================================================== --- app/models/project.rb (revision 10764) +++ app/models/project.rb (working copy) @@ -146,6 +146,36 @@ user.allowed_to?(:view_project, self) end + # Returns list of attributes that are hidden on all statuses of all trackers for +user+ or the current user. + def completely_hidden_attribute_names(user=nil) + user_real = user || User.current + roles = user_real.admin ? Role.all : user_real.roles_for_project(self) + return {} if roles.empty? + + result = {} + workflow_permissions = WorkflowPermission.where(:tracker_id => trackers.map(&:id), :old_status_id => IssueStatus.all.map(&:id), :role_id => roles.map(&:id), :rule => 'hidden').all + + if workflow_permissions.any? + workflow_rules = workflow_permissions.inject({}) do |h, wp| + h[wp.field_name] ||= [] + h[wp.field_name] << wp.rule + h + end + workflow_rules.each do |attr, rules| + next if rules.size < (roles.size * trackers.size * IssueStatus.all.size) + uniq_rules = rules.uniq + if uniq_rules.size == 1 + result[attr] = uniq_rules.first + else + result[attr] = 'required' + end + end + end + + result.keys + end + + # Returns a SQL conditions string used to find all projects visible by the specified user. # # Examples: Index: app/models/query.rb =================================================================== --- app/models/query.rb (revision 10764) +++ app/models/query.rb (working copy) @@ -44,8 +44,13 @@ end def value(issue) + hidden_fields = issue.hidden_attribute_names.map {|field| field.sub(/_id$/, '')} + if hidden_fields.include?(name.to_s) + "" + else issue.send name end + end def css_classes name @@ -360,6 +365,11 @@ Tracker.disabled_core_fields(trackers).each {|field| @available_filters.delete field } + + project.completely_hidden_attribute_names.each {|field| + @available_filters.delete field + } + @available_filters.each do |field, options| options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, '')) end @@ -451,10 +461,13 @@ def available_columns return @available_columns if @available_columns @available_columns = ::Query.available_columns.dup + + hidden_fields = project.completely_hidden_attribute_names.map {|field| field.sub(/_id$/, '')} + @available_columns += (project ? project.all_issue_custom_fields : IssueCustomField.find(:all) - ).collect {|cf| QueryCustomFieldColumn.new(cf) } + ).collect {|cf| QueryCustomFieldColumn.new(cf) }.reject{|column| hidden_fields.include?(column.custom_field.id.to_s) } if User.current.allowed_to?(:view_time_entries, project, :global => true) index = nil @@ -477,6 +490,10 @@ @available_columns.reject! {|column| disabled_fields.include?(column.name.to_s) } + + @available_columns.reject! {|column| + hidden_fields.include?(column.name.to_s) + } @available_columns end @@ -966,6 +983,7 @@ @available_filters ||= {} custom_fields.select(&:is_filter?).each do |field| + unless project.completely_hidden_attribute_names.include?(field.id.to_s) case field.field_format when "text" options = { :type => :text, :order => 20 } @@ -1002,6 +1020,7 @@ }) end end + end def add_associations_custom_fields_filters(*associations) fields_by_class = CustomField.where(:is_filter => true).group_by(&:class) Index: app/views/issues/_form_custom_fields.html.erb =================================================================== --- app/views/issues/_form_custom_fields.html.erb (revision 10764) +++ app/views/issues/_form_custom_fields.html.erb (working copy) @@ -1,7 +1,7 @@
<% i = 0 %> -<% split_on = (@issue.custom_field_values.size / 2.0).ceil - 1 %> +<% split_on = (@issue.editable_custom_field_values.size / 2.0).ceil - 1 %> <% @issue.editable_custom_field_values.each do |value| %>

<%= custom_field_tag_with_label :issue, value, :required => @issue.required_attribute?(value.custom_field_id) %>

<% if i == split_on -%> Index: app/views/issues/_history.html.erb =================================================================== --- app/views/issues/_history.html.erb (revision 10764) +++ app/views/issues/_history.html.erb (working copy) @@ -1,11 +1,12 @@ <% reply_links = authorize_for('issues', 'edit') -%> <% for journal in journals %> + <% if details_to_strings(journal.details).any? || journal.notes.blank? == false %>

<%= link_to "##{journal.indice}", {:anchor => "note-#{journal.indice}"}, :class => "journal-link" %> <%= avatar(journal.user, :size => "24") %> <%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %>

- + <% if journal.details.any? %>
    <% details_to_strings(journal.details).each do |string| %> @@ -17,6 +18,7 @@
<%= call_hook(:view_issues_history_journal_bottom, { :journal => journal }) %> + <% end %> <% end %> <% heads_for_wiki_formatter if User.current.allowed_to?(:edit_issue_notes, issue.project) || User.current.allowed_to?(:edit_own_issue_notes, issue.project) %> Index: app/views/issues/show.html.erb =================================================================== --- app/views/issues/show.html.erb (revision 10764) +++ app/views/issues/show.html.erb (working copy) @@ -33,29 +33,33 @@ <%= issue_fields_rows do |rows| + unless @issue.hidden_attribute?('status') rows.left l(:field_status), h(@issue.status.name), :class => 'status' + end + unless @issue.hidden_attribute?('priority') rows.left l(:field_priority), h(@issue.priority.name), :class => 'priority' + end - unless @issue.disabled_core_fields.include?('assigned_to_id') + unless @issue.disabled_core_fields.include?('assigned_to_id') || @issue.hidden_attribute?('assigned_to_id') rows.left l(:field_assigned_to), avatar(@issue.assigned_to, :size => "14").to_s.html_safe + (@issue.assigned_to ? link_to_user(@issue.assigned_to) : "-"), :class => 'assigned-to' end - unless @issue.disabled_core_fields.include?('category_id') + unless @issue.disabled_core_fields.include?('category_id') || @issue.hidden_attribute?('category_id') rows.left l(:field_category), h(@issue.category ? @issue.category.name : "-"), :class => 'category' end - unless @issue.disabled_core_fields.include?('fixed_version_id') + unless @issue.disabled_core_fields.include?('fixed_version_id') || @issue.hidden_attribute?('fixed_version_id') rows.left l(:field_fixed_version), (@issue.fixed_version ? link_to_version(@issue.fixed_version) : "-"), :class => 'fixed-version' end - unless @issue.disabled_core_fields.include?('start_date') + unless @issue.disabled_core_fields.include?('start_date') || @issue.hidden_attribute?('start_date') rows.right l(:field_start_date), format_date(@issue.start_date), :class => 'start-date' end - unless @issue.disabled_core_fields.include?('due_date') + unless @issue.disabled_core_fields.include?('due_date') || @issue.hidden_attribute?('due_date') rows.right l(:field_due_date), format_date(@issue.due_date), :class => 'due-date' end - unless @issue.disabled_core_fields.include?('done_ratio') + unless @issue.disabled_core_fields.include?('done_ratio') || @issue.hidden_attribute?('done_ratio') rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, :width => '80px', :legend => "#{@issue.done_ratio}%"), :class => 'progress' end - unless @issue.disabled_core_fields.include?('estimated_hours') + unless @issue.disabled_core_fields.include?('estimated_hours') || @issue.hidden_attribute?('estimated_hours') unless @issue.estimated_hours.nil? rows.right l(:field_estimated_hours), l_hours(@issue.estimated_hours), :class => 'estimated-hours' end Index: config/locales/en.yml =================================================================== --- config/locales/en.yml (revision 10764) +++ config/locales/en.yml (working copy) @@ -879,6 +879,7 @@ label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + label_hidden: " Hidden " label_attribute_of_project: "Project's %{name}" label_attribute_of_author: "Author's %{name}" label_attribute_of_assigned_to: "Assignee's %{name}" Index: lib/redmine/export/pdf.rb =================================================================== --- lib/redmine/export/pdf.rb (revision 10764) +++ lib/redmine/export/pdf.rb (working copy) @@ -520,17 +520,17 @@ pdf.Ln left = [] - left << [l(:field_status), issue.status] - left << [l(:field_priority), issue.priority] - left << [l(:field_assigned_to), issue.assigned_to] unless issue.disabled_core_fields.include?('assigned_to_id') - left << [l(:field_category), issue.category] unless issue.disabled_core_fields.include?('category_id') - left << [l(:field_fixed_version), issue.fixed_version] unless issue.disabled_core_fields.include?('fixed_version_id') + left << [l(:field_status), issue.status] unless issue.hidden_attribute?('status') + left << [l(:field_priority), issue.priority] unless issue.hidden_attribute?('priority') + left << [l(:field_assigned_to), issue.assigned_to] unless issue.disabled_core_fields.include?('assigned_to_id') or issue.hidden_attribute?('assigned_to_id') + left << [l(:field_category), issue.category] unless issue.disabled_core_fields.include?('category_id') or issue.hidden_attribute?('category_id') + left << [l(:field_fixed_version), issue.fixed_version] unless issue.disabled_core_fields.include?('fixed_version_id') or issue.hidden_attribute?('fixed_version_id') right = [] - right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date') - right << [l(:field_due_date), format_date(issue.due_date)] unless issue.disabled_core_fields.include?('due_date') - right << [l(:field_done_ratio), "#{issue.done_ratio}%"] unless issue.disabled_core_fields.include?('done_ratio') - right << [l(:field_estimated_hours), l_hours(issue.estimated_hours)] unless issue.disabled_core_fields.include?('estimated_hours') + right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date') or issue.hidden_attribute?('start_date') + right << [l(:field_due_date), format_date(issue.due_date)] unless issue.disabled_core_fields.include?('due_date') or issue.hidden_attribute?('due_date') + right << [l(:field_done_ratio), "#{issue.done_ratio}%"] unless issue.disabled_core_fields.include?('done_ratio') or issue.hidden_attribute?('done_ratio') + right << [l(:field_estimated_hours), l_hours(issue.estimated_hours)] unless issue.disabled_core_fields.include?('estimated_hours') or issue.hidden_attribute?('estimated_hours') right << [l(:label_spent_time), l_hours(issue.total_spent_hours)] if User.current.allowed_to?(:view_time_entries, issue.project) rows = left.size > right.size ? left.size : right.size @@ -541,9 +541,9 @@ right << nil end - half = (issue.custom_field_values.size / 2.0).ceil - issue.custom_field_values.each_with_index do |custom_value, i| - (i < half ? left : right) << [custom_value.custom_field.name, show_value(custom_value)] + half = (issue.viewable_custom_field_values.size / 2.0).ceil + issue.viewable_custom_field_values.each_with_index do |custom_value, i| + (i < half ? left : right) << [custom_value.custom_field.name, show_value(custom_value)] unless issue.hidden_attribute?(custom_value.custom_field.name) end rows = left.size > right.size ? left.size : right.size