diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index 5245d5ba0..7701cbfe2 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -40,8 +40,10 @@ class IssueQuery < Query QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true), QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours", :totalable => true), QueryColumn.new(:total_estimated_hours, - :sortable => -> { "COALESCE((SELECT SUM(estimated_hours) FROM #{Issue.table_name} subtasks" + - " WHERE #{Issue.visible_condition(User.current).gsub(/\bissues\b/, 'subtasks')} AND subtasks.root_id = #{Issue.table_name}.root_id AND subtasks.lft >= #{Issue.table_name}.lft AND subtasks.rgt <= #{Issue.table_name}.rgt), 0)" }, + :sortable => -> { + "COALESCE((SELECT SUM(estimated_hours) FROM #{Issue.table_name} subtasks" + + " WHERE #{Issue.visible_condition(User.current).gsub(/\bissues\b/, 'subtasks')} AND subtasks.root_id = #{Issue.table_name}.root_id AND subtasks.lft >= #{Issue.table_name}.lft AND subtasks.rgt <= #{Issue.table_name}.rgt), 0)" + }, :default_order => 'desc'), QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio", :groupable => true), TimestampQueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc', :groupable => true), diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 9701622c8..d2661d078 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -189,6 +189,13 @@ class TimeEntry < ActiveRecord::Base editable_custom_field_values(user).map(&:custom_field).uniq end + def visible_custom_field_values(user = nil) + user ||= User.current + custom_field_values.select do |value| + value.custom_field.visible_by?(project, user) + end + end + def assignable_users users = [] if project diff --git a/app/models/time_entry_custom_field.rb b/app/models/time_entry_custom_field.rb index 9ef820efb..601e1b962 100644 --- a/app/models/time_entry_custom_field.rb +++ b/app/models/time_entry_custom_field.rb @@ -21,5 +21,13 @@ class TimeEntryCustomField < CustomField def type_name :label_spent_time end -end + def visible_by?(project, user=User.current) + super || (roles & user.roles_for_project(project)).present? + end + + def validate_custom_field + super + errors.add(:base, l(:label_role_plural) + ' ' + l('activerecord.errors.messages.blank')) unless visible? || roles.present? + end +end diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erb index cac457ce2..e428a27c6 100644 --- a/app/views/custom_fields/_form.html.erb +++ b/app/views/custom_fields/_form.html.erb @@ -31,83 +31,75 @@
<%= f.check_box :is_required %>
- <% if @custom_field.format.is_filter_supported %> -<%= f.check_box :is_filter %>
- <% end %> - <% if @custom_field.format.searchable_supported %> -<%= f.check_box :searchable %>
- <% end %> +<%= f.check_box :is_required %>
+ <% if @custom_field.format.is_filter_supported %> +<%= f.check_box :is_filter %>
+ <% end %> + <% if @custom_field.format.searchable_supported %> +<%= f.check_box :searchable %>
+ <% end %> +<%= f.check_box :is_required %>
-<%= f.check_box :visible %>
-<%= f.check_box :editable %>
- <% if @custom_field.format.is_filter_supported %> -<%= f.check_box :is_filter %>
- <% end %> +<%= f.check_box :is_required %>
+<%= f.check_box :visible %>
+<%= f.check_box :editable %>
+ <% if @custom_field.format.is_filter_supported %> +<%= f.check_box :is_filter %>
+ <% end %> +<%= f.check_box :is_required %>
-<%= f.check_box :visible %>
- <% if @custom_field.format.searchable_supported %> -<%= f.check_box :searchable %>
- <% end %> - <% if @custom_field.format.is_filter_supported %> -<%= f.check_box :is_filter %>
- <% end %> +<%= f.check_box :is_required %>
+<%= f.check_box :visible %>
+ <% if @custom_field.format.searchable_supported %> +<%= f.check_box :searchable %>
+ <% end %> + <% if @custom_field.format.is_filter_supported %> +<%= f.check_box :is_filter %>
+ <% end %> +<%= f.check_box :is_required %>
- <% if @custom_field.format.is_filter_supported %> -<%= f.check_box :is_filter %>
- <% end %> +<%= f.check_box :is_required %>
+ <% if @custom_field.format.is_filter_supported %> +<%= f.check_box :is_filter %>
+ <% end %> +<%= f.check_box :is_required %>
- <% if @custom_field.format.is_filter_supported %> -<%= f.check_box :is_filter %>
- <% end %> +<%= f.check_box :is_required %>
+ <% if @custom_field.format.is_filter_supported %> +<%= f.check_box :is_filter %>
+ <% end %> +<%= f.check_box :is_required %>
- <% if @custom_field.format.is_filter_supported %> -<%= f.check_box :is_filter %>
- <% end %> +<%= f.check_box :is_required %>
+ <% if @custom_field.format.is_filter_supported %> +<%= f.check_box :is_filter %>
+ <% end %> +<%= f.check_box :is_required %>
- +