1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598
|
# BEGIN BPS TAGGED BLOCK {{{
#
# COPYRIGHT:
#
# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC
# <sales@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
#
#
# LICENSE:
#
# This work is made available to you under the terms of Version 2 of
# the GNU General Public License. A copy of that license should have
# been provided with this software, but in any event can be snarfed
# from www.gnu.org.
#
# This work is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 or visit their web page on the internet at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
#
#
# CONTRIBUTION SUBMISSION POLICY:
#
# (The following paragraph is not intended to limit the rights granted
# to you to modify and distribute this software under the terms of
# the GNU General Public License and is only of importance to you if
# you choose to contribute your changes and enhancements to the
# community by submitting them to Best Practical Solutions, LLC.)
#
# By intentionally submitting any modifications, corrections or
# derivatives to this work, or any other work intended for use with
# Request Tracker, to Best Practical Solutions, LLC, you confirm that
# you are the copyright holder for those contributions and you grant
# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
# royalty-free, perpetual, license to use, copy, create derivative
# works based on those contributions, and sublicense and distribute
# those contributions and any derivatives thereof.
#
# END BPS TAGGED BLOCK }}}
=head1 NAME
RT::Tickets - A collection of Ticket objects
=head1 SYNOPSIS
use RT::Tickets;
my $tickets = RT::Tickets->new($CurrentUser);
=head1 DESCRIPTION
A collection of RT::Tickets.
=head1 METHODS
=cut
package RT::Tickets;
use strict;
use warnings;
use base 'RT::SearchBuilder';
use Role::Basic 'with';
with 'RT::SearchBuilder::Role::Roles';
use Scalar::Util qw/blessed/;
use 5.010;
use RT::Ticket;
use RT::SQL;
sub Table { 'Tickets'}
use RT::CustomFields;
use RT::CustomRoles;
__PACKAGE__->RegisterCustomFieldJoin(@$_) for
[ "RT::Transaction" => sub { $_[0]->JoinTransactions } ],
[ "RT::Queue" => sub {
# XXX: Could avoid join and use main.Queue with some refactoring?
return $_[0]->{_sql_aliases}{queues} ||= $_[0]->Join(
ALIAS1 => 'main',
FIELD1 => 'Queue',
TABLE2 => 'Queues',
FIELD2 => 'id',
);
}
];
# Configuration Tables:
# FIELD_METADATA is a mapping of searchable Field name, to Type, and other
# metadata.
our %FIELD_METADATA = (
Status => [ 'STRING', ], #loc_left_pair
SLA => [ 'STRING', ], #loc_left_pair
Queue => [ 'QUEUE' ], #loc_left_pair
Type => [ 'ENUM', ], #loc_left_pair
Creator => [ 'ENUM' => 'User', ], #loc_left_pair
LastUpdatedBy => [ 'ENUM' => 'User', ], #loc_left_pair
Owner => [ 'WATCHERFIELD' => 'Owner', ], #loc_left_pair
EffectiveId => [ 'INT', ], #loc_left_pair
id => [ 'ID', ], #loc_left_pair
InitialPriority => [ 'INT', ], #loc_left_pair
FinalPriority => [ 'INT', ], #loc_left_pair
Priority => [ 'INT', ], #loc_left_pair
TimeLeft => [ 'INT', ], #loc_left_pair
TimeWorked => [ 'INT', ], #loc_left_pair
TimeEstimated => [ 'INT', ], #loc_left_pair
Linked => [ 'LINK' ], #loc_left_pair
LinkedTo => [ 'LINK' => 'To' ], #loc_left_pair
LinkedFrom => [ 'LINK' => 'From' ], #loc_left_pair
MemberOf => [ 'LINK' => To => 'MemberOf', ], #loc_left_pair
DependsOn => [ 'LINK' => To => 'DependsOn', ], #loc_left_pair
RefersTo => [ 'LINK' => To => 'RefersTo', ], #loc_left_pair
HasMember => [ 'LINK' => From => 'MemberOf', ], #loc_left_pair
DependentOn => [ 'LINK' => From => 'DependsOn', ], #loc_left_pair
DependedOnBy => [ 'LINK' => From => 'DependsOn', ], #loc_left_pair
ReferredToBy => [ 'LINK' => From => 'RefersTo', ], #loc_left_pair
Told => [ 'DATE' => 'Told', ], #loc_left_pair
Starts => [ 'DATE' => 'Starts', ], #loc_left_pair
Started => [ 'DATE' => 'Started', ], #loc_left_pair
Due => [ 'DATE' => 'Due', ], #loc_left_pair
Resolved => [ 'DATE' => 'Resolved', ], #loc_left_pair
LastUpdated => [ 'DATE' => 'LastUpdated', ], #loc_left_pair
Created => [ 'DATE' => 'Created', ], #loc_left_pair
Subject => [ 'STRING', ], #loc_left_pair
Content => [ 'TRANSCONTENT', ], #loc_left_pair
ContentType => [ 'TRANSFIELD', ], #loc_left_pair
Filename => [ 'TRANSFIELD', ], #loc_left_pair
TransactionDate => [ 'TRANSDATE', ], #loc_left_pair
Requestor => [ 'WATCHERFIELD' => 'Requestor', ], #loc_left_pair
Requestors => [ 'WATCHERFIELD' => 'Requestor', ], #loc_left_pair
Cc => [ 'WATCHERFIELD' => 'Cc', ], #loc_left_pair
AdminCc => [ 'WATCHERFIELD' => 'AdminCc', ], #loc_left_pair
Watcher => [ 'WATCHERFIELD', ], #loc_left_pair
QueueCc => [ 'WATCHERFIELD' => 'Cc' => 'Queue', ], #loc_left_pair
QueueAdminCc => [ 'WATCHERFIELD' => 'AdminCc' => 'Queue', ], #loc_left_pair
QueueWatcher => [ 'WATCHERFIELD' => undef => 'Queue', ], #loc_left_pair
CustomRole => [ 'WATCHERFIELD' ], # loc_left_pair
CustomFieldValue => [ 'CUSTOMFIELD' => 'Ticket' ], #loc_left_pair
CustomField => [ 'CUSTOMFIELD' => 'Ticket' ], #loc_left_pair
CF => [ 'CUSTOMFIELD' => 'Ticket' ], #loc_left_pair
TxnCF => [ 'CUSTOMFIELD' => 'Transaction' ], #loc_left_pair
TransactionCF => [ 'CUSTOMFIELD' => 'Transaction' ], #loc_left_pair
QueueCF => [ 'CUSTOMFIELD' => 'Queue' ], #loc_left_pair
Lifecycle => [ 'LIFECYCLE' ], #loc_left_pair
Updated => [ 'TRANSDATE', ], #loc_left_pair
UpdatedBy => [ 'TRANSCREATOR', ], #loc_left_pair
OwnerGroup => [ 'MEMBERSHIPFIELD' => 'Owner', ], #loc_left_pair
RequestorGroup => [ 'MEMBERSHIPFIELD' => 'Requestor', ], #loc_left_pair
CCGroup => [ 'MEMBERSHIPFIELD' => 'Cc', ], #loc_left_pair
AdminCCGroup => [ 'MEMBERSHIPFIELD' => 'AdminCc', ], #loc_left_pair
WatcherGroup => [ 'MEMBERSHIPFIELD', ], #loc_left_pair
HasAttribute => [ 'HASATTRIBUTE', 1 ],
HasNoAttribute => [ 'HASATTRIBUTE', 0 ],
);
# Lower Case version of FIELDS, for case insensitivity
our %LOWER_CASE_FIELDS = map { ( lc($_) => $_ ) } (keys %FIELD_METADATA);
our %SEARCHABLE_SUBFIELDS = (
User => [qw(
EmailAddress Name RealName Nickname Organization Address1 Address2
City State Zip Country WorkPhone HomePhone MobilePhone PagerPhone id
)],
);
# Mapping of Field Type to Function
our %dispatch = (
ENUM => \&_EnumLimit,
INT => \&_IntLimit,
ID => \&_IdLimit,
LINK => \&_LinkLimit,
DATE => \&_DateLimit,
STRING => \&_StringLimit,
QUEUE => \&_QueueLimit,
TRANSFIELD => \&_TransLimit,
TRANSCONTENT => \&_TransContentLimit,
TRANSDATE => \&_TransDateLimit,
TRANSCREATOR => \&_TransCreatorLimit,
WATCHERFIELD => \&_WatcherLimit,
MEMBERSHIPFIELD => \&_WatcherMembershipLimit,
CUSTOMFIELD => \&_CustomFieldLimit,
HASATTRIBUTE => \&_HasAttributeLimit,
LIFECYCLE => \&_LifecycleLimit,
);
# Default EntryAggregator per type
# if you specify OP, you must specify all valid OPs
my %DefaultEA = (
INT => 'AND',
ENUM => {
'=' => 'OR',
'!=' => 'AND'
},
DATE => {
'IS' => 'OR',
'IS NOT' => 'OR',
'=' => 'OR',
'>=' => 'AND',
'<=' => 'AND',
'>' => 'AND',
'<' => 'AND'
},
STRING => {
'=' => 'OR',
'!=' => 'AND',
'LIKE' => 'AND',
'NOT LIKE' => 'AND'
},
QUEUE => {
'=' => 'OR',
'!=' => 'AND',
'LIKE' => 'OR',
'NOT LIKE' => 'AND'
},
TRANSFIELD => 'AND',
TRANSDATE => 'AND',
LINK => 'OR',
LINKFIELD => 'AND',
TARGET => 'AND',
BASE => 'AND',
WATCHERFIELD => {
'=' => 'OR',
'!=' => 'AND',
'LIKE' => 'OR',
'NOT LIKE' => 'AND'
},
HASATTRIBUTE => {
'=' => 'AND',
'!=' => 'AND',
},
CUSTOMFIELD => 'OR',
);
sub FIELDS { return \%FIELD_METADATA }
our @SORTFIELDS = qw(id Status
Queue Subject
Owner Created Due Starts Started
Told
Resolved LastUpdated Priority TimeWorked TimeLeft);
=head2 SortFields
Returns the list of fields that lists of tickets can easily be sorted by
=cut
sub SortFields {
my $self = shift;
return (@SORTFIELDS);
}
# BEGIN SQL STUFF *********************************
sub CleanSlate {
my $self = shift;
$self->SUPER::CleanSlate( @_ );
delete $self->{$_} foreach qw(
_sql_cf_alias
_sql_group_members_aliases
_sql_object_cfv_alias
_sql_role_group_aliases
_sql_trattachalias
_sql_u_watchers_alias_for_sort
_sql_u_watchers_aliases
_sql_current_user_can_see_applied
);
}
=head1 Limit Helper Routines
These routines are the targets of a dispatch table depending on the
type of field. They all share the same signature:
my ($self,$field,$op,$value,@rest) = @_;
The values in @rest should be suitable for passing directly to
DBIx::SearchBuilder::Limit.
Essentially they are an expanded/broken out (and much simplified)
version of what ProcessRestrictions used to do. They're also much
more clearly delineated by the TYPE of field being processed.
=head2 _IdLimit
Handle ID field.
=cut
sub _IdLimit {
my ( $sb, $field, $op, $value, @rest ) = @_;
if ( $value eq '__Bookmarked__' ) {
return $sb->_BookmarkLimit( $field, $op, $value, @rest );
} else {
return $sb->_IntLimit( $field, $op, $value, @rest );
}
}
sub _BookmarkLimit {
my ( $sb, $field, $op, $value, @rest ) = @_;
die "Invalid operator $op for __Bookmarked__ search on $field"
unless $op =~ /^(=|!=)$/;
my @bookmarks = $sb->CurrentUser->UserObj->Bookmarks;
return $sb->Limit(
FIELD => $field,
OPERATOR => $op,
VALUE => 0,
@rest,
) unless @bookmarks;
# as bookmarked tickets can be merged we have to use a join
# but it should be pretty lightweight
my $tickets_alias = $sb->Join(
TYPE => 'LEFT',
ALIAS1 => 'main',
FIELD1 => 'id',
TABLE2 => 'Tickets',
FIELD2 => 'EffectiveId',
);
$op = $op eq '='? 'IN': 'NOT IN';
$sb->Limit(
ALIAS => $tickets_alias,
FIELD => 'id',
OPERATOR => $op,
VALUE => [ @bookmarks ],
@rest,
);
}
=head2 _EnumLimit
Handle Fields which are limited to certain values, and potentially
need to be looked up from another class.
This subroutine actually handles two different kinds of fields. For
some the user is responsible for limiting the values. (i.e. Status,
Type).
For others, the value specified by the user will be looked by via
specified class.
Meta Data:
name of class to lookup in (Optional)
=cut
sub _EnumLimit {
my ( $sb, $field, $op, $value, @rest ) = @_;
# SQL::Statement changes != to <>. (Can we remove this now?)
$op = "!=" if $op eq "<>";
die "Invalid Operation: $op for $field" unless $op =~ /^(?:=|!=|IN|NOT IN)$/i;
my $meta = $FIELD_METADATA{$field};
if ( defined $meta->[1] && defined $value ) {
my $class = "RT::" . $meta->[1];
if ( ref $value eq 'ARRAY' ) {
my @values;
for my $i (@$value) {
if ( $i !~ /^\d+$/ ) {
my $o = $class->new( $sb->CurrentUser );
$o->Load($i);
push @values, $o->Id || 0;
}
else {
push @values, $i;
}
}
$value = \@values;
}
elsif ( $value !~ /^\d+$/ ) {
my $o = $class->new( $sb->CurrentUser );
$o->Load($value);
$value = $o->Id || 0;
}
} elsif ( $field eq "Type" ) {
$value = lc $value if $value =~ /^(ticket|approval|reminder)$/i;
}
$sb->Limit(
FIELD => $field,
VALUE => $value,
OPERATOR => $op,
@rest,
);
}
=head2 _IntLimit
Handle fields where the values are limited to integers. (For example,
Priority, TimeWorked.)
Meta Data:
None
=cut
sub _IntLimit {
my ( $sb, $field, $op, $value, @rest ) = @_;
my $is_a_like = $op =~ /MATCHES|ENDSWITH|STARTSWITH|LIKE/i;
# We want to support <id LIKE '1%'> for ticket autocomplete,
# but we need to explicitly typecast on Postgres
if ( $is_a_like && RT->Config->Get('DatabaseType') eq 'Pg' ) {
return $sb->Limit(
FUNCTION => "CAST(main.$field AS TEXT)",
OPERATOR => $op,
VALUE => $value,
@rest,
);
}
$sb->Limit(
FIELD => $field,
VALUE => $value,
OPERATOR => $op,
@rest,
);
}
=head2 _LinkLimit
Handle fields which deal with links between tickets. (MemberOf, DependsOn)
Meta Data:
1: Direction (From, To)
2: Link Type (MemberOf, DependsOn, RefersTo)
=cut
sub _LinkLimit {
my ( $sb, $field, $op, $value, @rest ) = @_;
my $meta = $FIELD_METADATA{$field};
die "Invalid Operator $op for $field" unless $op =~ /^(=|!=|IS|IS NOT)$/io;
my $is_negative = 0;
if ( $op eq '!=' || $op =~ /\bNOT\b/i ) {
$is_negative = 1;
}
my $is_null = 0;
$is_null = 1 if !$value || $value =~ /^null$/io;
my $direction = $meta->[1] || '';
my ($matchfield, $linkfield) = ('', '');
if ( $direction eq 'To' ) {
($matchfield, $linkfield) = ("Target", "Base");
}
elsif ( $direction eq 'From' ) {
($matchfield, $linkfield) = ("Base", "Target");
}
elsif ( $direction ) {
die "Invalid link direction '$direction' for $field\n";
} else {
$sb->_OpenParen;
$sb->_LinkLimit( 'LinkedTo', $op, $value, @rest );
$sb->_LinkLimit(
'LinkedFrom', $op, $value, @rest,
ENTRYAGGREGATOR => (($is_negative && $is_null) || (!$is_null && !$is_negative))? 'OR': 'AND',
);
$sb->_CloseParen;
return;
}
my $is_local = 1;
if ( $is_null ) {
$op = ($op =~ /^(=|IS)$/i)? 'IS': 'IS NOT';
}
elsif ( $value =~ /\D/ ) {
$value = RT::URI->new( $sb->CurrentUser )->CanonicalizeURI( $value );
$is_local = 0;
}
$matchfield = "Local$matchfield" if $is_local;
#For doing a left join to find "unlinked tickets" we want to generate a query that looks like this
# SELECT main.* FROM Tickets main
# LEFT JOIN Links Links_1 ON ( (Links_1.Type = 'MemberOf')
# AND(main.id = Links_1.LocalTarget))
# WHERE Links_1.LocalBase IS NULL;
if ( $is_null ) {
my $linkalias = $sb->Join(
TYPE => 'LEFT',
ALIAS1 => 'main',
FIELD1 => 'id',
TABLE2 => 'Links',
FIELD2 => 'Local' . $linkfield
);
$sb->Limit(
LEFTJOIN => $linkalias,
FIELD => 'Type',
OPERATOR => '=',
VALUE => $meta->[2],
) if $meta->[2];
$sb->Limit(
@rest,
ALIAS => $linkalias,
FIELD => $matchfield,
OPERATOR => $op,
VALUE => 'NULL',
QUOTEVALUE => 0,
);
}
else {
my $linkalias = $sb->Join(
TYPE => 'LEFT',
ALIAS1 => 'main',
FIELD1 => 'id',
TABLE2 => 'Links',
FIELD2 => 'Local' . $linkfield
);
$sb->Limit(
LEFTJOIN => $linkalias,
FIELD => 'Type',
OPERATOR => '=',
VALUE => $meta->[2],
) if $meta->[2];
$sb->Limit(
LEFTJOIN => $linkalias,
FIELD => $matchfield,
OPERATOR => '=',
VALUE => $value,
);
$sb->Limit(
@rest,
ALIAS => $linkalias,
FIELD => $matchfield,
OPERATOR => $is_negative? 'IS': 'IS NOT',
VALUE => 'NULL',
QUOTEVALUE => 0,
);
}
}
=head2 _DateLimit
Handle date fields. (Created, LastTold..)
Meta Data:
1: type of link. (Probably not necessary.)
=cut
sub _DateLimit {
my ( $sb, $field, $op, $value, %rest ) = @_;
die "Invalid Date Op: $op"
unless $op =~ /^(=|>|<|>=|<=|IS(\s+NOT)?)$/i;
my $meta = $FIELD_METADATA{$field};
die "Incorrect Meta Data for $field"
unless ( defined $meta->[1] );
if ( $op =~ /^(IS(\s+NOT)?)$/i) {
return $sb->Limit(
FUNCTION => $sb->NotSetDateToNullFunction,
FIELD => $meta->[1],
OPERATOR => $op,
VALUE => "NULL",
%rest,
);
}
if ( my $subkey = $rest{SUBKEY} ) {
if ( $subkey eq 'DayOfWeek' && $op !~ /IS/i && $value =~ /[^0-9]/ ) {
for ( my $i = 0; $i < @RT::Date::DAYS_OF_WEEK; $i++ ) {
# Use a case-insensitive regex for better matching across
# locales since we don't have fc() and lc() is worse. Really
# we should be doing Unicode normalization too, but we don't do
# that elsewhere in RT.
#
# XXX I18N: Replace the regex with fc() once we're guaranteed 5.16.
next unless lc $RT::Date::DAYS_OF_WEEK[ $i ] eq lc $value
or $sb->CurrentUser->loc($RT::Date::DAYS_OF_WEEK[ $i ]) =~ /^\Q$value\E$/i;
$value = $i; last;
}
return $sb->Limit( FIELD => 'id', VALUE => 0, %rest )
if $value =~ /[^0-9]/;
}
elsif ( $subkey eq 'Month' && $op !~ /IS/i && $value =~ /[^0-9]/ ) {
for ( my $i = 0; $i < @RT::Date::MONTHS; $i++ ) {
# Use a case-insensitive regex for better matching across
# locales since we don't have fc() and lc() is worse. Really
# we should be doing Unicode normalization too, but we don't do
# that elsewhere in RT.
#
# XXX I18N: Replace the regex with fc() once we're guaranteed 5.16.
next unless lc $RT::Date::MONTHS[ $i ] eq lc $value
or $sb->CurrentUser->loc($RT::Date::MONTHS[ $i ]) =~ /^\Q$value\E$/i;
$value = $i + 1; last;
}
return $sb->Limit( FIELD => 'id', VALUE => 0, %rest )
if $value =~ /[^0-9]/;
}
my $tz;
if ( RT->Config->Get('ChartsTimezonesInDB') ) {
my $to = $sb->CurrentUser->UserObj->Timezone
|| RT->Config->Get('Timezone');
$tz = { From => 'UTC', To => $to }
if $to && lc $to ne 'utc';
}
# $subkey is validated by DateTimeFunction
my $function = $RT::Handle->DateTimeFunction(
Type => $subkey,
Field => $sb->NotSetDateToNullFunction,
Timezone => $tz,
);
return $sb->Limit(
FUNCTION => $function,
FIELD => $meta->[1],
OPERATOR => $op,
VALUE => $value,
%rest,
);
}
my $date;
# this is to make queries like "Due > 0" still work
$rest{QUOTEVALUE} = 1 if $value eq '0';
if ( $rest{QUOTEVALUE} ) {
$date = RT::Date->new( $sb->CurrentUser );
$date->Set( Format => 'unknown', Value => $value );
}
if ( $op eq "=" && $date ) {
# if we're specifying =, that means we want everything on a
# particular single day. in the database, we need to check for >
# and < the edges of that day.
$date->SetToMidnight( Timezone => 'user' );
my $daystart = $date->ISO;
$date->AddDay;
my $dayend = $date->ISO;
$sb->_OpenParen;
$sb->Limit(
FIELD => $meta->[1],
OPERATOR => ">=",
VALUE => $daystart,
%rest,
);
$sb->Limit(
FIELD => $meta->[1],
OPERATOR => "<",
VALUE => $dayend,
%rest,
ENTRYAGGREGATOR => 'AND',
);
$sb->_CloseParen;
}
else {
$sb->Limit(
FUNCTION => $sb->NotSetDateToNullFunction,
FIELD => $meta->[1],
OPERATOR => $op,
VALUE => $date ? $date->ISO : $value,
%rest,
);
}
}
=head2 _StringLimit
Handle simple fields which are just strings. (Subject,Type)
Meta Data:
None
=cut
sub _StringLimit {
my ( $sb, $field, $op, $value, @rest ) = @_;
# FIXME:
# Valid Operators:
# =, !=, LIKE, NOT LIKE
if ( RT->Config->Get('DatabaseType') eq 'Oracle'
&& (!defined $value || !length $value)
&& lc($op) ne 'is' && lc($op) ne 'is not'
) {
if ($op eq '!=' || $op =~ /^NOT\s/i) {
$op = 'IS NOT';
} else {
$op = 'IS';
}
$value = 'NULL';
}
if ($field eq "Status") {
if ( ref $value eq 'ARRAY' ) {
$value = [ map lc, @$value ];
}
else {
$value = lc $value;
}
}
$sb->Limit(
FIELD => $field,
OPERATOR => $op,
VALUE => $value,
CASESENSITIVE => 0,
@rest,
);
}
=head2 _QueueLimit
Handle Queue field supporting both "is" and "match".
Input should be a queue name or a partial string.
=cut
sub _QueueLimit {
my ($sb, $field, $op, $value, @rest ) = @_;
if ($op eq 'LIKE' || $op eq 'NOT LIKE') {
my $alias = $sb->{_sql_aliases}{queues} ||= $sb->Join(
ALIAS1 => 'main',
FIELD1 => 'Queue',
TABLE2 => 'Queues',
FIELD2 => 'id',
);
return $sb->Limit(
ALIAS => $alias,
FIELD => 'Name',
OPERATOR => $op,
VALUE => $value,
CASESENSITIVE => 0,
@rest,
);
}
if ( ref $value eq 'ARRAY' ) {
my @values;
for my $v ( @$value ) {
my $o = RT::Queue->new( $sb->CurrentUser );
$o->Load($v);
push @values, $o->Id || 0;
}
$value = \@values;
}
else {
my $o = RT::Queue->new( $sb->CurrentUser );
$o->Load($value);
$value = $o->Id || 0;
}
$sb->Limit(
FIELD => $field,
OPERATOR => $op,
VALUE => $value,
CASESENSITIVE => 0,
@rest,
);
}
=head2 _TransDateLimit
Handle fields limiting based on Transaction Date.
The inpupt value must be in a format parseable by Time::ParseDate
Meta Data:
None
=cut
# This routine should really be factored into translimit.
sub _TransDateLimit {
my ( $sb, $field, $op, $value, @rest ) = @_;
# See the comments for TransLimit, they apply here too
my $txn_alias = $sb->JoinTransactions;
my $date = RT::Date->new( $sb->CurrentUser );
$date->Set( Format => 'unknown', Value => $value );
$sb->_OpenParen;
if ( $op eq "=" ) {
# if we're specifying =, that means we want everything on a
# particular single day. in the database, we need to check for >
# and < the edges of that day.
$date->SetToMidnight( Timezone => 'user' );
my $daystart = $date->ISO;
$date->AddDay;
my $dayend = $date->ISO;
$sb->Limit(
ALIAS => $txn_alias,
FIELD => 'Created',
OPERATOR => ">=",
VALUE => $daystart,
@rest
);
$sb->Limit(
ALIAS => $txn_alias,
FIELD => 'Created',
OPERATOR => "<",
VALUE => $dayend,
@rest,
ENTRYAGGREGATOR => 'AND',
);
}
# not searching for a single day
else {
#Search for the right field
$sb->Limit(
ALIAS => $txn_alias,
FIELD => 'Created',
OPERATOR => $op,
VALUE => $date->ISO,
@rest
);
}
$sb->_CloseParen;
}
sub _TransCreatorLimit {
my ( $sb, $field, $op, $value, @rest ) = @_;
$op = "!=" if $op eq "<>";
die "Invalid Operation: $op for $field" unless $op eq "=" or $op eq "!=";
# See the comments for TransLimit, they apply here too
my $txn_alias = $sb->JoinTransactions;
if ( defined $value && $value !~ /^\d+$/ ) {
my $u = RT::User->new( $sb->CurrentUser );
$u->Load($value);
$value = $u->id || 0;
}
$sb->Limit( ALIAS => $txn_alias, FIELD => 'Creator', OPERATOR => $op, VALUE => $value, @rest );
}
=head2 _TransLimit
Limit based on the ContentType or the Filename of a transaction.
=cut
sub _TransLimit {
my ( $self, $field, $op, $value, %rest ) = @_;
my $txn_alias = $self->JoinTransactions;
unless ( defined $self->{_sql_trattachalias} ) {
$self->{_sql_trattachalias} = $self->Join(
TYPE => 'LEFT', # not all txns have an attachment
ALIAS1 => $txn_alias,
FIELD1 => 'id',
TABLE2 => 'Attachments',
FIELD2 => 'TransactionId',
);
}
$self->Limit(
%rest,
ALIAS => $self->{_sql_trattachalias},
FIELD => $field,
OPERATOR => $op,
VALUE => $value,
CASESENSITIVE => 0,
);
}
=head2 _TransContentLimit
Limit based on the Content of a transaction.
=cut
sub _TransContentLimit {
# Content search
# If only this was this simple. We've got to do something
# complicated here:
#Basically, we want to make sure that the limits apply to
#the same attachment, rather than just another attachment
#for the same ticket, no matter how many clauses we lump
#on.
# In the SQL, we might have
# (( Content = foo ) or ( Content = bar AND Content = baz ))
# The AND group should share the same Alias.
# Actually, maybe it doesn't matter. We use the same alias and it
# works itself out? (er.. different.)
# Steal more from _ProcessRestrictions
# FIXME: Maybe look at the previous FooLimit call, and if it was a
# TransLimit and EntryAggregator == AND, reuse the Aliases?
# Or better - store the aliases on a per subclause basis - since
# those are going to be the things we want to relate to each other,
# anyway.
# maybe we should not allow certain kinds of aggregation of these
# clauses and do a psuedo regex instead? - the problem is getting
# them all into the same subclause when you have (A op B op C) - the
# way they get parsed in the tree they're in different subclauses.
my ( $self, $field, $op, $value, %rest ) = @_;
$field = 'Content' if $field =~ /\W/;
my $config = RT->Config->Get('FullTextSearch') || {};
unless ( $config->{'Enable'} ) {
$self->Limit( %rest, FIELD => 'id', VALUE => 0 );
return;
}
my $txn_alias = $self->JoinTransactions;
unless ( defined $self->{_sql_trattachalias} ) {
$self->{_sql_trattachalias} = $self->Join(
TYPE => 'LEFT', # not all txns have an attachment
ALIAS1 => $txn_alias,
FIELD1 => 'id',
TABLE2 => 'Attachments',
FIELD2 => 'TransactionId',
);
}
$self->_OpenParen;
if ( $config->{'Indexed'} ) {
my $db_type = RT->Config->Get('DatabaseType');
my $alias;
if ( $config->{'Table'} and $config->{'Table'} ne "Attachments") {
$alias = $self->{'_sql_aliases'}{'full_text'} ||= $self->Join(
TYPE => 'LEFT',
ALIAS1 => $self->{'_sql_trattachalias'},
FIELD1 => 'id',
TABLE2 => $config->{'Table'},
FIELD2 => 'id',
);
} else {
$alias = $self->{'_sql_trattachalias'};
}
#XXX: handle negative searches
my $index = $config->{'Column'};
if ( $db_type eq 'Oracle' ) {
my $dbh = $RT::Handle->dbh;
my $alias = $self->{_sql_trattachalias};
$self->Limit(
%rest,
FUNCTION => "CONTAINS( $alias.$field, ".$dbh->quote($value) .")",
OPERATOR => '>',
VALUE => 0,
QUOTEVALUE => 0,
CASESENSITIVE => 1,
);
# this is required to trick DBIx::SB's LEFT JOINS optimizer
# into deciding that join is redundant as it is
$self->Limit(
ENTRYAGGREGATOR => 'AND',
ALIAS => $self->{_sql_trattachalias},
FIELD => 'Content',
OPERATOR => 'IS NOT',
VALUE => 'NULL',
);
}
elsif ( $db_type eq 'Pg' ) {
my $dbh = $RT::Handle->dbh;
$self->Limit(
%rest,
ALIAS => $alias,
FIELD => $index,
OPERATOR => '@@',
VALUE => 'plainto_tsquery('. $dbh->quote($value) .')',
QUOTEVALUE => 0,
);
}
elsif ( $db_type eq 'mysql' and not $config->{Sphinx}) {
my $dbh = $RT::Handle->dbh;
$self->Limit(
%rest,
FUNCTION => "MATCH($alias.Content)",
OPERATOR => 'AGAINST',
VALUE => "(". $dbh->quote($value) ." IN BOOLEAN MODE)",
QUOTEVALUE => 0,
);
# As with Oracle, above, this forces the LEFT JOINs into
# JOINS, which allows the FULLTEXT index to be used.
# Orthogonally, the IS NOT NULL clause also helps the
# optimizer decide to use the index.
$self->Limit(
ENTRYAGGREGATOR => 'AND',
ALIAS => $alias,
FIELD => "Content",
OPERATOR => 'IS NOT',
VALUE => 'NULL',
QUOTEVALUE => 0,
);
}
elsif ( $db_type eq 'mysql' ) {
# XXX: We could theoretically skip the join to Attachments,
# and have Sphinx simply index and group by the TicketId,
# and join Ticket.id to that attribute, which would be much
# more efficient -- however, this is only a possibility if
# there are no other transaction limits.
# This is a special character. Note that \ does not escape
# itself (in Sphinx 2.1.0, at least), so 'foo\;bar' becoming
# 'foo\\;bar' is not a vulnerability, and is still parsed as
# "foo, \, ;, then bar". Happily, the default mode is
# "all", meaning that boolean operators are not special.
$value =~ s/;/\\;/g;
my $max = $config->{'MaxMatches'};
$self->Limit(
%rest,
ALIAS => $alias,
FIELD => 'query',
OPERATOR => '=',
VALUE => "$value;limit=$max;maxmatches=$max",
);
}
} else {
$self->Limit(
%rest,
ALIAS => $txn_alias,
FIELD => 'Type',
OPERATOR => 'NOT IN',
VALUE => ['EmailRecord', 'CommentEmailRecord'],
);
$self->Limit(
ENTRYAGGREGATOR => 'AND',
ALIAS => $self->{_sql_trattachalias},
FIELD => $field,
OPERATOR => $op,
VALUE => $value,
CASESENSITIVE => 0,
);
}
if ( RT->Config->Get('DontSearchFileAttachments') ) {
$self->Limit(
ENTRYAGGREGATOR => 'AND',
ALIAS => $self->{_sql_trattachalias},
FIELD => 'Filename',
OPERATOR => 'IS',
VALUE => 'NULL',
);
}
$self->_CloseParen;
}
=head2 _CustomRoleDecipher
Try and turn a custom role descriptor (e.g. C<CustomRole.{Engineer}>) into
(role, column, original name).
=cut
sub _CustomRoleDecipher {
my ($self, $string) = @_;
# $column could be core fields like "EmailAddress" or CFs like
# "CustomField.{Department}", the CF format is used in OrderByCols.
my ($field, $column) = ($string =~ /^\{(.+?)\}(?:\.(.+))?$/);
my $role;
if ( $field =~ /\D/ ) {
my $roles = RT::CustomRoles->new( $self->CurrentUser );
$roles->Limit( FIELD => 'Name', VALUE => $field, CASESENSITIVE => 0 );
# custom roles are named uniquely, but just in case there are
# multiple matches, bail out as we don't know which one to use
$role = $roles->First;
if ( $role ) {
$role = undef if $roles->Next;
}
}
else {
$role = RT::CustomRole->new( $self->CurrentUser );
$role->Load( $field );
}
return ($role, $column, $field);
}
=head2 _WatcherLimit
Handle watcher limits. (Requestor, CC, etc..)
Meta Data:
1: Field to query on
=cut
sub _WatcherLimit {
my $self = shift;
my $field = shift;
my $op = shift;
my $value = shift;
my %rest = (@_);
my $meta = $FIELD_METADATA{ $field };
my $type = $meta->[1] || '';
my $class = $meta->[2] || 'Ticket';
my $column = $rest{SUBKEY};
if ($field eq 'CustomRole') {
my ($role, $col, $original_name) = $self->_CustomRoleDecipher( $column );
$column = $col || 'id';
$type = $role ? $role->GroupType : $original_name;
}
# Bail if the subfield is not allowed
if ( $column
and not grep { $_ eq $column } @{$SEARCHABLE_SUBFIELDS{'User'}})
{
die "Invalid watcher subfield: '$column'";
}
$self->RoleLimit(
TYPE => $type,
CLASS => "RT::$class",
FIELD => $column,
OPERATOR => $op,
VALUE => $value,
SUBCLAUSE => "ticketsql",
%rest,
);
}
=head2 _WatcherMembershipLimit
Handle watcher membership limits, i.e. whether the watcher belongs to a
specific group or not.
Meta Data:
1: Role to query on
=cut
sub _WatcherMembershipLimit {
my ( $self, $field, $op, $value, %rest ) = @_;
# we don't support anything but '='
die "Invalid $field Op: $op"
unless $op =~ /^=$/;
unless ( $value =~ /^\d+$/ ) {
my $group = RT::Group->new( $self->CurrentUser );
$group->LoadUserDefinedGroup( $value );
$value = $group->id || 0;
}
my $meta = $FIELD_METADATA{$field};
my $type = $meta->[1] || '';
if ( $type eq 'Owner' ) {
my $cgm_alias = $self->Join(
ALIAS1 => 'main',
FIELD1 => 'Owner',
TABLE2 => 'CachedGroupMembers',
FIELD2 => 'MemberId',
);
$self->Limit(
ALIAS => $cgm_alias,
FIELD => 'GroupId',
VALUE => $value,
OPERATOR => $op,
%rest,
);
}
else {
my $groups = $self->_RoleGroupsJoin( Name => $type, Class => $self->_RoleGroupClass, New => 1 );
my $group_members = $self->_GroupMembersJoin( GroupsAlias => $groups );
my $cgm = $self->NewAlias('CachedGroupMembers');
my $group_members_2 = $self->Join(
TYPE => 'LEFT',
ALIAS1 => $group_members,
FIELD1 => 'MemberId',
ALIAS2 => $cgm,
FIELD2 => 'GroupId',
);
$self->Limit(
LEFTJOIN => $group_members_2,
FIELD => 'GroupId',
OPERATOR => '!=',
VALUE => "$group_members_2.MemberId",
QUOTEVALUE => 0,
);
$self->Limit(
LEFTJOIN => $group_members_2,
ALIAS => $cgm,
FIELD => 'Disabled',
VALUE => 0,
ENTRYAGGREGATOR => 'AND',
);
my $users = $self->Join(
TYPE => 'LEFT',
ALIAS1 => $group_members_2,
FIELD1 => 'MemberId',
TABLE2 => 'Users',
FIELD2 => 'id',
);
my $cgm_2 = $self->NewAlias('CachedGroupMembers');
my $group_members_3 = $self->Join(
TYPE => 'LEFT',
ALIAS1 => $users,
FIELD1 => 'id',
ALIAS2 => $cgm_2,
FIELD2 => 'MemberId',
);
$self->Limit(
LEFTJOIN => $cgm_2,
ALIAS => $cgm_2,
FIELD => 'Disabled',
VALUE => 0,
);
$self->Limit(
ALIAS => $group_members_3,
FIELD => 'GroupId',
VALUE => $value,
OPERATOR => $op,
%rest,
);
}
}
=head2 _CustomFieldDecipher
Try and turn a CF descriptor into (cfid, cfname) object pair.
Takes an optional second parameter of the CF LookupType, defaults to Ticket CFs.
=cut
sub _CustomFieldDecipher {
my ($self, $string, $lookuptype) = @_;
$lookuptype ||= $self->_SingularClass->CustomFieldLookupType;
my ($object, $field, $column) = ($string =~ /^(?:(.+?)\.)?\{(.+)\}(?:\.(Content|LargeContent))?$/);
if ( !$field ) {
if ($string =~ /^(?:(\w+?)|\{(.*?)\})(?:\.(Content|LargeContent))?$/) {
$field = $1 || $2;
$column = $3;
}
else {
$field = $string;
}
}
my ($cf, $applied_to);
if ( $object ) {
my $record_class = RT::CustomField->RecordClassFromLookupType($lookuptype);
$applied_to = $record_class->new( $self->CurrentUser );
$applied_to->Load( $object );
if ( $applied_to->id ) {
RT->Logger->debug("Limiting to CFs identified by '$field' applied to $record_class #@{[$applied_to->id]} (loaded via '$object')");
}
else {
RT->Logger->warning("$record_class '$object' doesn't exist, parsed from '$string'");
$object = 0;
undef $applied_to;
}
}
if ( $field =~ /\D/ ) {
$object ||= '';
my $cfs = RT::CustomFields->new( $self->CurrentUser );
$cfs->Limit( FIELD => 'Name', VALUE => $field, CASESENSITIVE => 0 );
$cfs->LimitToLookupType($lookuptype);
if ($applied_to) {
$cfs->SetContextObject($applied_to);
$cfs->LimitToObjectId($applied_to->id);
}
# if there is more then one field the current user can
# see with the same name then we shouldn't return cf object
# as we don't know which one to use
$cf = $cfs->First;
if ( $cf ) {
$cf = undef if $cfs->Next;
}
}
else {
$cf = RT::CustomField->new( $self->CurrentUser );
$cf->Load( $field );
$cf->SetContextObject($applied_to)
if $cf->id and $applied_to;
}
return ($object, $field, $cf, $column);
}
=head2 _CustomFieldLimit
Limit based on CustomFields
Meta Data:
none
=cut
sub _CustomFieldLimit {
my ( $self, $_field, $op, $value, %rest ) = @_;
my $meta = $FIELD_METADATA{ $_field };
my $class = $meta->[1] || 'Ticket';
my $type = "RT::$class"->CustomFieldLookupType;
my $field = $rest{'SUBKEY'} || die "No field specified";
# For our sanity, we can only limit on one object at a time
my ($object, $cfid, $cf, $column);
($object, $field, $cf, $column) = $self->_CustomFieldDecipher( $field, $type );
$self->_LimitCustomField(
%rest,
LOOKUPTYPE => $type,
CUSTOMFIELD => $cf || $field,
KEY => $cf ? $cf->id : "$type-$object.$field",
OPERATOR => $op,
VALUE => $value,
COLUMN => $column,
SUBCLAUSE => "ticketsql",
);
}
sub _CustomFieldJoinByName {
my $self = shift;
my ($ObjectAlias, $cf, $type) = @_;
my ($ocfvalias, $CFs, $ocfalias) = $self->SUPER::_CustomFieldJoinByName(@_);
$self->Limit(
LEFTJOIN => $ocfalias,
ENTRYAGGREGATOR => 'OR',
FIELD => 'ObjectId',
VALUE => 'main.Queue',
QUOTEVALUE => 0,
);
return ($ocfvalias, $CFs, $ocfalias);
}
sub _HasAttributeLimit {
my ( $self, $field, $op, $value, %rest ) = @_;
my $alias = $self->Join(
TYPE => 'LEFT',
ALIAS1 => 'main',
FIELD1 => 'id',
TABLE2 => 'Attributes',
FIELD2 => 'ObjectId',
);
$self->Limit(
LEFTJOIN => $alias,
FIELD => 'ObjectType',
VALUE => 'RT::Ticket',
ENTRYAGGREGATOR => 'AND'
);
$self->Limit(
LEFTJOIN => $alias,
FIELD => 'Name',
OPERATOR => $op,
VALUE => $value,
ENTRYAGGREGATOR => 'AND'
);
$self->Limit(
%rest,
ALIAS => $alias,
FIELD => 'id',
OPERATOR => $FIELD_METADATA{$field}->[1]? 'IS NOT': 'IS',
VALUE => 'NULL',
QUOTEVALUE => 0,
);
}
sub _LifecycleLimit {
my ( $self, $field, $op, $value, %rest ) = @_;
die "Invalid Operator $op for $field" if $op =~ /^(IS|IS NOT)$/io;
my $queue = $self->{_sql_aliases}{queues} ||= $_[0]->Join(
ALIAS1 => 'main',
FIELD1 => 'Queue',
TABLE2 => 'Queues',
FIELD2 => 'id',
);
$self->Limit(
ALIAS => $queue,
FIELD => 'Lifecycle',
OPERATOR => $op,
VALUE => $value,
%rest,
);
}
# End Helper Functions
# End of SQL Stuff -------------------------------------------------
=head2 OrderByCols ARRAY
A modified version of the OrderBy method which automatically joins where
C<ALIAS> is set to the name of a watcher type.
=cut
sub OrderByCols {
my $self = shift;
my @args = @_;
my $clause;
my @res = ();
my $order = 0;
foreach my $row (@args) {
if ( $row->{ALIAS} ) {
push @res, $row;
next;
}
if ( $row->{FIELD} !~ /\./ ) {
my $meta = $FIELD_METADATA{ $row->{FIELD} };
unless ( $meta ) {
push @res, $row;
next;
}
if ( $meta->[0] eq 'QUEUE' ) {
my $alias = $self->Join(
TYPE => 'LEFT',
ALIAS1 => 'main',
FIELD1 => $row->{'FIELD'},
TABLE2 => 'Queues',
FIELD2 => 'id',
);
push @res, { %$row, ALIAS => $alias, FIELD => "Name", CASESENSITIVE => 0 };
} elsif ( ( $meta->[0] eq 'ENUM' && ($meta->[1]||'') eq 'User' )
|| ( $meta->[0] eq 'WATCHERFIELD' && ($meta->[1]||'') eq 'Owner' )
) {
my $alias = $self->Join(
TYPE => 'LEFT',
ALIAS1 => 'main',
FIELD1 => $row->{'FIELD'},
TABLE2 => 'Users',
FIELD2 => 'id',
);
push @res, { %$row, ALIAS => $alias, FIELD => "Name", CASESENSITIVE => 0 };
} else {
push @res, $row;
}
next;
}
my ( $field, $subkey ) = split /\./, $row->{FIELD}, 2;
my $meta = $FIELD_METADATA{$field};
if ( defined $meta->[0] && $meta->[0] eq 'WATCHERFIELD' ) {
my $type = $meta->[1] || '';
my $class = $meta->[2] || 'Ticket';
my $column = $subkey;
if ($field eq 'CustomRole') {
my ($role, $col, $original_name) = $self->_CustomRoleDecipher( $column );
$column = $col || 'id';
$type = $role ? $role->GroupType : $original_name;
}
# cache alias as we want to use one alias per watcher type for sorting
my $cache_key = join "-", $type, $class;
my $users = $self->{_sql_u_watchers_alias_for_sort}{ $cache_key };
unless ( $users ) {
$self->{_sql_u_watchers_alias_for_sort}{ $cache_key }
= $users = ( $self->_WatcherJoin( Name => $type, Class => "RT::" . $class ) )[2];
}
if ( $column =~ /^CustomField\.\{(.+)\}$/ ) {
my $cf_name = $1;
my $cf = RT::CustomField->new( $self->CurrentUser );
$cf->LoadByCols( LookupType => RT::User->CustomFieldLookupType, Name => $cf_name );
if ( $cf->id ) {
my $ocfvs = $self->NewAlias('ObjectCustomFieldValues');
$self->Join(
TYPE => 'LEFT',
ALIAS1 => $users,
FIELD1 => 'id',
ALIAS2 => $ocfvs,
FIELD2 => 'ObjectId',
);
$self->Limit(
LEFTJOIN => $ocfvs,
FIELD => 'CustomField',
VALUE => $cf->id,
ENTRYAGGREGATOR => 'AND',
);
# The following is copied from RT::SearchBuilder::_OrderByCF
my $CFvs = $self->Join(
TYPE => 'LEFT',
ALIAS1 => $ocfvs,
FIELD1 => 'CustomField',
TABLE2 => 'CustomFieldValues',
FIELD2 => 'CustomField',
);
$self->Limit(
LEFTJOIN => $CFvs,
FIELD => 'Name',
QUOTEVALUE => 0,
VALUE => "$ocfvs.Content",
ENTRYAGGREGATOR => 'AND'
);
push @res, { %$row, ALIAS => $CFvs, FIELD => 'SortOrder' },
{ %$row, ALIAS => $ocfvs, FIELD => 'Content' };
}
else {
RT->Logger->warning("Couldn't load user custom field $cf_name");
next;
}
}
else {
push @res, { %$row, ALIAS => $users, FIELD => $column };
}
} elsif ( defined $meta->[0] && $meta->[0] eq 'CUSTOMFIELD' ) {
my ($object, $field, $cf, $column) = $self->_CustomFieldDecipher( $subkey );
my $cfkey = $cf ? $cf->id : "$object.$field";
push @res, $self->_OrderByCF( $row, $cfkey, ($cf || $field) );
} elsif ( $field eq "Custom" && $subkey eq "Ownership") {
# PAW logic is "reversed"
my $order = "ASC";
if (exists $row->{ORDER} ) {
my $o = $row->{ORDER};
delete $row->{ORDER};
$order = "DESC" if $o =~ /asc/i;
}
# Ticket.Owner 1 0 X
# Unowned Tickets 0 1 X
# Else 0 0 X
foreach my $uid ( $self->CurrentUser->Id, RT->Nobody->Id ) {
if ( RT->Config->Get('DatabaseType') eq 'Oracle' ) {
my $f = ($row->{'ALIAS'} || 'main') .'.Owner';
push @res, {
%$row,
FIELD => undef,
ALIAS => '',
FUNCTION => "CASE WHEN $f=$uid THEN 1 ELSE 0 END",
ORDER => $order
};
} else {
push @res, {
%$row,
FIELD => undef,
FUNCTION => "Owner=$uid",
ORDER => $order
};
}
}
push @res, { %$row, FIELD => "Priority", ORDER => $order } ;
}
else {
push @res, $row;
}
}
return $self->SUPER::OrderByCols(@res);
}
sub _OpenParen {
$_[0]->SUPER::_OpenParen( $_[1] || 'ticketsql' );
}
sub _CloseParen {
$_[0]->SUPER::_CloseParen( $_[1] || 'ticketsql' );
}
sub Limit {
my $self = shift;
my %args = @_;
$self->{'must_redo_search'} = 1;
delete $self->{'raw_rows'};
delete $self->{'count_all'};
if ($self->{'using_restrictions'}) {
RT->Deprecated( Message => "Mixing old-style LimitFoo methods with Limit is deprecated" );
$self->LimitField(@_);
}
$args{SUBCLAUSE} ||= "ticketsql"
if $self->{parsing_ticketsql} and not $args{LEFTJOIN};
$self->{_sql_looking_at}{ lc $args{FIELD} } = 1
if $args{FIELD} and (not $args{ALIAS} or $args{ALIAS} eq "main");
$self->SUPER::Limit(%args);
}
=head2 LimitField
Takes a paramhash with the fields FIELD, OPERATOR, VALUE and DESCRIPTION
Generally best called from LimitFoo methods
=cut
sub LimitField {
my $self = shift;
my %args = (
FIELD => undef,
OPERATOR => '=',
VALUE => undef,
DESCRIPTION => undef,
@_
);
$args{'DESCRIPTION'} = $self->loc(
"[_1] [_2] [_3]", $args{'FIELD'},
$args{'OPERATOR'}, $args{'VALUE'}
)
if ( !defined $args{'DESCRIPTION'} );
if ($self->_isLimited > 1) {
RT->Deprecated( Message => "Mixing old-style LimitFoo methods with Limit is deprecated" );
}
$self->{using_restrictions} = 1;
my $index = $self->_NextIndex;
# make the TicketRestrictions hash the equivalent of whatever we just passed in;
%{ $self->{'TicketRestrictions'}{$index} } = %args;
$self->{'RecalcTicketLimits'} = 1;
return ($index);
}
=head2 LimitQueue
LimitQueue takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of = or !=. (It defaults to =).
VALUE is a queue id or Name.
=cut
sub LimitQueue {
my $self = shift;
my %args = (
VALUE => undef,
OPERATOR => '=',
@_
);
#TODO VALUE should also take queue objects
if ( defined $args{'VALUE'} && $args{'VALUE'} !~ /^\d+$/ ) {
my $queue = RT::Queue->new( $self->CurrentUser );
$queue->Load( $args{'VALUE'} );
$args{'VALUE'} = $queue->Id;
}
# What if they pass in an Id? Check for isNum() and convert to
# string.
#TODO check for a valid queue here
$self->LimitField(
FIELD => 'Queue',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join(
' ', $self->loc('Queue'), $args{'OPERATOR'}, $args{'VALUE'},
),
);
}
=head2 LimitStatus
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of = or !=.
VALUE is a status.
RT adds Status != 'deleted' until object has
allow_deleted_search internal property set.
$tickets->{'allow_deleted_search'} = 1;
$tickets->LimitStatus( VALUE => 'deleted' );
=cut
sub LimitStatus {
my $self = shift;
my %args = (
OPERATOR => '=',
@_
);
$self->LimitField(
FIELD => 'Status',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Status'), $args{'OPERATOR'},
$self->loc( $args{'VALUE'} ) ),
);
}
=head2 LimitToActiveStatus
Limits the status to L<RT::Queue/ActiveStatusArray>
TODO: make this respect lifecycles for the queues associated with the search
=cut
sub LimitToActiveStatus {
my $self = shift;
my @active = RT::Queue->ActiveStatusArray();
for my $active (@active) {
$self->LimitStatus(
VALUE => $active,
);
}
}
=head2 LimitToInactiveStatus
Limits the status to L<RT::Queue/InactiveStatusArray>
TODO: make this respect lifecycles for the queues associated with the search
=cut
sub LimitToInactiveStatus {
my $self = shift;
my @active = RT::Queue->InactiveStatusArray();
for my $active (@active) {
$self->LimitStatus(
VALUE => $active,
);
}
}
=head2 IgnoreType
If called, this search will not automatically limit the set of results found
to tickets of type "Ticket". Tickets of other types, such as "project" and
"approval" will be found.
=cut
sub IgnoreType {
my $self = shift;
# Instead of faking a Limit that later gets ignored, fake up the
# fact that we're already looking at type, so that the check in
# FromSQL goes down the right branch
# $self->LimitType(VALUE => '__any');
$self->{_sql_looking_at}{type} = 1;
}
=head2 LimitType
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of = or !=, it defaults to "=".
VALUE is a string to search for in the type of the ticket.
=cut
sub LimitType {
my $self = shift;
my %args = (
OPERATOR => '=',
VALUE => undef,
@_
);
$self->LimitField(
FIELD => 'Type',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Type'), $args{'OPERATOR'}, $args{'VALUE'}, ),
);
}
=head2 LimitSubject
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of = or !=.
VALUE is a string to search for in the subject of the ticket.
=cut
sub LimitSubject {
my $self = shift;
my %args = (@_);
$self->LimitField(
FIELD => 'Subject',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Subject'), $args{'OPERATOR'}, $args{'VALUE'}, ),
);
}
# Things that can be > < = !=
=head2 LimitId
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of =, >, < or !=.
VALUE is a ticket Id to search for
=cut
sub LimitId {
my $self = shift;
my %args = (
OPERATOR => '=',
@_
);
$self->LimitField(
FIELD => 'id',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION =>
join( ' ', $self->loc('Id'), $args{'OPERATOR'}, $args{'VALUE'}, ),
);
}
=head2 LimitPriority
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of =, >, < or !=.
VALUE is a value to match the ticket's priority against
=cut
sub LimitPriority {
my $self = shift;
my %args = (@_);
$self->LimitField(
FIELD => 'Priority',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Priority'),
$args{'OPERATOR'}, $args{'VALUE'}, ),
);
}
=head2 LimitInitialPriority
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of =, >, < or !=.
VALUE is a value to match the ticket's initial priority against
=cut
sub LimitInitialPriority {
my $self = shift;
my %args = (@_);
$self->LimitField(
FIELD => 'InitialPriority',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Initial Priority'), $args{'OPERATOR'},
$args{'VALUE'}, ),
);
}
=head2 LimitFinalPriority
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of =, >, < or !=.
VALUE is a value to match the ticket's final priority against
=cut
sub LimitFinalPriority {
my $self = shift;
my %args = (@_);
$self->LimitField(
FIELD => 'FinalPriority',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Final Priority'), $args{'OPERATOR'},
$args{'VALUE'}, ),
);
}
=head2 LimitTimeWorked
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of =, >, < or !=.
VALUE is a value to match the ticket's TimeWorked attribute
=cut
sub LimitTimeWorked {
my $self = shift;
my %args = (@_);
$self->LimitField(
FIELD => 'TimeWorked',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Time Worked'),
$args{'OPERATOR'}, $args{'VALUE'}, ),
);
}
=head2 LimitTimeLeft
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of =, >, < or !=.
VALUE is a value to match the ticket's TimeLeft attribute
=cut
sub LimitTimeLeft {
my $self = shift;
my %args = (@_);
$self->LimitField(
FIELD => 'TimeLeft',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Time Left'),
$args{'OPERATOR'}, $args{'VALUE'}, ),
);
}
=head2 LimitContent
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of =, LIKE, NOT LIKE or !=.
VALUE is a string to search for in the body of the ticket
=cut
sub LimitContent {
my $self = shift;
my %args = (@_);
$self->LimitField(
FIELD => 'Content',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Ticket content'), $args{'OPERATOR'},
$args{'VALUE'}, ),
);
}
=head2 LimitFilename
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of =, LIKE, NOT LIKE or !=.
VALUE is a string to search for in the body of the ticket
=cut
sub LimitFilename {
my $self = shift;
my %args = (@_);
$self->LimitField(
FIELD => 'Filename',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Attachment filename'), $args{'OPERATOR'},
$args{'VALUE'}, ),
);
}
=head2 LimitContentType
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of =, LIKE, NOT LIKE or !=.
VALUE is a content type to search ticket attachments for
=cut
sub LimitContentType {
my $self = shift;
my %args = (@_);
$self->LimitField(
FIELD => 'ContentType',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Ticket content type'), $args{'OPERATOR'},
$args{'VALUE'}, ),
);
}
=head2 LimitOwner
Takes a paramhash with the fields OPERATOR and VALUE.
OPERATOR is one of = or !=.
VALUE is a user id.
=cut
sub LimitOwner {
my $self = shift;
my %args = (
OPERATOR => '=',
@_
);
my $owner = RT::User->new( $self->CurrentUser );
$owner->Load( $args{'VALUE'} );
# FIXME: check for a valid $owner
$self->LimitField(
FIELD => 'Owner',
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
DESCRIPTION => join( ' ',
$self->loc('Owner'), $args{'OPERATOR'}, $owner->Name(), ),
);
}
=head2 LimitWatcher
Takes a paramhash with the fields OPERATOR, TYPE and VALUE.
OPERATOR is one of =, LIKE, NOT LIKE or !=.
VALUE is a value to match the ticket's watcher email addresses against
TYPE is the sort of watchers you want to match against. Leave it undef if you want to search all of them
=cut
sub LimitWatcher {
my $self = shift;
my %args = (
OPERATOR => '=',
VALUE => undef,
TYPE => undef,
@_
);
#build us up a description
my ( $watcher_type, $desc );
if ( $args{'TYPE'} ) {
$watcher_type = $args{'TYPE'};
}
else {
$watcher_type = "Watcher";
}
$self->LimitField(
FIELD => $watcher_type,
VALUE => $args{'VALUE'},
OPERATOR => $args{'OPERATOR'},
TYPE => $args{'TYPE'},
DESCRIPTION => join( ' ',
$self->loc($watcher_type),
$args{'OPERATOR'}, $args{'VALUE'}, ),
);
}
=head2 LimitLinkedTo
LimitLinkedTo takes a paramhash with two fields: TYPE and TARGET
TYPE limits the sort of link we want to search on
TYPE = { RefersTo, MemberOf, DependsOn }
TARGET is the id or URI of the TARGET of the link
=cut
sub LimitLinkedTo {
my $self = shift;
my %args = (
TARGET => undef,
TYPE => undef,
OPERATOR => '=',
@_
);
$self->LimitField(
FIELD => 'LinkedTo',
BASE => undef,
TARGET => $args{'TARGET'},
TYPE => $args{'TYPE'},
DESCRIPTION => $self->loc(
"Tickets [_1] by [_2]",
$self->loc( $args{'TYPE'} ),
$args{'TARGET'}
),
OPERATOR => $args{'OPERATOR'},
);
}
=head2 LimitLinkedFrom
LimitLinkedFrom takes a paramhash with two fields: TYPE and BASE
TYPE limits the sort of link we want to search on
BASE is the id or URI of the BASE of the link
=cut
sub LimitLinkedFrom {
my $self = shift;
my %args = (
BASE => undef,
TYPE => undef,
OPERATOR => '=',
@_
);
# translate RT2 From/To naming to RT3 TicketSQL naming
my %fromToMap = qw(DependsOn DependentOn
MemberOf HasMember
RefersTo ReferredToBy);
my $type = $args{'TYPE'};
$type = $fromToMap{$type} if exists( $fromToMap{$type} );
$self->LimitField(
FIELD => 'LinkedTo',
TARGET => undef,
BASE => $args{'BASE'},
TYPE => $type,
DESCRIPTION => $self->loc(
"Tickets [_1] [_2]",
$self->loc( $args{'TYPE'} ),
$args{'BASE'},
),
OPERATOR => $args{'OPERATOR'},
);
}
sub LimitMemberOf {
my $self = shift;
my $ticket_id = shift;
return $self->LimitLinkedTo(
@_,
TARGET => $ticket_id,
TYPE => 'MemberOf',
);
}
sub LimitHasMember {
my $self = shift;
my $ticket_id = shift;
return $self->LimitLinkedFrom(
@_,
BASE => "$ticket_id",
TYPE => 'HasMember',
);
}
sub LimitDependsOn {
my $self = shift;
my $ticket_id = shift;
return $self->LimitLinkedTo(
@_,
TARGET => $ticket_id,
TYPE => 'DependsOn',
);
}
sub LimitDependedOnBy {
my $self = shift;
my $ticket_id = shift;
return $self->LimitLinkedFrom(
@_,
BASE => $ticket_id,
TYPE => 'DependentOn',
);
}
sub LimitRefersTo {
my $self = shift;
my $ticket_id = shift;
return $self->LimitLinkedTo(
@_,
TARGET => $ticket_id,
TYPE => 'RefersTo',
);
}
sub LimitReferredToBy {
my $self = shift;
my $ticket_id = shift;
return $self->LimitLinkedFrom(
@_,
BASE => $ticket_id,
TYPE => 'ReferredToBy',
);
}
=head2 LimitDate (FIELD => 'DateField', OPERATOR => $oper, VALUE => $ISODate)
Takes a paramhash with the fields FIELD OPERATOR and VALUE.
OPERATOR is one of > or <
VALUE is a date and time in ISO format in GMT
FIELD is one of Starts, Started, Told, Created, Resolved, LastUpdated
There are also helper functions of the form LimitFIELD that eliminate
the need to pass in a FIELD argument.
=cut
sub LimitDate {
my $self = shift;
my %args = (
FIELD => undef,
VALUE => undef,
OPERATOR => undef,
@_
);
#Set the description if we didn't get handed it above
unless ( $args{'DESCRIPTION'} ) {
$args{'DESCRIPTION'} = $args{'FIELD'} . " "
. $args{'OPERATOR'} . " "
. $args{'VALUE'} . " GMT";
}
$self->LimitField(%args);
}
sub LimitCreated {
my $self = shift;
$self->LimitDate( FIELD => 'Created', @_ );
}
sub LimitDue {
my $self = shift;
$self->LimitDate( FIELD => 'Due', @_ );
}
sub LimitStarts {
my $self = shift;
$self->LimitDate( FIELD => 'Starts', @_ );
}
sub LimitStarted {
my $self = shift;
$self->LimitDate( FIELD => 'Started', @_ );
}
sub LimitResolved {
my $self = shift;
$self->LimitDate( FIELD => 'Resolved', @_ );
}
sub LimitTold {
my $self = shift;
$self->LimitDate( FIELD => 'Told', @_ );
}
sub LimitLastUpdated {
my $self = shift;
$self->LimitDate( FIELD => 'LastUpdated', @_ );
}
#
=head2 LimitTransactionDate (OPERATOR => $oper, VALUE => $ISODate)
Takes a paramhash with the fields FIELD OPERATOR and VALUE.
OPERATOR is one of > or <
VALUE is a date and time in ISO format in GMT
=cut
sub LimitTransactionDate {
my $self = shift;
my %args = (
FIELD => 'TransactionDate',
VALUE => undef,
OPERATOR => undef,
@_
);
# <20021217042756.GK28744@pallas.fsck.com>
# "Kill It" - Jesse.
#Set the description if we didn't get handed it above
unless ( $args{'DESCRIPTION'} ) {
$args{'DESCRIPTION'} = $args{'FIELD'} . " "
. $args{'OPERATOR'} . " "
. $args{'VALUE'} . " GMT";
}
$self->LimitField(%args);
}
=head2 LimitCustomField
Takes a paramhash of key/value pairs with the following keys:
=over 4
=item CUSTOMFIELD - CustomField name or id. If a name is passed, an additional parameter QUEUE may also be passed to distinguish the custom field.
=item OPERATOR - The usual Limit operators
=item VALUE - The value to compare against
=back
=cut
sub LimitCustomField {
my $self = shift;
my %args = (
VALUE => undef,
CUSTOMFIELD => undef,
OPERATOR => '=',
DESCRIPTION => undef,
FIELD => 'CustomFieldValue',
QUOTEVALUE => 1,
@_
);
my $CF = RT::CustomField->new( $self->CurrentUser );
if ( $args{CUSTOMFIELD} =~ /^\d+$/ ) {
$CF->Load( $args{CUSTOMFIELD} );
}
else {
$CF->LoadByName(
Name => $args{CUSTOMFIELD},
LookupType => RT::Ticket->CustomFieldLookupType,
ObjectId => $args{QUEUE},
);
$args{CUSTOMFIELD} = $CF->Id;
}
#If we are looking to compare with a null value.
if ( $args{'OPERATOR'} =~ /^is$/i ) {
$args{'DESCRIPTION'}
||= $self->loc( "Custom field [_1] has no value.", $CF->Name );
}
elsif ( $args{'OPERATOR'} =~ /^is not$/i ) {
$args{'DESCRIPTION'}
||= $self->loc( "Custom field [_1] has a value.", $CF->Name );
}
# if we're not looking to compare with a null value
else {
$args{'DESCRIPTION'} ||= $self->loc( "Custom field [_1] [_2] [_3]",
$CF->Name, $args{OPERATOR}, $args{VALUE} );
}
if ( defined $args{'QUEUE'} && $args{'QUEUE'} =~ /\D/ ) {
my $QueueObj = RT::Queue->new( $self->CurrentUser );
$QueueObj->Load( $args{'QUEUE'} );
$args{'QUEUE'} = $QueueObj->Id;
}
delete $args{'QUEUE'} unless defined $args{'QUEUE'} && length $args{'QUEUE'};
my @rest;
@rest = ( ENTRYAGGREGATOR => 'AND' )
if ( $CF->Type eq 'SelectMultiple' );
$self->LimitField(
VALUE => $args{VALUE},
FIELD => "CF"
.(defined $args{'QUEUE'}? ".$args{'QUEUE'}" : '' )
.".{" . $CF->Name . "}",
OPERATOR => $args{OPERATOR},
CUSTOMFIELD => 1,
@rest,
);
$self->{'RecalcTicketLimits'} = 1;
}
=head2 _NextIndex
Keep track of the counter for the array of restrictions
=cut
sub _NextIndex {
my $self = shift;
return ( $self->{'restriction_index'}++ );
}
sub _Init {
my $self = shift;
$self->{'table'} = "Tickets";
$self->{'RecalcTicketLimits'} = 1;
$self->{'restriction_index'} = 1;
$self->{'primary_key'} = "id";
delete $self->{'items_array'};
delete $self->{'item_map'};
delete $self->{'columns_to_display'};
$self->SUPER::_Init(@_);
$self->_InitSQL();
}
sub _InitSQL {
my $self = shift;
# Private Member Variables (which should get cleaned)
$self->{'_sql_transalias'} = undef;
$self->{'_sql_trattachalias'} = undef;
$self->{'_sql_cf_alias'} = undef;
$self->{'_sql_object_cfv_alias'} = undef;
$self->{'_sql_watcher_join_users_alias'} = undef;
$self->{'_sql_query'} = '';
$self->{'_sql_looking_at'} = {};
}
sub Count {
my $self = shift;
$self->_ProcessRestrictions() if ( $self->{'RecalcTicketLimits'} == 1 );
return ( $self->SUPER::Count() );
}
sub CountAll {
my $self = shift;
$self->_ProcessRestrictions() if ( $self->{'RecalcTicketLimits'} == 1 );
return ( $self->SUPER::CountAll() );
}
=head2 ItemsArrayRef
Returns a reference to the set of all items found in this search
=cut
sub ItemsArrayRef {
my $self = shift;
return $self->{'items_array'} if $self->{'items_array'};
my $placeholder = $self->_ItemsCounter;
$self->GotoFirstItem();
while ( my $item = $self->Next ) {
push( @{ $self->{'items_array'} }, $item );
}
$self->GotoItem($placeholder);
$self->{'items_array'}
= $self->ItemsOrderBy( $self->{'items_array'} );
return $self->{'items_array'};
}
sub ItemsArrayRefWindow {
my $self = shift;
my $window = shift;
my @old = ($self->_ItemsCounter, $self->RowsPerPage, $self->FirstRow+1);
$self->RowsPerPage( $window );
$self->FirstRow(1);
$self->GotoFirstItem;
my @res;
while ( my $item = $self->Next ) {
push @res, $item;
}
$self->RowsPerPage( $old[1] );
$self->FirstRow( $old[2] );
$self->GotoItem( $old[0] );
return \@res;
}
sub Next {
my $self = shift;
$self->_ProcessRestrictions() if ( $self->{'RecalcTicketLimits'} == 1 );
my $Ticket = $self->SUPER::Next;
return $Ticket unless $Ticket;
if ( $Ticket->__Value('Status') eq 'deleted'
&& !$self->{'allow_deleted_search'} )
{
return $self->Next;
}
elsif ( RT->Config->Get('UseSQLForACLChecks') ) {
# if we found a ticket with this option enabled then
# all tickets we found are ACLed, cache this fact
my $key = join ";:;", $self->CurrentUser->id, 'ShowTicket', 'RT::Ticket-'. $Ticket->id;
$RT::Principal::_ACL_CACHE->{ $key } = 1;
return $Ticket;
}
elsif ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
# has rights
return $Ticket;
}
else {
# If the user doesn't have the right to show this ticket
return $self->Next;
}
}
sub _DoSearch {
my $self = shift;
$self->CurrentUserCanSee if RT->Config->Get('UseSQLForACLChecks');
return $self->SUPER::_DoSearch( @_ );
}
sub _DoCount {
my $self = shift;
$self->CurrentUserCanSee if RT->Config->Get('UseSQLForACLChecks');
return $self->SUPER::_DoCount( @_ );
}
sub _RolesCanSee {
my $self = shift;
my $cache_key = 'RolesHasRight;:;ShowTicket';
if ( my $cached = $RT::Principal::_ACL_CACHE->{ $cache_key } ) {
return %$cached;
}
my $ACL = RT::ACL->new( RT->SystemUser );
$ACL->Limit( FIELD => 'RightName', VALUE => 'ShowTicket' );
$ACL->Limit( FIELD => 'PrincipalType', OPERATOR => '!=', VALUE => 'Group' );
my $principal_alias = $ACL->Join(
ALIAS1 => 'main',
FIELD1 => 'PrincipalId',
TABLE2 => 'Principals',
FIELD2 => 'id',
);
$ACL->Limit( ALIAS => $principal_alias, FIELD => 'Disabled', VALUE => 0 );
my %res = ();
foreach my $ACE ( @{ $ACL->ItemsArrayRef } ) {
my $role = $ACE->__Value('PrincipalType');
my $type = $ACE->__Value('ObjectType');
if ( $type eq 'RT::System' ) {
$res{ $role } = 1;
}
elsif ( $type eq 'RT::Queue' ) {
next if $res{ $role } && !ref $res{ $role };
push @{ $res{ $role } ||= [] }, $ACE->__Value('ObjectId');
}
else {
$RT::Logger->error('ShowTicket right is granted on unsupported object');
}
}
$RT::Principal::_ACL_CACHE->{ $cache_key } = \%res;
return %res;
}
sub _DirectlyCanSeeIn {
my $self = shift;
my $id = $self->CurrentUser->id;
my $cache_key = 'User-'. $id .';:;ShowTicket;:;DirectlyCanSeeIn';
if ( my $cached = $RT::Principal::_ACL_CACHE->{ $cache_key } ) {
return @$cached;
}
my $ACL = RT::ACL->new( RT->SystemUser );
$ACL->Limit( FIELD => 'RightName', VALUE => 'ShowTicket' );
my $principal_alias = $ACL->Join(
ALIAS1 => 'main',
FIELD1 => 'PrincipalId',
TABLE2 => 'Principals',
FIELD2 => 'id',
);
$ACL->Limit( ALIAS => $principal_alias, FIELD => 'Disabled', VALUE => 0 );
my $cgm_alias = $ACL->Join(
ALIAS1 => 'main',
FIELD1 => 'PrincipalId',
TABLE2 => 'CachedGroupMembers',
FIELD2 => 'GroupId',
);
$ACL->Limit( ALIAS => $cgm_alias, FIELD => 'MemberId', VALUE => $id );
$ACL->Limit( ALIAS => $cgm_alias, FIELD => 'Disabled', VALUE => 0 );
my @res = ();
foreach my $ACE ( @{ $ACL->ItemsArrayRef } ) {
my $type = $ACE->__Value('ObjectType');
if ( $type eq 'RT::System' ) {
# If user is direct member of a group that has the right
# on the system then he can see any ticket
$RT::Principal::_ACL_CACHE->{ $cache_key } = [-1];
return (-1);
}
elsif ( $type eq 'RT::Queue' ) {
push @res, $ACE->__Value('ObjectId');
}
else {
$RT::Logger->error('ShowTicket right is granted on unsupported object');
}
}
$RT::Principal::_ACL_CACHE->{ $cache_key } = \@res;
return @res;
}
sub CurrentUserCanSee {
my $self = shift;
return if $self->{'_sql_current_user_can_see_applied'};
return $self->{'_sql_current_user_can_see_applied'} = 1
if $self->CurrentUser->UserObj->HasRight(
Right => 'SuperUser', Object => $RT::System
);
local $self->{using_restrictions};
my $id = $self->CurrentUser->id;
# directly can see in all queues then we have nothing to do
my @direct_queues = $self->_DirectlyCanSeeIn;
return $self->{'_sql_current_user_can_see_applied'} = 1
if @direct_queues && $direct_queues[0] == -1;
my %roles = $self->_RolesCanSee;
{
my %skip = map { $_ => 1 } @direct_queues;
foreach my $role ( keys %roles ) {
next unless ref $roles{ $role };
my @queues = grep !$skip{$_}, @{ $roles{ $role } };
if ( @queues ) {
$roles{ $role } = \@queues;
} else {
delete $roles{ $role };
}
}
}
# there is no global watchers, only queues and tickes, if at
# some point we will add global roles then it's gonna blow
# the idea here is that if the right is set globaly for a role
# and user plays this role for a queue directly not a ticket
# then we have to check in advance
if ( my @tmp = grep $_ ne 'Owner' && !ref $roles{ $_ }, keys %roles ) {
my $groups = RT::Groups->new( RT->SystemUser );
$groups->Limit( FIELD => 'Domain', VALUE => 'RT::Queue-Role', CASESENSITIVE => 0 );
$groups->Limit(
FIELD => 'Name',
FUNCTION => 'LOWER(?)',
OPERATOR => 'IN',
VALUE => [ map {lc $_} @tmp ],
CASESENSITIVE => 1,
);
my $principal_alias = $groups->Join(
ALIAS1 => 'main',
FIELD1 => 'id',
TABLE2 => 'Principals',
FIELD2 => 'id',
);
$groups->Limit( ALIAS => $principal_alias, FIELD => 'Disabled', VALUE => 0 );
my $cgm_alias = $groups->Join(
ALIAS1 => 'main',
FIELD1 => 'id',
TABLE2 => 'CachedGroupMembers',
FIELD2 => 'GroupId',
);
$groups->Limit( ALIAS => $cgm_alias, FIELD => 'MemberId', VALUE => $id );
$groups->Limit( ALIAS => $cgm_alias, FIELD => 'Disabled', VALUE => 0 );
while ( my $group = $groups->Next ) {
push @direct_queues, $group->Instance;
}
}
unless ( @direct_queues || keys %roles ) {
$self->Limit(
SUBCLAUSE => 'ACL',
ALIAS => 'main',
FIELD => 'id',
VALUE => 0,
ENTRYAGGREGATOR => 'AND',
);
return $self->{'_sql_current_user_can_see_applied'} = 1;
}
{
my $join_roles = keys %roles;
$join_roles = 0 if $join_roles == 1 && $roles{'Owner'};
my ($role_group_alias, $cgm_alias);
if ( $join_roles ) {
$role_group_alias = $self->_RoleGroupsJoin( New => 1 );
$cgm_alias = $self->_GroupMembersJoin( GroupsAlias => $role_group_alias );
my $groups = RT::Groups->new( RT->SystemUser );
$groups->LimitToUserDefinedGroups;
$groups->WithMember( PrincipalId => $id, Recursively => 1 );
$self->Limit(
LEFTJOIN => $cgm_alias,
FIELD => 'MemberId',
OPERATOR => 'IN',
VALUE => [ $id, map { $_->id } @{ $groups->ItemsArrayRef } ],
);
}
my $limit_queues = sub {
my $ea = shift;
my @queues = @_;
return unless @queues;
$self->Limit(
SUBCLAUSE => 'ACL',
# RT::Transactions::CurrentUserCanSee reuses RT::Tickets::CurrentUserCanSee
ALIAS => $self->isa('RT::Transactions') ? $self->_JoinTickets : 'main',
FIELD => 'Queue',
OPERATOR => 'IN',
VALUE => [ @queues ],
ENTRYAGGREGATOR => $ea,
);
return 1;
};
$self->SUPER::_OpenParen('ACL');
my $ea = 'AND';
$ea = 'OR' if $limit_queues->( $ea, @direct_queues );
while ( my ($role, $queues) = each %roles ) {
$self->SUPER::_OpenParen('ACL');
if ( $role eq 'Owner' ) {
$self->Limit(
SUBCLAUSE => 'ACL',
FIELD => 'Owner',
VALUE => $id,
ENTRYAGGREGATOR => $ea,
# RT::Transactions::CurrentUserCanSee reuses RT::Tickets::CurrentUserCanSee
ALIAS => $self->isa('RT::Transactions') ? $self->_JoinTickets : 'main',
);
}
else {
$self->Limit(
SUBCLAUSE => 'ACL',
ALIAS => $cgm_alias,
FIELD => 'MemberId',
OPERATOR => 'IS NOT',
VALUE => 'NULL',
QUOTEVALUE => 0,
ENTRYAGGREGATOR => $ea,
);
$self->Limit(
SUBCLAUSE => 'ACL',
ALIAS => $role_group_alias,
FIELD => 'Name',
VALUE => $role,
ENTRYAGGREGATOR => 'AND',
CASESENSITIVE => 0,
);
}
$limit_queues->( 'AND', @$queues ) if ref $queues;
$ea = 'OR' if $ea eq 'AND';
$self->SUPER::_CloseParen('ACL');
}
$self->SUPER::_CloseParen('ACL');
}
return $self->{'_sql_current_user_can_see_applied'} = 1;
}
=head2 ClearRestrictions
Removes all restrictions irretrievably
=cut
sub ClearRestrictions {
my $self = shift;
delete $self->{'TicketRestrictions'};
$self->{_sql_looking_at} = {};
$self->{'RecalcTicketLimits'} = 1;
}
# Convert a set of oldstyle SB Restrictions to Clauses for RQL
sub _RestrictionsToClauses {
my $self = shift;
my %clause;
foreach my $row ( keys %{ $self->{'TicketRestrictions'} } ) {
my $restriction = $self->{'TicketRestrictions'}{$row};
# We need to reimplement the subclause aggregation that SearchBuilder does.
# Default Subclause is ALIAS.FIELD, and default ALIAS is 'main',
# Then SB AND's the different Subclauses together.
# So, we want to group things into Subclauses, convert them to
# SQL, and then join them with the appropriate DefaultEA.
# Then join each subclause group with AND.
my $field = $restriction->{'FIELD'};
my $realfield = $field; # CustomFields fake up a fieldname, so
# we need to figure that out
# One special case
# Rewrite LinkedTo meta field to the real field
if ( $field =~ /LinkedTo/ ) {
$realfield = $field = $restriction->{'TYPE'};
}
# Two special case
# Handle subkey fields with a different real field
if ( $field =~ /^(\w+)\./ ) {
$realfield = $1;
}
die "I don't know about $field yet"
unless ( exists $FIELD_METADATA{$realfield}
or $restriction->{CUSTOMFIELD} );
my $type = $FIELD_METADATA{$realfield}->[0];
my $op = $restriction->{'OPERATOR'};
my $value = (
grep {defined}
map { $restriction->{$_} } qw(VALUE TICKET BASE TARGET)
)[0];
# this performs the moral equivalent of defined or/dor/C<//>,
# without the short circuiting.You need to use a 'defined or'
# type thing instead of just checking for truth values, because
# VALUE could be 0.(i.e. "false")
# You could also use this, but I find it less aesthetic:
# (although it does short circuit)
#( defined $restriction->{'VALUE'}? $restriction->{VALUE} :
# defined $restriction->{'TICKET'} ?
# $restriction->{TICKET} :
# defined $restriction->{'BASE'} ?
# $restriction->{BASE} :
# defined $restriction->{'TARGET'} ?
# $restriction->{TARGET} )
my $ea = $restriction->{ENTRYAGGREGATOR}
|| $DefaultEA{$type}
|| "AND";
if ( ref $ea ) {
die "Invalid operator $op for $field ($type)"
unless exists $ea->{$op};
$ea = $ea->{$op};
}
# Each CustomField should be put into a different Clause so they
# are ANDed together.
if ( $restriction->{CUSTOMFIELD} ) {
$realfield = $field;
}
exists $clause{$realfield} or $clause{$realfield} = [];
# Escape Quotes
$field =~ s!(['\\])!\\$1!g;
$value =~ s!(['\\])!\\$1!g;
my $data = [ $ea, $type, $field, $op, $value ];
# here is where we store extra data, say if it's a keyword or
# something. (I.e. "TYPE SPECIFIC STUFF")
if (lc $ea eq 'none') {
$clause{$realfield} = [ $data ];
} else {
push @{ $clause{$realfield} }, $data;
}
}
return \%clause;
}
=head2 ClausesToSQL
=cut
sub ClausesToSQL {
my $self = shift;
my $clauses = shift;
my @sql;
for my $f (keys %{$clauses}) {
my $sql;
my $first = 1;
# Build SQL from the data hash
for my $data ( @{ $clauses->{$f} } ) {
$sql .= $data->[0] unless $first; $first=0; # ENTRYAGGREGATOR
$sql .= " '". $data->[2] . "' "; # FIELD
$sql .= $data->[3] . " "; # OPERATOR
$sql .= "'". $data->[4] . "' "; # VALUE
}
push @sql, " ( " . $sql . " ) ";
}
return join("AND",@sql);
}
sub _ProcessRestrictions {
my $self = shift;
delete $self->{'items_array'};
delete $self->{'item_map'};
delete $self->{'raw_rows'};
delete $self->{'count_all'};
my $sql = $self->Query;
if ( !$sql || $self->{'RecalcTicketLimits'} ) {
local $self->{using_restrictions};
# "Restrictions to Clauses Branch\n";
my $clauseRef = eval { $self->_RestrictionsToClauses; };
if ($@) {
$RT::Logger->error( "RestrictionsToClauses: " . $@ );
$self->FromSQL("");
}
else {
$sql = $self->ClausesToSQL($clauseRef);
$self->FromSQL($sql) if $sql;
}
}
$self->{'RecalcTicketLimits'} = 0;
}
=head2 _BuildItemMap
Build up a L</ItemMap> of first/last/next/prev items, so that we can
display search nav quickly.
=cut
sub _BuildItemMap {
my $self = shift;
my $window = RT->Config->Get('TicketsItemMapSize');
$self->{'item_map'} = {};
my $items = $self->ItemsArrayRefWindow( $window );
return unless $items && @$items;
my $prev = 0;
$self->{'item_map'}{'first'} = $items->[0]->EffectiveId;
for ( my $i = 0; $i < @$items; $i++ ) {
my $item = $items->[$i];
my $id = $item->EffectiveId;
$self->{'item_map'}{$id}{'defined'} = 1;
$self->{'item_map'}{$id}{'prev'} = $prev;
$self->{'item_map'}{$id}{'next'} = $items->[$i+1]->EffectiveId
if $items->[$i+1];
$prev = $id;
}
$self->{'item_map'}{'last'} = $prev
if !$window || @$items < $window;
}
=head2 ItemMap
Returns an a map of all items found by this search. The map is a hash
of the form:
{
first => <first ticket id found>,
last => <last ticket id found or undef>,
<ticket id> => {
prev => <the ticket id found before>,
next => <the ticket id found after>,
},
<ticket id> => {
prev => ...,
next => ...,
},
}
=cut
sub ItemMap {
my $self = shift;
$self->_BuildItemMap unless $self->{'item_map'};
return $self->{'item_map'};
}
=head2 PrepForSerialization
You don't want to serialize a big tickets object, as
the {items} hash will be instantly invalid _and_ eat
lots of space
=cut
sub PrepForSerialization {
my $self = shift;
delete $self->{'items'};
delete $self->{'items_array'};
$self->RedoSearch();
}
=head1 FLAGS
RT::Tickets supports several flags which alter search behavior:
allow_deleted_search (Otherwise never show deleted tickets in search results)
These flags are set by calling
$tickets->{'flagname'} = 1;
BUG: There should be an API for this
=cut
=head2 FromSQL
Convert a RT-SQL string into a set of SearchBuilder restrictions.
Returns (1, 'Status message') on success and (0, 'Error Message') on
failure.
=cut
sub _parser {
my ($self,$string) = @_;
require RT::Interface::Web::QueryBuilder::Tree;
my $tree = RT::Interface::Web::QueryBuilder::Tree->new;
my @results = $tree->ParseSQL(
Query => $string,
CurrentUser => $self->CurrentUser,
);
die join "; ", map { ref $_ eq 'ARRAY' ? $_->[ 0 ] : $_ } @results if @results;
if ( RT->Config->Get('EnablePriorityAsString') ) {
my $queues = $tree->GetReferencedQueues( CurrentUser => $self->CurrentUser );
my %config = RT->Config->Get('PriorityAsString');
my @names;
if (%$queues) {
for my $id ( keys %$queues ) {
my $queue = RT::Queue->new( $self->CurrentUser );
$queue->Load($id);
if ( $queue->Id ) {
push @names, $queue->__Value('Name'); # Skip ACL check
}
}
}
else {
@names = keys %config;
}
my %map;
for my $name (@names) {
if ( my $value = exists $config{$name} ? $config{$name} : $config{Default} ) {
my %hash = ref $value eq 'ARRAY' ? @$value : %$value;
for my $label ( keys %hash ) {
$map{lc $label} //= $hash{$label};
}
}
}
$tree->traverse(
sub {
my $node = shift;
return unless $node->isLeaf;
my $value = $node->getNodeValue;
if ( $value->{Key} =~ /^(?:Initial|Final)?Priority$/i ) {
$value->{Value} = $map{ lc $value->{Value} } if defined $map{ lc $value->{Value} };
}
}
);
}
my ( $active_status_node, $inactive_status_node );
my $escape_quotes = sub {
my $text = shift;
$text =~ s{(['\\])}{\\$1}g;
return $text;
};
$tree->traverse(
sub {
my $node = shift;
return unless $node->isLeaf and $node->getNodeValue;
my ($key, $subkey, $meta, $op, $value, $bundle)
= @{$node->getNodeValue}{qw/Key Subkey Meta Op Value Bundle/};
return unless $key eq "Status" && $value =~ /^(?:__(?:in)?active__)$/i;
my $parent = $node->getParent;
my $index = $node->getIndex;
if ( ( lc $value eq '__inactive__' && $op eq '=' ) || ( lc $value eq '__active__' && $op eq '!=' ) ) {
unless ( $inactive_status_node ) {
my %lifecycle =
map { $_ => $RT::Lifecycle::LIFECYCLES{ $_ }{ inactive } }
grep { @{ $RT::Lifecycle::LIFECYCLES{ $_ }{ inactive } || [] } }
grep { $_ ne '__maps__' && $RT::Lifecycle::LIFECYCLES_CACHE{ $_ }{ type } eq 'ticket' }
keys %RT::Lifecycle::LIFECYCLES;
return unless %lifecycle;
my $sql;
if ( keys %lifecycle == 1 ) {
$sql = join ' OR ', map { qq{ Status = '$_' } } map { $escape_quotes->($_) } map { @$_ } values %lifecycle;
}
else {
my @inactive_sql;
for my $name ( keys %lifecycle ) {
my $escaped_name = $escape_quotes->($name);
my $inactive_sql =
qq{Lifecycle = '$escaped_name'}
. ' AND ('
. join( ' OR ', map { qq{ Status = '$_' } } map { $escape_quotes->($_) } @{ $lifecycle{ $name } } ) . ')';
push @inactive_sql, qq{($inactive_sql)};
}
$sql = join ' OR ', @inactive_sql;
}
$inactive_status_node = RT::Interface::Web::QueryBuilder::Tree->new;
$inactive_status_node->ParseSQL(
Query => $sql,
CurrentUser => $self->CurrentUser,
);
}
$parent->removeChild( $node );
$parent->insertChild( $index, $inactive_status_node );
}
else {
unless ( $active_status_node ) {
my %lifecycle =
map {
$_ => [
@{ $RT::Lifecycle::LIFECYCLES{ $_ }{ initial } || [] },
@{ $RT::Lifecycle::LIFECYCLES{ $_ }{ active } || [] },
]
}
grep {
@{ $RT::Lifecycle::LIFECYCLES{ $_ }{ initial } || [] }
|| @{ $RT::Lifecycle::LIFECYCLES{ $_ }{ active } || [] }
}
grep { $_ ne '__maps__' && $RT::Lifecycle::LIFECYCLES_CACHE{ $_ }{ type } eq 'ticket' }
keys %RT::Lifecycle::LIFECYCLES;
return unless %lifecycle;
my $sql;
if ( keys %lifecycle == 1 ) {
$sql = join ' OR ', map { qq{ Status = '$_' } } map { $escape_quotes->($_) } map { @$_ } values %lifecycle;
}
else {
my @active_sql;
for my $name ( keys %lifecycle ) {
my $escaped_name = $escape_quotes->($name);
my $active_sql =
qq{Lifecycle = '$escaped_name'}
. ' AND ('
. join( ' OR ', map { qq{ Status = '$_' } } map { $escape_quotes->($_) } @{ $lifecycle{ $name } } ) . ')';
push @active_sql, qq{($active_sql)};
}
$sql = join ' OR ', @active_sql;
}
$active_status_node = RT::Interface::Web::QueryBuilder::Tree->new;
$active_status_node->ParseSQL(
Query => $sql,
CurrentUser => $self->CurrentUser,
);
}
$parent->removeChild( $node );
$parent->insertChild( $index, $active_status_node );
}
}
);
# Perform an optimization pass looking for watcher bundling
$tree->traverse(
sub {
my $node = shift;
return if $node->isLeaf;
return unless ($node->getNodeValue||'') eq "OR";
my %refs;
my @kids = grep {$_->{Meta}[0] eq "WATCHERFIELD"}
map {$_->getNodeValue}
grep {$_->isLeaf} $node->getAllChildren;
for (@kids) {
my $node = $_;
my ($key, $subkey, $op) = @{$node}{qw/Key Subkey Op/};
next if $node->{Meta}[1] and RT::Ticket->Role($node->{Meta}[1])->{Column};
next if $op =~ /^!=$|\bNOT\b/i;
next if $op =~ /^IS( NOT)?$/i and not $subkey;
$node->{Bundle} = $refs{$node->{Meta}[1] || ''} ||= [];
}
}
);
# Convert simple OR'd clauses to IN for better performance, e.g.
# (Status = 'new' OR Status = 'open' OR Status = 'stalled')
# to
# Status IN ('new', 'open', 'stalled')
$tree->traverse(
sub {
my $node = shift;
my $parent = $node->getParent;
return if $parent eq 'root'; # Skip root's root
# For simple searches like "Status = 'new' OR Status = 'open'",
# the OR node is also the root node, go up one level.
$node = $parent if $node->isLeaf && $parent->isRoot;
return if $node->isLeaf;
if ( ( $node->getNodeValue // '' ) =~ /^or$/i && $node->getChildCount > 1 ) {
my @children = $node->getAllChildren;
my %info;
for my $child (@children) {
# Only handle innermost ORs
return unless $child->isLeaf;
my $entry = $child->getNodeValue;
return unless $entry->{Op} =~ /^!?=$/;
# Handle String/Int/Id/Enum/Queue/Lifecycle only for
# now. Others have more complicated logic inside, which
# can't be easily converted.
return unless ( $entry->{Meta}[0] // '' ) =~ /^(?:STRING|INT|ID|ENUM|QUEUE|LIFECYCLE)$/;
for my $field (qw/Key SubKey Op Value/) {
$info{$field}{ $entry->{$field} // '' } ||= 1;
if ( $field eq 'Value' ) {
# In case it's meta value like __Bookmarked__
return if $entry->{Meta}[0] eq 'ID' && $entry->{$field} !~ /^\d+$/;
}
elsif ( keys %{ $info{$field} } > 1 ) {
return; # Skip if Key/SubKey/Op are different
}
}
}
my $first_child = shift @children;
my $entry = $first_child->getNodeValue;
$entry->{Op} = $info{Op}{'='} ? 'IN' : 'NOT IN';
$entry->{Value} = [ sort keys %{ $info{Value} } ];
if ( $node->isRoot ) {
$parent->removeChild($_) for @children;
}
else {
$parent->removeChild($node);
$parent->addChild($first_child);
}
}
}
);
my $ea = '';
$tree->traverse(
sub {
my $node = shift;
$ea = $node->getParent->getNodeValue if $node->getIndex > 0;
return $self->_OpenParen unless $node->isLeaf;
my ($key, $subkey, $meta, $op, $value, $bundle, $quote_value)
= @{$node->getNodeValue}{qw/Key Subkey Meta Op Value Bundle QuoteValue/};
# normalize key and get class (type)
my $class = $meta->[0];
# replace __CurrentUser__ with id
$value = $self->CurrentUser->id if $value eq '__CurrentUser__';
# replace __CurrentUserName__ with the username
$value = $self->CurrentUser->Name if $value eq '__CurrentUserName__';
my $sub = $dispatch{ $class }
or die "No dispatch method for class '$class'";
if ( defined $quote_value && !$quote_value && $value !~ /^(?:[+-]?[0-9]+|NULL)$/i ) {
my ( $class, $field );
# e.g. CF.Foo or CF.{Beta Date}
if ( $value =~ /^CF\.(?:\{(.*)}|(.*?))(?:\.(Content|LargeContent))?$/i ) {
my $cf = $1 || $2;
$field = $3 || 'Content';
my ( $ocfvalias ) = $self->_CustomFieldJoin( $cf, $cf );
$value = "$ocfvalias.$field";
$class = 'RT::ObjectCustomFieldValues';
}
# e.g. ObjectCustomFieldValues_1.Content
elsif ( $value =~ /^(\w+?)(?:_\d+)?\.(\w+)$/ ) {
my $table = $1;
$field = $2;
$class = $table =~ /main/i ? 'RT::Tickets' : "RT::$table";
}
else {
$class = 'RT::Tickets';
$field = $value;
}
my $valid;
if ( $class->can('RecordClass')
and ( my $record_class = $class->RecordClass ) )
{
$valid = $record_class->_ClassAccessible->{$field}
&& $record_class->_ClassAccessible->{$field}{read};
}
die $self->loc( "Wrong query, no such column '[_1]' in '[_2]'", $value, $string ) unless $valid;
# In case the column(e.g. LastUpdated) is defined in multiple tables
$value = "main.$value" if $class eq 'RT::Tickets' && $value =~ /^\w+$/;
if ( $class eq 'RT::ObjectCustomFieldValues' ) {
if ( RT->Config->Get('DatabaseType') eq 'Pg' ) {
my $cast_to;
if ($subkey) {
# like Requestor.id
if ( $subkey eq 'id' ) {
$cast_to = 'INTEGER';
}
}
elsif ( my $meta = $self->RecordClass->_ClassAccessible->{$key} ) {
if ( $meta->{is_numeric} ) {
$cast_to = 'INTEGER';
}
elsif ( $meta->{type} eq 'datetime' ) {
$cast_to = 'TIMESTAMP';
}
}
$value = "CAST($value AS $cast_to)" if $cast_to;
}
elsif ( RT->Config->Get('DatabaseType') eq 'Oracle' ) {
if ($subkey) {
# like Requestor.id
if ( $subkey eq 'id' ) {
$value = "TO_NUMBER($value)";
}
}
elsif ( my $meta = $self->RecordClass->_ClassAccessible->{$key} ) {
if ( $meta->{is_numeric} ) {
$value = "TO_NUMBER($value)";
}
elsif ( $meta->{type} eq 'datetime' ) {
$value = "TO_DATE($value,'YYYY-MM-DD HH24:MI:SS')";
}
}
}
}
}
# A reference to @res may be pushed onto $sub_tree{$key} from
# above, and we fill it here.
$sub->(
$self, $key, $op, $value,
ENTRYAGGREGATOR => $ea,
SUBKEY => $subkey,
BUNDLE => $bundle,
defined $quote_value ? ( QUOTEVALUE => $quote_value ) : (),
);
},
sub {
my $node = shift;
return $self->_CloseParen unless $node->isLeaf;
}
);
}
sub FromSQL {
my ($self,$query) = @_;
{
# preserve first_row and show_rows across the CleanSlate
local ($self->{'first_row'}, $self->{'show_rows'}, $self->{_sql_looking_at});
$self->CleanSlate;
$self->_InitSQL();
}
return (1, $self->loc("No Query")) unless $query;
$self->{_sql_query} = $query;
eval {
local $self->{parsing_ticketsql} = 1;
$self->_parser( $query );
};
if ( $@ ) {
my $error = "$@";
$RT::Logger->error("Couldn't parse query: $error");
return (0, $error);
}
# We only want to look at EffectiveId's (mostly) for these searches.
unless ( $self->{_sql_looking_at}{effectiveid} ) {
# instead of EffectiveId = id we do IsMerged IS NULL
$self->Limit(
FIELD => 'IsMerged',
OPERATOR => 'IS',
VALUE => 'NULL',
ENTRYAGGREGATOR => 'AND',
QUOTEVALUE => 0,
);
}
unless ( $self->{_sql_looking_at}{type} ) {
$self->Limit( FIELD => 'Type', VALUE => 'ticket' );
}
# We don't want deleted tickets unless 'allow_deleted_search' is set
unless( $self->{'allow_deleted_search'} ) {
$self->Limit(
FIELD => 'Status',
OPERATOR => '!=',
VALUE => 'deleted',
);
}
# set SB's dirty flag
$self->{'must_redo_search'} = 1;
$self->{'RecalcTicketLimits'} = 0;
return (1, $self->loc("Valid Query"));
}
=head2 Query
Returns the last string passed to L</FromSQL>.
=cut
sub Query {
my $self = shift;
return $self->{_sql_query};
}
sub CurrentUserCanSeeAll {
my $self = shift;
return 1 if RT->Config->Get('UseSQLForACLChecks');
return $self->CurrentUser->HasRight( Right => 'ShowTicket', Object => RT->System ) ? 1 : 0;
}
RT::Base->_ImportOverlays();
1;
|