##// END OF EJS Templates
Adds visibility condition to Issue.by_* count methods....
Jean-Philippe Lang -
r5245:fee9d605a353
parent child
Show More
@@ -647,14 +647,16 class Issue < ActiveRecord::Base
647 def self.by_subproject(project)
647 def self.by_subproject(project)
648 ActiveRecord::Base.connection.select_all("select s.id as status_id,
648 ActiveRecord::Base.connection.select_all("select s.id as status_id,
649 s.is_closed as closed,
649 s.is_closed as closed,
650 i.project_id as project_id,
650 #{Issue.table_name}.project_id as project_id,
651 count(i.id) as total
651 count(#{Issue.table_name}.id) as total
652 from
652 from
653 #{Issue.table_name} i, #{IssueStatus.table_name} s
653 #{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s
654 where
654 where
655 i.status_id=s.id
655 #{Issue.table_name}.status_id=s.id
656 and i.project_id IN (#{project.descendants.active.collect{|p| p.id}.join(',')})
656 and #{Issue.table_name}.project_id = #{Project.table_name}.id
657 group by s.id, s.is_closed, i.project_id") if project.descendants.active.any?
657 and #{visible_condition(User.current, :project => project, :with_subprojects => true)}
658 and #{Issue.table_name}.project_id <> #{project.id}
659 group by s.id, s.is_closed, #{Issue.table_name}.project_id") if project.descendants.active.any?
658 end
660 end
659 # End ReportsController extraction
661 # End ReportsController extraction
660
662
@@ -864,20 +866,19 class Issue < ActiveRecord::Base
864 select_field = options.delete(:field)
866 select_field = options.delete(:field)
865 joins = options.delete(:joins)
867 joins = options.delete(:joins)
866
868
867 where = "i.#{select_field}=j.id"
869 where = "#{Issue.table_name}.#{select_field}=j.id"
868
870
869 ActiveRecord::Base.connection.select_all("select s.id as status_id,
871 ActiveRecord::Base.connection.select_all("select s.id as status_id,
870 s.is_closed as closed,
872 s.is_closed as closed,
871 j.id as #{select_field},
873 j.id as #{select_field},
872 count(i.id) as total
874 count(#{Issue.table_name}.id) as total
873 from
875 from
874 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{joins} j
876 #{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s, #{joins} j
875 where
877 where
876 i.status_id=s.id
878 #{Issue.table_name}.status_id=s.id
877 and #{where}
879 and #{where}
878 and i.project_id=#{project.id}
880 and #{Issue.table_name}.project_id=#{Project.table_name}.id
881 and #{visible_condition(User.current, :project => project)}
879 group by s.id, s.is_closed, j.id")
882 group by s.id, s.is_closed, j.id")
880 end
883 end
881
882
883 end
884 end
@@ -788,45 +788,53 class IssueTest < ActiveSupport::TestCase
788 end
788 end
789
789
790 test "#by_tracker" do
790 test "#by_tracker" do
791 User.current = User.anonymous
791 groups = Issue.by_tracker(Project.find(1))
792 groups = Issue.by_tracker(Project.find(1))
792 assert_equal 3, groups.size
793 assert_equal 3, groups.size
793 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
794 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
794 end
795 end
795
796
796 test "#by_version" do
797 test "#by_version" do
798 User.current = User.anonymous
797 groups = Issue.by_version(Project.find(1))
799 groups = Issue.by_version(Project.find(1))
798 assert_equal 3, groups.size
800 assert_equal 3, groups.size
799 assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i}
801 assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i}
800 end
802 end
801
803
802 test "#by_priority" do
804 test "#by_priority" do
805 User.current = User.anonymous
803 groups = Issue.by_priority(Project.find(1))
806 groups = Issue.by_priority(Project.find(1))
804 assert_equal 4, groups.size
807 assert_equal 4, groups.size
805 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
808 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
806 end
809 end
807
810
808 test "#by_category" do
811 test "#by_category" do
812 User.current = User.anonymous
809 groups = Issue.by_category(Project.find(1))
813 groups = Issue.by_category(Project.find(1))
810 assert_equal 2, groups.size
814 assert_equal 2, groups.size
811 assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i}
815 assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i}
812 end
816 end
813
817
814 test "#by_assigned_to" do
818 test "#by_assigned_to" do
819 User.current = User.anonymous
815 groups = Issue.by_assigned_to(Project.find(1))
820 groups = Issue.by_assigned_to(Project.find(1))
816 assert_equal 2, groups.size
821 assert_equal 2, groups.size
817 assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i}
822 assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i}
818 end
823 end
819
824
820 test "#by_author" do
825 test "#by_author" do
826 User.current = User.anonymous
821 groups = Issue.by_author(Project.find(1))
827 groups = Issue.by_author(Project.find(1))
822 assert_equal 4, groups.size
828 assert_equal 4, groups.size
823 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
829 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
824 end
830 end
825
831
826 test "#by_subproject" do
832 test "#by_subproject" do
833 User.current = User.anonymous
827 groups = Issue.by_subproject(Project.find(1))
834 groups = Issue.by_subproject(Project.find(1))
828 assert_equal 2, groups.size
835 # Private descendant not visible
829 assert_equal 5, groups.inject(0) {|sum, group| sum + group['total'].to_i}
836 assert_equal 1, groups.size
837 assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i}
830 end
838 end
831
839
832
840
General Comments 0
You need to be logged in to leave comments. Login now