Compare commits
1678 Commits
plugin-hooks
...
1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| cac7b0423f | |||
| 4b52b7a8df | |||
| 6ed2e003a1 | |||
| 1cc116fe5c | |||
| 619c148719 | |||
| 0ae9cc7d07 | |||
| a2a3dae974 | |||
| 4f5dc94170 | |||
| 4775864d69 | |||
| d064f27271 | |||
| c6223864d0 | |||
| 5e259d41e2 | |||
| cd54efa0c9 | |||
| a84ea6866d | |||
| 83f1ecb980 | |||
| 69af1515d1 | |||
| ef5bca0fef | |||
| 0d5fca9ba5 | |||
| ad73f12a6b | |||
| 56af944afa | |||
| 48a5460da4 | |||
| bd1384db7d | |||
| 11ff334cd8 | |||
| 64d2221db5 | |||
| 43bbda1966 | |||
| 5a17b5ba39 | |||
| c6201ae15b | |||
| 305cab100f | |||
| 6ef240841c | |||
| bc3ad9af38 | |||
| c7d075fb68 | |||
| 672852baaf | |||
| 6eea3300f8 | |||
| 68bdbbac7d | |||
| e21b91485e | |||
| 6cb4ff7d89 | |||
| de17640489 | |||
| 7376ef2ad7 | |||
| c98f46d691 | |||
| acef1d5352 | |||
| d2f8feb7c5 | |||
| 116c7a7964 | |||
| 4083e7e622 | |||
| c5863c0ad0 | |||
| 70da33fc29 | |||
| 95c3c63cfe | |||
| 5db9a982cc | |||
| 41ff1b9cb2 | |||
| b2e903ff7c | |||
| 093853b56a | |||
| b10818f4a1 | |||
| b53de502ab | |||
| 69d9600f48 | |||
| 2562bc5bcd | |||
| d48eb2de47 | |||
| 5f93750c80 | |||
| 921b425b8e | |||
| d635fff3f5 | |||
| 43fabab950 | |||
| f08b2a394d | |||
| cf334cee31 | |||
| c56c0f411c | |||
| 759858d11d | |||
| 1a145dca25 | |||
| 28519714e0 | |||
| f18c0c790b | |||
| 3096166f09 | |||
| 345301284a | |||
| f484fe8556 | |||
| e94c45d548 | |||
| 080dc2212e | |||
| af726ea8f0 | |||
| 1a4b23731f | |||
| f3cc84b343 | |||
| e5ac73b7dc | |||
| b88b15183b | |||
| 6e529f82a7 | |||
| ab4bdc379e | |||
| c3c3460e0d | |||
| 2b203fe5ab | |||
| ef1c63efbf | |||
| 8c02e4c723 | |||
| 513c18d2d3 | |||
| e320017cf0 | |||
| 0d34c3731b | |||
| f97ff28628 | |||
| 52a92b1822 | |||
| 51d3f51159 | |||
| 908d44519c | |||
| 715c9d16ef | |||
| a1f73c8b20 | |||
| 3601c291d0 | |||
| 1933f9ddb2 | |||
| e474a6095b | |||
| 8c93cc4381 | |||
| cd097a5758 | |||
| a7b80fcc06 | |||
| e417d755e9 | |||
| 0fa124a92c | |||
| 36c82ecc1f | |||
| 469ff0fb4e | |||
| 2fda2c1826 | |||
| cbd4af236c | |||
| a499efd328 | |||
| faeae788be | |||
| edeb84a070 | |||
| 6a8dc735d3 | |||
| b897089729 | |||
| 4a4bc93278 | |||
| 1be15816dd | |||
| 80f7faf10a | |||
| 0a47389a65 | |||
| 306ca5e714 | |||
| f65c47e3a7 | |||
| da7c89bfd0 | |||
| 663f0c83b2 | |||
| 554c047d80 | |||
| a4e411c643 | |||
| a00d1eabd7 | |||
| e5180884c1 | |||
| 51c8f3143c | |||
| 0d938dff59 | |||
| 3db77a86a9 | |||
| b6cd076441 | |||
| 7ccdaee110 | |||
| 488879d9cf | |||
| e65c3cfc7d | |||
| a925435b29 | |||
| eabe8c51cd | |||
| c18cb9451d | |||
| df7edb843b | |||
| dfc448030d | |||
| 23f097e344 | |||
| 2c898d8a81 | |||
| 9b595c689d | |||
| 0fc884cf42 | |||
| 657aa624a4 | |||
| bf33b57aa4 | |||
| 0004b52646 | |||
| de51e16d2b | |||
| 760c933bd7 | |||
| 3bf6790826 | |||
| aa4d1fe816 | |||
| 2c0ce104e7 | |||
| e4e4b0f4b8 | |||
| 7e9d4811ec | |||
| 538642c5c4 | |||
| 4cb943571a | |||
| d22723ed04 | |||
| 88db9d0bdc | |||
| 0e1595ad56 | |||
| 6a6f403978 | |||
| f23aceba86 | |||
| 9ccccb9984 | |||
| c76b9edf6c | |||
| 734f8324ea | |||
| f77e5d093a | |||
| f35921d308 | |||
| 43e5bb75d2 | |||
| 2674c6116c | |||
| 5163904a3a | |||
| 9306f3ea6c | |||
| 71a4158fd0 | |||
| 5879273739 | |||
| 3979224693 | |||
| f3e3752759 | |||
| 77795d41ba | |||
| db453db497 | |||
| eb80b79c26 | |||
| f2993f6ed0 | |||
| 8df189ff86 | |||
| c88a467ddf | |||
| 2bbc948e06 | |||
| c499d2d150 | |||
| ce549933c8 | |||
| e8729feba7 | |||
| 4a51f10074 | |||
| 4524bc04e9 | |||
| 06d2c3fd4e | |||
| b93cf03483 | |||
| 883e7b1b94 | |||
| 43a5febf61 | |||
| 89aa60cbbd | |||
| 8cdcf308be | |||
| 84dfff5957 | |||
| d29adc9bb7 | |||
| 0de66f7f1c | |||
| 79b4f68176 | |||
| 5225fb70f5 | |||
| e584ae220d | |||
| 533590c29c | |||
| 6e6e260cea | |||
| 5e4eef1a4e | |||
| 4dd4300147 | |||
| b5d9a1dfbd | |||
| f741ca7269 | |||
| 388805ad58 | |||
| 0e0b8e0799 | |||
| 194dab8e96 | |||
| 0f999ef0e0 | |||
| 2ada68ae62 | |||
| f4be4d101b | |||
| 2f0fbef858 | |||
| 0097770626 | |||
| e6c8760ad7 | |||
| 6b88de1234 | |||
| 7203196212 | |||
| a179f261cd | |||
| 838f3195e7 | |||
| 6a1920915c | |||
| ad487bf7cc | |||
| c03b4c2e1e | |||
| 51d790b2f3 | |||
| 7621463acb | |||
| 2f5c17a0f6 | |||
| c3e8d1d512 | |||
| e605973ec4 | |||
| 8cc519e763 | |||
| 508df4a33a | |||
| e016f3ef13 | |||
| 54eea93def | |||
| d550c46160 | |||
| 8e3d1b694a | |||
| e109c9b6b6 | |||
| 7e4aa9ca92 | |||
| c312b8b058 | |||
| 4d19007fd1 | |||
| 7adf05810a | |||
| 054ff0db8e | |||
| 3dc4dbe302 | |||
| 63ed494f21 | |||
| b028a48c53 | |||
| 24b4c5f48d | |||
| 6ea1ef77e5 | |||
| 4e5078ebb0 | |||
| c7c3c0cc7c | |||
| 3e2e5a0a0c | |||
| ddaa95523a | |||
| 22c1e2b8cf | |||
| cfa1f0c231 | |||
| b99d4189b7 | |||
| c07696b578 | |||
| 43e3c43cbd | |||
| 1a73f8fa0f | |||
| fe066e793d | |||
| 332d88cd67 | |||
| 6511e94233 | |||
| 729bea1cf3 | |||
| 2af97616f7 | |||
| d65922afde | |||
| 3f3e30c2aa | |||
| 69769e1dfd | |||
| e8bc0b2980 | |||
| bd5fe10c13 | |||
| 12759fd416 | |||
| c58dc83e74 | |||
| 7514e12d33 | |||
| afdcd770dc | |||
| bc79caaf69 | |||
| be20d98040 | |||
| 3a99f18913 | |||
| ca6df3d78d | |||
| 976cba0c5d | |||
| cdb86d5ef7 | |||
| 3355ffe029 | |||
| 6817a45e7f | |||
| f2b227547e | |||
| fe1e3ccd18 | |||
| 44955a519c | |||
| f6d8752e44 | |||
| 3c0c0a7677 | |||
| b09a483aa9 | |||
| 0fd7e2d696 | |||
| 81d617cd5b | |||
| b52e75aad9 | |||
| f5f5a5f64f | |||
| 8699e5bbcd | |||
| ae55978515 | |||
| 8e57b1f6cd | |||
| c9197769fb | |||
| da84474391 | |||
| 9a85d4d063 | |||
| d6c299f57d | |||
| 241f79ac06 | |||
| 82310d3162 | |||
| 1ab77ee015 | |||
| 551993d3c2 | |||
| 049f47eaf0 | |||
| c174540a0e | |||
| 02cc0efdd7 | |||
| 26e9a0d919 | |||
| ddec53b9a2 | |||
| 113049412b | |||
| bda2aa474c | |||
| c7c43d38ce | |||
| bfed36ac84 | |||
| d6f9e576e8 | |||
| f1d16bc007 | |||
| 899f06612a | |||
| 7ae53845ac | |||
| aa521c5a5a | |||
| 3de1f2e157 | |||
| c68d853bf4 | |||
| 19d4ddf2f2 | |||
| 39c97279ca | |||
| f7bd0801f6 | |||
| 46ecc488a9 | |||
| b2dee55e72 | |||
| d581510af6 | |||
| 6ed9734cb9 | |||
| e24d6cc223 | |||
| 01dbba72ab | |||
| a2537b3969 | |||
| f838904a7e | |||
| 89cf2d256d | |||
| 0341ac80eb | |||
| 3d393a5711 | |||
| 93bcc68017 | |||
| 24ec3bb7a9 | |||
| 103698b371 | |||
| 87bc092d7c | |||
| 4878d749f4 | |||
| 46aa855572 | |||
| 6e68921590 | |||
| dab0c07fba | |||
| 08d7c5bfb4 | |||
| 77459f9ae4 | |||
| d46609f4bb | |||
| c6b2f1d606 | |||
| d828122009 | |||
| 026fbb99a6 | |||
| d18fba4ffe | |||
| 6f930e9be6 | |||
| 82dd1b2bf2 | |||
| 899fb1079f | |||
| 28e9bc5d82 | |||
| 0fcc436f22 | |||
| 74e85953f0 | |||
| c11d30ebc9 | |||
| b733accfe3 | |||
| 3dd9687d41 | |||
| 4f268c5606 | |||
| 9e22faa640 | |||
| b3330d3995 | |||
| 7b6b147761 | |||
| 49bfee0535 | |||
| c5f30fde28 | |||
| 038a88e970 | |||
| cec2b20793 | |||
| 0772391fe0 | |||
| d16c2d4cd3 | |||
| 2f8cf7f762 | |||
| a811f67748 | |||
| 0ee17b132c | |||
| 00cec500c6 | |||
| ea3e2b1121 | |||
| 7059d0b500 | |||
| 3168ee3d47 | |||
| 89b9700074 | |||
| 4fbffd7716 | |||
| 997e8bb0dd | |||
| 4a67c211ca | |||
| 8d086cb7d4 | |||
| c18f8d34fb | |||
| 6ed690eacc | |||
| 55a3ac764f | |||
| 541d830d2a | |||
| d2baf5f2a7 | |||
| 937d0c70f7 | |||
| 2c8a24092b | |||
| 1fec53cc25 | |||
| 00d7bc3766 | |||
| 0b17e735ea | |||
| d02ddefff4 | |||
| a8a49a26a1 | |||
| ed9eb2d684 | |||
| d04d3f181a | |||
| f50feca730 | |||
| 57a4cefd97 | |||
| 349a5d3b55 | |||
| 81ee2ff884 | |||
| 9482831313 | |||
| 597725d77c | |||
| 23c46c68ab | |||
| 3c20a9b0ac | |||
| be2004e398 | |||
| 446ef61680 | |||
| f5dfe8b2f5 | |||
| eac7fcff6e | |||
| fece6aa4d0 | |||
| 88339fd98b | |||
| 5a5d02dfb5 | |||
| 695bffe684 | |||
| 34ee5eccda | |||
| 8fb29d4d21 | |||
| 2ad8242ae7 | |||
| 6c8b87fbc8 | |||
| e5d300af0a | |||
| d7725ecc06 | |||
| 626b71622d | |||
| ea51dcf911 | |||
| cfe4d0e7db | |||
| 5bd912e9a2 | |||
| 112fc99311 | |||
| 155083ec97 | |||
| b86b9b898e | |||
| 778117fead | |||
| 39c585740d | |||
| 358e3194d7 | |||
| d43c860448 | |||
| df46d704e8 | |||
| a0364deb6a | |||
| a1a24483b5 | |||
| a5698b3745 | |||
| 7ef20cc169 | |||
| 2261ec7b95 | |||
| 080ad6a16c | |||
| 12ea682b66 | |||
| 8420f25109 | |||
| 675f28f895 | |||
| 9044305b93 | |||
| d1c90d9abf | |||
| 56268d146d | |||
| a8f56aad2c | |||
| d4525828b9 | |||
| 1bc00ac022 | |||
| 320c191f04 | |||
| 0ef9bc039d | |||
| 002f440bcd | |||
| 3eb815fddd | |||
| b4cf8ea525 | |||
| d55e1ec5b0 | |||
| ed2c98fcae | |||
| f8b52b13a0 | |||
| bddf3b5c2c | |||
| 9c7438aac6 | |||
| 1827d609a1 | |||
| dfe447f841 | |||
| 68a4cd38f5 | |||
| 64f4b50139 | |||
| da55be4e9a | |||
| 3873388f9b | |||
| 667a7256a7 | |||
| 0a05cc2a37 | |||
| ff77fb6aa9 | |||
| fe7d65922b | |||
| d7c9886b8c | |||
| ee64310df4 | |||
| 7b99adb3d6 | |||
| 1b65a44cfc | |||
| 23508f4f98 | |||
| a5ceb2f244 | |||
| 90c0e99d2a | |||
| 486f705494 | |||
| 602aa1d7ae | |||
| f6ac12ad9d | |||
| 75ac722ebc | |||
| 1e30e67043 | |||
| 99956ec248 | |||
| 518779d96d | |||
| eecc6864a9 | |||
| eb3b7d055a | |||
| f05b778065 | |||
| cab99aa5ad | |||
| e9810b5de6 | |||
| 4ac99328ff | |||
| c71cb84a91 | |||
| f69a4107f8 | |||
| 357a4eb7b9 | |||
| 88587b5916 | |||
| 4702a05ebb | |||
| 9ffee0a5a4 | |||
| 4cf2e7c216 | |||
| 4b3d4553e4 | |||
| c67cc7c285 | |||
| 857c7d16ff | |||
| ac5cfe7a62 | |||
| ff7eb7b23a | |||
| b7b4e27833 | |||
| 44a079fcd7 | |||
| b718d5dec2 | |||
| a359ffb397 | |||
| b1a92b9b2e | |||
| 04455783a7 | |||
| c36c924714 | |||
| a4c64ff84b | |||
| de2bef606d | |||
| 1052658df2 | |||
| 9c1efcfa48 | |||
| 45f3199aa9 | |||
| 8db9ecef08 | |||
| 9fb40b1a2f | |||
| 62c83bdd2e | |||
| 24fde6f109 | |||
| 6ea202f808 | |||
| 2a19efaf05 | |||
| 962827c793 | |||
| e4d06246cd | |||
| d63784569f | |||
| 5e1dc78d75 | |||
| 32bb0226e7 | |||
| 0704ac9444 | |||
| 569d13b7f5 | |||
| c4b01e5c13 | |||
| a54fa93b2e | |||
| e26eeef837 | |||
| d404d2f586 | |||
| 682829a904 | |||
| ff36245f3e | |||
| edab0f0cbb | |||
| bfcd5039f2 | |||
| e07e9d8bfe | |||
| baa1ad4256 | |||
| aa9951b38b | |||
| 9f59cd64ab | |||
| ffe8222257 | |||
| 18c7c0d3ee | |||
| fce25d4488 | |||
| 3b7e7be72a | |||
| 87e83c7285 | |||
| e1013c44a3 | |||
| c478fa7f90 | |||
| 0844a22b02 | |||
| 6be0e335fb | |||
| 1ebb78e412 | |||
| 7955e1eb9f | |||
| c5976333c2 | |||
| 1099d704b5 | |||
| e92802508e | |||
| cf9bb2699f | |||
| 4398386c48 | |||
| 503d613403 | |||
| 6ccbcfb589 | |||
| b5b6a5e971 | |||
| 3285230708 | |||
| 06ca18b042 | |||
| 9d120c872c | |||
| 008ad85d10 | |||
| 03b57415d6 | |||
| 77aeca5d55 | |||
| beb20e7c6e | |||
| 111950108a | |||
| 6bf0723d06 | |||
| 6a369f28dd | |||
| 1ba5779f94 | |||
| 488c192286 | |||
| 0e4525d76c | |||
| 8e3def7129 | |||
| 6b94614c36 | |||
| a011e9a9bf | |||
| 46d27f16d5 | |||
| 91a493e2c7 | |||
| b8cd280bec | |||
| 7eb9cca660 | |||
| dfabadf4f7 | |||
| 39b44b1cb9 | |||
| 1c11d3403e | |||
| 09e47a3b63 | |||
| 7e0ed924da | |||
| 0b34755eb0 | |||
| 9a452a5c35 | |||
| bb477a3a0f | |||
| 6610bb6b6c | |||
| f33231181f | |||
| c31a671973 | |||
| 4fb554e95d | |||
| 17512e7efd | |||
| d58762a52d | |||
| c66943c9b8 | |||
| 21b52d2fd9 | |||
| 72ceefd36e | |||
| 1f47d5856e | |||
| 008f35277e | |||
| d905f2ce7e | |||
| d72778619f | |||
| b63b5e5928 | |||
| 5c6ce51ec9 | |||
| ddeaf9da96 | |||
| 7959101288 | |||
| 4fe14e71c2 | |||
| a83501364d | |||
| 272869c654 | |||
| 7537e86fd2 | |||
| 9f6612651c | |||
| 1c3722b5cb | |||
| 34d14be556 | |||
| 8f9f56502d | |||
| 84abeac304 | |||
| 3918374d5c | |||
| 96fe47ea19 | |||
| b090098952 | |||
| f2520385e4 | |||
| 1de2a0b7c7 | |||
| 0fe389b841 | |||
| 8f85ba79bc | |||
| 40e2af7ab9 | |||
| 517a87f8c5 | |||
| efeebd4278 | |||
| e823efc41f | |||
| 174f014564 | |||
| 5266e328c0 | |||
| 84bf891bb5 | |||
| aab6e68865 | |||
| f2113e735d | |||
| a2b4bb0dfb | |||
| 8f33c6589d | |||
| 719cd7cfce | |||
| 5f8e9d7118 | |||
| e178123569 | |||
| c870a7b9ef | |||
| 8bc0f7888b | |||
| e02da72947 | |||
| 97c5362cfe | |||
| f5f26a44c1 | |||
| 184aae5bf2 | |||
| c051947161 | |||
| e5dc94fe82 | |||
| 7592a955fb | |||
| 346c569f98 | |||
| 8b8c24e61f | |||
| 25e131f176 | |||
| f134e72fec | |||
| 88fcf484d4 | |||
| 3d317a435b | |||
| 4c2264ee42 | |||
| 66540afc08 | |||
| 99b52c8796 | |||
| 915bbcfaff | |||
| 724141a39a | |||
| c2e2040fc0 | |||
| f9732b02a2 | |||
| b9151cb3e8 | |||
| 2416260af2 | |||
| 4af8765f15 | |||
| ae082205e2 | |||
| 43fd27fd0c | |||
| f3bcb705f7 | |||
| ebab5a0074 | |||
| b75e038255 | |||
| b0999e3764 | |||
| 1f06cf8899 | |||
| 5a9528cf3d | |||
| 9b0acce9c9 | |||
| 2398565193 | |||
| 14e88ec420 | |||
| 654ccddd76 | |||
| 58faed438d | |||
| d8c5549168 | |||
| 4bdfef4dc4 | |||
| 0485d3a524 | |||
| 4e3202d2a2 | |||
| d73fb1fab8 | |||
| c9bfdc009b | |||
| ec4ba23248 | |||
| 3fc655904f | |||
| e24358bc43 | |||
| dfd0b8bcdf | |||
| d84bd8edd8 | |||
| 71bc44a89d | |||
| 2a3a6da45a | |||
| 0176430f5c | |||
| b2018dfa8a | |||
| 1f1135e867 | |||
| c309210654 | |||
| bccf6496f8 | |||
| ba7cf9c3ce | |||
| 7d57833740 | |||
| 63c8675887 | |||
| 6838677e30 | |||
| ded602c89f | |||
| 534ce51154 | |||
| ea9a7c20e6 | |||
| ea0bc56a65 | |||
| 93bf1df5d4 | |||
| b2e4d8ad3f | |||
| 1a65eb8b08 | |||
| ed15b2aa14 | |||
| bc37fcee74 | |||
| cbeeaa4d4d | |||
| dfd0204052 | |||
| 326ed79b43 | |||
| 8c769c546f | |||
| 28f0b5ce4a | |||
| 0241003590 | |||
| d82738ad00 | |||
| cd110535a3 | |||
| bb8a397a13 | |||
| 8267ded518 | |||
| 1d8b4ee778 | |||
| 22d12032e7 | |||
| 4b83a0d848 | |||
| 58103680bd | |||
| 858f5cbf07 | |||
| b8b8cea288 | |||
| c31411ec00 | |||
| 8f40750ad7 | |||
| cc684803ba | |||
| d4ccce3c72 | |||
| d201c54455 | |||
| 7c14c6d42e | |||
| e02caeab0f | |||
| 87d14dea10 | |||
| 86a9d90f07 | |||
| 668ec7f694 | |||
| be41f7f473 | |||
| 3b9d8c2a72 | |||
| 6245f49934 | |||
| 54e37b12fd | |||
| 5f48256c20 | |||
| 7b77301eab | |||
| c201581c05 | |||
| 27e3fa2bed | |||
| 4ea714fb91 | |||
| 6994a81209 | |||
| b2a55bda0c | |||
| 962535255c | |||
| 9943f64ff0 | |||
| 03548f2d63 | |||
| 5667b2b7d1 | |||
| 279e81eb92 | |||
| 92ec35e657 | |||
| e64fb6a728 | |||
| e117dc8c9c | |||
| a842769c3f | |||
| ac56d1d5e5 | |||
| 72d208cb35 | |||
| 86874785b7 | |||
| a658679d29 | |||
| 06fff6295c | |||
| 9aa2b6b9a4 | |||
| 821f9eb390 | |||
| a3fcdfe391 | |||
| 97b4e75478 | |||
| 6fedbf60d5 | |||
| 6dfe0395a5 | |||
| 1a1bfbfb07 | |||
| a18676b669 | |||
| 4e73685af7 | |||
| 875eb47ad1 | |||
| 2e675342cb | |||
| a9fb11c0f5 | |||
| eecec44ed2 | |||
| 9f12a14382 | |||
| 5b787785b4 | |||
| 6842941adc | |||
| 383b2bd903 | |||
| 83717a9b75 | |||
| 9233a07a23 | |||
| de8dcc5b26 | |||
| f206dfe9b5 | |||
| a68d8a7b32 | |||
| 2cec9f87ab | |||
| cabf052127 | |||
| 2445250960 | |||
| 6ffe1926ab | |||
| 04ae25f6b0 | |||
| e5c4cfc688 | |||
| ff3d0fe4db | |||
| 2e0cbd2840 | |||
| 37d401ac58 | |||
| 5833ba9f81 | |||
| e615266e9a | |||
| 29301c8a38 | |||
| e76d4c5c4c | |||
| ac4937a767 | |||
| 29ab7b4108 | |||
| 07aa3c55bd | |||
| 739e11702a | |||
| d40756d611 | |||
| 50bab8b429 | |||
| a41ba2aed7 | |||
| b887cef7af | |||
| 6456f7c4a4 | |||
| 61c09b6442 | |||
| 257c92f8f9 | |||
| a150689be9 | |||
| 6531c3f887 | |||
| 945ea9b01c | |||
| 548d5a21f6 | |||
| 35333367df | |||
| ee9c2d3d88 | |||
| 70118fb136 | |||
| 07ffad4a7e | |||
| 5e539c31b0 | |||
| 4425acafff | |||
| afd2d4afc6 | |||
| 0b3e3471b0 | |||
| 0ac07afc67 | |||
| 6224f7caca | |||
| 1088c7360b | |||
| c5d8bbeb8c | |||
| 4c42e1a08f | |||
| ca250c1f2e | |||
| f65133093a | |||
| d8ba5c2a06 | |||
| 4450e6f24b | |||
| 9cd662f8dc | |||
| 22d3d5a3b0 | |||
| 531eb65557 | |||
| 38dc4d1cf9 | |||
| ac8a67191f | |||
| 94d34887cc | |||
| 8ffc61f66c | |||
| 480ccbf045 | |||
| 6656d41a41 | |||
| bcbf08017a | |||
| 4e811bebd1 | |||
| 19df1b636c | |||
| e6ac92487a | |||
| 30ad78e57d | |||
| e89d4825dd | |||
| dd633322f9 | |||
| 21e18c1eb4 | |||
| 52a6b0a21e | |||
| 41cbd239c4 | |||
| b4c55ea4de | |||
| 3477ded32a | |||
| cc3c8a717c | |||
| d3691239fa | |||
| 7b0cb6aba8 | |||
| fb349dc4ab | |||
| 9ec5c32861 | |||
| 041277235b | |||
| 8faa66f68f | |||
| 563c927e13 | |||
| aca6ed13fc | |||
| 8e3222195b | |||
| 275b555b09 | |||
| 7f4635022f | |||
| ede9960444 | |||
| d4ed5ec30b | |||
| 7707457145 | |||
| 847c7367b4 | |||
| 02d07d8a43 | |||
| d41544402c | |||
| edbfd09990 | |||
| 677d1769d6 | |||
| 609faba6a3 | |||
| cd1e094ce8 | |||
| 925104288a | |||
| ec670f56ac | |||
| f9fe92dcb3 | |||
| 5b97570693 | |||
| 71abeb5898 | |||
| f1f65794e4 | |||
| f5517cd834 | |||
| aae5c7d359 | |||
| e10577e9ed | |||
| a4d7a03b14 | |||
| 6fb80efdae | |||
| a49506ce5f | |||
| c28b044d68 | |||
| a39bc8f1f4 | |||
| 30526d55c3 | |||
| 9886827a66 | |||
| d7d72c43c8 | |||
| ff0e5b019c | |||
| 9ed048dc42 | |||
| 06ff26f092 | |||
| 560e915c50 | |||
| bb61c9a0ec | |||
| 6da352dc47 | |||
| cfd7d07b69 | |||
| 9e07fb5e04 | |||
| 26bbad5f23 | |||
| dcba9f18e6 | |||
| 5ec4d4cdab | |||
| bf0ddc2886 | |||
| 36d8f35192 | |||
| d41bd93acb | |||
| 1a9942ba99 | |||
| a9ee946053 | |||
| 6404945683 | |||
| 03d1edaef1 | |||
| 9c8daee045 | |||
| 6151e95e37 | |||
| e54d183d20 | |||
| ad90811e40 | |||
| 937823a0d8 | |||
| ef8ef596de | |||
| da22a9c8d6 | |||
| 5afa190a9a | |||
| 00f7a02959 | |||
| 9c287a0f98 | |||
| 6994d1c23b | |||
| 85f634481e | |||
| 202d01664a | |||
| 6ff5891100 | |||
| a7bb63a182 | |||
| aa07e8505e | |||
| 14c7a887ee | |||
| 72a396227a | |||
| 2221d68c4d | |||
| b3afde14fa | |||
| c48193f8c1 | |||
| 7642b5a9ab | |||
| 5e76040256 | |||
| 724cf47605 | |||
| 97383f78d0 | |||
| 199b213bbb | |||
| ddd14fe86b | |||
| 43995a43a5 | |||
| 6a54a0c94c | |||
| 9c282842a9 | |||
| 6da0542af4 | |||
| 62e58f26b0 | |||
| fbfb349496 | |||
| 211b13c9ec | |||
| 4ba8308507 | |||
| ea7ff8dd76 | |||
| 3224773ada | |||
| 964245e30a | |||
| 68c7af6c91 | |||
| c082cfc90e | |||
| 5db407ca59 | |||
| 53b002b497 | |||
| 85ce903cfa | |||
| 9c630cc2b7 | |||
| bd42b7cd9e | |||
| 70340910de | |||
| 2a5369e37d | |||
| d1ee28758f | |||
| 6bdd07275b | |||
| fe8f4e5b87 | |||
| 1d5479c1af | |||
| 52b5b29203 | |||
| ce8bd16020 | |||
| 7f94e3446f | |||
| 8141110eb2 | |||
| 9c9dc6e814 | |||
| 6e0a818caf | |||
| f7d7186c13 | |||
| e9a6730f4a | |||
| b87753c90d | |||
| f5eb1be268 | |||
| 3e52383988 | |||
| e5ed2b0f73 | |||
| 566d0a6ceb | |||
| 09a613b035 | |||
| 5ab33bca8e | |||
| a09f0e0e74 | |||
| da2854cf75 | |||
| 3df4df3438 | |||
| bae7579a72 | |||
| c6efc90041 | |||
| fba02769f3 | |||
| bbb5a47b2a | |||
| 88532b6817 | |||
| 682c5d1113 | |||
| 7dccf9fda6 | |||
| 814e138c2a | |||
| 9f59538241 | |||
| 752e263d3a | |||
| a7ea14f5af | |||
| 7319e8e235 | |||
| 7e1ac0e602 | |||
| 3704653c7a | |||
| 0985d4219c | |||
| f90b85f8be | |||
| 1930cf3d46 | |||
| 19f44cd1cb | |||
| 0a0d14d5a7 | |||
| 476ea76efb | |||
| ad1ffa06a0 | |||
| fa7bd1c71d | |||
| 29c0dae151 | |||
| 9fd14713c5 | |||
| d984422a1f | |||
| b557393252 | |||
| 24875be705 | |||
| 32c09fd5cf | |||
| 8887b6f3d3 | |||
| 15a14e55cd | |||
| 914ef1cb25 | |||
| 73ca9d9161 | |||
| 5ab582387e | |||
| 1be0b8f0cb | |||
| 070c18746e | |||
| 5d77f92ae6 | |||
| 7a5fe1c875 | |||
| a7e32302a6 | |||
| 6385217be0 | |||
| ac6ecdb360 | |||
| 31cf9be7ab | |||
| 6bb5508387 | |||
| bb44430b63 | |||
| 65cbd94e42 | |||
| 32ed656789 | |||
| 2a3fe1604a | |||
| 43200e2122 | |||
| df2e0dbcd7 | |||
| a59854ef9d | |||
| 10cbdf5d96 | |||
| c90878c817 | |||
| 1c03b98e5d | |||
| a4a41e05a8 | |||
| a6acc77904 | |||
| bab9b0d6ff | |||
| 81b84f641d | |||
| dea072f506 | |||
| 66839c12dd | |||
| ca166b30e1 | |||
| 3d65ed7aa0 | |||
| b7127e3c14 | |||
| e40241761a | |||
| 8c9fd662f0 | |||
| 5fbbdf7cb6 | |||
| 801ad70cb7 | |||
| c9c269abf7 | |||
| 8d6d9a80d2 | |||
| 3d78a1b3f3 | |||
| f1b5127cbb | |||
| 04e181b8b0 | |||
| b4be8849c0 | |||
| 3557e767e0 | |||
| 90810c0741 | |||
| c77806738a | |||
| b2a6176828 | |||
| 064ba5d8cd | |||
| 17cc0ba44a | |||
| 899aee4011 | |||
| 53a8264436 | |||
| 72f3c7f921 | |||
| 80acb00454 | |||
| ad34778cb1 | |||
| c2dfffd7f2 | |||
| 451ef7f21f | |||
| b67d624754 | |||
| e48cc150ec | |||
| 40a039ce1c | |||
| 7774642b03 | |||
| d516d9d9e5 | |||
| ec378bb446 | |||
| f0c676d3df | |||
| b44317b762 | |||
| 4181f85962 | |||
| 175ac71b2c | |||
| 47f264b15c | |||
| 5fc7d097fe | |||
| 9f45499936 | |||
| 7a3822448b | |||
| 6a9fcb23d0 | |||
| 3f52a0d3e8 | |||
| 57eadea091 | |||
| 5eae20f3d4 | |||
| 48e7b11065 | |||
| 1e7962bfe9 | |||
| 0100011e5c | |||
| 74d8739936 | |||
| eb7903c0ec | |||
| a42e56f65d | |||
| adbe164246 | |||
| 1852d907ba | |||
| 73eb1580ae | |||
| eb224378db | |||
| b622e0f8ce | |||
| c7c8dc71f2 | |||
| 2b585407cb | |||
| 4f4d447224 | |||
| 9701c33562 | |||
| 89719e205e | |||
| 03572ec569 | |||
| 554e569de1 | |||
| 04abeda1d7 | |||
| 7bd4590cd6 | |||
| 8375e98ade | |||
| e67fbdc315 | |||
| 36a55a0925 | |||
| dc8b804eba | |||
| 009b685b1d | |||
| 02ecc8aa15 | |||
| 608d6683da | |||
| 0d86bbf3ad | |||
| bd8ae3547e | |||
| 3227b32763 | |||
| 47f5713b1e | |||
| 56bdcf407f | |||
| df6e29f766 | |||
| 59dec17ddf | |||
| 38db62f1e7 | |||
| b78349d2ca | |||
| 700df9da8e | |||
| 71b55e54bf | |||
| a95a8aa40b | |||
| e63ccffd59 | |||
| 9fe6bcac74 | |||
| 4d892fd6d0 | |||
| 0aebb69c45 | |||
| d40bf20131 | |||
| 5b96d1b083 | |||
| 4c28291a19 | |||
| 589320337d | |||
| 46f52d306d | |||
| 21eb3c089d | |||
| 94cc23f103 | |||
| 4baf32b166 | |||
| 0f68334f0b | |||
| 0101e609f7 | |||
| a64b8695c8 | |||
| 67fd5f3dc9 | |||
| 7342a00e0a | |||
| 0123f7cde0 | |||
| 4596a35c0e | |||
| 82ea6c001d | |||
| 8cc8f5164d | |||
| 84de5fa3b0 | |||
| 0624bdb6c9 | |||
| 1c5a2ddfb0 | |||
| 79c074dbe5 | |||
| 66afc8c054 | |||
| 2bd419f23b | |||
| 1770fe54be | |||
| 1511b31377 | |||
| 79fd564b61 | |||
| 9c4a86d96c | |||
| 9819a6bfd1 | |||
| 95ba220b79 | |||
| 6b770fa70c | |||
| cf70f187dd | |||
| fe28193e4e | |||
| 9a986ac0a5 | |||
| 00b568c194 | |||
| b6c4b21b47 | |||
| 3fa9535670 | |||
| befe278fa9 | |||
| b9e95e7a70 | |||
| 33e7ae96ad | |||
| 04c428e059 | |||
| 24ee6b9a1b | |||
| aed1787d51 | |||
| 9525e5f147 | |||
| 5966f71c73 | |||
| ee4a754475 | |||
| 6359e51477 | |||
| d643d9a94c | |||
| 3183445aea | |||
| 9e4a118528 | |||
| b05ed594a0 | |||
| 4601ed2f3a | |||
| 13e2c727cf | |||
| d77be4e908 | |||
| d3038eee92 | |||
| 1c2cdedf19 | |||
| f9c9b054ba | |||
| bbc8d3d768 | |||
| b8eddf2014 | |||
| 9586269a06 | |||
| ff9da0bab0 | |||
| 5bdd429162 | |||
| e1b828de95 | |||
| 571494a028 | |||
| 2807b9c927 | |||
| 60dc357271 | |||
| 14e445c600 | |||
| 4500b606ce | |||
| f1b8bf22a2 | |||
| 8d53e433c5 | |||
| 85ad791d81 | |||
| 720f928cd2 | |||
| 8194cfaf86 | |||
| 876fb69271 | |||
| 48e26aa75b | |||
| 0310f43126 | |||
| 896e64b759 | |||
| a4e6e13b70 | |||
| dbf02e2654 | |||
| ca3960dee5 | |||
| 30171f3ab6 | |||
| f70be197e0 | |||
| 70efee1bc5 | |||
| 8cf3d7a492 | |||
| cf5658d7fe | |||
| 99fefbef52 | |||
| 2ce37783ea | |||
| 73f52af6e3 | |||
| b75a30a21a | |||
| 5b7a5c39a7 | |||
| a3fa56d988 | |||
| 0d01e07430 | |||
| 2d3b3cee15 | |||
| c687219113 | |||
| 27e3b31c1e | |||
| fc6d6b1e3b | |||
| b998572def | |||
| ff0c96011f | |||
| 4aa90cc072 | |||
| b11a1d852c | |||
| c9ca635fa7 | |||
| 33bd7f45e1 | |||
| bf107f000d | |||
| 299f1b87aa | |||
| 2a220a9e42 | |||
| ab5e07e83e | |||
| d3b2049851 | |||
| d08ac5628a | |||
| 4c312f3d6b | |||
| cbdf900629 | |||
| c83b41611a | |||
| 2ca4eea244 | |||
| f021c856c1 | |||
| 2679150ed4 | |||
| bbe8326477 | |||
| f794ae582c | |||
| ef903ba70e | |||
| da941734d7 | |||
| 0f494a53c9 | |||
| cf566a0c72 | |||
| 945ec8942a | |||
| 32d4378198 | |||
| f1aa0df326 | |||
| bf76988ebc | |||
| d590317856 | |||
| 1e1b34b567 | |||
| 01d6ef2e57 | |||
| c4af6efd25 | |||
| d1d1c9bfd0 | |||
| 83fe973c75 | |||
| 0bbebedada | |||
| 2fc7897044 | |||
| 10994e9027 | |||
| cd55529eaa | |||
| 837f074346 | |||
| a4544b0b26 | |||
| e1f96ca4db | |||
| 6c93b8d599 | |||
| 765f7abc60 | |||
| bcc9007196 | |||
| e944fc74df | |||
| ad059f9637 | |||
| 1ad2551559 | |||
| 41f3bae917 | |||
| 90c742e4f1 | |||
| 97e31c4026 | |||
| c9906480d3 | |||
| 51b745470c | |||
| 11346455a1 | |||
| 86adcdf8bb | |||
| 80eb3b85e4 | |||
| a2cca9ee87 | |||
| 1176f892d7 | |||
| 805b0c2a4e | |||
| 4972084345 | |||
| dfab202cde | |||
| b80caf762a | |||
| 8594206538 | |||
| c155b07ecb | |||
| 1d70916064 | |||
| b9e3fbcd83 | |||
| 0c4e40b89c | |||
| 254e224bd7 | |||
| 5014b63611 | |||
| 2cd718862b | |||
| b5915d3906 | |||
| 38d1b6e1bb | |||
| dacddd9897 | |||
| 1d783106a3 | |||
| a4882467cb | |||
| 08304afe54 | |||
| 12792d8068 | |||
| 99c2e98975 | |||
| ee1bb54ab6 | |||
| 48295a6c4b | |||
| 5ed2e78ae2 | |||
| d1a1e25bb8 | |||
| 27fd8a2436 | |||
| 00ce28f8d7 | |||
| b4640a0904 | |||
| a276926f42 | |||
| f6282f9600 | |||
| ffa6c5fe3e | |||
| d28d2d5ab8 | |||
| 31b3ebf071 | |||
| 75c10a1cac | |||
| 17d455c72f | |||
| 38b2c5a317 | |||
| da01ee7c37 | |||
| 3a28848ca0 | |||
| 1ca69f2af1 | |||
| 212bf1e2bb | |||
| 6768bec456 | |||
| c0f44db4f7 | |||
| 15996c348d | |||
| a64928fa6b | |||
| 09620eef76 | |||
| bc270b31c3 | |||
| cd83f72da4 | |||
| 260373aed7 | |||
| 4a5d3e0353 | |||
| 8590165238 | |||
| 748fb30f58 | |||
| 2644141a36 | |||
| ceb2320ef0 | |||
| dfc937340d | |||
| e0bda97b6f | |||
| d25b6d4686 | |||
| a66b1e77da | |||
| 7a5ce28921 | |||
| 16eb0421e5 | |||
| 538bd7cd7f | |||
| a22f3d6aa7 | |||
| e6aaa03cf0 | |||
| 24f3ee777d | |||
| 8b7fb7213f | |||
| 421539e3be | |||
| 2355324d73 | |||
| 6eee9dbf88 | |||
| 0819f00380 | |||
| 7bb9dd75db | |||
| 2e8a0bd562 | |||
| 102c551b5a | |||
| 45db63c207 | |||
| 94b04383f9 | |||
| 35f5e36838 | |||
| a140c9bd74 | |||
| bde72a5f40 | |||
| a7a4c9f848 | |||
| 76a9101998 | |||
| caf6b4b3f1 | |||
| 9a0814253c | |||
| fb1f72a09c | |||
| 03fd86034d | |||
| e42e09cf8b | |||
| 3c462ab9c2 | |||
| d775aee26d | |||
| 5c97a83a70 | |||
| 7776b5b665 | |||
| e48f0f04e7 | |||
| fee8ada214 | |||
| 3f80a89a69 | |||
| 4fd2e4aa90 | |||
| 67f82e32b4 | |||
| 1f89dad23a | |||
| 3de4a1d788 | |||
| ede011243b | |||
| 4ec5b1600a | |||
| 3ce1be14f7 | |||
| 22b4005fd3 | |||
| ce64a42250 | |||
| 2564f05037 | |||
| 02c2a83494 | |||
| 7cea286c23 | |||
| 3bb2fccaf1 | |||
| 840bb53f5b | |||
| e2952d3e5f | |||
| 040d0a32d2 | |||
| 83c9fcb13e | |||
| dcf5ba1ea6 | |||
| a37f4b9cf6 | |||
| 740ec7656f | |||
| 1bfbecbcab | |||
| 29f364f63c | |||
| b21b6c365c | |||
| c651184998 | |||
| 72d0843c1f | |||
| da98386bf7 | |||
| f02717ab94 | |||
| 63faea0c42 | |||
| 2aceccf285 | |||
| 66ff4cb7de | |||
| 5d2899ee1b | |||
| 2b6e332318 | |||
| fec86a9ce1 | |||
| 02acc7fc28 | |||
| ea603e4ea5 | |||
| 0ea3d150e1 | |||
| e93d02d228 | |||
| d9714bff32 | |||
| 70393f491d | |||
| 657fa55118 | |||
| a02ee73181 | |||
| 70fa891d48 | |||
| e2050d61fd | |||
| 1dfe63093b | |||
| 472ec31662 | |||
| e66945cbd8 | |||
| 8a0a25fceb | |||
| cf77c93cb4 | |||
| 956437b7fe | |||
| a464d26e73 | |||
| ea77929d62 | |||
| 996b2a5c1d | |||
| 50794b08a9 | |||
| 1b4f0c38ce | |||
| 5f9b1b0e0b | |||
| 93c04f2666 | |||
| 218e1bb267 | |||
| 1ce2ed065a | |||
| d3386a5af7 | |||
| 5330ca9b8c | |||
| 84247e7272 | |||
| e7b6a56a97 | |||
| 9572699301 | |||
| 84e70634fb | |||
| 94899e0339 | |||
| abacc2754e | |||
| 2fa8030afc | |||
| 0b2299c7d1 | |||
| 5f3f2e756b | |||
| dfc7a94578 | |||
| 0399b85ab6 | |||
| 9e5edfb728 | |||
| b8b473244c | |||
| 6e777b7453 | |||
| fce4615f10 | |||
| b5fcea9e74 | |||
| 5014b23c2a | |||
| a6b6dc60f4 | |||
| 9b1efcfaab | |||
| 546b98a118 | |||
| 7a441c1bc4 | |||
| c54f15e35f | |||
| db37e578f2 | |||
| 9e1192a54d | |||
| 06266c8fec | |||
| af7e586b06 | |||
| 0b94f4afa9 | |||
| 5a51412e6a | |||
| 752d574b49 | |||
| a303b5e2d5 | |||
| e61916ea91 | |||
| 86504acb4c | |||
| 3fdc273252 | |||
| 9882217847 | |||
| 5362a85f2b | |||
| f9ce4ff559 | |||
| fefc6e6bec | |||
| 97252c26ee | |||
| 94b5bbcb5d | |||
| 9c09fd20fb | |||
| 79b1347ba5 | |||
| 0cef17ce44 | |||
| d1b1f5977a | |||
| 33274b8d48 | |||
| 7c1d8ac00b | |||
| 243027e63a | |||
| 9d810f0059 | |||
| eaedf9ed52 | |||
| c894f74c5e | |||
| 8d8315d8f6 | |||
| 7f63f9a931 | |||
| 27af58ef1a | |||
| fb4bab748f | |||
| d771847078 | |||
| 3f4defe482 | |||
| 737bbb3d3d | |||
| 7a05f8ed66 | |||
| cbacc71dff | |||
| ad97165f1b | |||
| 8be1597ad0 | |||
| 1169ff05af | |||
| 876a9b6ffb | |||
| d545ca7360 | |||
| 1802fa9348 | |||
| 29bad1dc95 | |||
| 6a8be88ad6 | |||
| e8d0c26e43 | |||
| 4ed95ffff6 | |||
| 6f68a36679 | |||
| 79c33bbc83 | |||
| f6b2be81b9 | |||
| 486ecc6661 | |||
| 5166213fd3 | |||
| 57a4ee318a | |||
| d63746ab3e | |||
| 7619c286cc | |||
| 6157d20ec0 | |||
| 858eba2f1c | |||
| 365d92ebf4 | |||
| 11b9ceb054 | |||
| 9352bb527b | |||
| 47475acdaf | |||
| 9ae6e60c26 | |||
| 077723c90a | |||
| 81eee10d5b | |||
| 63c72fe87f | |||
| 006337fb0e | |||
| 4581baa5c0 | |||
| 203cf6333e | |||
| b7c1a5c0d5 | |||
| 0ecca9d8f1 | |||
| c58298835d | |||
| 42452a535f | |||
| d32b9b92cf | |||
| de31cd9ef6 | |||
| a9295a7740 | |||
| 8b3a8ac1b4 | |||
| b1cb9cd3bd | |||
| 76d33e1fb7 | |||
| 0dc6a41832 | |||
| 34b86628a0 | |||
| 66b9a76c7e | |||
| bbc43e71ee | |||
| ba20a67873 | |||
| 048fa5bd77 | |||
| 3bc2a5cf2f | |||
| 41dba2db86 | |||
| e85a9f8609 | |||
| b84dd8ec83 | |||
| 01fd8e685b | |||
| 1a6595aa17 | |||
| 9373f429d0 | |||
| b3442a7d39 | |||
| ed314caf7d | |||
| 1399f3dd12 | |||
| 7c99f8ad11 | |||
| 67159c12c5 | |||
| 0f1787ea0d | |||
| 6cd4f0c07e | |||
| d143019dbb | |||
| a3b9a5aa5f | |||
| 9b624fd1d6 | |||
| 8236563d6b | |||
| 5f9f6ea2e1 | |||
| 738fc579f0 | |||
| 0316fde06b | |||
| bcde2f4dce | |||
| 48ae6f38e1 | |||
| 16eda4c5c9 | |||
| b4101c8b65 | |||
| d967507dcb | |||
| d1b5bc1e82 | |||
| 6c54b0ba3b | |||
| bdbc7b337f | |||
| ff449b197f | |||
| a0c29d8f99 | |||
| 58fbf5e66f | |||
| ccbe48d779 | |||
| 64e67f754d | |||
| 6810972762 | |||
| e160a3eec1 | |||
| f16aae74dc | |||
| bc77cc2c5c | |||
| a4b07a36ed | |||
| 1894bef48a | |||
| 2ed9aa13f3 | |||
| 52e422da61 | |||
| 8b0016d71b | |||
| df761e01fa | |||
| 07962e2840 | |||
| 7fe7677cde | |||
| c4419e268f | |||
| cf1ad65cd2 | |||
| 193ed689fb | |||
| f2f54a711d | |||
| 0092a54e3b | |||
| 1ffa468240 | |||
| ae0ed7fd05 | |||
| b0e62e37ae | |||
| 3544d6398a | |||
| 5083e92772 | |||
| a37af7a226 | |||
| 85711f1d54 | |||
| 050d0d046a | |||
| 925ef8f4f0 | |||
| ad06bec6b6 | |||
| 433f2a043e | |||
| 394fc9c109 | |||
| 21979cf68a | |||
| 0177f732a2 | |||
| a3cf5dcded | |||
| 8bc89b6e73 | |||
| 2e7e26fbb4 | |||
| 9131cdf6b9 | |||
| fbf2646426 | |||
| edf6757a75 | |||
| 8cb75be0db | |||
| b09a18972d | |||
| 8a356baf3e | |||
| e1c4659752 | |||
| 72c9884dfc | |||
| 7afdb01f00 | |||
| 1d542a5113 | |||
| 199428804f | |||
| 6854827f1a | |||
| 5452fd2f5a | |||
| 701e00d865 | |||
| 4e36bd2ce1 | |||
| 124ea898d5 | |||
| 07b69fd7fc | |||
| 952ff4184e | |||
| 5c449f844e | |||
| 16e09bfd77 | |||
| 9e7bce6a94 | |||
| 710ac5344d | |||
| 36aeeb99d9 | |||
| 713ce06e40 | |||
| fcbd2b5228 | |||
| 14b4afeec9 | |||
| 3520961eae | |||
| 0961cdab31 | |||
| a987649b1a | |||
| 9afaf26d66 | |||
| a07a6d4aa4 | |||
| 25ed19cb35 | |||
| 1f862dbadb | |||
| 3ef92341fd | |||
| 225b6f4dc9 | |||
| 094520ab20 | |||
| 90dc93b81c | |||
| 323a26030b | |||
| 653d2aacbb | |||
| f6b05ea3fb | |||
| 3041041a62 | |||
| 691b09fd72 | |||
| f30a369d35 | |||
| 487ba400fc | |||
| 2e0cd9f196 | |||
| 59c961425e | |||
| 570d7e494e | |||
| 1f1fd9e034 | |||
| 35bb9307dc | |||
| 47679629f4 | |||
| 06f4b371ee | |||
| c3040104ff | |||
| 455abea320 | |||
| cc643ce932 | |||
| 6ef6459630 | |||
| 827e14eafe | |||
| 8fac9233de | |||
| 7385722441 | |||
| b73141a153 | |||
| 8d6b32645c | |||
| a592d6c40d | |||
| fb151463eb | |||
| 586f4e3831 | |||
| 2986afc05e | |||
| a8e3ddf382 | |||
| de7d367820 | |||
| f7acdd1afd | |||
| 4b9df2eac7 | |||
| 696d21f8c8 | |||
| dbad26c87d | |||
| 25b4139028 | |||
| ed349ca942 | |||
| bfd0fb067a | |||
| 8f3a04ce69 | |||
| 6ad989f828 | |||
| 5c6bee7f85 | |||
| d611339baa | |||
| 0cf15476a3 | |||
| 09eba46ec1 | |||
| ea627ca98d | |||
| 999d47f986 | |||
| 66a079f430 | |||
| e395d3e46d | |||
| 954bddbadf | |||
| 2042e3bbd9 | |||
| d93f96765b | |||
| e339d0bcc0 | |||
| dbf4438dda | |||
| 0d55652552 | |||
| 6fc62d393c | |||
| 5ef0af6710 | |||
| 116091a1d2 | |||
| 2f3f2d8b12 | |||
| 6db8fa8ef7 | |||
| af6b01f55d | |||
| a899904f63 | |||
| 53078ca949 | |||
| 910988133d | |||
| fab5c1fdef | |||
| ca2449d9cf | |||
| 41d44c5285 | |||
| d47400aa8d | |||
| 988f8d65fa | |||
| a3e729a263 | |||
| 237a3f52a2 | |||
| 1631019026 | |||
| 1650920339 | |||
| ab4873b83d | |||
| 2fdf4426cd | |||
| 361138e16d | |||
| 2e4e9b88d2 | |||
| 91a5fa32d7 | |||
| d1a504f768 | |||
| a332e0a4fe | |||
| 6034067d86 | |||
| 3197814c62 |
+20
@@ -0,0 +1,20 @@
|
|||||||
|
/config/additional_environment.rb
|
||||||
|
/config/database.yml
|
||||||
|
/config/email.yml
|
||||||
|
/config/initializers/session_store.rb
|
||||||
|
/coverage
|
||||||
|
/db/*.db
|
||||||
|
/db/*.sqlite3
|
||||||
|
/db/schema.rb
|
||||||
|
/files/*
|
||||||
|
/log/*.log*
|
||||||
|
/log/mongrel_debug
|
||||||
|
/public/dispatch.*
|
||||||
|
/public/plugin_assets
|
||||||
|
/tmp/*
|
||||||
|
/tmp/cache/*
|
||||||
|
/tmp/sessions/*
|
||||||
|
/tmp/sockets/*
|
||||||
|
/tmp/test/*
|
||||||
|
/vendor/rails
|
||||||
|
*.rbc
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
= Redmine
|
||||||
|
|
||||||
|
Redmine is a flexible project management web application written using Ruby on Rails framework.
|
||||||
|
|
||||||
|
More details can be found at in the doc directory or on the official website http://www.redmine.org
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,60 +16,24 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class AccountController < ApplicationController
|
class AccountController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
include CustomFieldsHelper
|
include CustomFieldsHelper
|
||||||
|
|
||||||
# prevents login action to be filtered by check_if_login_required application scope filter
|
# prevents login action to be filtered by check_if_login_required application scope filter
|
||||||
skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register, :activate]
|
skip_before_filter :check_if_login_required
|
||||||
|
|
||||||
# Show user's account
|
|
||||||
def show
|
|
||||||
@user = User.find_active(params[:id])
|
|
||||||
@custom_values = @user.custom_values.find(:all, :include => :custom_field)
|
|
||||||
|
|
||||||
# show only public projects and private projects that the logged in user is also a member of
|
|
||||||
@memberships = @user.memberships.select do |membership|
|
|
||||||
membership.project.is_public? || (User.current.member_of?(membership.project))
|
|
||||||
end
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
render_404
|
|
||||||
end
|
|
||||||
|
|
||||||
# Login request and validation
|
# Login request and validation
|
||||||
def login
|
def login
|
||||||
if request.get?
|
if request.get?
|
||||||
# Logout user
|
logout_user
|
||||||
self.logged_user = nil
|
|
||||||
else
|
else
|
||||||
# Authenticate user
|
authenticate_user
|
||||||
user = User.try_to_login(params[:username], params[:password])
|
|
||||||
if user.nil?
|
|
||||||
# Invalid credentials
|
|
||||||
flash.now[:error] = l(:notice_account_invalid_creditentials)
|
|
||||||
elsif user.new_record?
|
|
||||||
# Onthefly creation failed, display the registration form to fill/fix attributes
|
|
||||||
@user = user
|
|
||||||
session[:auth_source_registration] = {:login => user.login, :auth_source_id => user.auth_source_id }
|
|
||||||
render :action => 'register'
|
|
||||||
else
|
|
||||||
# Valid user
|
|
||||||
self.logged_user = user
|
|
||||||
# generate a key and set cookie if autologin
|
|
||||||
if params[:autologin] && Setting.autologin?
|
|
||||||
token = Token.create(:user => user, :action => 'autologin')
|
|
||||||
cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
|
|
||||||
end
|
|
||||||
redirect_back_or_default :controller => 'my', :action => 'page'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Log out current user and redirect to welcome page
|
# Log out current user and redirect to welcome page
|
||||||
def logout
|
def logout
|
||||||
cookies.delete :autologin
|
logout_user
|
||||||
Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) if User.current.logged?
|
|
||||||
self.logged_user = nil
|
|
||||||
redirect_to home_url
|
redirect_to home_url
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -95,9 +59,9 @@ class AccountController < ApplicationController
|
|||||||
if request.post?
|
if request.post?
|
||||||
user = User.find_by_mail(params[:mail])
|
user = User.find_by_mail(params[:mail])
|
||||||
# user not found in db
|
# user not found in db
|
||||||
flash.now[:error] = l(:notice_account_unknown_email) and return unless user
|
(flash.now[:error] = l(:notice_account_unknown_email); return) unless user
|
||||||
# user uses an external authentification
|
# user uses an external authentification
|
||||||
flash.now[:error] = l(:notice_can_t_change_password) and return if user.auth_source_id
|
(flash.now[:error] = l(:notice_can_t_change_password); return) if user.auth_source_id
|
||||||
# create a new token for password recovery
|
# create a new token for password recovery
|
||||||
token = Token.new(:user => user, :action => "recovery")
|
token = Token.new(:user => user, :action => "recovery")
|
||||||
if token.save
|
if token.save
|
||||||
@@ -133,31 +97,14 @@ class AccountController < ApplicationController
|
|||||||
else
|
else
|
||||||
@user.login = params[:user][:login]
|
@user.login = params[:user][:login]
|
||||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
|
||||||
|
|
||||||
case Setting.self_registration
|
case Setting.self_registration
|
||||||
when '1'
|
when '1'
|
||||||
# Email activation
|
register_by_email_activation(@user)
|
||||||
token = Token.new(:user => @user, :action => "register")
|
|
||||||
if @user.save and token.save
|
|
||||||
Mailer.deliver_register(token)
|
|
||||||
flash[:notice] = l(:notice_account_register_done)
|
|
||||||
redirect_to :action => 'login'
|
|
||||||
end
|
|
||||||
when '3'
|
when '3'
|
||||||
# Automatic activation
|
register_automatically(@user)
|
||||||
@user.status = User::STATUS_ACTIVE
|
|
||||||
if @user.save
|
|
||||||
self.logged_user = @user
|
|
||||||
flash[:notice] = l(:notice_account_activated)
|
|
||||||
redirect_to :controller => 'my', :action => 'account'
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
# Manual activation by the administrator
|
register_manually_by_administrator(@user)
|
||||||
if @user.save
|
|
||||||
# Sends an email to the administrators
|
|
||||||
Mailer.deliver_account_activation_request(@user)
|
|
||||||
flash[:notice] = l(:notice_account_pending)
|
|
||||||
redirect_to :action => 'login'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -178,14 +125,148 @@ class AccountController < ApplicationController
|
|||||||
redirect_to :action => 'login'
|
redirect_to :action => 'login'
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def logged_user=(user)
|
|
||||||
if user && user.is_a?(User)
|
def logout_user
|
||||||
User.current = user
|
if User.current.logged?
|
||||||
session[:user_id] = user.id
|
cookies.delete :autologin
|
||||||
else
|
Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin'])
|
||||||
User.current = User.anonymous
|
self.logged_user = nil
|
||||||
session[:user_id] = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def authenticate_user
|
||||||
|
if Setting.openid? && using_open_id?
|
||||||
|
open_id_authenticate(params[:openid_url])
|
||||||
|
else
|
||||||
|
password_authentication
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def password_authentication
|
||||||
|
user = User.try_to_login(params[:username], params[:password])
|
||||||
|
|
||||||
|
if user.nil?
|
||||||
|
invalid_credentials
|
||||||
|
elsif user.new_record?
|
||||||
|
onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id })
|
||||||
|
else
|
||||||
|
# Valid user
|
||||||
|
successful_authentication(user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def open_id_authenticate(openid_url)
|
||||||
|
authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration|
|
||||||
|
if result.successful?
|
||||||
|
user = User.find_or_initialize_by_identity_url(identity_url)
|
||||||
|
if user.new_record?
|
||||||
|
# Self-registration off
|
||||||
|
redirect_to(home_url) && return unless Setting.self_registration?
|
||||||
|
|
||||||
|
# Create on the fly
|
||||||
|
user.login = registration['nickname'] unless registration['nickname'].nil?
|
||||||
|
user.mail = registration['email'] unless registration['email'].nil?
|
||||||
|
user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil?
|
||||||
|
user.random_password
|
||||||
|
user.status = User::STATUS_REGISTERED
|
||||||
|
|
||||||
|
case Setting.self_registration
|
||||||
|
when '1'
|
||||||
|
register_by_email_activation(user) do
|
||||||
|
onthefly_creation_failed(user)
|
||||||
|
end
|
||||||
|
when '3'
|
||||||
|
register_automatically(user) do
|
||||||
|
onthefly_creation_failed(user)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
register_manually_by_administrator(user) do
|
||||||
|
onthefly_creation_failed(user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# Existing record
|
||||||
|
if user.active?
|
||||||
|
successful_authentication(user)
|
||||||
|
else
|
||||||
|
account_pending
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def successful_authentication(user)
|
||||||
|
# Valid user
|
||||||
|
self.logged_user = user
|
||||||
|
# generate a key and set cookie if autologin
|
||||||
|
if params[:autologin] && Setting.autologin?
|
||||||
|
token = Token.create(:user => user, :action => 'autologin')
|
||||||
|
cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
|
||||||
|
end
|
||||||
|
call_hook(:controller_account_success_authentication_after, {:user => user })
|
||||||
|
redirect_back_or_default :controller => 'my', :action => 'page'
|
||||||
|
end
|
||||||
|
|
||||||
|
# Onthefly creation failed, display the registration form to fill/fix attributes
|
||||||
|
def onthefly_creation_failed(user, auth_source_options = { })
|
||||||
|
@user = user
|
||||||
|
session[:auth_source_registration] = auth_source_options unless auth_source_options.empty?
|
||||||
|
render :action => 'register'
|
||||||
|
end
|
||||||
|
|
||||||
|
def invalid_credentials
|
||||||
|
logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}"
|
||||||
|
flash.now[:error] = l(:notice_account_invalid_creditentials)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Register a user for email activation.
|
||||||
|
#
|
||||||
|
# Pass a block for behavior when a user fails to save
|
||||||
|
def register_by_email_activation(user, &block)
|
||||||
|
token = Token.new(:user => user, :action => "register")
|
||||||
|
if user.save and token.save
|
||||||
|
Mailer.deliver_register(token)
|
||||||
|
flash[:notice] = l(:notice_account_register_done)
|
||||||
|
redirect_to :action => 'login'
|
||||||
|
else
|
||||||
|
yield if block_given?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Automatically register a user
|
||||||
|
#
|
||||||
|
# Pass a block for behavior when a user fails to save
|
||||||
|
def register_automatically(user, &block)
|
||||||
|
# Automatic activation
|
||||||
|
user.status = User::STATUS_ACTIVE
|
||||||
|
user.last_login_on = Time.now
|
||||||
|
if user.save
|
||||||
|
self.logged_user = user
|
||||||
|
flash[:notice] = l(:notice_account_activated)
|
||||||
|
redirect_to :controller => 'my', :action => 'account'
|
||||||
|
else
|
||||||
|
yield if block_given?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Manual activation by the administrator
|
||||||
|
#
|
||||||
|
# Pass a block for behavior when a user fails to save
|
||||||
|
def register_manually_by_administrator(user, &block)
|
||||||
|
if user.save
|
||||||
|
# Sends an email to the administrators
|
||||||
|
Mailer.deliver_account_activation_request(user)
|
||||||
|
account_pending
|
||||||
|
else
|
||||||
|
yield if block_given?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def account_pending
|
||||||
|
flash[:notice] = l(:notice_account_pending)
|
||||||
|
redirect_to :action => 'login'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class AdminController < ApplicationController
|
class AdminController < ApplicationController
|
||||||
layout 'base'
|
layout 'admin'
|
||||||
|
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
|
|
||||||
helper :sort
|
helper :sort
|
||||||
@@ -27,25 +28,24 @@ class AdminController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def projects
|
def projects
|
||||||
sort_init 'name', 'asc'
|
@status = params[:status] ? params[:status].to_i : 1
|
||||||
sort_update
|
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
||||||
|
|
||||||
@status = params[:status] ? params[:status].to_i : 0
|
unless params[:name].blank?
|
||||||
conditions = nil
|
name = "%#{params[:name].strip.downcase}%"
|
||||||
conditions = ["status=?", @status] unless @status == 0
|
c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name]
|
||||||
|
end
|
||||||
|
|
||||||
@project_count = Project.count(:conditions => conditions)
|
@projects = Project.find :all, :order => 'lft',
|
||||||
@project_pages = Paginator.new self, @project_count,
|
:conditions => c.conditions
|
||||||
per_page_option,
|
|
||||||
params['page']
|
|
||||||
@projects = Project.find :all, :order => sort_clause,
|
|
||||||
:conditions => conditions,
|
|
||||||
:limit => @project_pages.items_per_page,
|
|
||||||
:offset => @project_pages.current.offset
|
|
||||||
|
|
||||||
render :action => "projects", :layout => false if request.xhr?
|
render :action => "projects", :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def plugins
|
||||||
|
@plugins = Redmine::Plugin.all
|
||||||
|
end
|
||||||
|
|
||||||
# Loads the default configuration
|
# Loads the default configuration
|
||||||
# (roles, trackers, statuses, workflow, enumerations)
|
# (roles, trackers, statuses, workflow, enumerations)
|
||||||
def default_configuration
|
def default_configuration
|
||||||
@@ -76,11 +76,11 @@ class AdminController < ApplicationController
|
|||||||
|
|
||||||
def info
|
def info
|
||||||
@db_adapter_name = ActiveRecord::Base.connection.adapter_name
|
@db_adapter_name = ActiveRecord::Base.connection.adapter_name
|
||||||
@flags = {
|
@checklist = [
|
||||||
:default_admin_changed => User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?,
|
[:text_default_administrator_account_changed, User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?],
|
||||||
:file_repository_writable => File.writable?(Attachment.storage_path),
|
[:text_file_repository_writable, File.writable?(Attachment.storage_path)],
|
||||||
:rmagick_available => Object.const_defined?(:Magick)
|
[:text_plugin_assets_writable, File.writable?(Engines.public_directory)],
|
||||||
}
|
[:text_rmagick_available, Object.const_defined?(:Magick)]
|
||||||
@plugins = Redmine::Plugin.registered_plugins
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,219 +0,0 @@
|
|||||||
# redMine - project management software
|
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or
|
|
||||||
# modify it under the terms of the GNU General Public License
|
|
||||||
# as published by the Free Software Foundation; either version 2
|
|
||||||
# of the License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program 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, USA.
|
|
||||||
|
|
||||||
require 'uri'
|
|
||||||
|
|
||||||
class ApplicationController < ActionController::Base
|
|
||||||
before_filter :user_setup, :check_if_login_required, :set_localization
|
|
||||||
filter_parameter_logging :password
|
|
||||||
|
|
||||||
include Redmine::MenuManager::MenuController
|
|
||||||
helper Redmine::MenuManager::MenuHelper
|
|
||||||
|
|
||||||
REDMINE_SUPPORTED_SCM.each do |scm|
|
|
||||||
require_dependency "repository/#{scm.underscore}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_role
|
|
||||||
@current_role ||= User.current.role_for_project(@project)
|
|
||||||
end
|
|
||||||
|
|
||||||
def user_setup
|
|
||||||
# Check the settings cache for each request
|
|
||||||
Setting.check_cache
|
|
||||||
# Find the current user
|
|
||||||
User.current = find_current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the current user or nil if no user is logged in
|
|
||||||
def find_current_user
|
|
||||||
if session[:user_id]
|
|
||||||
# existing session
|
|
||||||
(User.find_active(session[:user_id]) rescue nil)
|
|
||||||
elsif cookies[:autologin] && Setting.autologin?
|
|
||||||
# auto-login feature
|
|
||||||
User.find_by_autologin_key(cookies[:autologin])
|
|
||||||
elsif params[:key] && accept_key_auth_actions.include?(params[:action])
|
|
||||||
# RSS key authentication
|
|
||||||
User.find_by_rss_key(params[:key])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# check if login is globally required to access the application
|
|
||||||
def check_if_login_required
|
|
||||||
# no check needed if user is already logged in
|
|
||||||
return true if User.current.logged?
|
|
||||||
require_login if Setting.login_required?
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_localization
|
|
||||||
User.current.language = nil unless User.current.logged?
|
|
||||||
lang = begin
|
|
||||||
if !User.current.language.blank? && GLoc.valid_language?(User.current.language)
|
|
||||||
User.current.language
|
|
||||||
elsif request.env['HTTP_ACCEPT_LANGUAGE']
|
|
||||||
accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.downcase
|
|
||||||
if !accept_lang.blank? && (GLoc.valid_language?(accept_lang) || GLoc.valid_language?(accept_lang = accept_lang.split('-').first))
|
|
||||||
User.current.language = accept_lang
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue
|
|
||||||
nil
|
|
||||||
end || Setting.default_language
|
|
||||||
set_language_if_valid(lang)
|
|
||||||
end
|
|
||||||
|
|
||||||
def require_login
|
|
||||||
if !User.current.logged?
|
|
||||||
redirect_to :controller => "account", :action => "login", :back_url => request.request_uri
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def require_admin
|
|
||||||
return unless require_login
|
|
||||||
if !User.current.admin?
|
|
||||||
render_403
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
# Authorize the user for the requested action
|
|
||||||
def authorize(ctrl = params[:controller], action = params[:action])
|
|
||||||
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project)
|
|
||||||
allowed ? true : (User.current.logged? ? render_403 : require_login)
|
|
||||||
end
|
|
||||||
|
|
||||||
# make sure that the user is a member of the project (or admin) if project is private
|
|
||||||
# used as a before_filter for actions that do not require any particular permission on the project
|
|
||||||
def check_project_privacy
|
|
||||||
if @project && @project.active?
|
|
||||||
if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
|
|
||||||
true
|
|
||||||
else
|
|
||||||
User.current.logged? ? render_403 : require_login
|
|
||||||
end
|
|
||||||
else
|
|
||||||
@project = nil
|
|
||||||
render_404
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def redirect_back_or_default(default)
|
|
||||||
back_url = params[:back_url]
|
|
||||||
if !back_url.blank?
|
|
||||||
uri = URI.parse(back_url)
|
|
||||||
# do not redirect user to another host
|
|
||||||
if uri.relative? || (uri.host == request.host)
|
|
||||||
redirect_to(back_url) and return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
redirect_to default
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_403
|
|
||||||
@project = nil
|
|
||||||
render :template => "common/403", :layout => !request.xhr?, :status => 403
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_404
|
|
||||||
render :template => "common/404", :layout => !request.xhr?, :status => 404
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_error(msg)
|
|
||||||
flash.now[:error] = msg
|
|
||||||
render :nothing => true, :layout => !request.xhr?, :status => 500
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_feed(items, options={})
|
|
||||||
@items = items || []
|
|
||||||
@items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
|
|
||||||
@items = @items.slice(0, Setting.feeds_limit.to_i)
|
|
||||||
@title = options[:title] || Setting.app_title
|
|
||||||
render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.accept_key_auth(*actions)
|
|
||||||
actions = actions.flatten.map(&:to_s)
|
|
||||||
write_inheritable_attribute('accept_key_auth_actions', actions)
|
|
||||||
end
|
|
||||||
|
|
||||||
def accept_key_auth_actions
|
|
||||||
self.class.read_inheritable_attribute('accept_key_auth_actions') || []
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO: move to model
|
|
||||||
def attach_files(obj, attachments)
|
|
||||||
attached = []
|
|
||||||
if attachments && attachments.is_a?(Hash)
|
|
||||||
attachments.each_value do |attachment|
|
|
||||||
file = attachment['file']
|
|
||||||
next unless file && file.size > 0
|
|
||||||
a = Attachment.create(:container => obj,
|
|
||||||
:file => file,
|
|
||||||
:description => attachment['description'].to_s.strip,
|
|
||||||
:author => User.current)
|
|
||||||
attached << a unless a.new_record?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
attached
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the number of objects that should be displayed
|
|
||||||
# on the paginated list
|
|
||||||
def per_page_option
|
|
||||||
per_page = nil
|
|
||||||
if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
|
|
||||||
per_page = params[:per_page].to_s.to_i
|
|
||||||
session[:per_page] = per_page
|
|
||||||
elsif session[:per_page]
|
|
||||||
per_page = session[:per_page]
|
|
||||||
else
|
|
||||||
per_page = Setting.per_page_options_array.first || 25
|
|
||||||
end
|
|
||||||
per_page
|
|
||||||
end
|
|
||||||
|
|
||||||
# qvalues http header parser
|
|
||||||
# code taken from webrick
|
|
||||||
def parse_qvalues(value)
|
|
||||||
tmp = []
|
|
||||||
if value
|
|
||||||
parts = value.split(/,\s*/)
|
|
||||||
parts.each {|part|
|
|
||||||
if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
|
|
||||||
val = m[1]
|
|
||||||
q = (m[2] or 1).to_f
|
|
||||||
tmp.push([val, q])
|
|
||||||
end
|
|
||||||
}
|
|
||||||
tmp = tmp.sort_by{|val, q| -q}
|
|
||||||
tmp.collect!{|val, q| val}
|
|
||||||
end
|
|
||||||
return tmp
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a string that can be used as filename value in Content-Disposition header
|
|
||||||
def filename_for_content_disposition(name)
|
|
||||||
request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -0,0 +1,363 @@
|
|||||||
|
# redMine - project management software
|
||||||
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
require 'uri'
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
|
class ApplicationController < ActionController::Base
|
||||||
|
include Redmine::I18n
|
||||||
|
|
||||||
|
layout 'base'
|
||||||
|
exempt_from_layout 'builder'
|
||||||
|
|
||||||
|
# Remove broken cookie after upgrade from 0.8.x (#4292)
|
||||||
|
# See https://rails.lighthouseapp.com/projects/8994/tickets/3360
|
||||||
|
# TODO: remove it when Rails is fixed
|
||||||
|
before_filter :delete_broken_cookies
|
||||||
|
def delete_broken_cookies
|
||||||
|
if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/
|
||||||
|
cookies.delete '_redmine_session'
|
||||||
|
redirect_to home_path
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
before_filter :user_setup, :check_if_login_required, :set_localization
|
||||||
|
filter_parameter_logging :password
|
||||||
|
protect_from_forgery
|
||||||
|
|
||||||
|
rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
|
||||||
|
|
||||||
|
include Redmine::Search::Controller
|
||||||
|
include Redmine::MenuManager::MenuController
|
||||||
|
helper Redmine::MenuManager::MenuHelper
|
||||||
|
|
||||||
|
Redmine::Scm::Base.all.each do |scm|
|
||||||
|
require_dependency "repository/#{scm.underscore}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_setup
|
||||||
|
# Check the settings cache for each request
|
||||||
|
Setting.check_cache
|
||||||
|
# Find the current user
|
||||||
|
User.current = find_current_user
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the current user or nil if no user is logged in
|
||||||
|
# and starts a session if needed
|
||||||
|
def find_current_user
|
||||||
|
if session[:user_id]
|
||||||
|
# existing session
|
||||||
|
(User.active.find(session[:user_id]) rescue nil)
|
||||||
|
elsif cookies[:autologin] && Setting.autologin?
|
||||||
|
# auto-login feature starts a new session
|
||||||
|
user = User.try_to_autologin(cookies[:autologin])
|
||||||
|
session[:user_id] = user.id if user
|
||||||
|
user
|
||||||
|
elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action])
|
||||||
|
# RSS key authentication does not start a session
|
||||||
|
User.find_by_rss_key(params[:key])
|
||||||
|
elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format])
|
||||||
|
if params[:key].present? && accept_key_auth_actions.include?(params[:action])
|
||||||
|
# Use API key
|
||||||
|
User.find_by_api_key(params[:key])
|
||||||
|
else
|
||||||
|
# HTTP Basic, either username/password or API key/random
|
||||||
|
authenticate_with_http_basic do |username, password|
|
||||||
|
User.try_to_login(username, password) || User.find_by_api_key(username)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sets the logged in user
|
||||||
|
def logged_user=(user)
|
||||||
|
reset_session
|
||||||
|
if user && user.is_a?(User)
|
||||||
|
User.current = user
|
||||||
|
session[:user_id] = user.id
|
||||||
|
else
|
||||||
|
User.current = User.anonymous
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# check if login is globally required to access the application
|
||||||
|
def check_if_login_required
|
||||||
|
# no check needed if user is already logged in
|
||||||
|
return true if User.current.logged?
|
||||||
|
require_login if Setting.login_required?
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_localization
|
||||||
|
lang = nil
|
||||||
|
if User.current.logged?
|
||||||
|
lang = find_language(User.current.language)
|
||||||
|
end
|
||||||
|
if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
|
||||||
|
accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
|
||||||
|
if !accept_lang.blank?
|
||||||
|
accept_lang = accept_lang.downcase
|
||||||
|
lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
lang ||= Setting.default_language
|
||||||
|
set_language_if_valid(lang)
|
||||||
|
end
|
||||||
|
|
||||||
|
def require_login
|
||||||
|
if !User.current.logged?
|
||||||
|
# Extract only the basic url parameters on non-GET requests
|
||||||
|
if request.get?
|
||||||
|
url = url_for(params)
|
||||||
|
else
|
||||||
|
url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
|
||||||
|
format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
|
||||||
|
format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
|
||||||
|
format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
|
||||||
|
format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def require_admin
|
||||||
|
return unless require_login
|
||||||
|
if !User.current.admin?
|
||||||
|
render_403
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def deny_access
|
||||||
|
User.current.logged? ? render_403 : require_login
|
||||||
|
end
|
||||||
|
|
||||||
|
# Authorize the user for the requested action
|
||||||
|
def authorize(ctrl = params[:controller], action = params[:action], global = false)
|
||||||
|
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project, :global => global)
|
||||||
|
allowed ? true : deny_access
|
||||||
|
end
|
||||||
|
|
||||||
|
# Authorize the user for the requested action outside a project
|
||||||
|
def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
|
||||||
|
authorize(ctrl, action, global)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Find project of id params[:id]
|
||||||
|
def find_project
|
||||||
|
@project = Project.find(params[:id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
# Find a project based on params[:project_id]
|
||||||
|
# TODO: some subclasses override this, see about merging their logic
|
||||||
|
def find_optional_project
|
||||||
|
@project = Project.find(params[:project_id]) unless params[:project_id].blank?
|
||||||
|
allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
|
||||||
|
allowed ? true : deny_access
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
# Finds and sets @project based on @object.project
|
||||||
|
def find_project_from_association
|
||||||
|
render_404 unless @object.present?
|
||||||
|
|
||||||
|
@project = @object.project
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_model_object
|
||||||
|
model = self.class.read_inheritable_attribute('model_object')
|
||||||
|
if model
|
||||||
|
@object = model.find(params[:id])
|
||||||
|
self.instance_variable_set('@' + controller_name.singularize, @object) if @object
|
||||||
|
end
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.model_object(model)
|
||||||
|
write_inheritable_attribute('model_object', model)
|
||||||
|
end
|
||||||
|
|
||||||
|
# make sure that the user is a member of the project (or admin) if project is private
|
||||||
|
# used as a before_filter for actions that do not require any particular permission on the project
|
||||||
|
def check_project_privacy
|
||||||
|
if @project && @project.active?
|
||||||
|
if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
|
||||||
|
true
|
||||||
|
else
|
||||||
|
User.current.logged? ? render_403 : require_login
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@project = nil
|
||||||
|
render_404
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def redirect_back_or_default(default)
|
||||||
|
back_url = CGI.unescape(params[:back_url].to_s)
|
||||||
|
if !back_url.blank?
|
||||||
|
begin
|
||||||
|
uri = URI.parse(back_url)
|
||||||
|
# do not redirect user to another host or to the login or register page
|
||||||
|
if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
|
||||||
|
redirect_to(back_url)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
rescue URI::InvalidURIError
|
||||||
|
# redirect to default
|
||||||
|
end
|
||||||
|
end
|
||||||
|
redirect_to default
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_403
|
||||||
|
@project = nil
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render :template => "common/403", :layout => (request.xhr? ? false : 'base'), :status => 403 }
|
||||||
|
format.atom { head 403 }
|
||||||
|
format.xml { head 403 }
|
||||||
|
format.js { head 403 }
|
||||||
|
format.json { head 403 }
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_404
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render :template => "common/404", :layout => !request.xhr?, :status => 404 }
|
||||||
|
format.atom { head 404 }
|
||||||
|
format.xml { head 404 }
|
||||||
|
format.js { head 404 }
|
||||||
|
format.json { head 404 }
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_error(msg)
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
flash.now[:error] = msg
|
||||||
|
render :text => '', :layout => !request.xhr?, :status => 500
|
||||||
|
}
|
||||||
|
format.atom { head 500 }
|
||||||
|
format.xml { head 500 }
|
||||||
|
format.js { head 500 }
|
||||||
|
format.json { head 500 }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def invalid_authenticity_token
|
||||||
|
if api_request?
|
||||||
|
logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
|
||||||
|
end
|
||||||
|
render_error "Invalid form authenticity token."
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_feed(items, options={})
|
||||||
|
@items = items || []
|
||||||
|
@items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
|
||||||
|
@items = @items.slice(0, Setting.feeds_limit.to_i)
|
||||||
|
@title = options[:title] || Setting.app_title
|
||||||
|
render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.accept_key_auth(*actions)
|
||||||
|
actions = actions.flatten.map(&:to_s)
|
||||||
|
write_inheritable_attribute('accept_key_auth_actions', actions)
|
||||||
|
end
|
||||||
|
|
||||||
|
def accept_key_auth_actions
|
||||||
|
self.class.read_inheritable_attribute('accept_key_auth_actions') || []
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the number of objects that should be displayed
|
||||||
|
# on the paginated list
|
||||||
|
def per_page_option
|
||||||
|
per_page = nil
|
||||||
|
if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
|
||||||
|
per_page = params[:per_page].to_s.to_i
|
||||||
|
session[:per_page] = per_page
|
||||||
|
elsif session[:per_page]
|
||||||
|
per_page = session[:per_page]
|
||||||
|
else
|
||||||
|
per_page = Setting.per_page_options_array.first || 25
|
||||||
|
end
|
||||||
|
per_page
|
||||||
|
end
|
||||||
|
|
||||||
|
# qvalues http header parser
|
||||||
|
# code taken from webrick
|
||||||
|
def parse_qvalues(value)
|
||||||
|
tmp = []
|
||||||
|
if value
|
||||||
|
parts = value.split(/,\s*/)
|
||||||
|
parts.each {|part|
|
||||||
|
if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
|
||||||
|
val = m[1]
|
||||||
|
q = (m[2] or 1).to_f
|
||||||
|
tmp.push([val, q])
|
||||||
|
end
|
||||||
|
}
|
||||||
|
tmp = tmp.sort_by{|val, q| -q}
|
||||||
|
tmp.collect!{|val, q| val}
|
||||||
|
end
|
||||||
|
return tmp
|
||||||
|
rescue
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a string that can be used as filename value in Content-Disposition header
|
||||||
|
def filename_for_content_disposition(name)
|
||||||
|
request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
|
||||||
|
end
|
||||||
|
|
||||||
|
def api_request?
|
||||||
|
%w(xml json).include? params[:format]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Renders a warning flash if obj has unsaved attachments
|
||||||
|
def render_attachment_warning_if_needed(obj)
|
||||||
|
flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Rescues an invalid query statement. Just in case...
|
||||||
|
def query_statement_invalid(exception)
|
||||||
|
logger.error "Query::StatementInvalid: #{exception.message}" if logger
|
||||||
|
session.delete(:query)
|
||||||
|
sort_clear if respond_to?(:sort_clear)
|
||||||
|
render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
|
||||||
|
end
|
||||||
|
|
||||||
|
# Converts the errors on an ActiveRecord object into a common JSON format
|
||||||
|
def object_errors_to_json(object)
|
||||||
|
object.errors.collect do |attribute, error|
|
||||||
|
{ attribute => error }
|
||||||
|
end.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,41 +16,72 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class AttachmentsController < ApplicationController
|
class AttachmentsController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
before_filter :find_project
|
before_filter :find_project
|
||||||
|
before_filter :file_readable, :read_authorize, :except => :destroy
|
||||||
|
before_filter :delete_authorize, :only => :destroy
|
||||||
|
|
||||||
|
verify :method => :post, :only => :destroy
|
||||||
|
|
||||||
def show
|
def show
|
||||||
if @attachment.is_diff?
|
if @attachment.is_diff?
|
||||||
@diff = File.new(@attachment.diskfile, "rb").read
|
@diff = File.new(@attachment.diskfile, "rb").read
|
||||||
render :action => 'diff'
|
render :action => 'diff'
|
||||||
elsif @attachment.is_text?
|
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
|
||||||
@content = File.new(@attachment.diskfile, "rb").read
|
@content = File.new(@attachment.diskfile, "rb").read
|
||||||
render :action => 'file'
|
render :action => 'file'
|
||||||
elsif
|
else
|
||||||
download
|
download
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def download
|
def download
|
||||||
@attachment.increment_download if @attachment.container.is_a?(Version)
|
if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project)
|
||||||
|
@attachment.increment_download
|
||||||
|
end
|
||||||
|
|
||||||
# images are sent inline
|
# images are sent inline
|
||||||
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
||||||
:type => @attachment.content_type,
|
:type => detect_content_type(@attachment),
|
||||||
:disposition => (@attachment.image? ? 'inline' : 'attachment')
|
:disposition => (@attachment.image? ? 'inline' : 'attachment')
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
# Make sure association callbacks are called
|
||||||
|
@attachment.container.attachments.delete(@attachment)
|
||||||
|
redirect_to :back
|
||||||
|
rescue ::ActionController::RedirectBackError
|
||||||
|
redirect_to :controller => 'projects', :action => 'show', :id => @project
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_project
|
||||||
@attachment = Attachment.find(params[:id])
|
@attachment = Attachment.find(params[:id])
|
||||||
# Show 404 if the filename in the url is wrong
|
# Show 404 if the filename in the url is wrong
|
||||||
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
|
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
|
||||||
|
|
||||||
@project = @attachment.project
|
@project = @attachment.project
|
||||||
permission = @attachment.container.is_a?(Version) ? :view_files : "view_#{@attachment.container.class.name.underscore.pluralize}".to_sym
|
|
||||||
allowed = User.current.allowed_to?(permission, @project)
|
|
||||||
allowed ? true : (User.current.logged? ? render_403 : require_login)
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Checks that the file exists and is readable
|
||||||
|
def file_readable
|
||||||
|
@attachment.readable? ? true : render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_authorize
|
||||||
|
@attachment.visible? ? true : deny_access
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_authorize
|
||||||
|
@attachment.deletable? ? true : deny_access
|
||||||
|
end
|
||||||
|
|
||||||
|
def detect_content_type(attachment)
|
||||||
|
content_type = attachment.content_type
|
||||||
|
if content_type.blank?
|
||||||
|
content_type = Redmine::MimeType.of(attachment.filename)
|
||||||
|
end
|
||||||
|
content_type.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,48 +16,46 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class AuthSourcesController < ApplicationController
|
class AuthSourcesController < ApplicationController
|
||||||
layout 'base'
|
layout 'admin'
|
||||||
|
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
|
|
||||||
def index
|
|
||||||
list
|
|
||||||
render :action => 'list' unless request.xhr?
|
|
||||||
end
|
|
||||||
|
|
||||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||||
:redirect_to => { :action => :list }
|
:redirect_to => { :template => :index }
|
||||||
|
|
||||||
def list
|
def index
|
||||||
@auth_source_pages, @auth_sources = paginate :auth_sources, :per_page => 10
|
@auth_source_pages, @auth_sources = paginate auth_source_class.name.tableize, :per_page => 10
|
||||||
render :action => "list", :layout => false if request.xhr?
|
render "auth_sources/index"
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@auth_source = AuthSourceLdap.new
|
@auth_source = auth_source_class.new
|
||||||
|
render 'auth_sources/new'
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@auth_source = AuthSourceLdap.new(params[:auth_source])
|
@auth_source = auth_source_class.new(params[:auth_source])
|
||||||
if @auth_source.save
|
if @auth_source.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
else
|
else
|
||||||
render :action => 'new'
|
render 'auth_sources/new'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@auth_source = AuthSource.find(params[:id])
|
@auth_source = AuthSource.find(params[:id])
|
||||||
|
render 'auth_sources/edit'
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@auth_source = AuthSource.find(params[:id])
|
@auth_source = AuthSource.find(params[:id])
|
||||||
if @auth_source.update_attributes(params[:auth_source])
|
if @auth_source.update_attributes(params[:auth_source])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
else
|
else
|
||||||
render :action => 'edit'
|
render 'auth_sources/edit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -67,9 +65,9 @@ class AuthSourcesController < ApplicationController
|
|||||||
@auth_method.test_connection
|
@auth_method.test_connection
|
||||||
flash[:notice] = l(:notice_successful_connection)
|
flash[:notice] = l(:notice_successful_connection)
|
||||||
rescue => text
|
rescue => text
|
||||||
flash[:error] = "Unable to connect (#{text})"
|
flash[:error] = l(:error_unable_to_connect, text.message)
|
||||||
end
|
end
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@@ -78,6 +76,12 @@ class AuthSourcesController < ApplicationController
|
|||||||
@auth_source.destroy
|
@auth_source.destroy
|
||||||
flash[:notice] = l(:notice_successful_delete)
|
flash[:notice] = l(:notice_successful_delete)
|
||||||
end
|
end
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def auth_source_class
|
||||||
|
AuthSource
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class BoardsController < ApplicationController
|
class BoardsController < ApplicationController
|
||||||
layout 'base'
|
default_search_scope :messages
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :find_board_if_available, :authorize
|
||||||
|
|
||||||
helper :messages
|
helper :messages
|
||||||
include MessagesHelper
|
include MessagesHelper
|
||||||
@@ -36,16 +36,29 @@ class BoardsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
sort_init "#{Message.table_name}.updated_on", "desc"
|
respond_to do |format|
|
||||||
sort_update
|
format.html {
|
||||||
|
sort_init 'updated_on', 'desc'
|
||||||
@topic_count = @board.topics.count
|
sort_update 'created_on' => "#{Message.table_name}.created_on",
|
||||||
@topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
|
'replies' => "#{Message.table_name}.replies_count",
|
||||||
@topics = @board.topics.find :all, :order => "#{Message.table_name}.sticky DESC, #{sort_clause}",
|
'updated_on' => "#{Message.table_name}.updated_on"
|
||||||
:include => [:author, {:last_reply => :author}],
|
|
||||||
:limit => @topic_pages.items_per_page,
|
@topic_count = @board.topics.count
|
||||||
:offset => @topic_pages.current.offset
|
@topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
|
||||||
render :action => 'show', :layout => !request.xhr?
|
@topics = @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '),
|
||||||
|
:include => [:author, {:last_reply => :author}],
|
||||||
|
:limit => @topic_pages.items_per_page,
|
||||||
|
:offset => @topic_pages.current.offset
|
||||||
|
@message = Message.new
|
||||||
|
render :action => 'show', :layout => !request.xhr?
|
||||||
|
}
|
||||||
|
format.atom {
|
||||||
|
@messages = @board.messages.find :all, :order => 'created_on DESC',
|
||||||
|
:include => [:author, :board],
|
||||||
|
:limit => Setting.feeds_limit.to_i
|
||||||
|
render_feed(@messages, :title => "#{@project}: #{@board}")
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
|
verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
|
||||||
@@ -55,30 +68,33 @@ class BoardsController < ApplicationController
|
|||||||
@board.project = @project
|
@board.project = @project
|
||||||
if request.post? && @board.save
|
if request.post? && @board.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
|
redirect_to_settings_in_projects
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
if request.post? && @board.update_attributes(params[:board])
|
if request.post? && @board.update_attributes(params[:board])
|
||||||
case params[:position]
|
redirect_to_settings_in_projects
|
||||||
when 'highest'; @board.move_to_top
|
|
||||||
when 'higher'; @board.move_higher
|
|
||||||
when 'lower'; @board.move_lower
|
|
||||||
when 'lowest'; @board.move_to_bottom
|
|
||||||
end if params[:position]
|
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@board.destroy
|
@board.destroy
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
|
redirect_to_settings_in_projects
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def redirect_to_settings_in_projects
|
||||||
|
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
|
||||||
|
end
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
@project = Project.find(params[:project_id])
|
@project = Project.find(params[:project_id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_board_if_available
|
||||||
@board = @project.boards.find(params[:id]) if params[:id]
|
@board = @project.boards.find(params[:id]) if params[:id]
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
class CalendarsController < ApplicationController
|
||||||
|
before_filter :find_optional_project
|
||||||
|
|
||||||
|
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||||
|
|
||||||
|
helper :issues
|
||||||
|
helper :projects
|
||||||
|
helper :queries
|
||||||
|
include QueriesHelper
|
||||||
|
|
||||||
|
def show
|
||||||
|
if params[:year] and params[:year].to_i > 1900
|
||||||
|
@year = params[:year].to_i
|
||||||
|
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
||||||
|
@month = params[:month].to_i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@year ||= Date.today.year
|
||||||
|
@month ||= Date.today.month
|
||||||
|
|
||||||
|
@calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
|
||||||
|
retrieve_query
|
||||||
|
@query.group_by = nil
|
||||||
|
if @query.valid?
|
||||||
|
events = []
|
||||||
|
events += @query.issues(:include => [:tracker, :assigned_to, :priority],
|
||||||
|
:conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
|
||||||
|
)
|
||||||
|
events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
|
||||||
|
|
||||||
|
@calendar.events = events
|
||||||
|
end
|
||||||
|
|
||||||
|
render :layout => false if request.xhr?
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,38 +16,28 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class CustomFieldsController < ApplicationController
|
class CustomFieldsController < ApplicationController
|
||||||
layout 'base'
|
layout 'admin'
|
||||||
|
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
|
|
||||||
def index
|
def index
|
||||||
list
|
|
||||||
render :action => 'list' unless request.xhr?
|
|
||||||
end
|
|
||||||
|
|
||||||
def list
|
|
||||||
@custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
|
@custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
|
||||||
@tab = params[:tab] || 'IssueCustomField'
|
@tab = params[:tab] || 'IssueCustomField'
|
||||||
render :action => "list", :layout => false if request.xhr?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
case params[:type]
|
@custom_field = begin
|
||||||
when "IssueCustomField"
|
if params[:type].to_s.match(/.+CustomField$/)
|
||||||
@custom_field = IssueCustomField.new(params[:custom_field])
|
params[:type].to_s.constantize.new(params[:custom_field])
|
||||||
@custom_field.trackers = Tracker.find(params[:tracker_ids]) if params[:tracker_ids]
|
end
|
||||||
when "UserCustomField"
|
rescue
|
||||||
@custom_field = UserCustomField.new(params[:custom_field])
|
end
|
||||||
when "ProjectCustomField"
|
(redirect_to(:action => 'index'); return) unless @custom_field.is_a?(CustomField)
|
||||||
@custom_field = ProjectCustomField.new(params[:custom_field])
|
|
||||||
when "TimeEntryCustomField"
|
|
||||||
@custom_field = TimeEntryCustomField.new(params[:custom_field])
|
|
||||||
else
|
|
||||||
redirect_to :action => 'list'
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if request.post? and @custom_field.save
|
if request.post? and @custom_field.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'list', :tab => @custom_field.class.name
|
call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
|
||||||
|
redirect_to :action => 'index', :tab => @custom_field.class.name
|
||||||
end
|
end
|
||||||
@trackers = Tracker.find(:all, :order => 'position')
|
@trackers = Tracker.find(:all, :order => 'position')
|
||||||
end
|
end
|
||||||
@@ -55,35 +45,18 @@ class CustomFieldsController < ApplicationController
|
|||||||
def edit
|
def edit
|
||||||
@custom_field = CustomField.find(params[:id])
|
@custom_field = CustomField.find(params[:id])
|
||||||
if request.post? and @custom_field.update_attributes(params[:custom_field])
|
if request.post? and @custom_field.update_attributes(params[:custom_field])
|
||||||
if @custom_field.is_a? IssueCustomField
|
|
||||||
@custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : []
|
|
||||||
end
|
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'list', :tab => @custom_field.class.name
|
call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
|
||||||
|
redirect_to :action => 'index', :tab => @custom_field.class.name
|
||||||
end
|
end
|
||||||
@trackers = Tracker.find(:all, :order => 'position')
|
@trackers = Tracker.find(:all, :order => 'position')
|
||||||
end
|
end
|
||||||
|
|
||||||
def move
|
|
||||||
@custom_field = CustomField.find(params[:id])
|
|
||||||
case params[:position]
|
|
||||||
when 'highest'
|
|
||||||
@custom_field.move_to_top
|
|
||||||
when 'higher'
|
|
||||||
@custom_field.move_higher
|
|
||||||
when 'lower'
|
|
||||||
@custom_field.move_lower
|
|
||||||
when 'lowest'
|
|
||||||
@custom_field.move_to_bottom
|
|
||||||
end if params[:position]
|
|
||||||
redirect_to :action => 'list', :tab => @custom_field.class.name
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@custom_field = CustomField.find(params[:id]).destroy
|
@custom_field = CustomField.find(params[:id]).destroy
|
||||||
redirect_to :action => 'list', :tab => @custom_field.class.name
|
redirect_to :action => 'index', :tab => @custom_field.class.name
|
||||||
rescue
|
rescue
|
||||||
flash[:error] = "Unable to delete custom field"
|
flash[:error] = l(:error_can_not_delete_custom_field)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,9 +16,11 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class DocumentsController < ApplicationController
|
class DocumentsController < ApplicationController
|
||||||
layout 'base'
|
default_search_scope :documents
|
||||||
|
model_object Document
|
||||||
before_filter :find_project, :only => [:index, :new]
|
before_filter :find_project, :only => [:index, :new]
|
||||||
before_filter :find_document, :except => [:index, :new]
|
before_filter :find_model_object, :except => [:index, :new]
|
||||||
|
before_filter :find_project_from_association, :except => [:index, :new]
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
||||||
helper :attachments
|
helper :attachments
|
||||||
@@ -28,7 +30,7 @@ class DocumentsController < ApplicationController
|
|||||||
documents = @project.documents.find :all, :include => [:attachments, :category]
|
documents = @project.documents.find :all, :include => [:attachments, :category]
|
||||||
case @sort_by
|
case @sort_by
|
||||||
when 'date'
|
when 'date'
|
||||||
@grouped = documents.group_by {|d| d.created_on.to_date }
|
@grouped = documents.group_by {|d| d.updated_on.to_date }
|
||||||
when 'title'
|
when 'title'
|
||||||
@grouped = documents.group_by {|d| d.title.first.upcase}
|
@grouped = documents.group_by {|d| d.title.first.upcase}
|
||||||
when 'author'
|
when 'author'
|
||||||
@@ -36,6 +38,7 @@ class DocumentsController < ApplicationController
|
|||||||
else
|
else
|
||||||
@grouped = documents.group_by(&:category)
|
@grouped = documents.group_by(&:category)
|
||||||
end
|
end
|
||||||
|
@document = @project.documents.build
|
||||||
render :layout => false if request.xhr?
|
render :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -46,15 +49,15 @@ class DocumentsController < ApplicationController
|
|||||||
def new
|
def new
|
||||||
@document = @project.documents.build(params[:document])
|
@document = @project.documents.build(params[:document])
|
||||||
if request.post? and @document.save
|
if request.post? and @document.save
|
||||||
attach_files(@document, params[:attachments])
|
attachments = Attachment.attach_files(@document, params[:attachments])
|
||||||
|
render_attachment_warning_if_needed(@document)
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
|
|
||||||
redirect_to :action => 'index', :project_id => @project
|
redirect_to :action => 'index', :project_id => @project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@categories = Enumeration::get_values('DCAT')
|
@categories = DocumentCategory.all
|
||||||
if request.post? and @document.update_attributes(params[:document])
|
if request.post? and @document.update_attributes(params[:document])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'show', :id => @document
|
redirect_to :action => 'show', :id => @document
|
||||||
@@ -67,13 +70,10 @@ class DocumentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_attachment
|
def add_attachment
|
||||||
attachments = attach_files(@document, params[:attachments])
|
attachments = Attachment.attach_files(@document, params[:attachments])
|
||||||
Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added')
|
render_attachment_warning_if_needed(@document)
|
||||||
redirect_to :action => 'show', :id => @document
|
|
||||||
end
|
Mailer.deliver_attachments_added(attachments[:files]) if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added')
|
||||||
|
|
||||||
def destroy_attachment
|
|
||||||
@document.attachments.find(params[:attachment_id]).destroy
|
|
||||||
redirect_to :action => 'show', :id => @document
|
redirect_to :action => 'show', :id => @document
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -83,11 +83,4 @@ private
|
|||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_document
|
|
||||||
@document = Document.find(params[:id])
|
|
||||||
@project = @document.project
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
render_404
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,8 +16,12 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class EnumerationsController < ApplicationController
|
class EnumerationsController < ApplicationController
|
||||||
layout 'base'
|
layout 'admin'
|
||||||
|
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
|
|
||||||
|
helper :custom_fields
|
||||||
|
include CustomFieldsHelper
|
||||||
|
|
||||||
def index
|
def index
|
||||||
list
|
list
|
||||||
@@ -32,14 +36,19 @@ class EnumerationsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@enumeration = Enumeration.new(:opt => params[:opt])
|
begin
|
||||||
|
@enumeration = params[:type].constantize.new
|
||||||
|
rescue NameError
|
||||||
|
@enumeration = Enumeration.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@enumeration = Enumeration.new(params[:enumeration])
|
@enumeration = Enumeration.new(params[:enumeration])
|
||||||
|
@enumeration.type = params[:enumeration][:type]
|
||||||
if @enumeration.save
|
if @enumeration.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'list', :opt => @enumeration.opt
|
redirect_to :action => 'list', :type => @enumeration.type
|
||||||
else
|
else
|
||||||
render :action => 'new'
|
render :action => 'new'
|
||||||
end
|
end
|
||||||
@@ -51,28 +60,14 @@ class EnumerationsController < ApplicationController
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
@enumeration = Enumeration.find(params[:id])
|
@enumeration = Enumeration.find(params[:id])
|
||||||
|
@enumeration.type = params[:enumeration][:type] if params[:enumeration][:type]
|
||||||
if @enumeration.update_attributes(params[:enumeration])
|
if @enumeration.update_attributes(params[:enumeration])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'list', :opt => @enumeration.opt
|
redirect_to :action => 'list', :type => @enumeration.type
|
||||||
else
|
else
|
||||||
render :action => 'edit'
|
render :action => 'edit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def move
|
|
||||||
@enumeration = Enumeration.find(params[:id])
|
|
||||||
case params[:position]
|
|
||||||
when 'highest'
|
|
||||||
@enumeration.move_to_top
|
|
||||||
when 'higher'
|
|
||||||
@enumeration.move_higher
|
|
||||||
when 'lower'
|
|
||||||
@enumeration.move_lower
|
|
||||||
when 'lowest'
|
|
||||||
@enumeration.move_to_bottom
|
|
||||||
end if params[:position]
|
|
||||||
redirect_to :action => 'index'
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@enumeration = Enumeration.find(params[:id])
|
@enumeration = Enumeration.find(params[:id])
|
||||||
@@ -81,12 +76,12 @@ class EnumerationsController < ApplicationController
|
|||||||
@enumeration.destroy
|
@enumeration.destroy
|
||||||
redirect_to :action => 'index'
|
redirect_to :action => 'index'
|
||||||
elsif params[:reassign_to_id]
|
elsif params[:reassign_to_id]
|
||||||
if reassign_to = Enumeration.find_by_opt_and_id(@enumeration.opt, params[:reassign_to_id])
|
if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id])
|
||||||
@enumeration.destroy(reassign_to)
|
@enumeration.destroy(reassign_to)
|
||||||
redirect_to :action => 'index'
|
redirect_to :action => 'index'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@enumerations = Enumeration.get_values(@enumeration.opt) - [@enumeration]
|
@enumerations = @enumeration.class.find(:all) - [@enumeration]
|
||||||
#rescue
|
#rescue
|
||||||
# flash[:error] = 'Unable to delete enumeration'
|
# flash[:error] = 'Unable to delete enumeration'
|
||||||
# redirect_to :action => 'index'
|
# redirect_to :action => 'index'
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
class GanttsController < ApplicationController
|
||||||
|
before_filter :find_optional_project
|
||||||
|
|
||||||
|
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||||
|
|
||||||
|
helper :issues
|
||||||
|
helper :projects
|
||||||
|
helper :queries
|
||||||
|
include QueriesHelper
|
||||||
|
helper :sort
|
||||||
|
include SortHelper
|
||||||
|
include Redmine::Export::PDF
|
||||||
|
|
||||||
|
def show
|
||||||
|
@gantt = Redmine::Helpers::Gantt.new(params)
|
||||||
|
retrieve_query
|
||||||
|
@query.group_by = nil
|
||||||
|
if @query.valid?
|
||||||
|
events = []
|
||||||
|
# Issues that have start and due dates
|
||||||
|
events += @query.issues(:include => [:tracker, :assigned_to, :priority],
|
||||||
|
:order => "start_date, due_date",
|
||||||
|
:conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
|
||||||
|
)
|
||||||
|
# Issues that don't have a due date but that are assigned to a version with a date
|
||||||
|
events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version],
|
||||||
|
:order => "start_date, effective_date",
|
||||||
|
:conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
|
||||||
|
)
|
||||||
|
# Versions
|
||||||
|
events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
|
||||||
|
|
||||||
|
@gantt.events = events
|
||||||
|
end
|
||||||
|
|
||||||
|
basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render :action => "show", :layout => !request.xhr? }
|
||||||
|
format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
|
||||||
|
format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class GroupsController < ApplicationController
|
||||||
|
layout 'admin'
|
||||||
|
|
||||||
|
before_filter :require_admin
|
||||||
|
|
||||||
|
helper :custom_fields
|
||||||
|
|
||||||
|
# GET /groups
|
||||||
|
# GET /groups.xml
|
||||||
|
def index
|
||||||
|
@groups = Group.find(:all, :order => 'lastname')
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # index.html.erb
|
||||||
|
format.xml { render :xml => @groups }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /groups/1
|
||||||
|
# GET /groups/1.xml
|
||||||
|
def show
|
||||||
|
@group = Group.find(params[:id])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # show.html.erb
|
||||||
|
format.xml { render :xml => @group }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /groups/new
|
||||||
|
# GET /groups/new.xml
|
||||||
|
def new
|
||||||
|
@group = Group.new
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # new.html.erb
|
||||||
|
format.xml { render :xml => @group }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /groups/1/edit
|
||||||
|
def edit
|
||||||
|
@group = Group.find(params[:id], :include => :projects)
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /groups
|
||||||
|
# POST /groups.xml
|
||||||
|
def create
|
||||||
|
@group = Group.new(params[:group])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @group.save
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
format.html { redirect_to(groups_path) }
|
||||||
|
format.xml { render :xml => @group, :status => :created, :location => @group }
|
||||||
|
else
|
||||||
|
format.html { render :action => "new" }
|
||||||
|
format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PUT /groups/1
|
||||||
|
# PUT /groups/1.xml
|
||||||
|
def update
|
||||||
|
@group = Group.find(params[:id])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @group.update_attributes(params[:group])
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
format.html { redirect_to(groups_path) }
|
||||||
|
format.xml { head :ok }
|
||||||
|
else
|
||||||
|
format.html { render :action => "edit" }
|
||||||
|
format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /groups/1
|
||||||
|
# DELETE /groups/1.xml
|
||||||
|
def destroy
|
||||||
|
@group = Group.find(params[:id])
|
||||||
|
@group.destroy
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to(groups_url) }
|
||||||
|
format.xml { head :ok }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_users
|
||||||
|
@group = Group.find(params[:id])
|
||||||
|
users = User.find_all_by_id(params[:user_ids])
|
||||||
|
@group.users << users if request.post?
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
|
||||||
|
format.js {
|
||||||
|
render(:update) {|page|
|
||||||
|
page.replace_html "tab-content-users", :partial => 'groups/users'
|
||||||
|
users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_user
|
||||||
|
@group = Group.find(params[:id])
|
||||||
|
@group.users.delete(User.find(params[:user_id])) if request.post?
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
|
||||||
|
format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def autocomplete_for_user
|
||||||
|
@group = Group.find(params[:id])
|
||||||
|
@users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users
|
||||||
|
render :layout => false
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit_membership
|
||||||
|
@group = Group.find(params[:id])
|
||||||
|
@membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
|
||||||
|
@membership.save if request.post?
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
|
||||||
|
format.js {
|
||||||
|
render(:update) {|page|
|
||||||
|
page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
|
||||||
|
page.visual_effect(:highlight, "member-#{@membership.id}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy_membership
|
||||||
|
@group = Group.find(params[:id])
|
||||||
|
Member.find(params[:membership_id]).destroy if request.post?
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
|
||||||
|
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -16,12 +16,42 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class IssueCategoriesController < ApplicationController
|
class IssueCategoriesController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
menu_item :settings
|
menu_item :settings
|
||||||
before_filter :find_project, :authorize
|
model_object IssueCategory
|
||||||
|
before_filter :find_model_object, :except => :new
|
||||||
|
before_filter :find_project_from_association, :except => :new
|
||||||
|
before_filter :find_project, :only => :new
|
||||||
|
before_filter :authorize
|
||||||
|
|
||||||
verify :method => :post, :only => :destroy
|
verify :method => :post, :only => :destroy
|
||||||
|
|
||||||
|
def new
|
||||||
|
@category = @project.issue_categories.build(params[:category])
|
||||||
|
if request.post?
|
||||||
|
if @category.save
|
||||||
|
respond_to do |format|
|
||||||
|
format.html do
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
|
||||||
|
end
|
||||||
|
format.js do
|
||||||
|
# IE doesn't support the replace_html rjs method for select box options
|
||||||
|
render(:update) {|page| page.replace "issue_category_id",
|
||||||
|
content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.js do
|
||||||
|
render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
if request.post? and @category.update_attributes(params[:category])
|
if request.post? and @category.update_attributes(params[:category])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
@@ -44,10 +74,16 @@ class IssueCategoriesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
# Wrap ApplicationController's find_model_object method to set
|
||||||
|
# @category instead of just @issue_category
|
||||||
|
def find_model_object
|
||||||
|
super
|
||||||
|
@category = @object
|
||||||
|
end
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
@category = IssueCategory.find(params[:id])
|
@project = Project.find(params[:project_id])
|
||||||
@project = @category.project
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,12 +16,14 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class IssueRelationsController < ApplicationController
|
class IssueRelationsController < ApplicationController
|
||||||
layout 'base'
|
before_filter :find_issue, :find_project_from_association, :authorize
|
||||||
before_filter :find_project, :authorize
|
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@relation = IssueRelation.new(params[:relation])
|
@relation = IssueRelation.new(params[:relation])
|
||||||
@relation.issue_from = @issue
|
@relation.issue_from = @issue
|
||||||
|
if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/)
|
||||||
|
@relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
|
||||||
|
end
|
||||||
@relation.save if request.post?
|
@relation.save if request.post?
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
||||||
@@ -50,9 +52,8 @@ class IssueRelationsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_issue
|
||||||
@issue = Issue.find(params[:issue_id])
|
@issue = @object = Issue.find(params[:issue_id])
|
||||||
@project = @issue.project
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,20 +16,16 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class IssueStatusesController < ApplicationController
|
class IssueStatusesController < ApplicationController
|
||||||
layout 'base'
|
layout 'admin'
|
||||||
|
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
|
|
||||||
verify :method => :post, :only => [ :destroy, :create, :update, :move ],
|
verify :method => :post, :only => [ :destroy, :create, :update, :move, :update_issue_done_ratio ],
|
||||||
:redirect_to => { :action => :list }
|
:redirect_to => { :action => :index }
|
||||||
|
|
||||||
def index
|
def index
|
||||||
list
|
|
||||||
render :action => 'list' unless request.xhr?
|
|
||||||
end
|
|
||||||
|
|
||||||
def list
|
|
||||||
@issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
|
@issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
|
||||||
render :action => "list", :layout => false if request.xhr?
|
render :action => "index", :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@@ -40,7 +36,7 @@ class IssueStatusesController < ApplicationController
|
|||||||
@issue_status = IssueStatus.new(params[:issue_status])
|
@issue_status = IssueStatus.new(params[:issue_status])
|
||||||
if @issue_status.save
|
if @issue_status.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
else
|
else
|
||||||
render :action => 'new'
|
render :action => 'new'
|
||||||
end
|
end
|
||||||
@@ -54,32 +50,26 @@ class IssueStatusesController < ApplicationController
|
|||||||
@issue_status = IssueStatus.find(params[:id])
|
@issue_status = IssueStatus.find(params[:id])
|
||||||
if @issue_status.update_attributes(params[:issue_status])
|
if @issue_status.update_attributes(params[:issue_status])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
else
|
else
|
||||||
render :action => 'edit'
|
render :action => 'edit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def move
|
|
||||||
@issue_status = IssueStatus.find(params[:id])
|
|
||||||
case params[:position]
|
|
||||||
when 'highest'
|
|
||||||
@issue_status.move_to_top
|
|
||||||
when 'higher'
|
|
||||||
@issue_status.move_higher
|
|
||||||
when 'lower'
|
|
||||||
@issue_status.move_lower
|
|
||||||
when 'lowest'
|
|
||||||
@issue_status.move_to_bottom
|
|
||||||
end if params[:position]
|
|
||||||
redirect_to :action => 'list'
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
IssueStatus.find(params[:id]).destroy
|
IssueStatus.find(params[:id]).destroy
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
rescue
|
rescue
|
||||||
flash[:error] = "Unable to delete issue status"
|
flash[:error] = l(:error_unable_delete_issue_status)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_issue_done_ratio
|
||||||
|
if IssueStatus.update_issue_done_ratios
|
||||||
|
flash[:notice] = l(:notice_issue_done_ratios_updated)
|
||||||
|
else
|
||||||
|
flash[:error] = l(:error_issue_done_ratios_not_updated)
|
||||||
|
end
|
||||||
|
redirect_to :action => 'index'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,23 +16,25 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class IssuesController < ApplicationController
|
class IssuesController < ApplicationController
|
||||||
layout 'base'
|
menu_item :new_issue, :only => [:new, :create]
|
||||||
menu_item :new_issue, :only => :new
|
default_search_scope :issues
|
||||||
|
|
||||||
before_filter :find_issue, :only => [:show, :edit, :reply, :destroy_attachment]
|
before_filter :find_issue, :only => [:show, :edit, :update, :reply]
|
||||||
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
|
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
|
||||||
before_filter :find_project, :only => [:new, :update_form, :preview]
|
before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete]
|
||||||
before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu]
|
before_filter :authorize, :except => [:index, :changes, :preview, :context_menu]
|
||||||
before_filter :find_optional_project, :only => [:index, :changes]
|
before_filter :find_optional_project, :only => [:index, :changes]
|
||||||
accept_key_auth :index, :changes
|
before_filter :check_for_default_issue_status, :only => [:new, :create]
|
||||||
|
before_filter :build_new_issue_from_params, :only => [:new, :create]
|
||||||
|
accept_key_auth :index, :show, :changes
|
||||||
|
|
||||||
|
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||||
|
|
||||||
helper :journals
|
helper :journals
|
||||||
helper :projects
|
helper :projects
|
||||||
include ProjectsHelper
|
include ProjectsHelper
|
||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
include CustomFieldsHelper
|
include CustomFieldsHelper
|
||||||
helper :ifpdf
|
|
||||||
include IfpdfHelper
|
|
||||||
helper :issue_relations
|
helper :issue_relations
|
||||||
include IssueRelationsHelper
|
include IssueRelationsHelper
|
||||||
helper :watchers
|
helper :watchers
|
||||||
@@ -40,35 +42,50 @@ class IssuesController < ApplicationController
|
|||||||
helper :attachments
|
helper :attachments
|
||||||
include AttachmentsHelper
|
include AttachmentsHelper
|
||||||
helper :queries
|
helper :queries
|
||||||
|
include QueriesHelper
|
||||||
helper :sort
|
helper :sort
|
||||||
include SortHelper
|
include SortHelper
|
||||||
include IssuesHelper
|
include IssuesHelper
|
||||||
helper :timelog
|
helper :timelog
|
||||||
|
include Redmine::Export::PDF
|
||||||
|
|
||||||
|
verify :method => [:post, :delete],
|
||||||
|
:only => :destroy,
|
||||||
|
:render => { :nothing => true, :status => :method_not_allowed }
|
||||||
|
|
||||||
|
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
||||||
|
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
|
||||||
|
|
||||||
def index
|
def index
|
||||||
sort_init "#{Issue.table_name}.id", "desc"
|
|
||||||
sort_update
|
|
||||||
retrieve_query
|
retrieve_query
|
||||||
|
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
|
||||||
|
sort_update(@query.sortable_columns)
|
||||||
|
|
||||||
if @query.valid?
|
if @query.valid?
|
||||||
limit = per_page_option
|
limit = case params[:format]
|
||||||
respond_to do |format|
|
when 'csv', 'pdf'
|
||||||
format.html { }
|
Setting.issues_export_limit.to_i
|
||||||
format.atom { }
|
when 'atom'
|
||||||
format.csv { limit = Setting.issues_export_limit.to_i }
|
Setting.feeds_limit.to_i
|
||||||
format.pdf { limit = Setting.issues_export_limit.to_i }
|
else
|
||||||
|
per_page_option
|
||||||
end
|
end
|
||||||
@issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
|
|
||||||
|
@issue_count = @query.issue_count
|
||||||
@issue_pages = Paginator.new self, @issue_count, limit, params['page']
|
@issue_pages = Paginator.new self, @issue_count, limit, params['page']
|
||||||
@issues = Issue.find :all, :order => sort_clause,
|
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
|
||||||
:include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
|
:order => sort_clause,
|
||||||
:conditions => @query.statement,
|
:offset => @issue_pages.current.offset,
|
||||||
:limit => limit,
|
:limit => limit)
|
||||||
:offset => @issue_pages.current.offset
|
@issue_count_by_group = @query.issue_count_by_group
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
|
format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
|
||||||
|
format.xml { render :layout => false }
|
||||||
|
format.json { render :text => @issues.to_json, :layout => false }
|
||||||
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
||||||
format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
|
format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
|
||||||
format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') }
|
format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# Send html if the query is not valid
|
# Send html if the query is not valid
|
||||||
@@ -79,14 +96,13 @@ class IssuesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def changes
|
def changes
|
||||||
sort_init "#{Issue.table_name}.id", "desc"
|
|
||||||
sort_update
|
|
||||||
retrieve_query
|
retrieve_query
|
||||||
|
sort_init 'id', 'desc'
|
||||||
|
sort_update(@query.sortable_columns)
|
||||||
|
|
||||||
if @query.valid?
|
if @query.valid?
|
||||||
@journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
|
@journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
|
||||||
:conditions => @query.statement,
|
:limit => 25)
|
||||||
:limit => 25,
|
|
||||||
:order => "#{Journal.table_name}.created_on DESC"
|
|
||||||
end
|
end
|
||||||
@title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
|
@title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
|
||||||
render :layout => false, :content_type => 'application/atom+xml'
|
render :layout => false, :content_type => 'application/atom+xml'
|
||||||
@@ -98,58 +114,50 @@ class IssuesController < ApplicationController
|
|||||||
@journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
|
@journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
|
||||||
@journals.each_with_index {|j,i| j.indice = i+1}
|
@journals.each_with_index {|j,i| j.indice = i+1}
|
||||||
@journals.reverse! if User.current.wants_comments_in_reverse_order?
|
@journals.reverse! if User.current.wants_comments_in_reverse_order?
|
||||||
|
@changesets = @issue.changesets.visible.all
|
||||||
|
@changesets.reverse! if User.current.wants_comments_in_reverse_order?
|
||||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||||
@priorities = Enumeration::get_values('IPRI')
|
@priorities = IssuePriority.all
|
||||||
@time_entry = TimeEntry.new
|
@time_entry = TimeEntry.new
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :template => 'issues/show.rhtml' }
|
format.html { render :template => 'issues/show.rhtml' }
|
||||||
|
format.xml { render :layout => false }
|
||||||
|
format.json { render :text => @issue.to_json, :layout => false }
|
||||||
format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
|
format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
|
||||||
format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
|
format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a new issue
|
# Add a new issue
|
||||||
# The new issue will be created from an existing one if copy_from parameter is given
|
# The new issue will be created from an existing one if copy_from parameter is given
|
||||||
def new
|
def new
|
||||||
@issue = Issue.new
|
render :action => 'new', :layout => !request.xhr?
|
||||||
@issue.copy_from(params[:copy_from]) if params[:copy_from]
|
end
|
||||||
@issue.project = @project
|
|
||||||
# Tracker must be set before custom field values
|
def create
|
||||||
@issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
|
call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
|
||||||
if @issue.tracker.nil?
|
if @issue.save
|
||||||
flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
|
attachments = Attachment.attach_files(@issue, params[:attachments])
|
||||||
render :nothing => true, :layout => true
|
render_attachment_warning_if_needed(@issue)
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
redirect_to(params[:continue] ? { :action => 'new', :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
|
||||||
|
{ :action => 'show', :id => @issue })
|
||||||
|
}
|
||||||
|
format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) }
|
||||||
|
format.json { render :text => @issue.to_json, :status => :created, :location => url_for(:controller => 'issues', :action => 'show'), :layout => false }
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
|
||||||
@issue.attributes = params[:issue]
|
|
||||||
@issue.author = User.current
|
|
||||||
|
|
||||||
default_status = IssueStatus.default
|
|
||||||
unless default_status
|
|
||||||
flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
|
|
||||||
render :nothing => true, :layout => true
|
|
||||||
return
|
|
||||||
end
|
|
||||||
@issue.status = default_status
|
|
||||||
@allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq
|
|
||||||
|
|
||||||
if request.get? || request.xhr?
|
|
||||||
@issue.start_date ||= Date.today
|
|
||||||
else
|
else
|
||||||
requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
|
respond_to do |format|
|
||||||
# Check that the user is allowed to apply the requested status
|
format.html { render :action => 'new' }
|
||||||
@issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
|
format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return }
|
||||||
if @issue.save
|
format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false }
|
||||||
attach_files(@issue, params[:attachments])
|
end
|
||||||
flash[:notice] = l(:notice_successful_create)
|
end
|
||||||
Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
|
|
||||||
redirect_to :controller => 'issues', :action => 'show', :id => @issue
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@priorities = Enumeration::get_values('IPRI')
|
|
||||||
render :layout => !request.xhr?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Attributes that can be updated on workflow transition (without :edit permission)
|
# Attributes that can be updated on workflow transition (without :edit permission)
|
||||||
@@ -157,42 +165,39 @@ class IssuesController < ApplicationController
|
|||||||
UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
|
UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
update_issue_from_params
|
||||||
@priorities = Enumeration::get_values('IPRI')
|
|
||||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
|
||||||
@time_entry = TimeEntry.new
|
|
||||||
|
|
||||||
@notes = params[:notes]
|
|
||||||
journal = @issue.init_journal(User.current, @notes)
|
|
||||||
# User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
|
|
||||||
if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
|
|
||||||
attrs = params[:issue].dup
|
|
||||||
attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
|
|
||||||
attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
|
|
||||||
@issue.attributes = attrs
|
|
||||||
end
|
|
||||||
|
|
||||||
if request.post?
|
@journal = @issue.current_journal
|
||||||
@time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
|
|
||||||
@time_entry.attributes = params[:time_entry]
|
respond_to do |format|
|
||||||
attachments = attach_files(@issue, params[:attachments])
|
format.html { }
|
||||||
attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
|
format.xml { }
|
||||||
if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save
|
end
|
||||||
# Log spend time
|
end
|
||||||
if current_role.allowed_to?(:log_time)
|
|
||||||
@time_entry.save
|
def update
|
||||||
end
|
update_issue_from_params
|
||||||
if !journal.new_record?
|
|
||||||
# Only send notification if something was actually changed
|
if @issue.save_issue_with_child_records(params, @time_entry)
|
||||||
flash[:notice] = l(:notice_successful_update)
|
render_attachment_warning_if_needed(@issue)
|
||||||
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
|
||||||
end
|
|
||||||
redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
|
respond_to do |format|
|
||||||
|
format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
|
||||||
|
format.xml { head :ok }
|
||||||
|
format.json { head :ok }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render_attachment_warning_if_needed(@issue)
|
||||||
|
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
|
||||||
|
@journal = @issue.current_journal
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render :action => 'edit' }
|
||||||
|
format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
|
||||||
|
format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::StaleObjectError
|
|
||||||
# Optimistic locking exception
|
|
||||||
flash.now[:error] = l(:notice_locking_conflict)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def reply
|
def reply
|
||||||
@@ -204,10 +209,13 @@ class IssuesController < ApplicationController
|
|||||||
user = @issue.author
|
user = @issue.author
|
||||||
text = @issue.description
|
text = @issue.description
|
||||||
end
|
end
|
||||||
content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
|
# Replaces pre blocks with [...]
|
||||||
content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
|
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
|
||||||
|
content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
||||||
|
content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||||||
|
|
||||||
render(:update) { |page|
|
render(:update) { |page|
|
||||||
page.<< "$('notes').value = \"#{content}\";"
|
page.<< "$('notes').value = \"#{escape_javascript content}\";"
|
||||||
page.show 'update'
|
page.show 'update'
|
||||||
page << "Form.Element.focus('notes');"
|
page << "Form.Element.focus('notes');"
|
||||||
page << "Element.scrollTo('update');"
|
page << "Element.scrollTo('update');"
|
||||||
@@ -217,70 +225,70 @@ class IssuesController < ApplicationController
|
|||||||
|
|
||||||
# Bulk edit a set of issues
|
# Bulk edit a set of issues
|
||||||
def bulk_edit
|
def bulk_edit
|
||||||
|
@issues.sort!
|
||||||
if request.post?
|
if request.post?
|
||||||
status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
|
attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
|
||||||
priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
|
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
|
||||||
assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
|
attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
|
||||||
category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
|
|
||||||
fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
|
|
||||||
|
|
||||||
unsaved_issue_ids = []
|
unsaved_issue_ids = []
|
||||||
@issues.each do |issue|
|
@issues.each do |issue|
|
||||||
|
issue.reload
|
||||||
journal = issue.init_journal(User.current, params[:notes])
|
journal = issue.init_journal(User.current, params[:notes])
|
||||||
issue.priority = priority if priority
|
issue.safe_attributes = attributes
|
||||||
issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
|
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
|
||||||
issue.category = category if category || params[:category_id] == 'none'
|
unless issue.save
|
||||||
issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
|
|
||||||
issue.start_date = params[:start_date] unless params[:start_date].blank?
|
|
||||||
issue.due_date = params[:due_date] unless params[:due_date].blank?
|
|
||||||
issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
|
|
||||||
# Don't save any change to the issue if the user is not authorized to apply the requested status
|
|
||||||
if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
|
|
||||||
# Send notification for each issue (if changed)
|
|
||||||
Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
|
|
||||||
else
|
|
||||||
# Keep unsaved issue ids to display them in flash error
|
# Keep unsaved issue ids to display them in flash error
|
||||||
unsaved_issue_ids << issue.id
|
unsaved_issue_ids << issue.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if unsaved_issue_ids.empty?
|
set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
|
||||||
flash[:notice] = l(:notice_successful_update) unless @issues.empty?
|
redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
|
||||||
else
|
|
||||||
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
|
|
||||||
end
|
|
||||||
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
# Find potential statuses the user could be allowed to switch issues to
|
@available_statuses = Workflow.available_statuses(@project)
|
||||||
@available_statuses = Workflow.find(:all, :include => :new_status,
|
@custom_fields = @project.all_issue_custom_fields
|
||||||
:conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def move
|
def move
|
||||||
@allowed_projects = []
|
@issues.sort!
|
||||||
# find projects to which the user is allowed to move the issue
|
@copy = params[:copy_options] && params[:copy_options][:copy]
|
||||||
if User.current.admin?
|
@allowed_projects = Issue.allowed_target_projects_on_move
|
||||||
# admin is allowed to move issues to any active (visible) project
|
|
||||||
@allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
|
|
||||||
else
|
|
||||||
User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)}
|
|
||||||
end
|
|
||||||
@target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
|
@target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
|
||||||
@target_project ||= @project
|
@target_project ||= @project
|
||||||
@trackers = @target_project.trackers
|
@trackers = @target_project.trackers
|
||||||
|
@available_statuses = Workflow.available_statuses(@project)
|
||||||
if request.post?
|
if request.post?
|
||||||
new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
|
new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
|
||||||
unsaved_issue_ids = []
|
unsaved_issue_ids = []
|
||||||
|
moved_issues = []
|
||||||
@issues.each do |issue|
|
@issues.each do |issue|
|
||||||
|
issue.reload
|
||||||
|
changed_attributes = {}
|
||||||
|
[:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute|
|
||||||
|
unless params[valid_attribute].blank?
|
||||||
|
changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
|
||||||
|
end
|
||||||
|
end
|
||||||
issue.init_journal(User.current)
|
issue.init_journal(User.current)
|
||||||
unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
|
call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
|
||||||
|
if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes})
|
||||||
|
moved_issues << r
|
||||||
|
else
|
||||||
|
unsaved_issue_ids << issue.id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if unsaved_issue_ids.empty?
|
set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
|
||||||
flash[:notice] = l(:notice_successful_update) unless @issues.empty?
|
|
||||||
|
if params[:follow]
|
||||||
|
if @issues.size == 1 && moved_issues.size == 1
|
||||||
|
redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
|
||||||
|
else
|
||||||
|
redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
|
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
|
||||||
end
|
end
|
||||||
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
render :layout => false if request.xhr?
|
render :layout => false if request.xhr?
|
||||||
@@ -303,23 +311,18 @@ class IssuesController < ApplicationController
|
|||||||
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
|
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# display the destroy form
|
unless params[:format] == 'xml' || params[:format] == 'json'
|
||||||
return
|
# display the destroy form if it's a user request
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@issues.each(&:destroy)
|
@issues.each(&:destroy)
|
||||||
redirect_to :action => 'index', :project_id => @project
|
respond_to do |format|
|
||||||
end
|
format.html { redirect_to :action => 'index', :project_id => @project }
|
||||||
|
format.xml { head :ok }
|
||||||
def destroy_attachment
|
format.json { head :ok }
|
||||||
a = @issue.attachments.find(params[:attachment_id])
|
end
|
||||||
a.destroy
|
|
||||||
journal = @issue.init_journal(User.current)
|
|
||||||
journal.details << JournalDetail.new(:property => 'attachment',
|
|
||||||
:prop_key => a.id,
|
|
||||||
:old_value => a.filename)
|
|
||||||
journal.save
|
|
||||||
redirect_to :action => 'show', :id => @issue
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def context_menu
|
def context_menu
|
||||||
@@ -327,37 +330,69 @@ class IssuesController < ApplicationController
|
|||||||
if (@issues.size == 1)
|
if (@issues.size == 1)
|
||||||
@issue = @issues.first
|
@issue = @issues.first
|
||||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||||
@assignables = @issue.assignable_users
|
|
||||||
@assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
|
|
||||||
end
|
end
|
||||||
projects = @issues.collect(&:project).compact.uniq
|
projects = @issues.collect(&:project).compact.uniq
|
||||||
@project = projects.first if projects.size == 1
|
@project = projects.first if projects.size == 1
|
||||||
|
|
||||||
@can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
|
@can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
|
||||||
:log_time => (@project && User.current.allowed_to?(:log_time, @project)),
|
:log_time => (@project && User.current.allowed_to?(:log_time, @project)),
|
||||||
:update => (@issue && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && !@allowed_statuses.empty?))),
|
:update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
|
||||||
:move => (@project && User.current.allowed_to?(:move_issues, @project)),
|
:move => (@project && User.current.allowed_to?(:move_issues, @project)),
|
||||||
:copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
|
:copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
|
||||||
:delete => (@project && User.current.allowed_to?(:delete_issues, @project))
|
:delete => (@project && User.current.allowed_to?(:delete_issues, @project))
|
||||||
}
|
}
|
||||||
|
if @project
|
||||||
@priorities = Enumeration.get_values('IPRI').reverse
|
@assignables = @project.assignable_users
|
||||||
|
@assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
|
||||||
|
@trackers = @project.trackers
|
||||||
|
end
|
||||||
|
|
||||||
|
@priorities = IssuePriority.all.reverse
|
||||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
@statuses = IssueStatus.find(:all, :order => 'position')
|
||||||
@back = request.env['HTTP_REFERER']
|
@back = params[:back_url] || request.env['HTTP_REFERER']
|
||||||
|
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_form
|
def update_form
|
||||||
@issue = Issue.new(params[:issue])
|
if params[:id].blank?
|
||||||
render :action => :new, :layout => false
|
@issue = Issue.new
|
||||||
|
@issue.project = @project
|
||||||
|
else
|
||||||
|
@issue = @project.issues.visible.find(params[:id])
|
||||||
|
end
|
||||||
|
@issue.attributes = params[:issue]
|
||||||
|
@allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
|
||||||
|
@priorities = IssuePriority.all
|
||||||
|
|
||||||
|
render :partial => 'attributes'
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview
|
def preview
|
||||||
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
||||||
@attachements = @issue.attachments if @issue
|
if @issue
|
||||||
@text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
|
@attachements = @issue.attachments
|
||||||
render :partial => 'common/preview'
|
@description = params[:issue] && params[:issue][:description]
|
||||||
|
if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
|
||||||
|
@description = nil
|
||||||
|
end
|
||||||
|
@notes = params[:notes]
|
||||||
|
else
|
||||||
|
@description = (params[:issue] ? params[:issue][:description] : nil)
|
||||||
|
end
|
||||||
|
render :layout => false
|
||||||
|
end
|
||||||
|
|
||||||
|
def auto_complete
|
||||||
|
@issues = []
|
||||||
|
q = params[:q].to_s
|
||||||
|
if q.match(/^\d+$/)
|
||||||
|
@issues << @project.issues.visible.find_by_id(q.to_i)
|
||||||
|
end
|
||||||
|
unless q.blank?
|
||||||
|
@issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
|
||||||
|
end
|
||||||
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -377,54 +412,77 @@ private
|
|||||||
@project = projects.first
|
@project = projects.first
|
||||||
else
|
else
|
||||||
# TODO: let users bulk edit/move/destroy issues from different projects
|
# TODO: let users bulk edit/move/destroy issues from different projects
|
||||||
render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
|
render_error 'Can not bulk edit/move/destroy issues from different projects'
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
@project = Project.find(params[:project_id])
|
project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
|
||||||
|
@project = Project.find(project_id)
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_optional_project
|
# Used by #edit and #update to set some common instance variables
|
||||||
return true unless params[:project_id]
|
# from the params
|
||||||
@project = Project.find(params[:project_id])
|
# TODO: Refactor, not everything in here is needed by #edit
|
||||||
authorize
|
def update_issue_from_params
|
||||||
rescue ActiveRecord::RecordNotFound
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||||
render_404
|
@priorities = IssuePriority.all
|
||||||
|
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||||
|
@time_entry = TimeEntry.new
|
||||||
|
|
||||||
|
@notes = params[:notes]
|
||||||
|
@issue.init_journal(User.current, @notes)
|
||||||
|
# User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
|
||||||
|
if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
|
||||||
|
attrs = params[:issue].dup
|
||||||
|
attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
|
||||||
|
attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
|
||||||
|
@issue.safe_attributes = attrs
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Retrieve query from session or build a new query
|
# TODO: Refactor, lots of extra code in here
|
||||||
def retrieve_query
|
def build_new_issue_from_params
|
||||||
if !params[:query_id].blank?
|
@issue = Issue.new
|
||||||
cond = "project_id IS NULL"
|
@issue.copy_from(params[:copy_from]) if params[:copy_from]
|
||||||
cond << " OR project_id = #{@project.id}" if @project
|
@issue.project = @project
|
||||||
@query = Query.find(params[:query_id], :conditions => cond)
|
# Tracker must be set before custom field values
|
||||||
@query.project = @project
|
@issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
|
||||||
session[:query] = {:id => @query.id, :project_id => @query.project_id}
|
if @issue.tracker.nil?
|
||||||
|
render_error l(:error_no_tracker_in_project)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if params[:issue].is_a?(Hash)
|
||||||
|
@issue.safe_attributes = params[:issue]
|
||||||
|
@issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
|
||||||
|
end
|
||||||
|
@issue.author = User.current
|
||||||
|
@issue.start_date ||= Date.today
|
||||||
|
@priorities = IssuePriority.all
|
||||||
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
|
||||||
|
if unsaved_issue_ids.empty?
|
||||||
|
flash[:notice] = l(:notice_successful_update) unless issues.empty?
|
||||||
else
|
else
|
||||||
if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
|
flash[:error] = l(:notice_failed_to_save_issues,
|
||||||
# Give it a name, required to be valid
|
:count => unsaved_issue_ids.size,
|
||||||
@query = Query.new(:name => "_")
|
:total => issues.size,
|
||||||
@query.project = @project
|
:ids => '#' + unsaved_issue_ids.join(', #'))
|
||||||
if params[:fields] and params[:fields].is_a? Array
|
end
|
||||||
params[:fields].each do |field|
|
end
|
||||||
@query.add_filter(field, params[:operators][field], params[:values][field])
|
|
||||||
end
|
def check_for_default_issue_status
|
||||||
else
|
if IssueStatus.default.nil?
|
||||||
@query.available_filters.keys.each do |field|
|
render_error l(:error_no_default_issue_status)
|
||||||
@query.add_short_filter(field, params[field]) if params[field]
|
return false
|
||||||
end
|
|
||||||
end
|
|
||||||
session[:query] = {:project_id => @query.project_id, :filters => @query.filters}
|
|
||||||
else
|
|
||||||
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
|
|
||||||
@query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters])
|
|
||||||
@query.project = @project
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,13 +16,13 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class JournalsController < ApplicationController
|
class JournalsController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
before_filter :find_journal
|
before_filter :find_journal
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
if request.post?
|
if request.post?
|
||||||
@journal.update_attributes(:notes => params[:notes]) if params[:notes]
|
@journal.update_attributes(:notes => params[:notes]) if params[:notes]
|
||||||
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
|
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
|
||||||
|
call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
|
||||||
format.js { render :action => 'update' }
|
format.js { render :action => 'update' }
|
||||||
@@ -33,7 +33,7 @@ class JournalsController < ApplicationController
|
|||||||
private
|
private
|
||||||
def find_journal
|
def find_journal
|
||||||
@journal = Journal.find(params[:id])
|
@journal = Journal.find(params[:id])
|
||||||
render_403 and return false unless @journal.editable_by?(User.current)
|
(render_403; return false) unless @journal.editable_by?(User.current)
|
||||||
@project = @journal.journalized.project
|
@project = @journal.journalized.project
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# redMine - project management software
|
||||||
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class LdapAuthSourcesController < AuthSourcesController
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def auth_source_class
|
||||||
|
AuthSourceLdap
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -37,8 +37,8 @@ class MailHandlerController < ActionController::Base
|
|||||||
|
|
||||||
def check_credential
|
def check_credential
|
||||||
User.current = nil
|
User.current = nil
|
||||||
unless Setting.mail_handler_api_enabled? && params[:key] == Setting.mail_handler_api_key
|
unless Setting.mail_handler_api_enabled? && params[:key].to_s == Setting.mail_handler_api_key
|
||||||
render :nothing => true, :status => 403
|
render :text => 'Access denied. Incoming emails WS is disabled or key is invalid.', :status => 403
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,16 +16,50 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class MembersController < ApplicationController
|
class MembersController < ApplicationController
|
||||||
layout 'base'
|
model_object Member
|
||||||
before_filter :find_member, :except => :new
|
before_filter :find_model_object, :except => [:new, :autocomplete_for_member]
|
||||||
before_filter :find_project, :only => :new
|
before_filter :find_project_from_association, :except => [:new, :autocomplete_for_member]
|
||||||
|
before_filter :find_project, :only => [:new, :autocomplete_for_member]
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@project.members << Member.new(params[:member]) if request.post?
|
members = []
|
||||||
|
if params[:member] && request.post?
|
||||||
|
attrs = params[:member].dup
|
||||||
|
if (user_ids = attrs.delete(:user_ids))
|
||||||
|
user_ids.each do |user_id|
|
||||||
|
members << Member.new(attrs.merge(:user_id => user_id))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
members << Member.new(attrs)
|
||||||
|
end
|
||||||
|
@project.members << members
|
||||||
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project }
|
if members.present? && members.all? {|m| m.valid? }
|
||||||
format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
|
|
||||||
|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
|
||||||
|
|
||||||
|
format.js {
|
||||||
|
render(:update) {|page|
|
||||||
|
page.replace_html "tab-content-members", :partial => 'projects/settings/members'
|
||||||
|
page << 'hideOnLoad()'
|
||||||
|
members.each {|member| page.visual_effect(:highlight, "member-#{member.id}") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
|
||||||
|
format.js {
|
||||||
|
render(:update) {|page|
|
||||||
|
errors = members.collect {|m|
|
||||||
|
m.errors.full_messages
|
||||||
|
}.flatten.uniq
|
||||||
|
|
||||||
|
page.alert(l(:notice_failed_to_save_members, :errors => errors.join(', ')))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -33,30 +67,34 @@ class MembersController < ApplicationController
|
|||||||
if request.post? and @member.update_attributes(params[:member])
|
if request.post? and @member.update_attributes(params[:member])
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
|
||||||
format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
|
format.js {
|
||||||
|
render(:update) {|page|
|
||||||
|
page.replace_html "tab-content-members", :partial => 'projects/settings/members'
|
||||||
|
page << 'hideOnLoad()'
|
||||||
|
page.visual_effect(:highlight, "member-#{@member.id}")
|
||||||
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@member.destroy
|
if request.post? && @member.deletable?
|
||||||
respond_to do |format|
|
@member.destroy
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
|
||||||
format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
|
format.js { render(:update) {|page|
|
||||||
|
page.replace_html "tab-content-members", :partial => 'projects/settings/members'
|
||||||
|
page << 'hideOnLoad()'
|
||||||
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
def find_project
|
|
||||||
@project = Project.find(params[:id])
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
render_404
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_member
|
def autocomplete_for_member
|
||||||
@member = Member.find(params[:id])
|
@principals = Principal.active.like(params[:q]).find(:all, :limit => 100) - @project.principals
|
||||||
@project = @member.project
|
render :layout => false
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
render_404
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,21 +16,37 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class MessagesController < ApplicationController
|
class MessagesController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
menu_item :boards
|
menu_item :boards
|
||||||
|
default_search_scope :messages
|
||||||
before_filter :find_board, :only => [:new, :preview]
|
before_filter :find_board, :only => [:new, :preview]
|
||||||
before_filter :find_message, :except => [:new, :preview]
|
before_filter :find_message, :except => [:new, :preview]
|
||||||
before_filter :authorize, :except => :preview
|
before_filter :authorize, :except => [:preview, :edit, :destroy]
|
||||||
|
|
||||||
verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
|
verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
|
||||||
|
verify :xhr => true, :only => :quote
|
||||||
|
|
||||||
|
helper :watchers
|
||||||
helper :attachments
|
helper :attachments
|
||||||
include AttachmentsHelper
|
include AttachmentsHelper
|
||||||
|
|
||||||
|
REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)
|
||||||
|
|
||||||
# Show a topic and its replies
|
# Show a topic and its replies
|
||||||
def show
|
def show
|
||||||
@replies = @topic.children
|
page = params[:page]
|
||||||
@replies.reverse! if User.current.wants_comments_in_reverse_order?
|
# Find the page of the requested reply
|
||||||
|
if params[:r] && page.nil?
|
||||||
|
offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i])
|
||||||
|
page = 1 + offset / REPLIES_PER_PAGE
|
||||||
|
end
|
||||||
|
|
||||||
|
@reply_count = @topic.children.count
|
||||||
|
@reply_pages = Paginator.new self, @reply_count, REPLIES_PER_PAGE, page
|
||||||
|
@replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}],
|
||||||
|
:order => "#{Message.table_name}.created_on ASC",
|
||||||
|
:limit => @reply_pages.items_per_page,
|
||||||
|
:offset => @reply_pages.current.offset)
|
||||||
|
|
||||||
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
||||||
render :action => "show", :layout => false if request.xhr?
|
render :action => "show", :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
@@ -45,7 +61,9 @@ class MessagesController < ApplicationController
|
|||||||
@message.sticky = params[:message]['sticky']
|
@message.sticky = params[:message]['sticky']
|
||||||
end
|
end
|
||||||
if request.post? && @message.save
|
if request.post? && @message.save
|
||||||
attach_files(@message, params[:attachments])
|
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
|
||||||
|
attachments = Attachment.attach_files(@message, params[:attachments])
|
||||||
|
render_attachment_warning_if_needed(@message)
|
||||||
redirect_to :action => 'show', :id => @message
|
redirect_to :action => 'show', :id => @message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -57,30 +75,53 @@ class MessagesController < ApplicationController
|
|||||||
@reply.board = @board
|
@reply.board = @board
|
||||||
@topic.children << @reply
|
@topic.children << @reply
|
||||||
if !@reply.new_record?
|
if !@reply.new_record?
|
||||||
attach_files(@reply, params[:attachments])
|
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
|
||||||
|
attachments = Attachment.attach_files(@reply, params[:attachments])
|
||||||
|
render_attachment_warning_if_needed(@reply)
|
||||||
end
|
end
|
||||||
redirect_to :action => 'show', :id => @topic
|
redirect_to :action => 'show', :id => @topic, :r => @reply
|
||||||
end
|
end
|
||||||
|
|
||||||
# Edit a message
|
# Edit a message
|
||||||
def edit
|
def edit
|
||||||
if params[:message] && User.current.allowed_to?(:edit_messages, @project)
|
(render_403; return false) unless @message.editable_by?(User.current)
|
||||||
|
if params[:message]
|
||||||
@message.locked = params[:message]['locked']
|
@message.locked = params[:message]['locked']
|
||||||
@message.sticky = params[:message]['sticky']
|
@message.sticky = params[:message]['sticky']
|
||||||
end
|
end
|
||||||
if request.post? && @message.update_attributes(params[:message])
|
if request.post? && @message.update_attributes(params[:message])
|
||||||
attach_files(@message, params[:attachments])
|
attachments = Attachment.attach_files(@message, params[:attachments])
|
||||||
|
render_attachment_warning_if_needed(@message)
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'show', :id => @topic
|
@message.reload
|
||||||
|
redirect_to :action => 'show', :board_id => @message.board, :id => @message.root, :r => (@message.parent_id && @message.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Delete a messages
|
# Delete a messages
|
||||||
def destroy
|
def destroy
|
||||||
|
(render_403; return false) unless @message.destroyable_by?(User.current)
|
||||||
@message.destroy
|
@message.destroy
|
||||||
redirect_to @message.parent.nil? ?
|
redirect_to @message.parent.nil? ?
|
||||||
{ :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } :
|
{ :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } :
|
||||||
{ :action => 'show', :id => @message.parent }
|
{ :action => 'show', :id => @message.parent, :r => @message }
|
||||||
|
end
|
||||||
|
|
||||||
|
def quote
|
||||||
|
user = @message.author
|
||||||
|
text = @message.content
|
||||||
|
subject = @message.subject.gsub('"', '\"')
|
||||||
|
subject = "RE: #{subject}" unless subject.starts_with?('RE:')
|
||||||
|
content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
|
||||||
|
content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
|
||||||
|
render(:update) { |page|
|
||||||
|
page << "$('reply_subject').value = \"#{subject}\";"
|
||||||
|
page.<< "$('message_content').value = \"#{content}\";"
|
||||||
|
page.show 'reply'
|
||||||
|
page << "Form.Element.focus('message_content');"
|
||||||
|
page << "Element.scrollTo('reply');"
|
||||||
|
page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;"
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview
|
def preview
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,11 +16,11 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class MyController < ApplicationController
|
class MyController < ApplicationController
|
||||||
helper :issues
|
|
||||||
|
|
||||||
layout 'base'
|
|
||||||
before_filter :require_login
|
before_filter :require_login
|
||||||
|
|
||||||
|
helper :issues
|
||||||
|
helper :custom_fields
|
||||||
|
|
||||||
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
||||||
'issuesreportedbyme' => :label_reported_issues,
|
'issuesreportedbyme' => :label_reported_issues,
|
||||||
'issueswatched' => :label_watched_issues,
|
'issueswatched' => :label_watched_issues,
|
||||||
@@ -28,14 +28,13 @@ class MyController < ApplicationController
|
|||||||
'calendar' => :label_calendar,
|
'calendar' => :label_calendar,
|
||||||
'documents' => :label_document_plural,
|
'documents' => :label_document_plural,
|
||||||
'timelog' => :label_spent_time
|
'timelog' => :label_spent_time
|
||||||
}.freeze
|
}.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
|
||||||
|
|
||||||
DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
|
DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
|
||||||
'right' => ['issuesreportedbyme']
|
'right' => ['issuesreportedbyme']
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
verify :xhr => true,
|
verify :xhr => true,
|
||||||
:session => :page_layout,
|
|
||||||
:only => [:add_block, :remove_block, :order_blocks]
|
:only => [:add_block, :remove_block, :order_blocks]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@@ -78,7 +77,11 @@ class MyController < ApplicationController
|
|||||||
# Manage user's password
|
# Manage user's password
|
||||||
def password
|
def password
|
||||||
@user = User.current
|
@user = User.current
|
||||||
flash[:error] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
|
unless @user.change_password_allowed?
|
||||||
|
flash[:error] = l(:notice_can_t_change_password)
|
||||||
|
redirect_to :action => 'account'
|
||||||
|
return
|
||||||
|
end
|
||||||
if request.post?
|
if request.post?
|
||||||
if @user.check_password?(params[:password])
|
if @user.check_password?(params[:password])
|
||||||
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||||
@@ -94,43 +97,65 @@ class MyController < ApplicationController
|
|||||||
|
|
||||||
# Create a new feeds key
|
# Create a new feeds key
|
||||||
def reset_rss_key
|
def reset_rss_key
|
||||||
if request.post? && User.current.rss_token
|
if request.post?
|
||||||
User.current.rss_token.destroy
|
if User.current.rss_token
|
||||||
|
User.current.rss_token.destroy
|
||||||
|
User.current.reload
|
||||||
|
end
|
||||||
|
User.current.rss_key
|
||||||
flash[:notice] = l(:notice_feeds_access_key_reseted)
|
flash[:notice] = l(:notice_feeds_access_key_reseted)
|
||||||
end
|
end
|
||||||
redirect_to :action => 'account'
|
redirect_to :action => 'account'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Create a new API key
|
||||||
|
def reset_api_key
|
||||||
|
if request.post?
|
||||||
|
if User.current.api_token
|
||||||
|
User.current.api_token.destroy
|
||||||
|
User.current.reload
|
||||||
|
end
|
||||||
|
User.current.api_key
|
||||||
|
flash[:notice] = l(:notice_api_access_key_reseted)
|
||||||
|
end
|
||||||
|
redirect_to :action => 'account'
|
||||||
|
end
|
||||||
|
|
||||||
# User's page layout configuration
|
# User's page layout configuration
|
||||||
def page_layout
|
def page_layout
|
||||||
@user = User.current
|
@user = User.current
|
||||||
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
||||||
session[:page_layout] = @blocks
|
|
||||||
%w(top left right).each {|f| session[:page_layout][f] ||= [] }
|
|
||||||
@block_options = []
|
@block_options = []
|
||||||
BLOCKS.each {|k, v| @block_options << [l(v), k]}
|
BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a block to user's page
|
# Add a block to user's page
|
||||||
# The block is added on top of the page
|
# The block is added on top of the page
|
||||||
# params[:block] : id of the block to add
|
# params[:block] : id of the block to add
|
||||||
def add_block
|
def add_block
|
||||||
block = params[:block]
|
block = params[:block].to_s.underscore
|
||||||
render(:nothing => true) and return unless block && (BLOCKS.keys.include? block)
|
(render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
|
||||||
@user = User.current
|
@user = User.current
|
||||||
|
layout = @user.pref[:my_page_layout] || {}
|
||||||
# remove if already present in a group
|
# remove if already present in a group
|
||||||
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
|
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||||
# add it on top
|
# add it on top
|
||||||
session[:page_layout]['top'].unshift block
|
layout['top'].unshift block
|
||||||
|
@user.pref[:my_page_layout] = layout
|
||||||
|
@user.pref.save
|
||||||
render :partial => "block", :locals => {:user => @user, :block_name => block}
|
render :partial => "block", :locals => {:user => @user, :block_name => block}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove a block to user's page
|
# Remove a block to user's page
|
||||||
# params[:block] : id of the block to remove
|
# params[:block] : id of the block to remove
|
||||||
def remove_block
|
def remove_block
|
||||||
block = params[:block]
|
block = params[:block].to_s.underscore
|
||||||
|
@user = User.current
|
||||||
# remove block in all groups
|
# remove block in all groups
|
||||||
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
|
layout = @user.pref[:my_page_layout] || {}
|
||||||
|
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||||
|
@user.pref[:my_page_layout] = layout
|
||||||
|
@user.pref.save
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -139,23 +164,20 @@ class MyController < ApplicationController
|
|||||||
# params[:list-(top|left|right)] : array of block ids of the group
|
# params[:list-(top|left|right)] : array of block ids of the group
|
||||||
def order_blocks
|
def order_blocks
|
||||||
group = params[:group]
|
group = params[:group]
|
||||||
group_items = params["list-#{group}"]
|
@user = User.current
|
||||||
if group_items and group_items.is_a? Array
|
if group.is_a?(String)
|
||||||
# remove group blocks if they are presents in other groups
|
group_items = (params["list-#{group}"] || []).collect(&:underscore)
|
||||||
%w(top left right).each {|f|
|
if group_items and group_items.is_a? Array
|
||||||
session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
|
layout = @user.pref[:my_page_layout] || {}
|
||||||
}
|
# remove group blocks if they are presents in other groups
|
||||||
session[:page_layout][group] = group_items
|
%w(top left right).each {|f|
|
||||||
|
layout[f] = (layout[f] || []) - group_items
|
||||||
|
}
|
||||||
|
layout[group] = group_items
|
||||||
|
@user.pref[:my_page_layout] = layout
|
||||||
|
@user.pref.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Save user's page layout
|
|
||||||
def page_layout_save
|
|
||||||
@user = User.current
|
|
||||||
@user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
|
|
||||||
@user.pref.save
|
|
||||||
session[:page_layout] = nil
|
|
||||||
redirect_to :action => 'page'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,8 +16,10 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class NewsController < ApplicationController
|
class NewsController < ApplicationController
|
||||||
layout 'base'
|
default_search_scope :news
|
||||||
before_filter :find_news, :except => [:new, :index, :preview]
|
model_object News
|
||||||
|
before_filter :find_model_object, :except => [:new, :index, :preview]
|
||||||
|
before_filter :find_project_from_association, :except => [:new, :index, :preview]
|
||||||
before_filter :find_project, :only => [:new, :preview]
|
before_filter :find_project, :only => [:new, :preview]
|
||||||
before_filter :authorize, :except => [:index, :preview]
|
before_filter :authorize, :except => [:index, :preview]
|
||||||
before_filter :find_optional_project, :only => :index
|
before_filter :find_optional_project, :only => :index
|
||||||
@@ -26,11 +28,13 @@ class NewsController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
@news_pages, @newss = paginate :news,
|
@news_pages, @newss = paginate :news,
|
||||||
:per_page => 10,
|
:per_page => 10,
|
||||||
:conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
|
:conditions => Project.allowed_to_condition(User.current, :view_news, :project => @project),
|
||||||
:include => [:author, :project],
|
:include => [:author, :project],
|
||||||
:order => "#{News.table_name}.created_on DESC"
|
:order => "#{News.table_name}.created_on DESC"
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :layout => false if request.xhr? }
|
format.html { render :layout => false if request.xhr? }
|
||||||
|
format.xml { render :xml => @newss.to_xml }
|
||||||
|
format.json { render :json => @newss.to_json }
|
||||||
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -46,7 +50,6 @@ class NewsController < ApplicationController
|
|||||||
@news.attributes = params[:news]
|
@news.attributes = params[:news]
|
||||||
if @news.save
|
if @news.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
|
|
||||||
redirect_to :controller => 'news', :action => 'index', :project_id => @project
|
redirect_to :controller => 'news', :action => 'index', :project_id => @project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -66,6 +69,7 @@ class NewsController < ApplicationController
|
|||||||
flash[:notice] = l(:label_comment_added)
|
flash[:notice] = l(:label_comment_added)
|
||||||
redirect_to :action => 'show', :id => @news
|
redirect_to :action => 'show', :id => @news
|
||||||
else
|
else
|
||||||
|
show
|
||||||
render :action => 'show'
|
render :action => 'show'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -86,13 +90,6 @@ class NewsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_news
|
|
||||||
@news = News.find(params[:id])
|
|
||||||
@project = @news.project
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
render_404
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
@project = Project.find(params[:project_id])
|
@project = Project.find(params[:project_id])
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,28 +16,30 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class ProjectsController < ApplicationController
|
class ProjectsController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
menu_item :overview
|
menu_item :overview
|
||||||
menu_item :activity, :only => :activity
|
menu_item :activity, :only => :activity
|
||||||
menu_item :roadmap, :only => :roadmap
|
menu_item :roadmap, :only => :roadmap
|
||||||
menu_item :files, :only => [:list_files, :add_file]
|
menu_item :files, :only => [:list_files, :add_file]
|
||||||
menu_item :settings, :only => :settings
|
menu_item :settings, :only => :settings
|
||||||
menu_item :issues, :only => [:changelog]
|
|
||||||
|
|
||||||
before_filter :find_project, :except => [ :index, :list, :add, :activity ]
|
before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ]
|
||||||
before_filter :find_optional_project, :only => :activity
|
before_filter :find_optional_project, :only => :activity
|
||||||
before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
|
before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy, :activity ]
|
||||||
before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
|
before_filter :authorize_global, :only => :add
|
||||||
accept_key_auth :activity, :calendar
|
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
|
||||||
|
accept_key_auth :activity, :index
|
||||||
|
|
||||||
|
after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller|
|
||||||
|
if controller.request.post?
|
||||||
|
controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
helper :sort
|
helper :sort
|
||||||
include SortHelper
|
include SortHelper
|
||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
include CustomFieldsHelper
|
include CustomFieldsHelper
|
||||||
helper :ifpdf
|
|
||||||
include IfpdfHelper
|
|
||||||
helper :issues
|
helper :issues
|
||||||
helper IssuesHelper
|
|
||||||
helper :queries
|
helper :queries
|
||||||
include QueriesHelper
|
include QueriesHelper
|
||||||
helper :repositories
|
helper :repositories
|
||||||
@@ -46,70 +48,127 @@ class ProjectsController < ApplicationController
|
|||||||
|
|
||||||
# Lists visible projects
|
# Lists visible projects
|
||||||
def index
|
def index
|
||||||
projects = Project.find :all,
|
|
||||||
:conditions => Project.visible_by(User.current),
|
|
||||||
:include => :parent
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
@project_tree = projects.group_by {|p| p.parent || p}
|
@projects = Project.visible.find(:all, :order => 'lft')
|
||||||
@project_tree.keys.each {|p| @project_tree[p] -= [p]}
|
}
|
||||||
|
format.xml {
|
||||||
|
@projects = Project.visible.find(:all, :order => 'lft')
|
||||||
}
|
}
|
||||||
format.atom {
|
format.atom {
|
||||||
render_feed(projects.sort_by(&:created_on).reverse.slice(0, Setting.feeds_limit.to_i),
|
projects = Project.visible.find(:all, :order => 'created_on DESC',
|
||||||
:title => "#{Setting.app_title}: #{l(:label_project_latest)}")
|
:limit => Setting.feeds_limit.to_i)
|
||||||
|
render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a new project
|
# Add a new project
|
||||||
def add
|
def add
|
||||||
|
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||||
|
@trackers = Tracker.all
|
||||||
|
@project = Project.new(params[:project])
|
||||||
|
if request.get?
|
||||||
|
@project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
|
||||||
|
@project.trackers = Tracker.all
|
||||||
|
@project.is_public = Setting.default_projects_public?
|
||||||
|
@project.enabled_module_names = Setting.default_projects_modules
|
||||||
|
else
|
||||||
|
@project.enabled_module_names = params[:enabled_modules]
|
||||||
|
if validate_parent_id && @project.save
|
||||||
|
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||||
|
# Add current user as a project member if he is not admin
|
||||||
|
unless User.current.admin?
|
||||||
|
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||||
|
m = Member.new(:user => User.current, :roles => [r])
|
||||||
|
@project.members << m
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
redirect_to :controller => 'projects', :action => 'settings', :id => @project
|
||||||
|
}
|
||||||
|
format.xml { head :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def copy
|
||||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||||
@trackers = Tracker.all
|
@trackers = Tracker.all
|
||||||
@root_projects = Project.find(:all,
|
@root_projects = Project.find(:all,
|
||||||
:conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
|
:conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
|
||||||
:order => 'name')
|
:order => 'name')
|
||||||
@project = Project.new(params[:project])
|
@source_project = Project.find(params[:id])
|
||||||
if request.get?
|
if request.get?
|
||||||
@project.trackers = Tracker.all
|
@project = Project.copy_from(@source_project)
|
||||||
@project.is_public = Setting.default_projects_public?
|
if @project
|
||||||
@project.enabled_module_names = Redmine::AccessControl.available_project_modules
|
@project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
|
||||||
else
|
else
|
||||||
@project.enabled_module_names = params[:enabled_modules]
|
|
||||||
if @project.save
|
|
||||||
flash[:notice] = l(:notice_successful_create)
|
|
||||||
redirect_to :controller => 'admin', :action => 'projects'
|
redirect_to :controller => 'admin', :action => 'projects'
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
|
Mailer.with_deliveries(params[:notifications] == '1') do
|
||||||
|
@project = Project.new(params[:project])
|
||||||
|
@project.enabled_module_names = params[:enabled_modules]
|
||||||
|
if validate_parent_id && @project.copy(@source_project, :only => params[:only])
|
||||||
|
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
redirect_to :controller => 'admin', :action => 'projects'
|
||||||
|
elsif !@project.new_record?
|
||||||
|
# Project was created
|
||||||
|
# But some objects were not copied due to validation failures
|
||||||
|
# (eg. issues from disabled trackers)
|
||||||
|
# TODO: inform about that
|
||||||
|
redirect_to :controller => 'admin', :action => 'projects'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
redirect_to :controller => 'admin', :action => 'projects'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Show @project
|
# Show @project
|
||||||
def show
|
def show
|
||||||
@members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
|
if params[:jump]
|
||||||
@subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
|
# try to redirect to the requested menu item
|
||||||
|
redirect_to_project_menu_item(@project, params[:jump]) && return
|
||||||
|
end
|
||||||
|
|
||||||
|
@users_by_role = @project.users_by_role
|
||||||
|
@subprojects = @project.children.visible
|
||||||
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
||||||
@trackers = @project.rolled_up_trackers
|
@trackers = @project.rolled_up_trackers
|
||||||
|
|
||||||
cond = @project.project_condition(Setting.display_subprojects_issues?)
|
cond = @project.project_condition(Setting.display_subprojects_issues?)
|
||||||
Issue.visible_by(User.current) do
|
|
||||||
@open_issues_by_tracker = Issue.count(:group => :tracker,
|
@open_issues_by_tracker = Issue.visible.count(:group => :tracker,
|
||||||
:include => [:project, :status, :tracker],
|
:include => [:project, :status, :tracker],
|
||||||
:conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
|
:conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
|
||||||
@total_issues_by_tracker = Issue.count(:group => :tracker,
|
@total_issues_by_tracker = Issue.visible.count(:group => :tracker,
|
||||||
:include => [:project, :status, :tracker],
|
:include => [:project, :status, :tracker],
|
||||||
:conditions => cond)
|
:conditions => cond)
|
||||||
end
|
|
||||||
TimeEntry.visible_by(User.current) do
|
TimeEntry.visible_by(User.current) do
|
||||||
@total_hours = TimeEntry.sum(:hours,
|
@total_hours = TimeEntry.sum(:hours,
|
||||||
:include => :project,
|
:include => :project,
|
||||||
:conditions => cond).to_f
|
:conditions => cond).to_f
|
||||||
end
|
end
|
||||||
@key = User.current.rss_key
|
@key = User.current.rss_key
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.xml
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def settings
|
def settings
|
||||||
@root_projects = Project.find(:all,
|
|
||||||
:conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
|
|
||||||
:order => 'name')
|
|
||||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||||
@issue_category ||= IssueCategory.new
|
@issue_category ||= IssueCategory.new
|
||||||
@member ||= @project.members.new
|
@member ||= @project.members.new
|
||||||
@@ -120,233 +179,183 @@ class ProjectsController < ApplicationController
|
|||||||
|
|
||||||
# Edit @project
|
# Edit @project
|
||||||
def edit
|
def edit
|
||||||
if request.post?
|
if request.get?
|
||||||
|
else
|
||||||
@project.attributes = params[:project]
|
@project.attributes = params[:project]
|
||||||
if @project.save
|
if validate_parent_id && @project.save
|
||||||
flash[:notice] = l(:notice_successful_update)
|
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||||
redirect_to :action => 'settings', :id => @project
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to :action => 'settings', :id => @project
|
||||||
|
}
|
||||||
|
format.xml { head :ok }
|
||||||
|
end
|
||||||
else
|
else
|
||||||
settings
|
respond_to do |format|
|
||||||
render :action => 'settings'
|
format.html {
|
||||||
|
settings
|
||||||
|
render :action => 'settings'
|
||||||
|
}
|
||||||
|
format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def modules
|
def modules
|
||||||
@project.enabled_module_names = params[:enabled_modules]
|
@project.enabled_module_names = params[:enabled_modules]
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'settings', :id => @project, :tab => 'modules'
|
redirect_to :action => 'settings', :id => @project, :tab => 'modules'
|
||||||
end
|
end
|
||||||
|
|
||||||
def archive
|
def archive
|
||||||
@project.archive if request.post? && @project.active?
|
if request.post?
|
||||||
redirect_to :controller => 'admin', :action => 'projects'
|
unless @project.archive
|
||||||
|
flash[:error] = l(:error_can_not_archive_project)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def unarchive
|
def unarchive
|
||||||
@project.unarchive if request.post? && !@project.active?
|
@project.unarchive if request.post? && !@project.active?
|
||||||
redirect_to :controller => 'admin', :action => 'projects'
|
redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Delete @project
|
# Delete @project
|
||||||
def destroy
|
def destroy
|
||||||
@project_to_destroy = @project
|
@project_to_destroy = @project
|
||||||
if request.post? and params[:confirm]
|
if request.get?
|
||||||
@project_to_destroy.destroy
|
# display confirmation view
|
||||||
redirect_to :controller => 'admin', :action => 'projects'
|
else
|
||||||
|
if params[:format] == 'xml' || params[:confirm]
|
||||||
|
@project_to_destroy.destroy
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to :controller => 'admin', :action => 'projects' }
|
||||||
|
format.xml { head :ok }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
# hide project in layout
|
# hide project in layout
|
||||||
@project = nil
|
@project = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a new issue category to @project
|
|
||||||
def add_issue_category
|
|
||||||
@category = @project.issue_categories.build(params[:category])
|
|
||||||
if request.post? and @category.save
|
|
||||||
respond_to do |format|
|
|
||||||
format.html do
|
|
||||||
flash[:notice] = l(:notice_successful_create)
|
|
||||||
redirect_to :action => 'settings', :tab => 'categories', :id => @project
|
|
||||||
end
|
|
||||||
format.js do
|
|
||||||
# IE doesn't support the replace_html rjs method for select box options
|
|
||||||
render(:update) {|page| page.replace "issue_category_id",
|
|
||||||
content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Add a new version to @project
|
|
||||||
def add_version
|
|
||||||
@version = @project.versions.build(params[:version])
|
|
||||||
if request.post? and @version.save
|
|
||||||
flash[:notice] = l(:notice_successful_create)
|
|
||||||
redirect_to :action => 'settings', :tab => 'versions', :id => @project
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_file
|
def add_file
|
||||||
if request.post?
|
if request.post?
|
||||||
@version = @project.versions.find_by_id(params[:version_id])
|
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
|
||||||
attachments = attach_files(@version, params[:attachments])
|
attachments = Attachment.attach_files(container, params[:attachments])
|
||||||
Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
|
render_attachment_warning_if_needed(container)
|
||||||
|
|
||||||
|
if !attachments.empty? && Setting.notified_events.include?('file_added')
|
||||||
|
Mailer.deliver_attachments_added(attachments[:files])
|
||||||
|
end
|
||||||
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
||||||
|
return
|
||||||
end
|
end
|
||||||
@versions = @project.versions.sort
|
@versions = @project.versions.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_files
|
def save_activities
|
||||||
sort_init "#{Attachment.table_name}.filename", "asc"
|
if request.post? && params[:enumerations]
|
||||||
sort_update
|
Project.transaction do
|
||||||
@versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
|
params[:enumerations].each do |id, activity|
|
||||||
render :layout => !request.xhr?
|
@project.update_or_create_time_entry_activity(id, activity)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset_activities
|
||||||
|
@project.time_entry_activities.each do |time_entry_activity|
|
||||||
|
time_entry_activity.destroy(time_entry_activity.parent)
|
||||||
|
end
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
|
||||||
end
|
end
|
||||||
|
|
||||||
# Show changelog for @project
|
def list_files
|
||||||
def changelog
|
sort_init 'filename', 'asc'
|
||||||
@trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
|
sort_update 'filename' => "#{Attachment.table_name}.filename",
|
||||||
retrieve_selected_tracker_ids(@trackers)
|
'created_on' => "#{Attachment.table_name}.created_on",
|
||||||
@versions = @project.versions.sort
|
'size' => "#{Attachment.table_name}.filesize",
|
||||||
|
'downloads' => "#{Attachment.table_name}.downloads"
|
||||||
|
|
||||||
|
@containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
|
||||||
|
@containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
|
||||||
|
render :layout => !request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
def roadmap
|
def roadmap
|
||||||
@trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
|
@trackers = @project.trackers.find(:all, :order => 'position')
|
||||||
retrieve_selected_tracker_ids(@trackers)
|
retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
|
||||||
@versions = @project.versions.sort
|
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||||
@versions = @versions.select {|v| !v.completed? } unless params[:completed]
|
project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
|
||||||
|
|
||||||
|
@versions = @project.shared_versions || []
|
||||||
|
@versions += @project.rolled_up_versions.visible if @with_subprojects
|
||||||
|
@versions = @versions.uniq.sort
|
||||||
|
@versions.reject! {|version| version.closed? || version.completed? } unless params[:completed]
|
||||||
|
|
||||||
|
@issues_by_version = {}
|
||||||
|
unless @selected_tracker_ids.empty?
|
||||||
|
@versions.each do |version|
|
||||||
|
issues = version.fixed_issues.visible.find(:all,
|
||||||
|
:include => [:project, :status, :tracker, :priority],
|
||||||
|
:conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids},
|
||||||
|
:order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
|
||||||
|
@issues_by_version[version] = issues
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
|
||||||
end
|
end
|
||||||
|
|
||||||
def activity
|
def activity
|
||||||
@days = Setting.activity_days_default.to_i
|
@days = Setting.activity_days_default.to_i
|
||||||
|
|
||||||
if params[:from]
|
if params[:from]
|
||||||
begin; @date_to = params[:from].to_date; rescue; end
|
begin; @date_to = params[:from].to_date + 1; rescue; end
|
||||||
end
|
end
|
||||||
|
|
||||||
@date_to ||= Date.today + 1
|
@date_to ||= Date.today + 1
|
||||||
@date_from = @date_to - @days
|
@date_from = @date_to - @days
|
||||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||||
|
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
|
||||||
|
|
||||||
@activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, :with_subprojects => @with_subprojects)
|
@activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
|
||||||
|
:with_subprojects => @with_subprojects,
|
||||||
|
:author => @author)
|
||||||
@activity.scope_select {|t| !params["show_#{t}"].nil?}
|
@activity.scope_select {|t| !params["show_#{t}"].nil?}
|
||||||
@activity.default_scope! if @activity.scope.empty?
|
@activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
|
||||||
|
|
||||||
events = @activity.events(@date_from, @date_to)
|
events = @activity.events(@date_from, @date_to)
|
||||||
|
|
||||||
respond_to do |format|
|
if events.empty? || stale?(:etag => [events.first, User.current])
|
||||||
format.html {
|
respond_to do |format|
|
||||||
@events_by_day = events.group_by(&:event_date)
|
format.html {
|
||||||
render :layout => false if request.xhr?
|
@events_by_day = events.group_by(&:event_date)
|
||||||
}
|
render :layout => false if request.xhr?
|
||||||
format.atom {
|
}
|
||||||
title = (@scope.size == 1) ? l("label_#{@scope.first.singularize}_plural") : l(:label_activity)
|
format.atom {
|
||||||
render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
|
title = l(:label_activity)
|
||||||
}
|
if @author
|
||||||
end
|
title = @author.name
|
||||||
end
|
elsif @activity.scope.size == 1
|
||||||
|
title = l("label_#{@activity.scope.first.singularize}_plural")
|
||||||
def calendar
|
end
|
||||||
@trackers = @project.rolled_up_trackers
|
render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
|
||||||
retrieve_selected_tracker_ids(@trackers)
|
}
|
||||||
|
|
||||||
if params[:year] and params[:year].to_i > 1900
|
|
||||||
@year = params[:year].to_i
|
|
||||||
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
|
||||||
@month = params[:month].to_i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@year ||= Date.today.year
|
|
||||||
@month ||= Date.today.month
|
|
||||||
@calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
|
|
||||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
|
||||||
events = []
|
|
||||||
@project.issues_with_subprojects(@with_subprojects) do
|
|
||||||
events += Issue.find(:all,
|
|
||||||
:include => [:tracker, :status, :assigned_to, :priority, :project],
|
|
||||||
:conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
|
|
||||||
) unless @selected_tracker_ids.empty?
|
|
||||||
events += Version.find(:all, :include => :project,
|
|
||||||
:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
|
|
||||||
end
|
|
||||||
@calendar.events = events
|
|
||||||
|
|
||||||
render :layout => false if request.xhr?
|
|
||||||
end
|
|
||||||
|
|
||||||
def gantt
|
|
||||||
@trackers = @project.rolled_up_trackers
|
|
||||||
retrieve_selected_tracker_ids(@trackers)
|
|
||||||
|
|
||||||
if params[:year] and params[:year].to_i >0
|
|
||||||
@year_from = params[:year].to_i
|
|
||||||
if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
|
|
||||||
@month_from = params[:month].to_i
|
|
||||||
else
|
|
||||||
@month_from = 1
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
@month_from ||= Date.today.month
|
|
||||||
@year_from ||= Date.today.year
|
|
||||||
end
|
end
|
||||||
|
|
||||||
zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
|
|
||||||
@zoom = (zoom > 0 && zoom < 5) ? zoom : 2
|
|
||||||
months = (params[:months] || User.current.pref[:gantt_months]).to_i
|
|
||||||
@months = (months > 0 && months < 25) ? months : 6
|
|
||||||
|
|
||||||
# Save gantt paramters as user preference (zoom and months count)
|
|
||||||
if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
|
|
||||||
User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
|
|
||||||
User.current.preference.save
|
|
||||||
end
|
|
||||||
|
|
||||||
@date_from = Date.civil(@year_from, @month_from, 1)
|
|
||||||
@date_to = (@date_from >> @months) - 1
|
|
||||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
|
||||||
|
|
||||||
@events = []
|
|
||||||
@project.issues_with_subprojects(@with_subprojects) do
|
|
||||||
# Issues that have start and due dates
|
|
||||||
@events += Issue.find(:all,
|
|
||||||
:order => "start_date, due_date",
|
|
||||||
:include => [:tracker, :status, :assigned_to, :priority, :project],
|
|
||||||
:conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
|
|
||||||
) unless @selected_tracker_ids.empty?
|
|
||||||
# Issues that don't have a due date but that are assigned to a version with a date
|
|
||||||
@events += Issue.find(:all,
|
|
||||||
:order => "start_date, effective_date",
|
|
||||||
:include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
|
|
||||||
:conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
|
|
||||||
) unless @selected_tracker_ids.empty?
|
|
||||||
@events += Version.find(:all, :include => :project,
|
|
||||||
:conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
|
|
||||||
end
|
|
||||||
@events.sort! {|x,y| x.start_date <=> y.start_date }
|
|
||||||
|
|
||||||
if params[:format]=='pdf'
|
|
||||||
@options_for_rfpdf ||= {}
|
|
||||||
@options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
|
|
||||||
render :template => "projects/gantt.rfpdf", :layout => false
|
|
||||||
elsif params[:format]=='png' && respond_to?('gantt_image')
|
|
||||||
image = gantt_image(@events, @date_from, @months, @zoom)
|
|
||||||
image.format = 'PNG'
|
|
||||||
send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
|
|
||||||
else
|
|
||||||
render :template => "projects/gantt.rhtml"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
# Find project of id params[:id]
|
|
||||||
# if not found, redirect to project list
|
|
||||||
# Used as a before_filter
|
|
||||||
def find_project
|
|
||||||
@project = Project.find(params[:id])
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
def find_optional_project
|
def find_optional_project
|
||||||
return true unless params[:id]
|
return true unless params[:id]
|
||||||
@project = Project.find(params[:id])
|
@project = Project.find(params[:id])
|
||||||
@@ -355,11 +364,26 @@ private
|
|||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
def retrieve_selected_tracker_ids(selectable_trackers)
|
def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
|
||||||
if ids = params[:tracker_ids]
|
if ids = params[:tracker_ids]
|
||||||
@selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
|
@selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
|
||||||
else
|
else
|
||||||
@selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
|
@selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Validates parent_id param according to user's permissions
|
||||||
|
# TODO: move it to Project model in a validation that depends on User.current
|
||||||
|
def validate_parent_id
|
||||||
|
return true if User.current.admin?
|
||||||
|
parent_id = params[:project] && params[:project][:parent_id]
|
||||||
|
if parent_id || @project.new_record?
|
||||||
|
parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
|
||||||
|
unless @project.allowed_parents.include?(parent)
|
||||||
|
@project.errors.add :parent_id, :invalid
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class QueriesController < ApplicationController
|
class QueriesController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
menu_item :issues
|
menu_item :issues
|
||||||
before_filter :find_query, :except => :new
|
before_filter :find_query, :except => :new
|
||||||
before_filter :find_optional_project, :only => :new
|
before_filter :find_optional_project, :only => :new
|
||||||
@@ -25,12 +24,11 @@ class QueriesController < ApplicationController
|
|||||||
@query = Query.new(params[:query])
|
@query = Query.new(params[:query])
|
||||||
@query.project = params[:query_is_for_all] ? nil : @project
|
@query.project = params[:query_is_for_all] ? nil : @project
|
||||||
@query.user = User.current
|
@query.user = User.current
|
||||||
@query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
|
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
|
||||||
@query.column_names = nil if params[:default_columns]
|
@query.column_names = nil if params[:default_columns]
|
||||||
|
|
||||||
params[:fields].each do |field|
|
@query.add_filters(params[:fields], params[:operators], params[:values]) if params[:fields]
|
||||||
@query.add_filter(field, params[:operators][field], params[:values][field])
|
@query.group_by ||= params[:group_by]
|
||||||
end if params[:fields]
|
|
||||||
|
|
||||||
if request.post? && params[:confirm] && @query.save
|
if request.post? && params[:confirm] && @query.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
@@ -43,12 +41,10 @@ class QueriesController < ApplicationController
|
|||||||
def edit
|
def edit
|
||||||
if request.post?
|
if request.post?
|
||||||
@query.filters = {}
|
@query.filters = {}
|
||||||
params[:fields].each do |field|
|
@query.add_filters(params[:fields], params[:operators], params[:values]) if params[:fields]
|
||||||
@query.add_filter(field, params[:operators][field], params[:values][field])
|
|
||||||
end if params[:fields]
|
|
||||||
@query.attributes = params[:query]
|
@query.attributes = params[:query]
|
||||||
@query.project = nil if params[:query_is_for_all]
|
@query.project = nil if params[:query_is_for_all]
|
||||||
@query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
|
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
|
||||||
@query.column_names = nil if params[:default_columns]
|
@query.column_names = nil if params[:default_columns]
|
||||||
|
|
||||||
if @query.save
|
if @query.save
|
||||||
@@ -74,7 +70,7 @@ private
|
|||||||
|
|
||||||
def find_optional_project
|
def find_optional_project
|
||||||
@project = Project.find(params[:project_id]) if params[:project_id]
|
@project = Project.find(params[:project_id]) if params[:project_id]
|
||||||
User.current.allowed_to?(:save_queries, @project, :global => true)
|
render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,222 +16,80 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class ReportsController < ApplicationController
|
class ReportsController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
menu_item :issues
|
menu_item :issues
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :authorize, :find_issue_statuses
|
||||||
|
|
||||||
def issue_report
|
def issue_report
|
||||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
@trackers = @project.trackers
|
||||||
|
@versions = @project.shared_versions.sort
|
||||||
|
@priorities = IssuePriority.all
|
||||||
|
@categories = @project.issue_categories
|
||||||
|
@assignees = @project.members.collect { |m| m.user }.sort
|
||||||
|
@authors = @project.members.collect { |m| m.user }.sort
|
||||||
|
@subprojects = @project.descendants.visible
|
||||||
|
|
||||||
|
@issues_by_tracker = Issue.by_tracker(@project)
|
||||||
|
@issues_by_version = Issue.by_version(@project)
|
||||||
|
@issues_by_priority = Issue.by_priority(@project)
|
||||||
|
@issues_by_category = Issue.by_category(@project)
|
||||||
|
@issues_by_assigned_to = Issue.by_assigned_to(@project)
|
||||||
|
@issues_by_author = Issue.by_author(@project)
|
||||||
|
@issues_by_subproject = Issue.by_subproject(@project) || []
|
||||||
|
|
||||||
|
render :template => "reports/issue_report"
|
||||||
|
end
|
||||||
|
|
||||||
|
def issue_report_details
|
||||||
case params[:detail]
|
case params[:detail]
|
||||||
when "tracker"
|
when "tracker"
|
||||||
@field = "tracker_id"
|
@field = "tracker_id"
|
||||||
@rows = @project.trackers
|
@rows = @project.trackers
|
||||||
@data = issues_by_tracker
|
@data = Issue.by_tracker(@project)
|
||||||
@report_title = l(:field_tracker)
|
@report_title = l(:field_tracker)
|
||||||
render :template => "reports/issue_report_details"
|
|
||||||
when "version"
|
when "version"
|
||||||
@field = "fixed_version_id"
|
@field = "fixed_version_id"
|
||||||
@rows = @project.versions.sort
|
@rows = @project.shared_versions.sort
|
||||||
@data = issues_by_version
|
@data = Issue.by_version(@project)
|
||||||
@report_title = l(:field_version)
|
@report_title = l(:field_version)
|
||||||
render :template => "reports/issue_report_details"
|
|
||||||
when "priority"
|
when "priority"
|
||||||
@field = "priority_id"
|
@field = "priority_id"
|
||||||
@rows = Enumeration::get_values('IPRI')
|
@rows = IssuePriority.all
|
||||||
@data = issues_by_priority
|
@data = Issue.by_priority(@project)
|
||||||
@report_title = l(:field_priority)
|
@report_title = l(:field_priority)
|
||||||
render :template => "reports/issue_report_details"
|
|
||||||
when "category"
|
when "category"
|
||||||
@field = "category_id"
|
@field = "category_id"
|
||||||
@rows = @project.issue_categories
|
@rows = @project.issue_categories
|
||||||
@data = issues_by_category
|
@data = Issue.by_category(@project)
|
||||||
@report_title = l(:field_category)
|
@report_title = l(:field_category)
|
||||||
render :template => "reports/issue_report_details"
|
|
||||||
when "assigned_to"
|
when "assigned_to"
|
||||||
@field = "assigned_to_id"
|
@field = "assigned_to_id"
|
||||||
@rows = @project.members.collect { |m| m.user }
|
@rows = @project.members.collect { |m| m.user }.sort
|
||||||
@data = issues_by_assigned_to
|
@data = Issue.by_assigned_to(@project)
|
||||||
@report_title = l(:field_assigned_to)
|
@report_title = l(:field_assigned_to)
|
||||||
render :template => "reports/issue_report_details"
|
|
||||||
when "author"
|
when "author"
|
||||||
@field = "author_id"
|
@field = "author_id"
|
||||||
@rows = @project.members.collect { |m| m.user }
|
@rows = @project.members.collect { |m| m.user }.sort
|
||||||
@data = issues_by_author
|
@data = Issue.by_author(@project)
|
||||||
@report_title = l(:field_author)
|
@report_title = l(:field_author)
|
||||||
render :template => "reports/issue_report_details"
|
|
||||||
when "subproject"
|
when "subproject"
|
||||||
@field = "project_id"
|
@field = "project_id"
|
||||||
@rows = @project.active_children
|
@rows = @project.descendants.visible
|
||||||
@data = issues_by_subproject
|
@data = Issue.by_subproject(@project) || []
|
||||||
@report_title = l(:field_subproject)
|
@report_title = l(:field_subproject)
|
||||||
render :template => "reports/issue_report_details"
|
|
||||||
else
|
|
||||||
@trackers = @project.trackers
|
|
||||||
@versions = @project.versions.sort
|
|
||||||
@priorities = Enumeration::get_values('IPRI')
|
|
||||||
@categories = @project.issue_categories
|
|
||||||
@assignees = @project.members.collect { |m| m.user }
|
|
||||||
@authors = @project.members.collect { |m| m.user }
|
|
||||||
@subprojects = @project.active_children
|
|
||||||
issues_by_tracker
|
|
||||||
issues_by_version
|
|
||||||
issues_by_priority
|
|
||||||
issues_by_category
|
|
||||||
issues_by_assigned_to
|
|
||||||
issues_by_author
|
|
||||||
issues_by_subproject
|
|
||||||
|
|
||||||
render :template => "reports/issue_report"
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
respond_to do |format|
|
||||||
def delays
|
if @field
|
||||||
@trackers = Tracker.find(:all)
|
format.html {}
|
||||||
if request.get?
|
else
|
||||||
@selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
|
format.html { redirect_to :action => 'issue_report', :id => @project }
|
||||||
else
|
end
|
||||||
@selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
|
|
||||||
end
|
end
|
||||||
@selected_tracker_ids ||= []
|
|
||||||
@raw =
|
|
||||||
ActiveRecord::Base.connection.select_all("SELECT datediff( a.created_on, b.created_on ) as delay, count(a.id) as total
|
|
||||||
FROM issue_histories a, issue_histories b, issues i
|
|
||||||
WHERE a.status_id =5
|
|
||||||
AND a.issue_id = b.issue_id
|
|
||||||
AND a.issue_id = i.id
|
|
||||||
AND i.tracker_id in (#{@selected_tracker_ids.join(',')})
|
|
||||||
AND b.id = (
|
|
||||||
SELECT min( c.id )
|
|
||||||
FROM issue_histories c
|
|
||||||
WHERE b.issue_id = c.issue_id )
|
|
||||||
GROUP BY delay") unless @selected_tracker_ids.empty?
|
|
||||||
@raw ||=[]
|
|
||||||
|
|
||||||
@x_from = 0
|
|
||||||
@x_to = 0
|
|
||||||
@y_from = 0
|
|
||||||
@y_to = 0
|
|
||||||
@sum_total = 0
|
|
||||||
@sum_delay = 0
|
|
||||||
@raw.each do |r|
|
|
||||||
@x_to = [r['delay'].to_i, @x_to].max
|
|
||||||
@y_to = [r['total'].to_i, @y_to].max
|
|
||||||
@sum_total = @sum_total + r['total'].to_i
|
|
||||||
@sum_delay = @sum_delay + r['total'].to_i * r['delay'].to_i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
# Find project of id params[:id]
|
|
||||||
def find_project
|
|
||||||
@project = Project.find(params[:id])
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
render_404
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def issues_by_tracker
|
private
|
||||||
@issues_by_tracker ||=
|
|
||||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
|
||||||
s.is_closed as closed,
|
|
||||||
t.id as tracker_id,
|
|
||||||
count(i.id) as total
|
|
||||||
from
|
|
||||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{Tracker.table_name} t
|
|
||||||
where
|
|
||||||
i.status_id=s.id
|
|
||||||
and i.tracker_id=t.id
|
|
||||||
and i.project_id=#{@project.id}
|
|
||||||
group by s.id, s.is_closed, t.id")
|
|
||||||
end
|
|
||||||
|
|
||||||
def issues_by_version
|
def find_issue_statuses
|
||||||
@issues_by_version ||=
|
@statuses = IssueStatus.find(:all, :order => 'position')
|
||||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
|
||||||
s.is_closed as closed,
|
|
||||||
v.id as fixed_version_id,
|
|
||||||
count(i.id) as total
|
|
||||||
from
|
|
||||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{Version.table_name} v
|
|
||||||
where
|
|
||||||
i.status_id=s.id
|
|
||||||
and i.fixed_version_id=v.id
|
|
||||||
and i.project_id=#{@project.id}
|
|
||||||
group by s.id, s.is_closed, v.id")
|
|
||||||
end
|
|
||||||
|
|
||||||
def issues_by_priority
|
|
||||||
@issues_by_priority ||=
|
|
||||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
|
||||||
s.is_closed as closed,
|
|
||||||
p.id as priority_id,
|
|
||||||
count(i.id) as total
|
|
||||||
from
|
|
||||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{Enumeration.table_name} p
|
|
||||||
where
|
|
||||||
i.status_id=s.id
|
|
||||||
and i.priority_id=p.id
|
|
||||||
and i.project_id=#{@project.id}
|
|
||||||
group by s.id, s.is_closed, p.id")
|
|
||||||
end
|
|
||||||
|
|
||||||
def issues_by_category
|
|
||||||
@issues_by_category ||=
|
|
||||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
|
||||||
s.is_closed as closed,
|
|
||||||
c.id as category_id,
|
|
||||||
count(i.id) as total
|
|
||||||
from
|
|
||||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{IssueCategory.table_name} c
|
|
||||||
where
|
|
||||||
i.status_id=s.id
|
|
||||||
and i.category_id=c.id
|
|
||||||
and i.project_id=#{@project.id}
|
|
||||||
group by s.id, s.is_closed, c.id")
|
|
||||||
end
|
|
||||||
|
|
||||||
def issues_by_assigned_to
|
|
||||||
@issues_by_assigned_to ||=
|
|
||||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
|
||||||
s.is_closed as closed,
|
|
||||||
a.id as assigned_to_id,
|
|
||||||
count(i.id) as total
|
|
||||||
from
|
|
||||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{User.table_name} a
|
|
||||||
where
|
|
||||||
i.status_id=s.id
|
|
||||||
and i.assigned_to_id=a.id
|
|
||||||
and i.project_id=#{@project.id}
|
|
||||||
group by s.id, s.is_closed, a.id")
|
|
||||||
end
|
|
||||||
|
|
||||||
def issues_by_author
|
|
||||||
@issues_by_author ||=
|
|
||||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
|
||||||
s.is_closed as closed,
|
|
||||||
a.id as author_id,
|
|
||||||
count(i.id) as total
|
|
||||||
from
|
|
||||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{User.table_name} a
|
|
||||||
where
|
|
||||||
i.status_id=s.id
|
|
||||||
and i.author_id=a.id
|
|
||||||
and i.project_id=#{@project.id}
|
|
||||||
group by s.id, s.is_closed, a.id")
|
|
||||||
end
|
|
||||||
|
|
||||||
def issues_by_subproject
|
|
||||||
@issues_by_subproject ||=
|
|
||||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
|
||||||
s.is_closed as closed,
|
|
||||||
i.project_id as project_id,
|
|
||||||
count(i.id) as total
|
|
||||||
from
|
|
||||||
#{Issue.table_name} i, #{IssueStatus.table_name} s
|
|
||||||
where
|
|
||||||
i.status_id=s.id
|
|
||||||
and i.project_id IN (#{@project.active_children.collect{|p| p.id}.join(',')})
|
|
||||||
group by s.id, s.is_closed, i.project_id") if @project.active_children.any?
|
|
||||||
@issues_by_subproject ||= []
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -23,8 +23,10 @@ class ChangesetNotFound < Exception; end
|
|||||||
class InvalidRevisionParam < Exception; end
|
class InvalidRevisionParam < Exception; end
|
||||||
|
|
||||||
class RepositoriesController < ApplicationController
|
class RepositoriesController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
menu_item :repository
|
menu_item :repository
|
||||||
|
menu_item :settings, :only => :edit
|
||||||
|
default_search_scope :changesets
|
||||||
|
|
||||||
before_filter :find_repository, :except => :edit
|
before_filter :find_repository, :except => :edit
|
||||||
before_filter :find_project, :only => :edit
|
before_filter :find_project, :only => :edit
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
@@ -42,7 +44,28 @@ class RepositoriesController < ApplicationController
|
|||||||
@repository.attributes = params[:repository]
|
@repository.attributes = params[:repository]
|
||||||
@repository.save
|
@repository.save
|
||||||
end
|
end
|
||||||
render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'}
|
render(:update) do |page|
|
||||||
|
page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'
|
||||||
|
if @repository && !@project.repository
|
||||||
|
@project.reload #needed to reload association
|
||||||
|
page.replace_html "main-menu", render_main_menu(@project)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def committers
|
||||||
|
@committers = @repository.committers
|
||||||
|
@users = @project.users
|
||||||
|
additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
|
||||||
|
@users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
|
||||||
|
@users.compact!
|
||||||
|
@users.sort!
|
||||||
|
if request.post? && params[:committers].is_a?(Hash)
|
||||||
|
# Build a hash with repository usernames as keys and corresponding user ids as values
|
||||||
|
@repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to :action => 'committers', :id => @project
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@@ -50,31 +73,26 @@ class RepositoriesController < ApplicationController
|
|||||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
|
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
# check if new revisions have been committed in the repository
|
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
||||||
@repository.fetch_changesets if Setting.autofetch_changesets?
|
|
||||||
# root entries
|
|
||||||
@entries = @repository.entries('', @rev)
|
|
||||||
# latest changesets
|
|
||||||
@changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC")
|
|
||||||
show_error_not_found unless @entries || @changesets.any?
|
|
||||||
end
|
|
||||||
|
|
||||||
def browse
|
|
||||||
@entries = @repository.entries(@path, @rev)
|
@entries = @repository.entries(@path, @rev)
|
||||||
if request.xhr?
|
if request.xhr?
|
||||||
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
||||||
else
|
else
|
||||||
show_error_not_found and return unless @entries
|
(show_error_not_found; return) unless @entries
|
||||||
|
@changesets = @repository.latest_changesets(@path, @rev)
|
||||||
@properties = @repository.properties(@path, @rev)
|
@properties = @repository.properties(@path, @rev)
|
||||||
render :action => 'browse'
|
render :action => 'show'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias_method :browse, :show
|
||||||
|
|
||||||
def changes
|
def changes
|
||||||
@entry = @repository.entry(@path, @rev)
|
@entry = @repository.entry(@path, @rev)
|
||||||
show_error_not_found and return unless @entry
|
(show_error_not_found; return) unless @entry
|
||||||
@changesets = @repository.changesets_for_path(@path)
|
@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
|
||||||
@properties = @repository.properties(@path, @rev)
|
@properties = @repository.properties(@path, @rev)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -85,7 +103,8 @@ class RepositoriesController < ApplicationController
|
|||||||
params['page']
|
params['page']
|
||||||
@changesets = @repository.changesets.find(:all,
|
@changesets = @repository.changesets.find(:all,
|
||||||
:limit => @changeset_pages.items_per_page,
|
:limit => @changeset_pages.items_per_page,
|
||||||
:offset => @changeset_pages.current.offset)
|
:offset => @changeset_pages.current.offset,
|
||||||
|
:include => [:user, :repository])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :layout => false if request.xhr? }
|
format.html { render :layout => false if request.xhr? }
|
||||||
@@ -95,15 +114,15 @@ class RepositoriesController < ApplicationController
|
|||||||
|
|
||||||
def entry
|
def entry
|
||||||
@entry = @repository.entry(@path, @rev)
|
@entry = @repository.entry(@path, @rev)
|
||||||
show_error_not_found and return unless @entry
|
(show_error_not_found; return) unless @entry
|
||||||
|
|
||||||
# If the entry is a dir, show the browser
|
# If the entry is a dir, show the browser
|
||||||
browse and return if @entry.is_dir?
|
(show; return) if @entry.is_dir?
|
||||||
|
|
||||||
@content = @repository.cat(@path, @rev)
|
@content = @repository.cat(@path, @rev)
|
||||||
show_error_not_found and return unless @content
|
(show_error_not_found; return) unless @content
|
||||||
if 'raw' == params[:format] || @content.is_binary_data?
|
if 'raw' == params[:format] || @content.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte)
|
||||||
# Force the download if it's a binary file
|
# Force the download
|
||||||
send_data @content, :filename => @path.split('/').last
|
send_data @content, :filename => @path.split('/').last
|
||||||
else
|
else
|
||||||
# Prevent empty lines when displaying a file with Windows style eol
|
# Prevent empty lines when displaying a file with Windows style eol
|
||||||
@@ -112,18 +131,16 @@ class RepositoriesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def annotate
|
def annotate
|
||||||
|
@entry = @repository.entry(@path, @rev)
|
||||||
|
(show_error_not_found; return) unless @entry
|
||||||
|
|
||||||
@annotate = @repository.scm.annotate(@path, @rev)
|
@annotate = @repository.scm.annotate(@path, @rev)
|
||||||
render_error l(:error_scm_annotate) and return if @annotate.nil? || @annotate.empty?
|
(render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def revision
|
def revision
|
||||||
@changeset = @repository.changesets.find_by_revision(@rev)
|
@changeset = @repository.find_changeset_by_name(@rev)
|
||||||
raise ChangesetNotFound unless @changeset
|
raise ChangesetNotFound unless @changeset
|
||||||
@changes_count = @changeset.changes.size
|
|
||||||
@changes_pages = Paginator.new self, @changes_count, 150, params['page']
|
|
||||||
@changes = @changeset.changes.find(:all,
|
|
||||||
:limit => @changes_pages.items_per_page,
|
|
||||||
:offset => @changes_pages.current.offset)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
@@ -136,7 +153,7 @@ class RepositoriesController < ApplicationController
|
|||||||
def diff
|
def diff
|
||||||
if params[:format] == 'diff'
|
if params[:format] == 'diff'
|
||||||
@diff = @repository.diff(@path, @rev, @rev_to)
|
@diff = @repository.diff(@path, @rev, @rev_to)
|
||||||
show_error_not_found and return unless @diff
|
(show_error_not_found; return) unless @diff
|
||||||
filename = "changeset_r#{@rev}"
|
filename = "changeset_r#{@rev}"
|
||||||
filename << "_r#{@rev_to}" if @rev_to
|
filename << "_r#{@rev_to}" if @rev_to
|
||||||
send_data @diff.join, :filename => "#{filename}.diff",
|
send_data @diff.join, :filename => "#{filename}.diff",
|
||||||
@@ -180,23 +197,14 @@ class RepositoriesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
|
||||||
@project = Project.find(params[:id])
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
render_404
|
|
||||||
end
|
|
||||||
|
|
||||||
REV_PARAM_RE = %r{^[a-f0-9]*$}
|
|
||||||
|
|
||||||
def find_repository
|
def find_repository
|
||||||
@project = Project.find(params[:id])
|
@project = Project.find(params[:id])
|
||||||
@repository = @project.repository
|
@repository = @project.repository
|
||||||
render_404 and return false unless @repository
|
(render_404; return false) unless @repository
|
||||||
@path = params[:path].join('/') unless params[:path].nil?
|
@path = params[:path].join('/') unless params[:path].nil?
|
||||||
@path ||= ''
|
@path ||= ''
|
||||||
@rev = params[:rev]
|
@rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip
|
||||||
@rev_to = params[:rev_to]
|
@rev_to = params[:rev_to]
|
||||||
raise InvalidRevisionParam unless @rev.to_s.match(REV_PARAM_RE) && @rev.to_s.match(REV_PARAM_RE)
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
rescue InvalidRevisionParam
|
rescue InvalidRevisionParam
|
||||||
@@ -225,8 +233,7 @@ private
|
|||||||
changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
|
changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
|
||||||
|
|
||||||
fields = []
|
fields = []
|
||||||
month_names = l(:actionview_datehelper_select_month_names_abbr).split(',')
|
12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
|
||||||
12.times {|m| fields << month_names[((Date.today.month - 1 - m) % 12)]}
|
|
||||||
|
|
||||||
graph = SVG::Graph::Bar.new(
|
graph = SVG::Graph::Bar.new(
|
||||||
:height => 300,
|
:height => 300,
|
||||||
@@ -255,7 +262,7 @@ private
|
|||||||
|
|
||||||
def graph_commits_per_author(repository)
|
def graph_commits_per_author(repository)
|
||||||
commits_by_author = repository.changesets.count(:all, :group => :committer)
|
commits_by_author = repository.changesets.count(:all, :group => :committer)
|
||||||
commits_by_author.sort! {|x, y| x.last <=> y.last}
|
commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
|
||||||
|
|
||||||
changes_by_author = repository.changes.count(:all, :group => :committer)
|
changes_by_author = repository.changes.count(:all, :group => :committer)
|
||||||
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
|
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
|
||||||
|
|||||||
@@ -16,20 +16,16 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class RolesController < ApplicationController
|
class RolesController < ApplicationController
|
||||||
layout 'base'
|
layout 'admin'
|
||||||
|
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
|
|
||||||
verify :method => :post, :only => [ :destroy, :move ],
|
verify :method => :post, :only => [ :destroy, :move ],
|
||||||
:redirect_to => { :action => :list }
|
:redirect_to => { :action => :index }
|
||||||
|
|
||||||
def index
|
def index
|
||||||
list
|
|
||||||
render :action => 'list' unless request.xhr?
|
|
||||||
end
|
|
||||||
|
|
||||||
def list
|
|
||||||
@role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
|
@role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
|
||||||
render :action => "list", :layout => false if request.xhr?
|
render :action => "index", :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@@ -41,7 +37,7 @@ class RolesController < ApplicationController
|
|||||||
@role.workflows.copy(copy_from)
|
@role.workflows.copy(copy_from)
|
||||||
end
|
end
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
end
|
end
|
||||||
@permissions = @role.setable_permissions
|
@permissions = @role.setable_permissions
|
||||||
@roles = Role.find :all, :order => 'builtin, position'
|
@roles = Role.find :all, :order => 'builtin, position'
|
||||||
@@ -51,7 +47,7 @@ class RolesController < ApplicationController
|
|||||||
@role = Role.find(params[:id])
|
@role = Role.find(params[:id])
|
||||||
if request.post? and @role.update_attributes(params[:role])
|
if request.post? and @role.update_attributes(params[:role])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
end
|
end
|
||||||
@permissions = @role.setable_permissions
|
@permissions = @role.setable_permissions
|
||||||
end
|
end
|
||||||
@@ -59,46 +55,10 @@ class RolesController < ApplicationController
|
|||||||
def destroy
|
def destroy
|
||||||
@role = Role.find(params[:id])
|
@role = Role.find(params[:id])
|
||||||
@role.destroy
|
@role.destroy
|
||||||
redirect_to :action => 'list'
|
|
||||||
rescue
|
|
||||||
flash[:error] = 'This role is in use and can not be deleted.'
|
|
||||||
redirect_to :action => 'index'
|
redirect_to :action => 'index'
|
||||||
end
|
rescue
|
||||||
|
flash[:error] = l(:error_can_not_remove_role)
|
||||||
def move
|
redirect_to :action => 'index'
|
||||||
@role = Role.find(params[:id])
|
|
||||||
case params[:position]
|
|
||||||
when 'highest'
|
|
||||||
@role.move_to_top
|
|
||||||
when 'higher'
|
|
||||||
@role.move_higher
|
|
||||||
when 'lower'
|
|
||||||
@role.move_lower
|
|
||||||
when 'lowest'
|
|
||||||
@role.move_to_bottom
|
|
||||||
end if params[:position]
|
|
||||||
redirect_to :action => 'list'
|
|
||||||
end
|
|
||||||
|
|
||||||
def workflow
|
|
||||||
@role = Role.find_by_id(params[:role_id])
|
|
||||||
@tracker = Tracker.find_by_id(params[:tracker_id])
|
|
||||||
|
|
||||||
if request.post?
|
|
||||||
Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
|
|
||||||
(params[:issue_status] || []).each { |old, news|
|
|
||||||
news.each { |new|
|
|
||||||
@role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if @role.save
|
|
||||||
flash[:notice] = l(:notice_successful_update)
|
|
||||||
redirect_to :action => 'workflow', :role_id => @role, :tracker_id => @tracker
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@roles = Role.find(:all, :order => 'builtin, position')
|
|
||||||
@trackers = Tracker.find(:all, :order => 'position')
|
|
||||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def report
|
def report
|
||||||
@@ -110,7 +70,7 @@ class RolesController < ApplicationController
|
|||||||
role.save
|
role.save
|
||||||
end
|
end
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class SearchController < ApplicationController
|
class SearchController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
|
|
||||||
before_filter :find_optional_project
|
before_filter :find_optional_project
|
||||||
|
|
||||||
helper :messages
|
helper :messages
|
||||||
@@ -36,7 +34,7 @@ class SearchController < ApplicationController
|
|||||||
when 'my_projects'
|
when 'my_projects'
|
||||||
User.current.memberships.collect(&:project)
|
User.current.memberships.collect(&:project)
|
||||||
when 'subprojects'
|
when 'subprojects'
|
||||||
@project ? ([ @project ] + @project.active_children) : nil
|
@project ? (@project.self_and_descendants.active) : nil
|
||||||
else
|
else
|
||||||
@project
|
@project
|
||||||
end
|
end
|
||||||
@@ -45,12 +43,12 @@ class SearchController < ApplicationController
|
|||||||
begin; offset = params[:offset].to_time if params[:offset]; rescue; end
|
begin; offset = params[:offset].to_time if params[:offset]; rescue; end
|
||||||
|
|
||||||
# quick jump to an issue
|
# quick jump to an issue
|
||||||
if @question.match(/^#?(\d+)$/) && Issue.find_by_id($1, :include => :project, :conditions => Project.visible_by(User.current))
|
if @question.match(/^#?(\d+)$/) && Issue.visible.find_by_id($1.to_i)
|
||||||
redirect_to :controller => "issues", :action => "show", :id => $1
|
redirect_to :controller => "issues", :action => "show", :id => $1
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@object_types = %w(issues news documents changesets wiki_pages messages projects)
|
@object_types = Redmine::Search.available_search_types.dup
|
||||||
if projects_to_search.is_a? Project
|
if projects_to_search.is_a? Project
|
||||||
# don't search projects
|
# don't search projects
|
||||||
@object_types.delete('projects')
|
@object_types.delete('projects')
|
||||||
@@ -64,21 +62,19 @@ class SearchController < ApplicationController
|
|||||||
# extract tokens from the question
|
# extract tokens from the question
|
||||||
# eg. hello "bye bye" => ["hello", "bye bye"]
|
# eg. hello "bye bye" => ["hello", "bye bye"]
|
||||||
@tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
|
@tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
|
||||||
# tokens must be at least 3 character long
|
# tokens must be at least 2 characters long
|
||||||
@tokens = @tokens.uniq.select {|w| w.length > 2 }
|
@tokens = @tokens.uniq.select {|w| w.length > 1 }
|
||||||
|
|
||||||
if !@tokens.empty?
|
if !@tokens.empty?
|
||||||
# no more than 5 tokens to search for
|
# no more than 5 tokens to search for
|
||||||
@tokens.slice! 5..-1 if @tokens.size > 5
|
@tokens.slice! 5..-1 if @tokens.size > 5
|
||||||
# strings used in sql like statement
|
|
||||||
like_tokens = @tokens.collect {|w| "%#{w.downcase}%"}
|
|
||||||
|
|
||||||
@results = []
|
@results = []
|
||||||
@results_by_type = Hash.new {|h,k| h[k] = 0}
|
@results_by_type = Hash.new {|h,k| h[k] = 0}
|
||||||
|
|
||||||
limit = 10
|
limit = 10
|
||||||
@scope.each do |s|
|
@scope.each do |s|
|
||||||
r, c = s.singularize.camelcase.constantize.search(like_tokens, projects_to_search,
|
r, c = s.singularize.camelcase.constantize.search(@tokens, projects_to_search,
|
||||||
:all_words => @all_words,
|
:all_words => @all_words,
|
||||||
:titles_only => @titles_only,
|
:titles_only => @titles_only,
|
||||||
:limit => (limit+1),
|
:limit => (limit+1),
|
||||||
|
|||||||
@@ -5,27 +5,28 @@
|
|||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class SettingsController < ApplicationController
|
class SettingsController < ApplicationController
|
||||||
layout 'base'
|
layout 'admin'
|
||||||
before_filter :require_admin
|
|
||||||
|
|
||||||
|
before_filter :require_admin
|
||||||
|
|
||||||
def index
|
def index
|
||||||
edit
|
edit
|
||||||
render :action => 'edit'
|
render :action => 'edit'
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted)
|
@notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted wiki_content_added wiki_content_updated)
|
||||||
if request.post? && params[:settings] && params[:settings].is_a?(Hash)
|
if request.post? && params[:settings] && params[:settings].is_a?(Hash)
|
||||||
settings = (params[:settings] || {}).dup.symbolize_keys
|
settings = (params[:settings] || {}).dup.symbolize_keys
|
||||||
settings.each do |name, value|
|
settings.each do |name, value|
|
||||||
@@ -40,17 +41,21 @@ class SettingsController < ApplicationController
|
|||||||
@options = {}
|
@options = {}
|
||||||
@options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
|
@options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
|
||||||
@deliveries = ActionMailer::Base.perform_deliveries
|
@deliveries = ActionMailer::Base.perform_deliveries
|
||||||
|
|
||||||
|
@guessed_host_and_path = request.host_with_port.dup
|
||||||
|
@guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def plugin
|
def plugin
|
||||||
plugin_id = params[:id].to_sym
|
@plugin = Redmine::Plugin.find(params[:id])
|
||||||
@plugin = Redmine::Plugin.registered_plugins[plugin_id]
|
|
||||||
if request.post?
|
if request.post?
|
||||||
Setting["plugin_#{plugin_id}"] = params[:settings]
|
Setting["plugin_#{@plugin.id}"] = params[:settings]
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'plugin', :id => params[:id]
|
redirect_to :action => 'plugin', :id => @plugin.id
|
||||||
end
|
end
|
||||||
@partial = @plugin.settings[:partial]
|
@partial = @plugin.settings[:partial]
|
||||||
@settings = Setting["plugin_#{plugin_id}"]
|
@settings = Setting["plugin_#{@plugin.id}"]
|
||||||
|
rescue Redmine::PluginNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,32 +16,52 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class SysController < ActionController::Base
|
class SysController < ActionController::Base
|
||||||
wsdl_service_name 'Sys'
|
before_filter :check_enabled
|
||||||
web_service_api SysApi
|
|
||||||
web_service_scaffold :invoke
|
|
||||||
|
|
||||||
before_invocation :check_enabled
|
|
||||||
|
|
||||||
# Returns the projects list, with their repositories
|
|
||||||
def projects
|
def projects
|
||||||
Project.find(:all, :include => :repository)
|
p = Project.active.has_module(:repository).find(:all, :include => :repository, :order => 'identifier')
|
||||||
|
render :xml => p.to_xml(:include => :repository)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_project_repository
|
||||||
|
project = Project.find(params[:id])
|
||||||
|
if project.repository
|
||||||
|
render :nothing => true, :status => 409
|
||||||
|
else
|
||||||
|
logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
|
||||||
|
project.repository = Repository.factory(params[:vendor], params[:repository])
|
||||||
|
if project.repository && project.repository.save
|
||||||
|
render :xml => project.repository, :status => 201
|
||||||
|
else
|
||||||
|
render :nothing => true, :status => 422
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def fetch_changesets
|
||||||
|
projects = []
|
||||||
|
if params[:id]
|
||||||
|
projects << Project.active.has_module(:repository).find(params[:id])
|
||||||
|
else
|
||||||
|
projects = Project.active.has_module(:repository).find(:all, :include => :repository)
|
||||||
|
end
|
||||||
|
projects.each do |project|
|
||||||
|
if project.repository
|
||||||
|
project.repository.fetch_changesets
|
||||||
|
end
|
||||||
|
end
|
||||||
|
render :nothing => true, :status => 200
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render :nothing => true, :status => 404
|
||||||
end
|
end
|
||||||
|
|
||||||
# Registers a repository for the given project identifier
|
protected
|
||||||
# (Subversion specific)
|
|
||||||
def repository_created(identifier, url)
|
|
||||||
project = Project.find_by_identifier(identifier)
|
|
||||||
# Do not create the repository if the project has already one
|
|
||||||
return 0 unless project && project.repository.nil?
|
|
||||||
logger.debug "Repository for #{project.name} was created"
|
|
||||||
repository = Repository.factory('Subversion', :project => project, :url => url)
|
|
||||||
repository.save
|
|
||||||
repository.id || 0
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
def check_enabled
|
||||||
|
User.current = nil
|
||||||
def check_enabled(name, args)
|
unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
|
||||||
Setting.sys_api_enabled?
|
render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,9 +16,10 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class TimelogController < ApplicationController
|
class TimelogController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
menu_item :issues
|
menu_item :issues
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :authorize, :only => [:edit, :destroy]
|
||||||
|
before_filter :find_optional_project, :only => [:report, :details]
|
||||||
|
before_filter :load_available_criterias, :only => [:report]
|
||||||
|
|
||||||
verify :method => :post, :only => :destroy, :redirect_to => { :action => :details }
|
verify :method => :post, :only => :destroy, :redirect_to => { :action => :details }
|
||||||
|
|
||||||
@@ -30,43 +31,6 @@ class TimelogController < ApplicationController
|
|||||||
include CustomFieldsHelper
|
include CustomFieldsHelper
|
||||||
|
|
||||||
def report
|
def report
|
||||||
@available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
|
|
||||||
:klass => Project,
|
|
||||||
:label => :label_project},
|
|
||||||
'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
|
|
||||||
:klass => Version,
|
|
||||||
:label => :label_version},
|
|
||||||
'category' => {:sql => "#{Issue.table_name}.category_id",
|
|
||||||
:klass => IssueCategory,
|
|
||||||
:label => :field_category},
|
|
||||||
'member' => {:sql => "#{TimeEntry.table_name}.user_id",
|
|
||||||
:klass => User,
|
|
||||||
:label => :label_member},
|
|
||||||
'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
|
|
||||||
:klass => Tracker,
|
|
||||||
:label => :label_tracker},
|
|
||||||
'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
|
|
||||||
:klass => Enumeration,
|
|
||||||
:label => :label_activity},
|
|
||||||
'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
|
|
||||||
:klass => Issue,
|
|
||||||
:label => :label_issue}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add list and boolean custom fields as available criterias
|
|
||||||
@project.all_issue_custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
|
|
||||||
@available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = #{Issue.table_name}.id)",
|
|
||||||
:format => cf.field_format,
|
|
||||||
:label => cf.name}
|
|
||||||
end
|
|
||||||
|
|
||||||
# Add list and boolean time entry custom fields
|
|
||||||
TimeEntryCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
|
|
||||||
@available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'TimeEntry' AND c.customized_id = #{TimeEntry.table_name}.id)",
|
|
||||||
:format => cf.field_format,
|
|
||||||
:label => cf.name}
|
|
||||||
end
|
|
||||||
|
|
||||||
@criterias = params[:criterias] || []
|
@criterias = params[:criterias] || []
|
||||||
@criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
|
@criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
|
||||||
@criterias.uniq!
|
@criterias.uniq!
|
||||||
@@ -79,14 +43,23 @@ class TimelogController < ApplicationController
|
|||||||
unless @criterias.empty?
|
unless @criterias.empty?
|
||||||
sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
|
sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
|
||||||
sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
|
sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
|
||||||
|
sql_condition = ''
|
||||||
|
|
||||||
|
if @project.nil?
|
||||||
|
sql_condition = Project.allowed_to_condition(User.current, :view_time_entries)
|
||||||
|
elsif @issue.nil?
|
||||||
|
sql_condition = @project.project_condition(Setting.display_subprojects_issues?)
|
||||||
|
else
|
||||||
|
sql_condition = "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
|
||||||
|
end
|
||||||
|
|
||||||
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
|
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
|
||||||
sql << " FROM #{TimeEntry.table_name}"
|
sql << " FROM #{TimeEntry.table_name}"
|
||||||
sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
|
sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
|
||||||
sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
|
sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
|
||||||
sql << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?)
|
sql << " WHERE"
|
||||||
sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries)
|
sql << " (%s) AND" % sql_condition
|
||||||
sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
|
sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from), ActiveRecord::Base.connection.quoted_date(@to)]
|
||||||
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
|
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
|
||||||
|
|
||||||
@hours = ActiveRecord::Base.connection.select_all(sql)
|
@hours = ActiveRecord::Base.connection.select_all(sql)
|
||||||
@@ -130,17 +103,27 @@ class TimelogController < ApplicationController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :layout => !request.xhr? }
|
format.html { render :layout => !request.xhr? }
|
||||||
format.csv { send_data(report_to_csv(@criterias, @periods, @hours).read, :type => 'text/csv; header=present', :filename => 'timelog.csv') }
|
format.csv { send_data(report_to_csv(@criterias, @periods, @hours), :type => 'text/csv; header=present', :filename => 'timelog.csv') }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def details
|
def details
|
||||||
sort_init 'spent_on', 'desc'
|
sort_init 'spent_on', 'desc'
|
||||||
sort_update
|
sort_update 'spent_on' => 'spent_on',
|
||||||
|
'user' => 'user_id',
|
||||||
|
'activity' => 'activity_id',
|
||||||
|
'project' => "#{Project.table_name}.name",
|
||||||
|
'issue' => 'issue_id',
|
||||||
|
'hours' => 'hours'
|
||||||
|
|
||||||
cond = ARCondition.new
|
cond = ARCondition.new
|
||||||
cond << (@issue.nil? ? @project.project_condition(Setting.display_subprojects_issues?) :
|
if @project.nil?
|
||||||
["#{TimeEntry.table_name}.issue_id = ?", @issue.id])
|
cond << Project.allowed_to_condition(User.current, :view_time_entries)
|
||||||
|
elsif @issue.nil?
|
||||||
|
cond << @project.project_condition(Setting.display_subprojects_issues?)
|
||||||
|
else
|
||||||
|
cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
|
||||||
|
end
|
||||||
|
|
||||||
retrieve_date_range
|
retrieve_date_range
|
||||||
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
|
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
|
||||||
@@ -149,7 +132,7 @@ class TimelogController < ApplicationController
|
|||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
# Paginate results
|
# Paginate results
|
||||||
@entry_count = TimeEntry.count(:include => :project, :conditions => cond.conditions)
|
@entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions)
|
||||||
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
|
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
|
||||||
@entries = TimeEntry.find(:all,
|
@entries = TimeEntry.find(:all,
|
||||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||||
@@ -157,7 +140,7 @@ class TimelogController < ApplicationController
|
|||||||
:order => sort_clause,
|
:order => sort_clause,
|
||||||
:limit => @entry_pages.items_per_page,
|
:limit => @entry_pages.items_per_page,
|
||||||
:offset => @entry_pages.current.offset)
|
:offset => @entry_pages.current.offset)
|
||||||
@total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f
|
@total_hours = TimeEntry.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f
|
||||||
|
|
||||||
render :layout => !request.xhr?
|
render :layout => !request.xhr?
|
||||||
}
|
}
|
||||||
@@ -175,30 +158,36 @@ class TimelogController < ApplicationController
|
|||||||
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
|
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
|
||||||
:conditions => cond.conditions,
|
:conditions => cond.conditions,
|
||||||
:order => sort_clause)
|
:order => sort_clause)
|
||||||
send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
render_403 and return if @time_entry && !@time_entry.editable_by?(User.current)
|
(render_403; return) if @time_entry && !@time_entry.editable_by?(User.current)
|
||||||
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
|
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
|
||||||
@time_entry.attributes = params[:time_entry]
|
@time_entry.attributes = params[:time_entry]
|
||||||
|
|
||||||
|
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
|
||||||
|
|
||||||
if request.post? and @time_entry.save
|
if request.post? and @time_entry.save
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to(params[:back_url].blank? ? {:action => 'details', :project_id => @time_entry.project} : params[:back_url])
|
redirect_back_or_default :action => 'details', :project_id => @time_entry.project
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
render_404 and return unless @time_entry
|
(render_404; return) unless @time_entry
|
||||||
render_403 and return unless @time_entry.editable_by?(User.current)
|
(render_403; return) unless @time_entry.editable_by?(User.current)
|
||||||
@time_entry.destroy
|
if @time_entry.destroy && @time_entry.destroyed?
|
||||||
flash[:notice] = l(:notice_successful_delete)
|
flash[:notice] = l(:notice_successful_delete)
|
||||||
|
else
|
||||||
|
flash[:error] = l(:notice_unable_delete_time_entry)
|
||||||
|
end
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
rescue RedirectBackError
|
rescue ::ActionController::RedirectBackError
|
||||||
redirect_to :action => 'details', :project_id => @time_entry.project
|
redirect_to :action => 'details', :project_id => @time_entry.project
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -220,6 +209,16 @@ private
|
|||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_optional_project
|
||||||
|
if !params[:issue_id].blank?
|
||||||
|
@issue = Issue.find(params[:issue_id])
|
||||||
|
@project = @issue.project
|
||||||
|
elsif !params[:project_id].blank?
|
||||||
|
@project = Project.find(params[:project_id])
|
||||||
|
end
|
||||||
|
deny_access unless User.current.allowed_to?(:view_time_entries, @project, :global => true)
|
||||||
|
end
|
||||||
|
|
||||||
# Retrieves the date range based on predefined ranges or specific from/to param dates
|
# Retrieves the date range based on predefined ranges or specific from/to param dates
|
||||||
def retrieve_date_range
|
def retrieve_date_range
|
||||||
@free_period = false
|
@free_period = false
|
||||||
@@ -262,7 +261,57 @@ private
|
|||||||
end
|
end
|
||||||
|
|
||||||
@from, @to = @to, @from if @from && @to && @from > @to
|
@from, @to = @to, @from if @from && @to && @from > @to
|
||||||
@from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today) - 1
|
@from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) - 1
|
||||||
@to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today)
|
@to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_available_criterias
|
||||||
|
@available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
|
||||||
|
:klass => Project,
|
||||||
|
:label => :label_project},
|
||||||
|
'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
|
||||||
|
:klass => Version,
|
||||||
|
:label => :label_version},
|
||||||
|
'category' => {:sql => "#{Issue.table_name}.category_id",
|
||||||
|
:klass => IssueCategory,
|
||||||
|
:label => :field_category},
|
||||||
|
'member' => {:sql => "#{TimeEntry.table_name}.user_id",
|
||||||
|
:klass => User,
|
||||||
|
:label => :label_member},
|
||||||
|
'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
|
||||||
|
:klass => Tracker,
|
||||||
|
:label => :label_tracker},
|
||||||
|
'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
|
||||||
|
:klass => TimeEntryActivity,
|
||||||
|
:label => :label_activity},
|
||||||
|
'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
|
||||||
|
:klass => Issue,
|
||||||
|
:label => :label_issue}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add list and boolean custom fields as available criterias
|
||||||
|
custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields)
|
||||||
|
custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
|
||||||
|
@available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = #{Issue.table_name}.id)",
|
||||||
|
:format => cf.field_format,
|
||||||
|
:label => cf.name}
|
||||||
|
end if @project
|
||||||
|
|
||||||
|
# Add list and boolean time entry custom fields
|
||||||
|
TimeEntryCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
|
||||||
|
@available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'TimeEntry' AND c.customized_id = #{TimeEntry.table_name}.id)",
|
||||||
|
:format => cf.field_format,
|
||||||
|
:label => cf.name}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Add list and boolean time entry activity custom fields
|
||||||
|
TimeEntryActivityCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
|
||||||
|
@available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Enumeration' AND c.customized_id = #{TimeEntry.table_name}.activity_id)",
|
||||||
|
:format => cf.field_format,
|
||||||
|
:label => cf.name}
|
||||||
|
end
|
||||||
|
|
||||||
|
call_hook(:controller_timelog_available_criterias, { :available_criterias => @available_criterias, :project => @project })
|
||||||
|
@available_criterias
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,20 +16,15 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class TrackersController < ApplicationController
|
class TrackersController < ApplicationController
|
||||||
layout 'base'
|
layout 'admin'
|
||||||
|
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
|
|
||||||
|
verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
|
||||||
|
|
||||||
def index
|
def index
|
||||||
list
|
|
||||||
render :action => 'list' unless request.xhr?
|
|
||||||
end
|
|
||||||
|
|
||||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
|
||||||
verify :method => :post, :only => [ :destroy, :move ], :redirect_to => { :action => :list }
|
|
||||||
|
|
||||||
def list
|
|
||||||
@tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
|
@tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
|
||||||
render :action => "list", :layout => false if request.xhr?
|
render :action => "index", :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@@ -40,41 +35,30 @@ class TrackersController < ApplicationController
|
|||||||
@tracker.workflows.copy(copy_from)
|
@tracker.workflows.copy(copy_from)
|
||||||
end
|
end
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
|
return
|
||||||
end
|
end
|
||||||
@trackers = Tracker.find :all, :order => 'position'
|
@trackers = Tracker.find :all, :order => 'position'
|
||||||
|
@projects = Project.find(:all)
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@tracker = Tracker.find(params[:id])
|
@tracker = Tracker.find(params[:id])
|
||||||
if request.post? and @tracker.update_attributes(params[:tracker])
|
if request.post? and @tracker.update_attributes(params[:tracker])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
@projects = Project.find(:all)
|
||||||
|
|
||||||
def move
|
|
||||||
@tracker = Tracker.find(params[:id])
|
|
||||||
case params[:position]
|
|
||||||
when 'highest'
|
|
||||||
@tracker.move_to_top
|
|
||||||
when 'higher'
|
|
||||||
@tracker.move_higher
|
|
||||||
when 'lower'
|
|
||||||
@tracker.move_lower
|
|
||||||
when 'lowest'
|
|
||||||
@tracker.move_to_bottom
|
|
||||||
end if params[:position]
|
|
||||||
redirect_to :action => 'list'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@tracker = Tracker.find(params[:id])
|
@tracker = Tracker.find(params[:id])
|
||||||
unless @tracker.issues.empty?
|
unless @tracker.issues.empty?
|
||||||
flash[:error] = "This tracker contains issues and can\'t be deleted."
|
flash[:error] = l(:error_can_not_delete_tracker)
|
||||||
else
|
else
|
||||||
@tracker.destroy
|
@tracker.destroy
|
||||||
end
|
end
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'index'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,8 +16,9 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
layout 'base'
|
layout 'admin'
|
||||||
before_filter :require_admin
|
|
||||||
|
before_filter :require_admin, :except => :show
|
||||||
|
|
||||||
helper :sort
|
helper :sort
|
||||||
include SortHelper
|
include SortHelper
|
||||||
@@ -25,28 +26,51 @@ class UsersController < ApplicationController
|
|||||||
include CustomFieldsHelper
|
include CustomFieldsHelper
|
||||||
|
|
||||||
def index
|
def index
|
||||||
list
|
|
||||||
render :action => 'list' unless request.xhr?
|
|
||||||
end
|
|
||||||
|
|
||||||
def list
|
|
||||||
sort_init 'login', 'asc'
|
sort_init 'login', 'asc'
|
||||||
sort_update
|
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
||||||
|
|
||||||
@status = params[:status] ? params[:status].to_i : 1
|
@status = params[:status] ? params[:status].to_i : 1
|
||||||
conditions = "status <> 0"
|
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
||||||
conditions = ["status=?", @status] unless @status == 0
|
|
||||||
|
unless params[:name].blank?
|
||||||
|
name = "%#{params[:name].strip.downcase}%"
|
||||||
|
c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name]
|
||||||
|
end
|
||||||
|
|
||||||
@user_count = User.count(:conditions => conditions)
|
@user_count = User.count(:conditions => c.conditions)
|
||||||
@user_pages = Paginator.new self, @user_count,
|
@user_pages = Paginator.new self, @user_count,
|
||||||
per_page_option,
|
per_page_option,
|
||||||
params['page']
|
params['page']
|
||||||
@users = User.find :all,:order => sort_clause,
|
@users = User.find :all,:order => sort_clause,
|
||||||
:conditions => conditions,
|
:conditions => c.conditions,
|
||||||
:limit => @user_pages.items_per_page,
|
:limit => @user_pages.items_per_page,
|
||||||
:offset => @user_pages.current.offset
|
:offset => @user_pages.current.offset
|
||||||
|
|
||||||
render :action => "list", :layout => false if request.xhr?
|
render :layout => !request.xhr?
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@user = User.find(params[:id])
|
||||||
|
@custom_values = @user.custom_values
|
||||||
|
|
||||||
|
# show only public projects and private projects that the logged in user is also a member of
|
||||||
|
@memberships = @user.memberships.select do |membership|
|
||||||
|
membership.project.is_public? || (User.current.member_of?(membership.project))
|
||||||
|
end
|
||||||
|
|
||||||
|
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
|
||||||
|
@events_by_day = events.group_by(&:event_date)
|
||||||
|
|
||||||
|
unless User.current.admin?
|
||||||
|
if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
|
||||||
|
render_404
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
render :layout => 'base'
|
||||||
|
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
def add
|
def add
|
||||||
@@ -60,7 +84,9 @@ class UsersController < ApplicationController
|
|||||||
if @user.save
|
if @user.save
|
||||||
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
|
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'list'
|
redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} :
|
||||||
|
{:controller => 'users', :action => 'edit', :id => @user})
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@auth_sources = AuthSource.find(:all)
|
@auth_sources = AuthSource.find(:all)
|
||||||
@@ -72,30 +98,50 @@ class UsersController < ApplicationController
|
|||||||
@user.admin = params[:user][:admin] if params[:user][:admin]
|
@user.admin = params[:user][:admin] if params[:user][:admin]
|
||||||
@user.login = params[:user][:login] if params[:user][:login]
|
@user.login = params[:user][:login] if params[:user][:login]
|
||||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
|
||||||
if @user.update_attributes(params[:user])
|
@user.group_ids = params[:user][:group_ids] if params[:user][:group_ids]
|
||||||
|
@user.attributes = params[:user]
|
||||||
|
# Was the account actived ? (do it before User#save clears the change)
|
||||||
|
was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
|
||||||
|
if @user.save
|
||||||
|
if was_activated
|
||||||
|
Mailer.deliver_account_activated(@user)
|
||||||
|
elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil?
|
||||||
|
Mailer.deliver_account_information(@user, params[:password])
|
||||||
|
end
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
# Give a string to redirect_to otherwise it would use status param as the response code
|
redirect_to :back
|
||||||
redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@auth_sources = AuthSource.find(:all)
|
@auth_sources = AuthSource.find(:all)
|
||||||
@roles = Role.find_all_givable
|
|
||||||
@projects = Project.find(:all, :order => 'name', :conditions => "status=#{Project::STATUS_ACTIVE}") - @user.projects
|
|
||||||
@membership ||= Member.new
|
@membership ||= Member.new
|
||||||
@memberships = @user.memberships
|
rescue ::ActionController::RedirectBackError
|
||||||
|
redirect_to :controller => 'users', :action => 'edit', :id => @user
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit_membership
|
def edit_membership
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
@membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
|
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
|
||||||
@membership.attributes = params[:membership]
|
|
||||||
@membership.save if request.post?
|
@membership.save if request.post?
|
||||||
redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
|
respond_to do |format|
|
||||||
|
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
|
||||||
|
format.js {
|
||||||
|
render(:update) {|page|
|
||||||
|
page.replace_html "tab-content-memberships", :partial => 'users/memberships'
|
||||||
|
page.visual_effect(:highlight, "member-#{@membership.id}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_membership
|
def destroy_membership
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
Member.find(params[:membership_id]).destroy if request.post?
|
@membership = Member.find(params[:membership_id])
|
||||||
redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
|
if request.post? && @membership.deletable?
|
||||||
|
@membership.destroy
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
|
||||||
|
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,32 +16,77 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class VersionsController < ApplicationController
|
class VersionsController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
menu_item :roadmap
|
menu_item :roadmap
|
||||||
before_filter :find_project, :authorize
|
model_object Version
|
||||||
|
before_filter :find_model_object, :except => [:new, :close_completed]
|
||||||
|
before_filter :find_project_from_association, :except => [:new, :close_completed]
|
||||||
|
before_filter :find_project, :only => [:new, :close_completed]
|
||||||
|
before_filter :authorize
|
||||||
|
|
||||||
|
helper :custom_fields
|
||||||
|
helper :projects
|
||||||
|
|
||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def new
|
||||||
if request.post? and @version.update_attributes(params[:version])
|
@version = @project.versions.build
|
||||||
flash[:notice] = l(:notice_successful_update)
|
if params[:version]
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
attributes = params[:version].dup
|
||||||
|
attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
|
||||||
|
@version.attributes = attributes
|
||||||
end
|
end
|
||||||
|
if request.post?
|
||||||
|
if @version.save
|
||||||
|
respond_to do |format|
|
||||||
|
format.html do
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||||
|
end
|
||||||
|
format.js do
|
||||||
|
# IE doesn't support the replace_html rjs method for select box options
|
||||||
|
render(:update) {|page| page.replace "issue_fixed_version_id",
|
||||||
|
content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.js do
|
||||||
|
render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
if request.post? && params[:version]
|
||||||
|
attributes = params[:version].dup
|
||||||
|
attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
|
||||||
|
if @version.update_attributes(attributes)
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def close_completed
|
||||||
|
if request.post?
|
||||||
|
@project.close_completed_versions
|
||||||
|
end
|
||||||
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@version.destroy
|
if @version.fixed_issues.empty?
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
@version.destroy
|
||||||
rescue
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||||
flash[:error] = "Unable to delete version"
|
else
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
flash[:error] = l(:notice_unable_delete_version)
|
||||||
end
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||||
|
end
|
||||||
def destroy_file
|
|
||||||
@version.attachments.find(params[:attachment_id]).destroy
|
|
||||||
flash[:notice] = l(:notice_successful_delete)
|
|
||||||
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_by
|
def status_by
|
||||||
@@ -53,9 +98,8 @@ class VersionsController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_project
|
||||||
@version = Version.find(params[:id])
|
@project = Project.find(params[:project_id])
|
||||||
@project = @version.project
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,31 +16,54 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class WatchersController < ApplicationController
|
class WatchersController < ApplicationController
|
||||||
layout 'base'
|
before_filter :find_project
|
||||||
before_filter :require_login, :find_project, :check_project_privacy
|
before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
|
||||||
|
before_filter :authorize, :only => [:new, :destroy]
|
||||||
|
|
||||||
def add
|
verify :method => :post,
|
||||||
user = User.current
|
:only => [ :watch, :unwatch ],
|
||||||
@watched.add_watcher(user)
|
:render => { :nothing => true, :status => :method_not_allowed }
|
||||||
|
|
||||||
|
def watch
|
||||||
|
if @watched.respond_to?(:visible?) && !@watched.visible?(User.current)
|
||||||
|
render_403
|
||||||
|
else
|
||||||
|
set_watcher(User.current, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def unwatch
|
||||||
|
set_watcher(User.current, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@watcher = Watcher.new(params[:watcher])
|
||||||
|
@watcher.watchable = @watched
|
||||||
|
@watcher.save if request.post?
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :back }
|
format.html { redirect_to :back }
|
||||||
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
format.js do
|
||||||
|
render :update do |page|
|
||||||
|
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue RedirectBackError
|
rescue ::ActionController::RedirectBackError
|
||||||
render :text => 'Watcher added.', :layout => true
|
render :text => 'Watcher added.', :layout => true
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove
|
def destroy
|
||||||
user = User.current
|
@watched.set_watcher(User.find(params[:user_id]), false) if request.post?
|
||||||
@watched.remove_watcher(user)
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :back }
|
format.html { redirect_to :back }
|
||||||
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
format.js do
|
||||||
|
render :update do |page|
|
||||||
|
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue RedirectBackError
|
|
||||||
render :text => 'Watcher removed.', :layout => true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_project
|
||||||
klass = Object.const_get(params[:object_type].camelcase)
|
klass = Object.const_get(params[:object_type].camelcase)
|
||||||
@@ -50,4 +73,29 @@ private
|
|||||||
rescue
|
rescue
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_watcher(user, watching)
|
||||||
|
@watched.set_watcher(user, watching)
|
||||||
|
if params[:replace].present?
|
||||||
|
if params[:replace].is_a? Array
|
||||||
|
replace_ids = params[:replace]
|
||||||
|
else
|
||||||
|
replace_ids = [params[:replace]]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
replace_ids = ['watcher']
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to :back }
|
||||||
|
format.js do
|
||||||
|
render(:update) do |page|
|
||||||
|
replace_ids.each do |replace_id|
|
||||||
|
page.replace_html replace_id, watcher_link(@watched, user, :replace => replace_ids)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue ::ActionController::RedirectBackError
|
||||||
|
render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,10 +16,15 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class WelcomeController < ApplicationController
|
class WelcomeController < ApplicationController
|
||||||
layout 'base'
|
caches_action :robots
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@news = News.latest User.current
|
@news = News.latest User.current
|
||||||
@projects = Project.latest User.current
|
@projects = Project.latest User.current
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def robots
|
||||||
|
@projects = Project.all_public.active
|
||||||
|
render :layout => false, :content_type => 'text/plain'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,20 +18,22 @@
|
|||||||
require 'diff'
|
require 'diff'
|
||||||
|
|
||||||
class WikiController < ApplicationController
|
class WikiController < ApplicationController
|
||||||
layout 'base'
|
default_search_scope :wiki_pages
|
||||||
before_filter :find_wiki, :authorize
|
before_filter :find_wiki, :authorize
|
||||||
|
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
|
||||||
|
|
||||||
verify :method => :post, :only => [:destroy, :destroy_attachment, :protect], :redirect_to => { :action => :index }
|
verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index }
|
||||||
|
|
||||||
helper :attachments
|
helper :attachments
|
||||||
include AttachmentsHelper
|
include AttachmentsHelper
|
||||||
|
helper :watchers
|
||||||
|
|
||||||
# display a page (in editing mode if it doesn't exist)
|
# display a page (in editing mode if it doesn't exist)
|
||||||
def index
|
def index
|
||||||
page_title = params[:page]
|
page_title = params[:page]
|
||||||
@page = @wiki.find_or_new_page(page_title)
|
@page = @wiki.find_or_new_page(page_title)
|
||||||
if @page.new_record?
|
if @page.new_record?
|
||||||
if User.current.allowed_to?(:edit_wiki_pages, @project)
|
if User.current.allowed_to?(:edit_wiki_pages, @project) && editable?
|
||||||
edit
|
edit
|
||||||
render :action => 'edit'
|
render :action => 'edit'
|
||||||
else
|
else
|
||||||
@@ -39,16 +41,23 @@ class WikiController < ApplicationController
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@content = @page.content_for_version(params[:version])
|
if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
|
||||||
if params[:export] == 'html'
|
# Redirects user to the current version if he's not allowed to view previous versions
|
||||||
export = render_to_string :action => 'export', :layout => false
|
redirect_to :version => nil
|
||||||
send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
|
|
||||||
return
|
|
||||||
elsif params[:export] == 'txt'
|
|
||||||
send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@editable = editable?
|
@content = @page.content_for_version(params[:version])
|
||||||
|
if User.current.allowed_to?(:export_wiki_pages, @project)
|
||||||
|
if params[:format] == 'html'
|
||||||
|
export = render_to_string :action => 'export', :layout => false
|
||||||
|
send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
|
||||||
|
return
|
||||||
|
elsif params[:format] == 'txt'
|
||||||
|
send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@editable = editable?
|
||||||
render :action => 'show'
|
render :action => 'show'
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -59,11 +68,16 @@ class WikiController < ApplicationController
|
|||||||
@page.content = WikiContent.new(:page => @page) if @page.new_record?
|
@page.content = WikiContent.new(:page => @page) if @page.new_record?
|
||||||
|
|
||||||
@content = @page.content_for_version(params[:version])
|
@content = @page.content_for_version(params[:version])
|
||||||
@content.text = "h1. #{@page.pretty_title}" if @content.text.blank?
|
@content.text = initial_page_content(@page) if @content.text.blank?
|
||||||
# don't keep previous comment
|
# don't keep previous comment
|
||||||
@content.comments = nil
|
@content.comments = nil
|
||||||
if request.post?
|
if request.get?
|
||||||
|
# To prevent StaleObjectError exception when reverting to a previous version
|
||||||
|
@content.version = @page.content.version
|
||||||
|
else
|
||||||
if !@page.new_record? && @content.text == params[:content][:text]
|
if !@page.new_record? && @content.text == params[:content][:text]
|
||||||
|
attachments = Attachment.attach_files(@page, params[:attachments])
|
||||||
|
render_attachment_warning_if_needed(@page)
|
||||||
# don't save if text wasn't changed
|
# don't save if text wasn't changed
|
||||||
redirect_to :action => 'index', :id => @project, :page => @page.title
|
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||||||
return
|
return
|
||||||
@@ -74,6 +88,9 @@ class WikiController < ApplicationController
|
|||||||
@content.author = User.current
|
@content.author = User.current
|
||||||
# if page is new @page.save will also save content, but not if page isn't a new record
|
# if page is new @page.save will also save content, but not if page isn't a new record
|
||||||
if (@page.new_record? ? @page.save : @content.save)
|
if (@page.new_record? ? @page.save : @content.save)
|
||||||
|
attachments = Attachment.attach_files(@page, params[:attachments])
|
||||||
|
render_attachment_warning_if_needed(@page)
|
||||||
|
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
|
||||||
redirect_to :action => 'index', :id => @project, :page => @page.title
|
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -84,8 +101,7 @@ class WikiController < ApplicationController
|
|||||||
|
|
||||||
# rename a page
|
# rename a page
|
||||||
def rename
|
def rename
|
||||||
@page = @wiki.find_page(params[:page])
|
return render_403 unless editable?
|
||||||
return render_403 unless editable?
|
|
||||||
@page.redirect_existing_links = true
|
@page.redirect_existing_links = true
|
||||||
# used to display the *original* title if some AR validation errors occur
|
# used to display the *original* title if some AR validation errors occur
|
||||||
@original_title = @page.pretty_title
|
@original_title = @page.pretty_title
|
||||||
@@ -96,15 +112,12 @@ class WikiController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def protect
|
def protect
|
||||||
page = @wiki.find_page(params[:page])
|
@page.update_attribute :protected, params[:protected]
|
||||||
page.update_attribute :protected, params[:protected]
|
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||||||
redirect_to :action => 'index', :id => @project, :page => page.title
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# show page history
|
# show page history
|
||||||
def history
|
def history
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
|
|
||||||
@version_count = @page.content.versions.count
|
@version_count = @page.content.versions.count
|
||||||
@version_pages = Paginator.new self, @version_count, per_page_option, params['p']
|
@version_pages = Paginator.new self, @version_count, per_page_option, params['p']
|
||||||
# don't load text
|
# don't load text
|
||||||
@@ -118,21 +131,41 @@ class WikiController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def diff
|
def diff
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
@diff = @page.diff(params[:version], params[:version_from])
|
@diff = @page.diff(params[:version], params[:version_from])
|
||||||
render_404 unless @diff
|
render_404 unless @diff
|
||||||
end
|
end
|
||||||
|
|
||||||
def annotate
|
def annotate
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
@annotate = @page.annotate(params[:version])
|
@annotate = @page.annotate(params[:version])
|
||||||
|
render_404 unless @annotate
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove a wiki page and its history
|
# Removes a wiki page and its history
|
||||||
|
# Children can be either set as root pages, removed or reassigned to another parent page
|
||||||
def destroy
|
def destroy
|
||||||
@page = @wiki.find_page(params[:page])
|
return render_403 unless editable?
|
||||||
return render_403 unless editable?
|
|
||||||
@page.destroy if @page
|
@descendants_count = @page.descendants.size
|
||||||
|
if @descendants_count > 0
|
||||||
|
case params[:todo]
|
||||||
|
when 'nullify'
|
||||||
|
# Nothing to do
|
||||||
|
when 'destroy'
|
||||||
|
# Removes all its descendants
|
||||||
|
@page.descendants.each(&:destroy)
|
||||||
|
when 'reassign'
|
||||||
|
# Reassign children to another parent page
|
||||||
|
reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i)
|
||||||
|
return unless reassign_to
|
||||||
|
@page.children.each do |child|
|
||||||
|
child.update_attribute(:parent, reassign_to)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@reassignable_to = @wiki.pages - @page.self_and_descendants
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@page.destroy
|
||||||
redirect_to :action => 'special', :id => @project, :page => 'Page_index'
|
redirect_to :action => 'special', :id => @project, :page => 'Page_index'
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -150,13 +183,18 @@ class WikiController < ApplicationController
|
|||||||
@pages_by_parent_id = @pages.group_by(&:parent_id)
|
@pages_by_parent_id = @pages.group_by(&:parent_id)
|
||||||
# export wiki to a single html file
|
# export wiki to a single html file
|
||||||
when 'export'
|
when 'export'
|
||||||
@pages = @wiki.pages.find :all, :order => 'title'
|
if User.current.allowed_to?(:export_wiki_pages, @project)
|
||||||
export = render_to_string :action => 'export_multiple', :layout => false
|
@pages = @wiki.pages.find :all, :order => 'title'
|
||||||
send_data(export, :type => 'text/html', :filename => "wiki.html")
|
export = render_to_string :action => 'export_multiple', :layout => false
|
||||||
|
send_data(export, :type => 'text/html', :filename => "wiki.html")
|
||||||
|
else
|
||||||
|
redirect_to :action => 'index', :id => @project, :page => nil
|
||||||
|
end
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
# requested special page doesn't exist, redirect to default page
|
# requested special page doesn't exist, redirect to default page
|
||||||
redirect_to :action => 'index', :id => @project, :page => nil and return
|
redirect_to :action => 'index', :id => @project, :page => nil
|
||||||
|
return
|
||||||
end
|
end
|
||||||
render :action => "special_#{page_title}"
|
render :action => "special_#{page_title}"
|
||||||
end
|
end
|
||||||
@@ -174,16 +212,9 @@ class WikiController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_attachment
|
def add_attachment
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
return render_403 unless editable?
|
return render_403 unless editable?
|
||||||
attach_files(@page, params[:attachments])
|
attachments = Attachment.attach_files(@page, params[:attachments])
|
||||||
redirect_to :action => 'index', :page => @page.title
|
render_attachment_warning_if_needed(@page)
|
||||||
end
|
|
||||||
|
|
||||||
def destroy_attachment
|
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
return render_403 unless editable?
|
|
||||||
@page.attachments.find(params[:attachment_id]).destroy
|
|
||||||
redirect_to :action => 'index', :page => @page.title
|
redirect_to :action => 'index', :page => @page.title
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -197,8 +228,21 @@ private
|
|||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Finds the requested page and returns a 404 error if it doesn't exist
|
||||||
|
def find_existing_page
|
||||||
|
@page = @wiki.find_page(params[:page])
|
||||||
|
render_404 if @page.nil?
|
||||||
|
end
|
||||||
|
|
||||||
# Returns true if the current user is allowed to edit the page, otherwise false
|
# Returns true if the current user is allowed to edit the page, otherwise false
|
||||||
def editable?(page = @page)
|
def editable?(page = @page)
|
||||||
page.editable_by?(User.current)
|
page.editable_by?(User.current)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the default content of a new wiki page
|
||||||
|
def initial_page_content(page)
|
||||||
|
helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
|
||||||
|
extend helper unless self.instance_of?(helper)
|
||||||
|
helper.instance_method(:initial_page_content).bind(self).call(page)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class WikisController < ApplicationController
|
class WikisController < ApplicationController
|
||||||
layout 'base'
|
|
||||||
menu_item :settings
|
menu_item :settings
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :authorize
|
||||||
|
|
||||||
@@ -35,11 +34,4 @@ class WikisController < ApplicationController
|
|||||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'wiki'
|
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'wiki'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
def find_project
|
|
||||||
@project = Project.find(params[:id])
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
render_404
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class WorkflowsController < ApplicationController
|
||||||
|
layout 'admin'
|
||||||
|
|
||||||
|
before_filter :require_admin
|
||||||
|
before_filter :find_roles
|
||||||
|
before_filter :find_trackers
|
||||||
|
|
||||||
|
def index
|
||||||
|
@workflow_counts = Workflow.count_by_tracker_and_role
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@role = Role.find_by_id(params[:role_id])
|
||||||
|
@tracker = Tracker.find_by_id(params[:tracker_id])
|
||||||
|
|
||||||
|
if request.post?
|
||||||
|
Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
|
||||||
|
(params[:issue_status] || []).each { |old, news|
|
||||||
|
news.each { |new|
|
||||||
|
@role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if @role.save
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
|
||||||
|
if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
|
||||||
|
@statuses = @tracker.issue_statuses
|
||||||
|
end
|
||||||
|
@statuses ||= IssueStatus.find(:all, :order => 'position')
|
||||||
|
end
|
||||||
|
|
||||||
|
def copy
|
||||||
|
|
||||||
|
if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
|
||||||
|
@source_tracker = nil
|
||||||
|
else
|
||||||
|
@source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
|
||||||
|
end
|
||||||
|
if params[:source_role_id].blank? || params[:source_role_id] == 'any'
|
||||||
|
@source_role = nil
|
||||||
|
else
|
||||||
|
@source_role = Role.find_by_id(params[:source_role_id].to_i)
|
||||||
|
end
|
||||||
|
|
||||||
|
@target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids])
|
||||||
|
@target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids])
|
||||||
|
|
||||||
|
if request.post?
|
||||||
|
if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
|
||||||
|
flash.now[:error] = l(:error_workflow_copy_source)
|
||||||
|
elsif @target_trackers.nil? || @target_roles.nil?
|
||||||
|
flash.now[:error] = l(:error_workflow_copy_target)
|
||||||
|
else
|
||||||
|
Workflow.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def find_roles
|
||||||
|
@roles = Role.find(:all, :order => 'builtin, position')
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_trackers
|
||||||
|
@trackers = Tracker.find(:all, :order => 'position')
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -17,7 +17,15 @@
|
|||||||
|
|
||||||
module AdminHelper
|
module AdminHelper
|
||||||
def project_status_options_for_select(selected)
|
def project_status_options_for_select(selected)
|
||||||
options_for_select([[l(:label_all), "*"],
|
options_for_select([[l(:label_all), ''],
|
||||||
[l(:status_active), 1]], selected)
|
[l(:status_active), 1]], selected)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def css_project_classes(project)
|
||||||
|
s = 'project'
|
||||||
|
s << ' root' if project.root?
|
||||||
|
s << ' child' if project.child?
|
||||||
|
s << (project.leaf? ? ' leaf' : ' parent')
|
||||||
|
s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+501
-240
@@ -5,26 +5,27 @@
|
|||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require 'coderay'
|
require 'forwardable'
|
||||||
require 'coderay/helpers/file_type'
|
require 'cgi'
|
||||||
|
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
include Redmine::WikiFormatting::Macros::Definitions
|
include Redmine::WikiFormatting::Macros::Definitions
|
||||||
|
include Redmine::I18n
|
||||||
|
include GravatarHelper::PublicMethods
|
||||||
|
|
||||||
|
extend Forwardable
|
||||||
|
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
|
||||||
|
|
||||||
def current_role
|
|
||||||
@current_role ||= User.current.role_for_project(@project)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return true if user is authorized for controller/action, otherwise false
|
# Return true if user is authorized for controller/action, otherwise false
|
||||||
def authorize_for(controller, action)
|
def authorize_for(controller, action)
|
||||||
User.current.allowed_to?({:controller => controller, :action => action}, @project)
|
User.current.allowed_to?({:controller => controller, :action => action}, @project)
|
||||||
@@ -35,18 +36,53 @@ module ApplicationHelper
|
|||||||
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display a link to user's account page
|
# Display a link to remote if user is authorized
|
||||||
def link_to_user(user)
|
def link_to_remote_if_authorized(name, options = {}, html_options = nil)
|
||||||
user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
|
url = options[:url] || {}
|
||||||
|
link_to_remote(name, options, html_options) if authorize_for(url[:controller] || params[:controller], url[:action])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Displays a link to user's account page if active
|
||||||
|
def link_to_user(user, options={})
|
||||||
|
if user.is_a?(User)
|
||||||
|
name = h(user.name(options[:format]))
|
||||||
|
if user.active?
|
||||||
|
link_to name, :controller => 'users', :action => 'show', :id => user
|
||||||
|
else
|
||||||
|
name
|
||||||
|
end
|
||||||
|
else
|
||||||
|
h(user.to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Displays a link to +issue+ with its subject.
|
||||||
|
# Examples:
|
||||||
|
#
|
||||||
|
# link_to_issue(issue) # => Defect #6: This is the subject
|
||||||
|
# link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
|
||||||
|
# link_to_issue(issue, :subject => false) # => Defect #6
|
||||||
|
# link_to_issue(issue, :project => true) # => Foo - Defect #6
|
||||||
|
#
|
||||||
def link_to_issue(issue, options={})
|
def link_to_issue(issue, options={})
|
||||||
options[:class] ||= ''
|
title = nil
|
||||||
options[:class] << ' issue'
|
subject = nil
|
||||||
options[:class] << ' closed' if issue.closed?
|
if options[:subject] == false
|
||||||
link_to "#{issue.tracker.name} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue}, options
|
title = truncate(issue.subject, :length => 60)
|
||||||
|
else
|
||||||
|
subject = issue.subject
|
||||||
|
if options[:truncate]
|
||||||
|
subject = truncate(subject, :length => options[:truncate])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
s = link_to "#{issue.tracker} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue},
|
||||||
|
:class => issue.css_classes,
|
||||||
|
:title => title
|
||||||
|
s << ": #{h subject}" if subject
|
||||||
|
s = "#{h issue.project} - " + s if options[:project]
|
||||||
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generates a link to an attachment.
|
# Generates a link to an attachment.
|
||||||
# Options:
|
# Options:
|
||||||
# * :text - Link text (default to attachment filename)
|
# * :text - Link text (default to attachment filename)
|
||||||
@@ -54,140 +90,303 @@ module ApplicationHelper
|
|||||||
def link_to_attachment(attachment, options={})
|
def link_to_attachment(attachment, options={})
|
||||||
text = options.delete(:text) || attachment.filename
|
text = options.delete(:text) || attachment.filename
|
||||||
action = options.delete(:download) ? 'download' : 'show'
|
action = options.delete(:download) ? 'download' : 'show'
|
||||||
|
|
||||||
link_to(h(text), {:controller => 'attachments', :action => action, :id => attachment, :filename => attachment.filename }, options)
|
link_to(h(text), {:controller => 'attachments', :action => action, :id => attachment, :filename => attachment.filename }, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generates a link to a SCM revision
|
||||||
|
# Options:
|
||||||
|
# * :text - Link text (default to the formatted revision)
|
||||||
|
def link_to_revision(revision, project, options={})
|
||||||
|
text = options.delete(:text) || format_revision(revision)
|
||||||
|
|
||||||
|
link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision}, :title => l(:label_revision_id, revision))
|
||||||
|
end
|
||||||
|
|
||||||
def toggle_link(name, id, options={})
|
def toggle_link(name, id, options={})
|
||||||
onclick = "Element.toggle('#{id}'); "
|
onclick = "Element.toggle('#{id}'); "
|
||||||
onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
|
onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
|
||||||
onclick << "return false;"
|
onclick << "return false;"
|
||||||
link_to(name, "#", :onclick => onclick)
|
link_to(name, "#", :onclick => onclick)
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_to_function(name, function, html_options = {})
|
def image_to_function(name, function, html_options = {})
|
||||||
html_options.symbolize_keys!
|
html_options.symbolize_keys!
|
||||||
tag(:input, html_options.merge({
|
tag(:input, html_options.merge({
|
||||||
:type => "image", :src => image_path(name),
|
:type => "image", :src => image_path(name),
|
||||||
:onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
|
:onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
|
||||||
}))
|
}))
|
||||||
end
|
end
|
||||||
|
|
||||||
def prompt_to_remote(name, text, param, url, html_options = {})
|
def prompt_to_remote(name, text, param, url, html_options = {})
|
||||||
html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
|
html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
|
||||||
link_to name, {}, html_options
|
link_to name, {}, html_options
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_date(date)
|
def format_activity_title(text)
|
||||||
return nil unless date
|
h(truncate_single_line(text, :length => 100))
|
||||||
# "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
|
|
||||||
@date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
|
|
||||||
date.strftime(@date_format)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_time(time, include_date = true)
|
def format_activity_day(date)
|
||||||
return nil unless time
|
date == Date.today ? l(:label_today).titleize : format_date(date)
|
||||||
time = time.to_time if time.is_a?(String)
|
|
||||||
zone = User.current.time_zone
|
|
||||||
local = zone ? time.in_time_zone(zone) : (time.utc? ? time.utc_to_local : time)
|
|
||||||
@date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
|
|
||||||
@time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
|
|
||||||
include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def format_activity_description(text)
|
||||||
|
h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "<br />")
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_version_name(version)
|
||||||
|
if version.project == @project
|
||||||
|
h(version)
|
||||||
|
else
|
||||||
|
h("#{version.project} - #{version}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def due_date_distance_in_words(date)
|
||||||
|
if date
|
||||||
|
l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_page_hierarchy(pages, node=nil)
|
||||||
|
content = ''
|
||||||
|
if pages[node]
|
||||||
|
content << "<ul class=\"pages-hierarchy\">\n"
|
||||||
|
pages[node].each do |page|
|
||||||
|
content << "<li>"
|
||||||
|
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :id => page.project, :page => page.title},
|
||||||
|
:title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
|
||||||
|
content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
|
||||||
|
content << "</li>\n"
|
||||||
|
end
|
||||||
|
content << "</ul>\n"
|
||||||
|
end
|
||||||
|
content
|
||||||
|
end
|
||||||
|
|
||||||
|
# Renders flash messages
|
||||||
|
def render_flash_messages
|
||||||
|
s = ''
|
||||||
|
flash.each do |k,v|
|
||||||
|
s << content_tag('div', v, :class => "flash #{k}")
|
||||||
|
end
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
|
# Renders tabs and their content
|
||||||
|
def render_tabs(tabs)
|
||||||
|
if tabs.any?
|
||||||
|
render :partial => 'common/tabs', :locals => {:tabs => tabs}
|
||||||
|
else
|
||||||
|
content_tag 'p', l(:label_no_data), :class => "nodata"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Renders the project quick-jump box
|
||||||
|
def render_project_jump_box
|
||||||
|
# Retrieve them now to avoid a COUNT query
|
||||||
|
projects = User.current.projects.all
|
||||||
|
if projects.any?
|
||||||
|
s = '<select onchange="if (this.value != \'\') { window.location = this.value; }">' +
|
||||||
|
"<option value=''>#{ l(:label_jump_to_a_project) }</option>" +
|
||||||
|
'<option value="" disabled="disabled">---</option>'
|
||||||
|
s << project_tree_options_for_select(projects, :selected => @project) do |p|
|
||||||
|
{ :value => url_for(:controller => 'projects', :action => 'show', :id => p, :jump => current_menu_item) }
|
||||||
|
end
|
||||||
|
s << '</select>'
|
||||||
|
s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def project_tree_options_for_select(projects, options = {})
|
||||||
|
s = ''
|
||||||
|
project_tree(projects) do |project, level|
|
||||||
|
name_prefix = (level > 0 ? (' ' * 2 * level + '» ') : '')
|
||||||
|
tag_options = {:value => project.id}
|
||||||
|
if project == options[:selected] || (options[:selected].respond_to?(:include?) && options[:selected].include?(project))
|
||||||
|
tag_options[:selected] = 'selected'
|
||||||
|
else
|
||||||
|
tag_options[:selected] = nil
|
||||||
|
end
|
||||||
|
tag_options.merge!(yield(project)) if block_given?
|
||||||
|
s << content_tag('option', name_prefix + h(project), tag_options)
|
||||||
|
end
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
|
# Yields the given block for each project with its level in the tree
|
||||||
|
def project_tree(projects, &block)
|
||||||
|
ancestors = []
|
||||||
|
projects.sort_by(&:lft).each do |project|
|
||||||
|
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
||||||
|
ancestors.pop
|
||||||
|
end
|
||||||
|
yield project, ancestors.size
|
||||||
|
ancestors << project
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def project_nested_ul(projects, &block)
|
||||||
|
s = ''
|
||||||
|
if projects.any?
|
||||||
|
ancestors = []
|
||||||
|
projects.sort_by(&:lft).each do |project|
|
||||||
|
if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
|
||||||
|
s << "<ul>\n"
|
||||||
|
else
|
||||||
|
ancestors.pop
|
||||||
|
s << "</li>"
|
||||||
|
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
||||||
|
ancestors.pop
|
||||||
|
s << "</ul></li>\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
s << "<li>"
|
||||||
|
s << yield(project).to_s
|
||||||
|
ancestors << project
|
||||||
|
end
|
||||||
|
s << ("</li></ul>\n" * ancestors.size)
|
||||||
|
end
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
|
def principals_check_box_tags(name, principals)
|
||||||
|
s = ''
|
||||||
|
principals.sort.each do |principal|
|
||||||
|
s << "<label>#{ check_box_tag name, principal.id, false } #{h principal}</label>\n"
|
||||||
|
end
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
# Truncates and returns the string as a single line
|
# Truncates and returns the string as a single line
|
||||||
def truncate_single_line(string, *args)
|
def truncate_single_line(string, *args)
|
||||||
truncate(string, *args).gsub(%r{[\r\n]+}m, ' ')
|
truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Truncates at line break after 250 characters or options[:length]
|
||||||
|
def truncate_lines(string, options={})
|
||||||
|
length = options[:length] || 250
|
||||||
|
if string.to_s =~ /\A(.{#{length}}.*?)$/m
|
||||||
|
"#{$1}..."
|
||||||
|
else
|
||||||
|
string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def html_hours(text)
|
def html_hours(text)
|
||||||
text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
|
text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
|
||||||
end
|
end
|
||||||
|
|
||||||
def authoring(created, author)
|
def authoring(created, author, options={})
|
||||||
time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
|
l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created))
|
||||||
author_tag = (author.is_a?(User) && !author.anonymous?) ? link_to(h(author), :controller => 'account', :action => 'show', :id => author) : h(author || 'Anonymous')
|
|
||||||
l(:label_added_time_by, author_tag, time_tag)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def l_or_humanize(s)
|
def time_tag(time)
|
||||||
l_has_string?("label_#{s}".to_sym) ? l("label_#{s}".to_sym) : s.to_s.humanize
|
text = distance_of_time_in_words(Time.now, time)
|
||||||
end
|
if @project
|
||||||
|
link_to(text, {:controller => 'projects', :action => 'activity', :id => @project, :from => time.to_date}, :title => format_time(time))
|
||||||
def day_name(day)
|
else
|
||||||
l(:general_day_names).split(',')[day-1]
|
content_tag('acronym', text, :title => format_time(time))
|
||||||
end
|
end
|
||||||
|
|
||||||
def month_name(month)
|
|
||||||
l(:actionview_datehelper_select_month_names).split(',')[month-1]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def syntax_highlight(name, content)
|
def syntax_highlight(name, content)
|
||||||
type = CodeRay::FileType[name]
|
Redmine::SyntaxHighlighting.highlight_by_filename(content, name)
|
||||||
type ? CodeRay.scan(content, type).html : h(content)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_path_param(path)
|
def to_path_param(path)
|
||||||
path.to_s.split(%r{[/\\]}).select {|p| !p.blank?}
|
path.to_s.split(%r{[/\\]}).select {|p| !p.blank?}
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_links_full(paginator, count=nil, options={})
|
def pagination_links_full(paginator, count=nil, options={})
|
||||||
page_param = options.delete(:page_param) || :page
|
page_param = options.delete(:page_param) || :page
|
||||||
|
per_page_links = options.delete(:per_page_links)
|
||||||
url_param = params.dup
|
url_param = params.dup
|
||||||
# don't reuse params if filters are present
|
# don't reuse query params if filters are present
|
||||||
url_param.clear if url_param.has_key?(:set_filter)
|
url_param.merge!(:fields => nil, :values => nil, :operators => nil) if url_param.delete(:set_filter)
|
||||||
|
|
||||||
html = ''
|
html = ''
|
||||||
html << link_to_remote(('« ' + l(:label_previous)),
|
if paginator.current.previous
|
||||||
{:update => 'content',
|
html << link_to_remote_content_update('« ' + l(:label_previous), url_param.merge(page_param => paginator.current.previous)) + ' '
|
||||||
:url => url_param.merge(page_param => paginator.current.previous),
|
end
|
||||||
:complete => 'window.scrollTo(0,0)'},
|
|
||||||
{:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
|
|
||||||
|
|
||||||
html << (pagination_links_each(paginator, options) do |n|
|
html << (pagination_links_each(paginator, options) do |n|
|
||||||
link_to_remote(n.to_s,
|
link_to_remote_content_update(n.to_s, url_param.merge(page_param => n))
|
||||||
{:url => {:params => url_param.merge(page_param => n)},
|
|
||||||
:update => 'content',
|
|
||||||
:complete => 'window.scrollTo(0,0)'},
|
|
||||||
{:href => url_for(:params => url_param.merge(page_param => n))})
|
|
||||||
end || '')
|
end || '')
|
||||||
|
|
||||||
html << ' ' + link_to_remote((l(:label_next) + ' »'),
|
if paginator.current.next
|
||||||
{:update => 'content',
|
html << ' ' + link_to_remote_content_update((l(:label_next) + ' »'), url_param.merge(page_param => paginator.current.next))
|
||||||
:url => url_param.merge(page_param => paginator.current.next),
|
|
||||||
:complete => 'window.scrollTo(0,0)'},
|
|
||||||
{:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
|
|
||||||
|
|
||||||
unless count.nil?
|
|
||||||
html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
html
|
unless count.nil?
|
||||||
|
html << " (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})"
|
||||||
|
if per_page_links != false && links = per_page_links(paginator.items_per_page)
|
||||||
|
html << " | #{links}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
html
|
||||||
end
|
end
|
||||||
|
|
||||||
def per_page_links(selected=nil)
|
def per_page_links(selected=nil)
|
||||||
url_param = params.dup
|
url_param = params.dup
|
||||||
url_param.clear if url_param.has_key?(:set_filter)
|
url_param.clear if url_param.has_key?(:set_filter)
|
||||||
|
|
||||||
links = Setting.per_page_options_array.collect do |n|
|
links = Setting.per_page_options_array.collect do |n|
|
||||||
n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
|
n == selected ? n : link_to_remote(n, {:update => "content",
|
||||||
|
:url => params.dup.merge(:per_page => n),
|
||||||
|
:method => :get},
|
||||||
{:href => url_for(url_param.merge(:per_page => n))})
|
{:href => url_for(url_param.merge(:per_page => n))})
|
||||||
end
|
end
|
||||||
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
|
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reorder_links(name, url)
|
||||||
|
link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), :method => :post, :title => l(:label_sort_highest)) +
|
||||||
|
link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), url.merge({"#{name}[move_to]" => 'higher'}), :method => :post, :title => l(:label_sort_higher)) +
|
||||||
|
link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), url.merge({"#{name}[move_to]" => 'lower'}), :method => :post, :title => l(:label_sort_lower)) +
|
||||||
|
link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), url.merge({"#{name}[move_to]" => 'lowest'}), :method => :post, :title => l(:label_sort_lowest))
|
||||||
|
end
|
||||||
|
|
||||||
def breadcrumb(*args)
|
def breadcrumb(*args)
|
||||||
elements = args.flatten
|
elements = args.flatten
|
||||||
elements.any? ? content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') : nil
|
elements.any? ? content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def other_formats_links(&block)
|
||||||
|
concat('<p class="other-formats">' + l(:label_export_to))
|
||||||
|
yield Redmine::Views::OtherFormatsBuilder.new(self)
|
||||||
|
concat('</p>')
|
||||||
|
end
|
||||||
|
|
||||||
|
def page_header_title
|
||||||
|
if @project.nil? || @project.new_record?
|
||||||
|
h(Setting.app_title)
|
||||||
|
else
|
||||||
|
b = []
|
||||||
|
ancestors = (@project.root? ? [] : @project.ancestors.visible)
|
||||||
|
if ancestors.any?
|
||||||
|
root = ancestors.shift
|
||||||
|
b << link_to(h(root), {:controller => 'projects', :action => 'show', :id => root, :jump => current_menu_item}, :class => 'root')
|
||||||
|
if ancestors.size > 2
|
||||||
|
b << '…'
|
||||||
|
ancestors = ancestors[-2, 2]
|
||||||
|
end
|
||||||
|
b += ancestors.collect {|p| link_to(h(p), {:controller => 'projects', :action => 'show', :id => p, :jump => current_menu_item}, :class => 'ancestor') }
|
||||||
|
end
|
||||||
|
b << h(@project)
|
||||||
|
b.join(' » ')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def html_title(*args)
|
def html_title(*args)
|
||||||
if args.empty?
|
if args.empty?
|
||||||
title = []
|
title = []
|
||||||
title << @project.name if @project
|
title << @project.name if @project
|
||||||
title += @html_title if @html_title
|
title += @html_title if @html_title
|
||||||
title << Setting.app_title
|
title << Setting.app_title
|
||||||
title.compact.join(' - ')
|
title.select {|t| !t.blank? }.join(' - ')
|
||||||
else
|
else
|
||||||
@html_title ||= []
|
@html_title ||= []
|
||||||
@html_title += args
|
@html_title += args
|
||||||
@@ -210,63 +409,87 @@ module ApplicationHelper
|
|||||||
text = args.shift
|
text = args.shift
|
||||||
when 2
|
when 2
|
||||||
obj = args.shift
|
obj = args.shift
|
||||||
text = obj.send(args.shift).to_s
|
attr = args.shift
|
||||||
|
text = obj.send(attr).to_s
|
||||||
else
|
else
|
||||||
raise ArgumentError, 'invalid arguments to textilizable'
|
raise ArgumentError, 'invalid arguments to textilizable'
|
||||||
end
|
end
|
||||||
return '' if text.blank?
|
return '' if text.blank?
|
||||||
|
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
|
||||||
only_path = options.delete(:only_path) == false ? false : true
|
only_path = options.delete(:only_path) == false ? false : true
|
||||||
|
|
||||||
# when using an image link, try to use an attachment, if possible
|
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
|
||||||
attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
|
|
||||||
|
parse_non_pre_blocks(text) do |text|
|
||||||
if attachments
|
[:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
|
||||||
text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
|
send method_name, text, project, obj, attr, only_path, options
|
||||||
style = $1
|
end
|
||||||
filename = $6
|
end
|
||||||
rf = Regexp.new(filename, Regexp::IGNORECASE)
|
end
|
||||||
# search for the picture in attachments
|
|
||||||
if found = attachments.detect { |att| att.filename =~ rf }
|
def parse_non_pre_blocks(text)
|
||||||
image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
|
s = StringScanner.new(text)
|
||||||
desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1")
|
tags = []
|
||||||
alt = desc.blank? ? nil : "(#{desc})"
|
parsed = ''
|
||||||
"!#{style}#{image_url}#{alt}!"
|
while !s.eos?
|
||||||
|
s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
|
||||||
|
text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
|
||||||
|
if tags.empty?
|
||||||
|
yield text
|
||||||
|
end
|
||||||
|
parsed << text
|
||||||
|
if tag
|
||||||
|
if closing
|
||||||
|
if tags.last == tag.downcase
|
||||||
|
tags.pop
|
||||||
|
end
|
||||||
else
|
else
|
||||||
"!#{style}#{filename}!"
|
tags << tag.downcase
|
||||||
|
end
|
||||||
|
parsed << full_tag
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# Close any non closing tags
|
||||||
|
while tag = tags.pop
|
||||||
|
parsed << "</#{tag}>"
|
||||||
|
end
|
||||||
|
parsed
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_inline_attachments(text, project, obj, attr, only_path, options)
|
||||||
|
# when using an image link, try to use an attachment, if possible
|
||||||
|
if options[:attachments] || (obj && obj.respond_to?(:attachments))
|
||||||
|
attachments = nil
|
||||||
|
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
|
||||||
|
filename, ext, alt, alttext = $1.downcase, $2, $3, $4
|
||||||
|
attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
|
||||||
|
# search for the picture in attachments
|
||||||
|
if found = attachments.detect { |att| att.filename.downcase == filename }
|
||||||
|
image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
|
||||||
|
desc = found.description.to_s.gsub('"', '')
|
||||||
|
if !desc.blank? && alttext.blank?
|
||||||
|
alt = " title=\"#{desc}\" alt=\"#{desc}\""
|
||||||
|
end
|
||||||
|
"src=\"#{image_url}\"#{alt}"
|
||||||
|
else
|
||||||
|
m
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
text = (Setting.text_formatting == 'textile') ?
|
|
||||||
Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } :
|
|
||||||
simple_format(auto_link(h(text)))
|
|
||||||
|
|
||||||
# different methods for formatting wiki links
|
# Wiki links
|
||||||
case options[:wiki_links]
|
#
|
||||||
when :local
|
# Examples:
|
||||||
# used for local links to html files
|
# [[mypage]]
|
||||||
format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" }
|
# [[mypage|mytext]]
|
||||||
when :anchor
|
# wiki links can refer other project wikis, using project name or identifier:
|
||||||
# used for single-file wiki export
|
# [[project:]] -> wiki starting page
|
||||||
format_wiki_link = Proc.new {|project, title, anchor| "##{title}" }
|
# [[project:|mytext]]
|
||||||
else
|
# [[project:mypage]]
|
||||||
format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
|
# [[project:mypage|mytext]]
|
||||||
end
|
def parse_wiki_links(text, project, obj, attr, only_path, options)
|
||||||
|
text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
|
||||||
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
|
|
||||||
|
|
||||||
# Wiki links
|
|
||||||
#
|
|
||||||
# Examples:
|
|
||||||
# [[mypage]]
|
|
||||||
# [[mypage|mytext]]
|
|
||||||
# wiki links can refer other project wikis, using project name or identifier:
|
|
||||||
# [[project:]] -> wiki starting page
|
|
||||||
# [[project:|mytext]]
|
|
||||||
# [[project:mypage]]
|
|
||||||
# [[project:mypage|mytext]]
|
|
||||||
text = text.gsub(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
|
|
||||||
link_project = project
|
link_project = project
|
||||||
esc, all, page, title = $1, $2, $3, $5
|
esc, all, page, title = $1, $2, $3, $5
|
||||||
if esc.nil?
|
if esc.nil?
|
||||||
@@ -275,7 +498,7 @@ module ApplicationHelper
|
|||||||
page = $2
|
page = $2
|
||||||
title ||= $1 if page.blank?
|
title ||= $1 if page.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
if link_project && link_project.wiki
|
if link_project && link_project.wiki
|
||||||
# extract anchor
|
# extract anchor
|
||||||
anchor = nil
|
anchor = nil
|
||||||
@@ -284,60 +507,68 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
# check if page exists
|
# check if page exists
|
||||||
wiki_page = link_project.wiki.find_page(page)
|
wiki_page = link_project.wiki.find_page(page)
|
||||||
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor),
|
url = case options[:wiki_links]
|
||||||
:class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
when :local; "#{title}.html"
|
||||||
|
when :anchor; "##{title}" # used for single-file wiki export
|
||||||
|
else
|
||||||
|
url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
|
||||||
|
end
|
||||||
|
link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
||||||
else
|
else
|
||||||
# project or wiki doesn't exist
|
# project or wiki doesn't exist
|
||||||
title || page
|
all
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
all
|
all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
# Redmine links
|
|
||||||
#
|
# Redmine links
|
||||||
# Examples:
|
#
|
||||||
# Issues:
|
# Examples:
|
||||||
# #52 -> Link to issue #52
|
# Issues:
|
||||||
# Changesets:
|
# #52 -> Link to issue #52
|
||||||
# r52 -> Link to revision 52
|
# Changesets:
|
||||||
# commit:a85130f -> Link to scmid starting with a85130f
|
# r52 -> Link to revision 52
|
||||||
# Documents:
|
# commit:a85130f -> Link to scmid starting with a85130f
|
||||||
# document#17 -> Link to document with id 17
|
# Documents:
|
||||||
# document:Greetings -> Link to the document with title "Greetings"
|
# document#17 -> Link to document with id 17
|
||||||
# document:"Some document" -> Link to the document with title "Some document"
|
# document:Greetings -> Link to the document with title "Greetings"
|
||||||
# Versions:
|
# document:"Some document" -> Link to the document with title "Some document"
|
||||||
# version#3 -> Link to version with id 3
|
# Versions:
|
||||||
# version:1.0.0 -> Link to version named "1.0.0"
|
# version#3 -> Link to version with id 3
|
||||||
# version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
|
# version:1.0.0 -> Link to version named "1.0.0"
|
||||||
# Attachments:
|
# version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
|
||||||
# attachment:file.zip -> Link to the attachment of the current object named file.zip
|
# Attachments:
|
||||||
# Source files:
|
# attachment:file.zip -> Link to the attachment of the current object named file.zip
|
||||||
# source:some/file -> Link to the file located at /some/file in the project's repository
|
# Source files:
|
||||||
# source:some/file@52 -> Link to the file's revision 52
|
# source:some/file -> Link to the file located at /some/file in the project's repository
|
||||||
# source:some/file#L120 -> Link to line 120 of the file
|
# source:some/file@52 -> Link to the file's revision 52
|
||||||
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
|
# source:some/file#L120 -> Link to line 120 of the file
|
||||||
# export:some/file -> Force the download of the file
|
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
|
||||||
text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|\s|<|$)}) do |m|
|
# export:some/file -> Force the download of the file
|
||||||
leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
|
# Forum messages:
|
||||||
|
# message#1218 -> Link to message with id 1218
|
||||||
|
def parse_redmine_links(text, project, obj, attr, only_path, options)
|
||||||
|
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
|
||||||
|
leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8
|
||||||
link = nil
|
link = nil
|
||||||
if esc.nil?
|
if esc.nil?
|
||||||
if prefix.nil? && sep == 'r'
|
if prefix.nil? && sep == 'r'
|
||||||
if project && (changeset = project.changesets.find_by_revision(oid))
|
if project && (changeset = project.changesets.find_by_revision(identifier))
|
||||||
link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
|
link = link_to("r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
||||||
:class => 'changeset',
|
:class => 'changeset',
|
||||||
:title => truncate_single_line(changeset.comments, 100))
|
:title => truncate_single_line(changeset.comments, :length => 100))
|
||||||
end
|
end
|
||||||
elsif sep == '#'
|
elsif sep == '#'
|
||||||
oid = oid.to_i
|
oid = identifier.to_i
|
||||||
case prefix
|
case prefix
|
||||||
when nil
|
when nil
|
||||||
if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
|
if issue = Issue.visible.find_by_id(oid, :include => :status)
|
||||||
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
|
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
|
||||||
:class => (issue.closed? ? 'issue closed' : 'issue'),
|
:class => issue.css_classes,
|
||||||
:title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
|
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
|
||||||
link = content_tag('del', link) if issue.closed?
|
|
||||||
end
|
end
|
||||||
when 'document'
|
when 'document'
|
||||||
if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
|
if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
|
||||||
@@ -349,10 +580,25 @@ module ApplicationHelper
|
|||||||
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
||||||
:class => 'version'
|
:class => 'version'
|
||||||
end
|
end
|
||||||
|
when 'message'
|
||||||
|
if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
|
||||||
|
link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path,
|
||||||
|
:controller => 'messages',
|
||||||
|
:action => 'show',
|
||||||
|
:board_id => message.board,
|
||||||
|
:id => message.root,
|
||||||
|
:anchor => (message.parent ? "message-#{message.id}" : nil)},
|
||||||
|
:class => 'message'
|
||||||
|
end
|
||||||
|
when 'project'
|
||||||
|
if p = Project.visible.find_by_id(oid)
|
||||||
|
link = link_to h(p.name), {:only_path => only_path, :controller => 'projects', :action => 'show', :id => p},
|
||||||
|
:class => 'project'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
elsif sep == ':'
|
elsif sep == ':'
|
||||||
# removes the double quotes if any
|
# removes the double quotes if any
|
||||||
name = oid.gsub(%r{^"(.*)"$}, "\\1")
|
name = identifier.gsub(%r{^"(.*)"$}, "\\1")
|
||||||
case prefix
|
case prefix
|
||||||
when 'document'
|
when 'document'
|
||||||
if project && document = project.documents.find_by_title(name)
|
if project && document = project.documents.find_by_title(name)
|
||||||
@@ -368,7 +614,7 @@ module ApplicationHelper
|
|||||||
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
||||||
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
||||||
:class => 'changeset',
|
:class => 'changeset',
|
||||||
:title => truncate_single_line(changeset.comments, 100)
|
:title => truncate_single_line(changeset.comments, :length => 100)
|
||||||
end
|
end
|
||||||
when 'source', 'export'
|
when 'source', 'export'
|
||||||
if project && project.repository
|
if project && project.repository
|
||||||
@@ -382,19 +628,23 @@ module ApplicationHelper
|
|||||||
:class => (prefix == 'export' ? 'source download' : 'source')
|
:class => (prefix == 'export' ? 'source download' : 'source')
|
||||||
end
|
end
|
||||||
when 'attachment'
|
when 'attachment'
|
||||||
|
attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
|
||||||
if attachments && attachment = attachments.detect {|a| a.filename == name }
|
if attachments && attachment = attachments.detect {|a| a.filename == name }
|
||||||
link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
|
link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
|
||||||
:class => 'attachment'
|
:class => 'attachment'
|
||||||
end
|
end
|
||||||
|
when 'project'
|
||||||
|
if p = Project.visible.find(:first, :conditions => ["identifier = :s OR LOWER(name) = :s", {:s => name.downcase}])
|
||||||
|
link = link_to h(p.name), {:only_path => only_path, :controller => 'projects', :action => 'show', :id => p},
|
||||||
|
:class => 'project'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
leading + (link || "#{prefix}#{sep}#{oid}")
|
leading + (link || "#{prefix}#{sep}#{identifier}")
|
||||||
end
|
end
|
||||||
|
|
||||||
text
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Same as Rails' simple_format helper without using paragraphs
|
# Same as Rails' simple_format helper without using paragraphs
|
||||||
def simple_format_without_paragraph(text)
|
def simple_format_without_paragraph(text)
|
||||||
text.to_s.
|
text.to_s.
|
||||||
@@ -402,86 +652,68 @@ module ApplicationHelper
|
|||||||
gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
|
gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
|
||||||
gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_messages_for(object_name, options = {})
|
|
||||||
options = options.symbolize_keys
|
|
||||||
object = instance_variable_get("@#{object_name}")
|
|
||||||
if object && !object.errors.empty?
|
|
||||||
# build full_messages here with controller current language
|
|
||||||
full_messages = []
|
|
||||||
object.errors.each do |attr, msg|
|
|
||||||
next if msg.nil?
|
|
||||||
msg = msg.first if msg.is_a? Array
|
|
||||||
if attr == "base"
|
|
||||||
full_messages << l(msg)
|
|
||||||
else
|
|
||||||
full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# retrieve custom values error messages
|
|
||||||
if object.errors[:custom_values]
|
|
||||||
object.custom_values.each do |v|
|
|
||||||
v.errors.each do |attr, msg|
|
|
||||||
next if msg.nil?
|
|
||||||
msg = msg.first if msg.is_a? Array
|
|
||||||
full_messages << "« " + v.custom_field.name + " » " + l(msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
content_tag("div",
|
|
||||||
content_tag(
|
|
||||||
options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
|
|
||||||
) +
|
|
||||||
content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
|
|
||||||
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
|
|
||||||
)
|
|
||||||
else
|
|
||||||
""
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def lang_options_for_select(blank=true)
|
def lang_options_for_select(blank=true)
|
||||||
(blank ? [["(auto)", ""]] : []) +
|
(blank ? [["(auto)", ""]] : []) +
|
||||||
GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
|
valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
|
||||||
end
|
end
|
||||||
|
|
||||||
def label_tag_for(name, option_tags = nil, options = {})
|
def label_tag_for(name, option_tags = nil, options = {})
|
||||||
label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
|
label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
|
||||||
content_tag("label", label_text)
|
content_tag("label", label_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def labelled_tabular_form_for(name, object, options, &proc)
|
def labelled_tabular_form_for(name, object, options, &proc)
|
||||||
options[:html] ||= {}
|
options[:html] ||= {}
|
||||||
options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
|
options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
|
||||||
form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
|
form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def back_url_hidden_field_tag
|
def back_url_hidden_field_tag
|
||||||
back_url = params[:back_url] || request.env['HTTP_REFERER']
|
back_url = params[:back_url] || request.env['HTTP_REFERER']
|
||||||
hidden_field_tag('back_url', back_url) unless back_url.blank?
|
back_url = CGI.unescape(back_url.to_s)
|
||||||
|
hidden_field_tag('back_url', CGI.escape(back_url)) unless back_url.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_all_links(form_name)
|
def check_all_links(form_name)
|
||||||
link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
|
link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
|
||||||
" | " +
|
" | " +
|
||||||
link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
|
link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
|
||||||
end
|
end
|
||||||
|
|
||||||
def progress_bar(pcts, options={})
|
def progress_bar(pcts, options={})
|
||||||
pcts = [pcts, pcts] unless pcts.is_a?(Array)
|
pcts = [pcts, pcts] unless pcts.is_a?(Array)
|
||||||
|
pcts = pcts.collect(&:round)
|
||||||
pcts[1] = pcts[1] - pcts[0]
|
pcts[1] = pcts[1] - pcts[0]
|
||||||
pcts << (100 - pcts[1] - pcts[0])
|
pcts << (100 - pcts[1] - pcts[0])
|
||||||
width = options[:width] || '100px;'
|
width = options[:width] || '100px;'
|
||||||
legend = options[:legend] || ''
|
legend = options[:legend] || ''
|
||||||
content_tag('table',
|
content_tag('table',
|
||||||
content_tag('tr',
|
content_tag('tr',
|
||||||
(pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
|
(pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : '') +
|
||||||
(pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
|
(pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : '') +
|
||||||
(pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
|
(pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : '')
|
||||||
), :class => 'progress', :style => "width: #{width};") +
|
), :class => 'progress', :style => "width: #{width};") +
|
||||||
content_tag('p', legend, :class => 'pourcent')
|
content_tag('p', legend, :class => 'pourcent')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def checked_image(checked=true)
|
||||||
|
if checked
|
||||||
|
image_tag 'toggle_check.png'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def context_menu(url)
|
||||||
|
unless @context_menu_included
|
||||||
|
content_for :header_tags do
|
||||||
|
javascript_include_tag('context_menu') +
|
||||||
|
stylesheet_link_tag('context_menu')
|
||||||
|
end
|
||||||
|
@context_menu_included = true
|
||||||
|
end
|
||||||
|
javascript_tag "new ContextMenu('#{ url_for(url) }')"
|
||||||
|
end
|
||||||
|
|
||||||
def context_menu_link(name, url, options={})
|
def context_menu_link(name, url, options={})
|
||||||
options[:class] ||= ''
|
options[:class] ||= ''
|
||||||
if options.delete(:selected)
|
if options.delete(:selected)
|
||||||
@@ -497,7 +729,7 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
link_to name, url, options
|
link_to name, url, options
|
||||||
end
|
end
|
||||||
|
|
||||||
def calendar_for(field_id)
|
def calendar_for(field_id)
|
||||||
include_calendar_headers_tags
|
include_calendar_headers_tags
|
||||||
image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
|
image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
|
||||||
@@ -508,33 +740,62 @@ module ApplicationHelper
|
|||||||
unless @calendar_headers_tags_included
|
unless @calendar_headers_tags_included
|
||||||
@calendar_headers_tags_included = true
|
@calendar_headers_tags_included = true
|
||||||
content_for :header_tags do
|
content_for :header_tags do
|
||||||
|
start_of_week = case Setting.start_of_week.to_i
|
||||||
|
when 1
|
||||||
|
'Calendar._FD = 1;' # Monday
|
||||||
|
when 7
|
||||||
|
'Calendar._FD = 0;' # Sunday
|
||||||
|
else
|
||||||
|
'' # use language
|
||||||
|
end
|
||||||
|
|
||||||
javascript_include_tag('calendar/calendar') +
|
javascript_include_tag('calendar/calendar') +
|
||||||
javascript_include_tag("calendar/lang/calendar-#{current_language}.js") +
|
javascript_include_tag("calendar/lang/calendar-#{current_language.to_s.downcase}.js") +
|
||||||
|
javascript_tag(start_of_week) +
|
||||||
javascript_include_tag('calendar/calendar-setup') +
|
javascript_include_tag('calendar/calendar-setup') +
|
||||||
stylesheet_link_tag('calendar')
|
stylesheet_link_tag('calendar')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def wikitoolbar_for(field_id)
|
|
||||||
return '' unless Setting.text_formatting == 'textile'
|
|
||||||
|
|
||||||
help_link = l(:setting_text_formatting) + ': ' +
|
|
||||||
link_to(l(:label_help), compute_public_path('wiki_syntax', 'help', 'html'),
|
|
||||||
:onclick => "window.open(\"#{ compute_public_path('wiki_syntax', 'help', 'html') }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;")
|
|
||||||
|
|
||||||
javascript_include_tag('jstoolbar/jstoolbar') +
|
|
||||||
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") +
|
|
||||||
javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.setHelpLink('#{help_link}'); toolbar.draw();")
|
|
||||||
end
|
|
||||||
|
|
||||||
def content_for(name, content = nil, &block)
|
def content_for(name, content = nil, &block)
|
||||||
@has_content ||= {}
|
@has_content ||= {}
|
||||||
@has_content[name] = true
|
@has_content[name] = true
|
||||||
super(name, content, &block)
|
super(name, content, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_content?(name)
|
def has_content?(name)
|
||||||
(@has_content && @has_content[name]) || false
|
(@has_content && @has_content[name]) || false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the avatar image tag for the given +user+ if avatars are enabled
|
||||||
|
# +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
|
||||||
|
def avatar(user, options = { })
|
||||||
|
if Setting.gravatar_enabled?
|
||||||
|
options.merge!({:ssl => Setting.protocol == 'https', :default => Setting.gravatar_default})
|
||||||
|
email = nil
|
||||||
|
if user.respond_to?(:mail)
|
||||||
|
email = user.mail
|
||||||
|
elsif user.to_s =~ %r{<(.+?)>}
|
||||||
|
email = $1
|
||||||
|
end
|
||||||
|
return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def wiki_helper
|
||||||
|
helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
|
||||||
|
extend helper
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
def link_to_remote_content_update(text, url_params)
|
||||||
|
link_to_remote(text,
|
||||||
|
{:url => url_params, :method => :get, :update => 'content', :complete => 'window.scrollTo(0,0)'},
|
||||||
|
{:href => url_for(:params => url_params)}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,10 +16,15 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module AttachmentsHelper
|
module AttachmentsHelper
|
||||||
# displays the links to a collection of attachments
|
# Displays view/delete links to the attachments of the given object
|
||||||
def link_to_attachments(attachments, options = {})
|
# Options:
|
||||||
if attachments.any?
|
# :author -- author names are not displayed if set to false
|
||||||
render :partial => 'attachments/links', :locals => {:attachments => attachments, :options => options}
|
def link_to_attachments(container, options = {})
|
||||||
|
options.assert_valid_keys(:author)
|
||||||
|
|
||||||
|
if container.attachments.any?
|
||||||
|
options = {:deletable => container.attachments_deletable?, :author => true}.merge(options)
|
||||||
|
render :partial => 'attachments/links', :locals => {:attachments => container.attachments, :options => options}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,15 @@
|
|||||||
module CustomFieldsHelper
|
module CustomFieldsHelper
|
||||||
|
|
||||||
def custom_fields_tabs
|
def custom_fields_tabs
|
||||||
tabs = [{:name => 'IssueCustomField', :label => :label_issue_plural},
|
tabs = [{:name => 'IssueCustomField', :partial => 'custom_fields/index', :label => :label_issue_plural},
|
||||||
{:name => 'TimeEntryCustomField', :label => :label_spent_time},
|
{:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
|
||||||
{:name => 'ProjectCustomField', :label => :label_project_plural},
|
{:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
|
||||||
{:name => 'UserCustomField', :label => :label_user_plural}
|
{:name => 'VersionCustomField', :partial => 'custom_fields/index', :label => :label_version_plural},
|
||||||
|
{:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
|
||||||
|
{:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural},
|
||||||
|
{:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index', :label => TimeEntryActivity::OptionName},
|
||||||
|
{:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index', :label => IssuePriority::OptionName},
|
||||||
|
{:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index', :label => DocumentCategory::OptionName}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,15 +35,16 @@ module CustomFieldsHelper
|
|||||||
custom_field = custom_value.custom_field
|
custom_field = custom_value.custom_field
|
||||||
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
||||||
field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
||||||
|
|
||||||
case custom_field.field_format
|
field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
|
||||||
|
case field_format.edit_as
|
||||||
when "date"
|
when "date"
|
||||||
text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
|
text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
|
||||||
calendar_for(field_id)
|
calendar_for(field_id)
|
||||||
when "text"
|
when "text"
|
||||||
text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%')
|
text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%')
|
||||||
when "bool"
|
when "bool"
|
||||||
check_box_tag(field_name, '1', custom_value.true?, :id => field_id) + hidden_field_tag(field_name, '0')
|
hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, :id => field_id)
|
||||||
when "list"
|
when "list"
|
||||||
blank_option = custom_field.is_required? ?
|
blank_option = custom_field.is_required? ?
|
||||||
(custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
|
(custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
|
||||||
@@ -61,6 +67,27 @@ module CustomFieldsHelper
|
|||||||
def custom_field_tag_with_label(name, custom_value)
|
def custom_field_tag_with_label(name, custom_value)
|
||||||
custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
|
custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def custom_field_tag_for_bulk_edit(name, custom_field)
|
||||||
|
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
||||||
|
field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
||||||
|
field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
|
||||||
|
case field_format.edit_as
|
||||||
|
when "date"
|
||||||
|
text_field_tag(field_name, '', :id => field_id, :size => 10) +
|
||||||
|
calendar_for(field_id)
|
||||||
|
when "text"
|
||||||
|
text_area_tag(field_name, '', :id => field_id, :rows => 3, :style => 'width:90%')
|
||||||
|
when "bool"
|
||||||
|
select_tag(field_name, options_for_select([[l(:label_no_change_option), ''],
|
||||||
|
[l(:general_text_yes), '1'],
|
||||||
|
[l(:general_text_no), '0']]), :id => field_id)
|
||||||
|
when "list"
|
||||||
|
select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values), :id => field_id)
|
||||||
|
else
|
||||||
|
text_field_tag(field_name, '', :id => field_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Return a string used to display a custom value
|
# Return a string used to display a custom value
|
||||||
def show_value(custom_value)
|
def show_value(custom_value)
|
||||||
@@ -70,19 +97,11 @@ module CustomFieldsHelper
|
|||||||
|
|
||||||
# Return a string used to display a custom value
|
# Return a string used to display a custom value
|
||||||
def format_value(value, field_format)
|
def format_value(value, field_format)
|
||||||
return "" unless value && !value.empty?
|
Redmine::CustomFieldFormat.format_value(value, field_format) # Proxy
|
||||||
case field_format
|
|
||||||
when "date"
|
|
||||||
begin; format_date(value.to_date); rescue; value end
|
|
||||||
when "bool"
|
|
||||||
l_YesNo(value == "1")
|
|
||||||
else
|
|
||||||
value
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return an array of custom field formats which can be used in select_tag
|
# Return an array of custom field formats which can be used in select_tag
|
||||||
def custom_field_formats_for_select
|
def custom_field_formats_for_select
|
||||||
CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] }
|
Redmine::CustomFieldFormat.as_select
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
module GroupsHelper
|
||||||
|
# Options for the new membership projects combo-box
|
||||||
|
def options_for_membership_project_select(user, projects)
|
||||||
|
options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---")
|
||||||
|
options << project_tree_options_for_select(projects) do |p|
|
||||||
|
{:disabled => (user.projects.include?(p))}
|
||||||
|
end
|
||||||
|
options
|
||||||
|
end
|
||||||
|
|
||||||
|
def group_settings_tabs
|
||||||
|
tabs = [{:name => 'general', :partial => 'groups/general', :label => :label_general},
|
||||||
|
{:name => 'users', :partial => 'groups/users', :label => :label_user_plural},
|
||||||
|
{:name => 'memberships', :partial => 'groups/memberships', :label => :label_project_plural}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
# redMine - project management software
|
|
||||||
# Copyright (C) 2006 Jean-Philippe Lang
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or
|
|
||||||
# modify it under the terms of the GNU General Public License
|
|
||||||
# as published by the Free Software Foundation; either version 2
|
|
||||||
# of the License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program 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, USA.
|
|
||||||
|
|
||||||
require 'iconv'
|
|
||||||
require 'rfpdf/chinese'
|
|
||||||
|
|
||||||
module IfpdfHelper
|
|
||||||
|
|
||||||
class IFPDF < FPDF
|
|
||||||
include GLoc
|
|
||||||
attr_accessor :footer_date
|
|
||||||
|
|
||||||
def initialize(lang)
|
|
||||||
super()
|
|
||||||
set_language_if_valid lang
|
|
||||||
case current_language.to_s
|
|
||||||
when 'ja'
|
|
||||||
extend(PDF_Japanese)
|
|
||||||
AddSJISFont()
|
|
||||||
@font_for_content = 'SJIS'
|
|
||||||
@font_for_footer = 'SJIS'
|
|
||||||
when 'zh'
|
|
||||||
extend(PDF_Chinese)
|
|
||||||
AddGBFont()
|
|
||||||
@font_for_content = 'GB'
|
|
||||||
@font_for_footer = 'GB'
|
|
||||||
when 'zh-tw'
|
|
||||||
extend(PDF_Chinese)
|
|
||||||
AddBig5Font()
|
|
||||||
@font_for_content = 'Big5'
|
|
||||||
@font_for_footer = 'Big5'
|
|
||||||
else
|
|
||||||
@font_for_content = 'Arial'
|
|
||||||
@font_for_footer = 'Helvetica'
|
|
||||||
end
|
|
||||||
SetCreator("redMine #{Redmine::VERSION}")
|
|
||||||
SetFont(@font_for_content)
|
|
||||||
end
|
|
||||||
|
|
||||||
def SetFontStyle(style, size)
|
|
||||||
SetFont(@font_for_content, style, size)
|
|
||||||
end
|
|
||||||
|
|
||||||
def Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
|
|
||||||
@ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
|
|
||||||
# these quotation marks are not correctly rendered in the pdf
|
|
||||||
txt = txt.gsub(/[“”]/, '"') if txt
|
|
||||||
txt = begin
|
|
||||||
# 0x5c char handling
|
|
||||||
txtar = txt.split('\\')
|
|
||||||
txtar << '' if txt[-1] == ?\\
|
|
||||||
txtar.collect {|x| @ic.iconv(x)}.join('\\').gsub(/\\/, "\\\\\\\\")
|
|
||||||
rescue
|
|
||||||
txt
|
|
||||||
end || ''
|
|
||||||
super w,h,txt,border,ln,align,fill,link
|
|
||||||
end
|
|
||||||
|
|
||||||
def Footer
|
|
||||||
SetFont(@font_for_footer, 'I', 8)
|
|
||||||
SetY(-15)
|
|
||||||
SetX(15)
|
|
||||||
Cell(0, 5, @footer_date, 0, 0, 'L')
|
|
||||||
SetY(-15)
|
|
||||||
SetX(-30)
|
|
||||||
Cell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
+118
-40
@@ -15,23 +15,76 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require 'csv'
|
|
||||||
|
|
||||||
module IssuesHelper
|
module IssuesHelper
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
|
||||||
|
def issue_list(issues, &block)
|
||||||
|
ancestors = []
|
||||||
|
issues.each do |issue|
|
||||||
|
while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
|
||||||
|
ancestors.pop
|
||||||
|
end
|
||||||
|
yield issue, ancestors.size
|
||||||
|
ancestors << issue unless issue.leaf?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def render_issue_tooltip(issue)
|
def render_issue_tooltip(issue)
|
||||||
@cached_label_start_date ||= l(:field_start_date)
|
@cached_label_start_date ||= l(:field_start_date)
|
||||||
@cached_label_due_date ||= l(:field_due_date)
|
@cached_label_due_date ||= l(:field_due_date)
|
||||||
@cached_label_assigned_to ||= l(:field_assigned_to)
|
@cached_label_assigned_to ||= l(:field_assigned_to)
|
||||||
@cached_label_priority ||= l(:field_priority)
|
@cached_label_priority ||= l(:field_priority)
|
||||||
|
|
||||||
link_to_issue(issue) + ": #{h(issue.subject)}<br /><br />" +
|
link_to_issue(issue) + "<br /><br />" +
|
||||||
"<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" +
|
"<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" +
|
||||||
"<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
|
"<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
|
||||||
"<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
|
"<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
|
||||||
"<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
|
"<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_issue_subject_with_tree(issue)
|
||||||
|
s = ''
|
||||||
|
issue.ancestors.each do |ancestor|
|
||||||
|
s << '<div>' + content_tag('p', link_to_issue(ancestor))
|
||||||
|
end
|
||||||
|
s << '<div>' + content_tag('h3', h(issue.subject))
|
||||||
|
s << '</div>' * (issue.ancestors.size + 1)
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_descendants_tree(issue)
|
||||||
|
s = '<form><table class="list issues">'
|
||||||
|
issue_list(issue.descendants.sort_by(&:lft)) do |child, level|
|
||||||
|
s << content_tag('tr',
|
||||||
|
content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
|
||||||
|
content_tag('td', link_to_issue(child, :truncate => 60), :class => 'subject') +
|
||||||
|
content_tag('td', h(child.status)) +
|
||||||
|
content_tag('td', link_to_user(child.assigned_to)) +
|
||||||
|
content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
|
||||||
|
:class => "issue issue-#{child.id} hascontextmenu #{level > 0 ? "idnt idnt-#{level}" : nil}")
|
||||||
|
end
|
||||||
|
s << '</form></table>'
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_custom_fields_rows(issue)
|
||||||
|
return if issue.custom_field_values.empty?
|
||||||
|
ordered_values = []
|
||||||
|
half = (issue.custom_field_values.size / 2.0).ceil
|
||||||
|
half.times do |i|
|
||||||
|
ordered_values << issue.custom_field_values[i]
|
||||||
|
ordered_values << issue.custom_field_values[i + half]
|
||||||
|
end
|
||||||
|
s = "<tr>\n"
|
||||||
|
n = 0
|
||||||
|
ordered_values.compact.each do |value|
|
||||||
|
s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
|
||||||
|
s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
|
||||||
|
n += 1
|
||||||
|
end
|
||||||
|
s << "</tr>\n"
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
def sidebar_queries
|
def sidebar_queries
|
||||||
unless @sidebar_queries
|
unless @sidebar_queries
|
||||||
@@ -40,6 +93,7 @@ module IssuesHelper
|
|||||||
# Project specific queries and global queries
|
# Project specific queries and global queries
|
||||||
visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
|
visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
|
||||||
@sidebar_queries = Query.find(:all,
|
@sidebar_queries = Query.find(:all,
|
||||||
|
:select => 'id, name',
|
||||||
:order => "name ASC",
|
:order => "name ASC",
|
||||||
:conditions => visible.conditions)
|
:conditions => visible.conditions)
|
||||||
end
|
end
|
||||||
@@ -49,32 +103,25 @@ module IssuesHelper
|
|||||||
def show_detail(detail, no_html=false)
|
def show_detail(detail, no_html=false)
|
||||||
case detail.property
|
case detail.property
|
||||||
when 'attr'
|
when 'attr'
|
||||||
label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym)
|
field = detail.prop_key.to_s.gsub(/\_id$/, "")
|
||||||
case detail.prop_key
|
label = l(("field_" + field).to_sym)
|
||||||
when 'due_date', 'start_date'
|
case
|
||||||
|
when ['due_date', 'start_date'].include?(detail.prop_key)
|
||||||
value = format_date(detail.value.to_date) if detail.value
|
value = format_date(detail.value.to_date) if detail.value
|
||||||
old_value = format_date(detail.old_value.to_date) if detail.old_value
|
old_value = format_date(detail.old_value.to_date) if detail.old_value
|
||||||
when 'project_id'
|
|
||||||
p = Project.find_by_id(detail.value) and value = p.name if detail.value
|
when ['project_id', 'status_id', 'tracker_id', 'assigned_to_id', 'priority_id', 'category_id', 'fixed_version_id'].include?(detail.prop_key)
|
||||||
p = Project.find_by_id(detail.old_value) and old_value = p.name if detail.old_value
|
value = find_name_by_reflection(field, detail.value)
|
||||||
when 'status_id'
|
old_value = find_name_by_reflection(field, detail.old_value)
|
||||||
s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value
|
|
||||||
s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value
|
when detail.prop_key == 'estimated_hours'
|
||||||
when 'tracker_id'
|
value = "%0.02f" % detail.value.to_f unless detail.value.blank?
|
||||||
t = Tracker.find_by_id(detail.value) and value = t.name if detail.value
|
old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
|
||||||
t = Tracker.find_by_id(detail.old_value) and old_value = t.name if detail.old_value
|
|
||||||
when 'assigned_to_id'
|
when detail.prop_key == 'parent_id'
|
||||||
u = User.find_by_id(detail.value) and value = u.name if detail.value
|
label = l(:field_parent_issue)
|
||||||
u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value
|
value = "##{detail.value}" unless detail.value.blank?
|
||||||
when 'priority_id'
|
old_value = "##{detail.old_value}" unless detail.old_value.blank?
|
||||||
e = Enumeration.find_by_id(detail.value) and value = e.name if detail.value
|
|
||||||
e = Enumeration.find_by_id(detail.old_value) and old_value = e.name if detail.old_value
|
|
||||||
when 'category_id'
|
|
||||||
c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value
|
|
||||||
c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value
|
|
||||||
when 'fixed_version_id'
|
|
||||||
v = Version.find_by_id(detail.value) and value = v.name if detail.value
|
|
||||||
v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value
|
|
||||||
end
|
end
|
||||||
when 'cf'
|
when 'cf'
|
||||||
custom_field = CustomField.find_by_id(detail.prop_key)
|
custom_field = CustomField.find_by_id(detail.prop_key)
|
||||||
@@ -86,7 +133,8 @@ module IssuesHelper
|
|||||||
when 'attachment'
|
when 'attachment'
|
||||||
label = l(:label_attachment)
|
label = l(:label_attachment)
|
||||||
end
|
end
|
||||||
|
call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value })
|
||||||
|
|
||||||
label ||= detail.prop_key
|
label ||= detail.prop_key
|
||||||
value ||= detail.value
|
value ||= detail.value
|
||||||
old_value ||= detail.old_value
|
old_value ||= detail.old_value
|
||||||
@@ -107,28 +155,31 @@ module IssuesHelper
|
|||||||
case detail.property
|
case detail.property
|
||||||
when 'attr', 'cf'
|
when 'attr', 'cf'
|
||||||
if !detail.old_value.blank?
|
if !detail.old_value.blank?
|
||||||
label + " " + l(:text_journal_changed, old_value, value)
|
l(:text_journal_changed, :label => label, :old => old_value, :new => value)
|
||||||
else
|
else
|
||||||
label + " " + l(:text_journal_set_to, value)
|
l(:text_journal_set_to, :label => label, :value => value)
|
||||||
end
|
end
|
||||||
when 'attachment'
|
when 'attachment'
|
||||||
"#{label} #{value} #{l(:label_added)}"
|
l(:text_journal_added, :label => label, :value => value)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
case detail.property
|
l(:text_journal_deleted, :label => label, :old => old_value)
|
||||||
when 'attr', 'cf'
|
end
|
||||||
label + " " + l(:text_journal_deleted) + " (#{old_value})"
|
end
|
||||||
when 'attachment'
|
|
||||||
"#{label} #{old_value} #{l(:label_deleted)}"
|
# Find the name of an associated record stored in the field attribute
|
||||||
end
|
def find_name_by_reflection(field, id)
|
||||||
|
association = Issue.reflect_on_association(field.to_sym)
|
||||||
|
if association
|
||||||
|
record = association.class_name.constantize.find_by_id(id)
|
||||||
|
return record.name if record
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def issues_to_csv(issues, project = nil)
|
def issues_to_csv(issues, project = nil)
|
||||||
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||||
decimal_separator = l(:general_csv_decimal_separator)
|
decimal_separator = l(:general_csv_decimal_separator)
|
||||||
export = StringIO.new
|
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
|
||||||
# csv header fields
|
# csv header fields
|
||||||
headers = [ "#",
|
headers = [ "#",
|
||||||
l(:field_status),
|
l(:field_status),
|
||||||
@@ -144,6 +195,7 @@ module IssuesHelper
|
|||||||
l(:field_due_date),
|
l(:field_due_date),
|
||||||
l(:field_done_ratio),
|
l(:field_done_ratio),
|
||||||
l(:field_estimated_hours),
|
l(:field_estimated_hours),
|
||||||
|
l(:field_parent_issue),
|
||||||
l(:field_created_on),
|
l(:field_created_on),
|
||||||
l(:field_updated_on)
|
l(:field_updated_on)
|
||||||
]
|
]
|
||||||
@@ -170,6 +222,7 @@ module IssuesHelper
|
|||||||
format_date(issue.due_date),
|
format_date(issue.due_date),
|
||||||
issue.done_ratio,
|
issue.done_ratio,
|
||||||
issue.estimated_hours.to_s.gsub('.', decimal_separator),
|
issue.estimated_hours.to_s.gsub('.', decimal_separator),
|
||||||
|
issue.parent_id,
|
||||||
format_time(issue.created_on),
|
format_time(issue.created_on),
|
||||||
format_time(issue.updated_on)
|
format_time(issue.updated_on)
|
||||||
]
|
]
|
||||||
@@ -178,7 +231,32 @@ module IssuesHelper
|
|||||||
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
export.rewind
|
|
||||||
export
|
export
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def gantt_zoom_link(gantt, in_or_out)
|
||||||
|
img_attributes = {:style => 'height:1.4em; width:1.4em; margin-left: 3px;'} # em for accessibility
|
||||||
|
|
||||||
|
case in_or_out
|
||||||
|
when :in
|
||||||
|
if gantt.zoom < 4
|
||||||
|
link_to_remote(l(:text_zoom_in) + image_tag('zoom_in.png', img_attributes.merge(:alt => l(:text_zoom_in))),
|
||||||
|
{:url => gantt.params.merge(:zoom => (gantt.zoom+1)), :update => 'content'},
|
||||||
|
{:href => url_for(gantt.params.merge(:zoom => (gantt.zoom+1)))})
|
||||||
|
else
|
||||||
|
l(:text_zoom_in) +
|
||||||
|
image_tag('zoom_in_g.png', img_attributes.merge(:alt => l(:text_zoom_in)))
|
||||||
|
end
|
||||||
|
|
||||||
|
when :out
|
||||||
|
if gantt.zoom > 1
|
||||||
|
link_to_remote(l(:text_zoom_out) + image_tag('zoom_out.png', img_attributes.merge(:alt => l(:text_zoom_out))),
|
||||||
|
{:url => gantt.params.merge(:zoom => (gantt.zoom-1)), :update => 'content'},
|
||||||
|
{:href => url_for(gantt.params.merge(:zoom => (gantt.zoom-1)))})
|
||||||
|
else
|
||||||
|
l(:text_zoom_out) +
|
||||||
|
image_tag('zoom_out_g.png', img_attributes.merge(:alt => l(:text_zoom_out)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,21 +16,23 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module JournalsHelper
|
module JournalsHelper
|
||||||
def render_notes(journal, options={})
|
def render_notes(issue, journal, options={})
|
||||||
content = ''
|
content = ''
|
||||||
editable = journal.editable_by?(User.current)
|
editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project)))
|
||||||
links = []
|
links = []
|
||||||
if !journal.notes.blank?
|
if !journal.notes.blank?
|
||||||
|
links << link_to_remote(image_tag('comment.png'),
|
||||||
|
{ :url => {:controller => 'issues', :action => 'reply', :id => issue, :journal_id => journal} },
|
||||||
|
:title => l(:button_quote)) if options[:reply_links]
|
||||||
links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes",
|
links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes",
|
||||||
{ :controller => 'journals', :action => 'edit', :id => journal },
|
{ :controller => 'journals', :action => 'edit', :id => journal },
|
||||||
:title => l(:button_edit)) if editable
|
:title => l(:button_edit)) if editable
|
||||||
links << link_to_remote(image_tag('comment.png'),
|
|
||||||
{ :url => {:controller => 'issues', :action => 'reply', :id => journal.journalized, :journal_id => journal} },
|
|
||||||
:title => l(:button_reply)) if options[:reply_links]
|
|
||||||
end
|
end
|
||||||
content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty?
|
content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty?
|
||||||
content << textilizable(journal, :notes)
|
content << textilizable(journal, :notes)
|
||||||
content_tag('div', content, :id => "journal-#{journal.id}-notes", :class => (editable ? 'wiki editable' : 'wiki'))
|
css_classes = "wiki"
|
||||||
|
css_classes << " editable" if editable
|
||||||
|
content_tag('div', content, :id => "journal-#{journal.id}-notes", :class => css_classes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_in_place_notes_editor(text, field_id, url, options={})
|
def link_to_in_place_notes_editor(text, field_id, url, options={})
|
||||||
|
|||||||
@@ -19,10 +19,11 @@ module MessagesHelper
|
|||||||
|
|
||||||
def link_to_message(message)
|
def link_to_message(message)
|
||||||
return '' unless message
|
return '' unless message
|
||||||
link_to h(truncate(message.subject, 60)), :controller => 'messages',
|
link_to h(truncate(message.subject, :length => 60)), :controller => 'messages',
|
||||||
:action => 'show',
|
:action => 'show',
|
||||||
:board_id => message.board_id,
|
:board_id => message.board_id,
|
||||||
:id => message.root,
|
:id => message.root,
|
||||||
|
:r => (message.parent_id && message.id),
|
||||||
:anchor => (message.parent_id ? "message-#{message.id}" : nil)
|
:anchor => (message.parent_id ? "message-#{message.id}" : nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+67
-157
@@ -18,19 +18,7 @@
|
|||||||
module ProjectsHelper
|
module ProjectsHelper
|
||||||
def link_to_version(version, options = {})
|
def link_to_version(version, options = {})
|
||||||
return '' unless version && version.is_a?(Version)
|
return '' unless version && version.is_a?(Version)
|
||||||
link_to h(version.name), { :controller => 'versions', :action => 'show', :id => version }, options
|
link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
|
||||||
end
|
|
||||||
|
|
||||||
def format_activity_title(text)
|
|
||||||
h(truncate_single_line(text, 100))
|
|
||||||
end
|
|
||||||
|
|
||||||
def format_activity_day(date)
|
|
||||||
date == Date.today ? l(:label_today).titleize : format_date(date)
|
|
||||||
end
|
|
||||||
|
|
||||||
def format_activity_description(text)
|
|
||||||
h(truncate(text.to_s, 250).gsub(%r{<(pre|code)>.*$}m, '...'))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_settings_tabs
|
def project_settings_tabs
|
||||||
@@ -41,158 +29,80 @@ module ProjectsHelper
|
|||||||
{:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
|
{:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
|
||||||
{:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
|
{:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
|
||||||
{:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
|
{:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
|
||||||
{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}
|
{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
|
||||||
|
{:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
|
||||||
]
|
]
|
||||||
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generates a gantt image
|
def parent_project_select_tag(project)
|
||||||
# Only defined if RMagick is avalaible
|
selected = project.parent
|
||||||
def gantt_image(events, date_from, months, zoom)
|
# retrieve the requested parent project
|
||||||
date_to = (date_from >> months)-1
|
parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
|
||||||
show_weeks = zoom > 1
|
if parent_id
|
||||||
show_days = zoom > 2
|
selected = (parent_id.blank? ? nil : Project.find(parent_id))
|
||||||
|
|
||||||
subject_width = 320
|
|
||||||
header_heigth = 18
|
|
||||||
# width of one day in pixels
|
|
||||||
zoom = zoom*2
|
|
||||||
g_width = (date_to - date_from + 1)*zoom
|
|
||||||
g_height = 20 * events.length + 20
|
|
||||||
headers_heigth = (show_weeks ? 2*header_heigth : header_heigth)
|
|
||||||
height = g_height + headers_heigth
|
|
||||||
|
|
||||||
imgl = Magick::ImageList.new
|
|
||||||
imgl.new_image(subject_width+g_width+1, height)
|
|
||||||
gc = Magick::Draw.new
|
|
||||||
|
|
||||||
# Subjects
|
|
||||||
top = headers_heigth + 20
|
|
||||||
gc.fill('black')
|
|
||||||
gc.stroke('transparent')
|
|
||||||
gc.stroke_width(1)
|
|
||||||
events.each do |i|
|
|
||||||
gc.text(4, top + 2, (i.is_a?(Issue) ? i.subject : i.name))
|
|
||||||
top = top + 20
|
|
||||||
end
|
|
||||||
|
|
||||||
# Months headers
|
|
||||||
month_f = date_from
|
|
||||||
left = subject_width
|
|
||||||
months.times do
|
|
||||||
width = ((month_f >> 1) - month_f) * zoom
|
|
||||||
gc.fill('white')
|
|
||||||
gc.stroke('grey')
|
|
||||||
gc.stroke_width(1)
|
|
||||||
gc.rectangle(left, 0, left + width, height)
|
|
||||||
gc.fill('black')
|
|
||||||
gc.stroke('transparent')
|
|
||||||
gc.stroke_width(1)
|
|
||||||
gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
|
|
||||||
left = left + width
|
|
||||||
month_f = month_f >> 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Weeks headers
|
options = ''
|
||||||
if show_weeks
|
options << "<option value=''></option>" if project.allowed_parents.include?(nil)
|
||||||
left = subject_width
|
options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
|
||||||
height = header_heigth
|
content_tag('select', options, :name => 'project[parent_id]', :id => 'project_parent_id')
|
||||||
if date_from.cwday == 1
|
end
|
||||||
# date_from is monday
|
|
||||||
week_f = date_from
|
|
||||||
else
|
|
||||||
# find next monday after date_from
|
|
||||||
week_f = date_from + (7 - date_from.cwday + 1)
|
|
||||||
width = (7 - date_from.cwday + 1) * zoom
|
|
||||||
gc.fill('white')
|
|
||||||
gc.stroke('grey')
|
|
||||||
gc.stroke_width(1)
|
|
||||||
gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1)
|
|
||||||
left = left + width
|
|
||||||
end
|
|
||||||
while week_f <= date_to
|
|
||||||
width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
|
|
||||||
gc.fill('white')
|
|
||||||
gc.stroke('grey')
|
|
||||||
gc.stroke_width(1)
|
|
||||||
gc.rectangle(left.round, header_heigth, left.round + width, 2*header_heigth + g_height-1)
|
|
||||||
gc.fill('black')
|
|
||||||
gc.stroke('transparent')
|
|
||||||
gc.stroke_width(1)
|
|
||||||
gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s)
|
|
||||||
left = left + width
|
|
||||||
week_f = week_f+7
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Days details (week-end in grey)
|
|
||||||
if show_days
|
|
||||||
left = subject_width
|
|
||||||
height = g_height + header_heigth - 1
|
|
||||||
wday = date_from.cwday
|
|
||||||
(date_to - date_from + 1).to_i.times do
|
|
||||||
width = zoom
|
|
||||||
gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
|
|
||||||
gc.stroke('grey')
|
|
||||||
gc.stroke_width(1)
|
|
||||||
gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1)
|
|
||||||
left = left + width
|
|
||||||
wday = wday + 1
|
|
||||||
wday = 1 if wday > 7
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# border
|
|
||||||
gc.fill('transparent')
|
|
||||||
gc.stroke('grey')
|
|
||||||
gc.stroke_width(1)
|
|
||||||
gc.rectangle(0, 0, subject_width+g_width, headers_heigth)
|
|
||||||
gc.stroke('black')
|
|
||||||
gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1)
|
|
||||||
|
|
||||||
# content
|
|
||||||
top = headers_heigth + 20
|
|
||||||
gc.stroke('transparent')
|
|
||||||
events.each do |i|
|
|
||||||
if i.is_a?(Issue)
|
|
||||||
i_start_date = (i.start_date >= date_from ? i.start_date : date_from )
|
|
||||||
i_end_date = (i.due_date <= date_to ? i.due_date : date_to )
|
|
||||||
i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor
|
|
||||||
i_done_date = (i_done_date <= date_from ? date_from : i_done_date )
|
|
||||||
i_done_date = (i_done_date >= date_to ? date_to : i_done_date )
|
|
||||||
i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
|
|
||||||
|
|
||||||
i_left = subject_width + ((i_start_date - date_from)*zoom).floor
|
|
||||||
i_width = ((i_end_date - i_start_date + 1)*zoom).floor # total width of the issue
|
|
||||||
d_width = ((i_done_date - i_start_date)*zoom).floor # done width
|
|
||||||
l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor : 0 # delay width
|
|
||||||
|
|
||||||
gc.fill('grey')
|
# Renders a tree of projects as a nested set of unordered lists
|
||||||
gc.rectangle(i_left, top, i_left + i_width, top - 6)
|
# The given collection may be a subset of the whole project tree
|
||||||
gc.fill('red')
|
# (eg. some intermediate nodes are private and can not be seen)
|
||||||
gc.rectangle(i_left, top, i_left + l_width, top - 6) if l_width > 0
|
def render_project_hierarchy(projects)
|
||||||
gc.fill('blue')
|
s = ''
|
||||||
gc.rectangle(i_left, top, i_left + d_width, top - 6) if d_width > 0
|
if projects.any?
|
||||||
gc.fill('black')
|
ancestors = []
|
||||||
gc.text(i_left + i_width + 5,top + 1, "#{i.status.name} #{i.done_ratio}%")
|
original_project = @project
|
||||||
else
|
projects.each do |project|
|
||||||
i_left = subject_width + ((i.start_date - date_from)*zoom).floor
|
# set the project environment to please macros.
|
||||||
gc.fill('green')
|
@project = project
|
||||||
gc.rectangle(i_left, top, i_left + 6, top - 6)
|
if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
|
||||||
gc.fill('black')
|
s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
|
||||||
gc.text(i_left + 11, top + 1, i.name)
|
else
|
||||||
|
ancestors.pop
|
||||||
|
s << "</li>"
|
||||||
|
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
||||||
|
ancestors.pop
|
||||||
|
s << "</ul></li>\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
classes = (ancestors.empty? ? 'root' : 'child')
|
||||||
|
s << "<li class='#{classes}'><div class='#{classes}'>" +
|
||||||
|
link_to(h(project), {:controller => 'projects', :action => 'show', :id => project}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
|
||||||
|
s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank?
|
||||||
|
s << "</div>\n"
|
||||||
|
ancestors << project
|
||||||
end
|
end
|
||||||
top = top + 20
|
s << ("</li></ul>\n" * ancestors.size)
|
||||||
|
@project = original_project
|
||||||
|
end
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a set of options for a select field, grouped by project.
|
||||||
|
def version_options_for_select(versions, selected=nil)
|
||||||
|
grouped = Hash.new {|h,k| h[k] = []}
|
||||||
|
versions.each do |version|
|
||||||
|
grouped[version.project.name] << [version.name, version.id]
|
||||||
|
end
|
||||||
|
# Add in the selected
|
||||||
|
if selected && !versions.include?(selected)
|
||||||
|
grouped[selected.project.name] << [selected.name, selected.id]
|
||||||
end
|
end
|
||||||
|
|
||||||
# today red line
|
if grouped.keys.size > 1
|
||||||
if Date.today >= date_from and Date.today <= date_to
|
grouped_options_for_select(grouped, selected && selected.id)
|
||||||
gc.stroke('red')
|
else
|
||||||
x = (Date.today-date_from+1)*zoom + subject_width
|
options_for_select((grouped.values.first || []), selected && selected.id)
|
||||||
gc.line(x, headers_heigth, x, headers_heigth + g_height-1)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
gc.draw(imgl)
|
def format_version_sharing(sharing)
|
||||||
imgl
|
sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
|
||||||
end if Object.const_defined?(:Magick)
|
l("label_version_sharing_#{sharing}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,31 +22,78 @@ module QueriesHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def column_header(column)
|
def column_header(column)
|
||||||
column.sortable ? sort_header_tag(column.sortable, :caption => column.caption,
|
column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
|
||||||
:default_order => column.default_order) :
|
:default_order => column.default_order) :
|
||||||
content_tag('th', column.caption)
|
content_tag('th', column.caption)
|
||||||
end
|
end
|
||||||
|
|
||||||
def column_content(column, issue)
|
def column_content(column, issue)
|
||||||
if column.is_a?(QueryCustomFieldColumn)
|
value = column.value(issue)
|
||||||
cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
|
|
||||||
show_value(cv)
|
case value.class.name
|
||||||
else
|
when 'String'
|
||||||
value = issue.send(column.name)
|
if column.name == :subject
|
||||||
if value.is_a?(Date)
|
link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
|
||||||
format_date(value)
|
|
||||||
elsif value.is_a?(Time)
|
|
||||||
format_time(value)
|
|
||||||
else
|
else
|
||||||
case column.name
|
h(value)
|
||||||
when :subject
|
end
|
||||||
h((@project.nil? || @project != issue.project) ? "#{issue.project.name} - " : '') +
|
when 'Time'
|
||||||
link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
|
format_time(value)
|
||||||
when :done_ratio
|
when 'Date'
|
||||||
progress_bar(value, :width => '80px')
|
format_date(value)
|
||||||
|
when 'Fixnum', 'Float'
|
||||||
|
if column.name == :done_ratio
|
||||||
|
progress_bar(value, :width => '80px')
|
||||||
|
else
|
||||||
|
value.to_s
|
||||||
|
end
|
||||||
|
when 'User'
|
||||||
|
link_to_user value
|
||||||
|
when 'Project'
|
||||||
|
link_to(h(value), :controller => 'projects', :action => 'show', :id => value)
|
||||||
|
when 'Version'
|
||||||
|
link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
|
||||||
|
when 'TrueClass'
|
||||||
|
l(:general_text_Yes)
|
||||||
|
when 'FalseClass'
|
||||||
|
l(:general_text_No)
|
||||||
|
when 'Issue'
|
||||||
|
link_to_issue(value, :subject => false)
|
||||||
|
else
|
||||||
|
h(value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Retrieve query from session or build a new query
|
||||||
|
def retrieve_query
|
||||||
|
if !params[:query_id].blank?
|
||||||
|
cond = "project_id IS NULL"
|
||||||
|
cond << " OR project_id = #{@project.id}" if @project
|
||||||
|
@query = Query.find(params[:query_id], :conditions => cond)
|
||||||
|
@query.project = @project
|
||||||
|
session[:query] = {:id => @query.id, :project_id => @query.project_id}
|
||||||
|
sort_clear
|
||||||
|
else
|
||||||
|
if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
|
||||||
|
# Give it a name, required to be valid
|
||||||
|
@query = Query.new(:name => "_")
|
||||||
|
@query.project = @project
|
||||||
|
if params[:fields] and params[:fields].is_a? Array
|
||||||
|
params[:fields].each do |field|
|
||||||
|
@query.add_filter(field, params[:operators][field], params[:values][field])
|
||||||
|
end
|
||||||
else
|
else
|
||||||
h(value)
|
@query.available_filters.keys.each do |field|
|
||||||
|
@query.add_short_filter(field, params[field]) if params[field]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@query.group_by = params[:group_by]
|
||||||
|
@query.column_names = params[:query] && params[:query][:column_names]
|
||||||
|
session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
|
||||||
|
else
|
||||||
|
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
|
||||||
|
@query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
|
||||||
|
@query.project = @project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ module RepositoriesHelper
|
|||||||
txt.to_s[0,8]
|
txt.to_s[0,8]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def truncate_at_line_break(text, length = 255)
|
||||||
|
if text
|
||||||
|
text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def render_properties(properties)
|
def render_properties(properties)
|
||||||
unless properties.nil? || properties.empty?
|
unless properties.nil? || properties.empty?
|
||||||
content = ''
|
content = ''
|
||||||
@@ -32,6 +38,80 @@ module RepositoriesHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_changeset_changes
|
||||||
|
changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
|
||||||
|
case change.action
|
||||||
|
when 'A'
|
||||||
|
# Detects moved/copied files
|
||||||
|
if !change.from_path.blank?
|
||||||
|
change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
|
||||||
|
end
|
||||||
|
change
|
||||||
|
when 'D'
|
||||||
|
@changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
|
||||||
|
else
|
||||||
|
change
|
||||||
|
end
|
||||||
|
end.compact
|
||||||
|
|
||||||
|
tree = { }
|
||||||
|
changes.each do |change|
|
||||||
|
p = tree
|
||||||
|
dirs = change.path.to_s.split('/').select {|d| !d.blank?}
|
||||||
|
path = ''
|
||||||
|
dirs.each do |dir|
|
||||||
|
path += '/' + dir
|
||||||
|
p[:s] ||= {}
|
||||||
|
p = p[:s]
|
||||||
|
p[path] ||= {}
|
||||||
|
p = p[path]
|
||||||
|
end
|
||||||
|
p[:c] = change
|
||||||
|
end
|
||||||
|
|
||||||
|
render_changes_tree(tree[:s])
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_changes_tree(tree)
|
||||||
|
return '' if tree.nil?
|
||||||
|
|
||||||
|
output = ''
|
||||||
|
output << '<ul>'
|
||||||
|
tree.keys.sort.each do |file|
|
||||||
|
style = 'change'
|
||||||
|
text = File.basename(h(file))
|
||||||
|
if s = tree[file][:s]
|
||||||
|
style << ' folder'
|
||||||
|
path_param = to_path_param(@repository.relative_path(file))
|
||||||
|
text = link_to(text, :controller => 'repositories',
|
||||||
|
:action => 'show',
|
||||||
|
:id => @project,
|
||||||
|
:path => path_param,
|
||||||
|
:rev => @changeset.revision)
|
||||||
|
output << "<li class='#{style}'>#{text}</li>"
|
||||||
|
output << render_changes_tree(s)
|
||||||
|
elsif c = tree[file][:c]
|
||||||
|
style << " change-#{c.action}"
|
||||||
|
path_param = to_path_param(@repository.relative_path(c.path))
|
||||||
|
text = link_to(text, :controller => 'repositories',
|
||||||
|
:action => 'entry',
|
||||||
|
:id => @project,
|
||||||
|
:path => path_param,
|
||||||
|
:rev => @changeset.revision) unless c.action == 'D'
|
||||||
|
text << " - #{c.revision}" unless c.revision.blank?
|
||||||
|
text << ' (' + link_to('diff', :controller => 'repositories',
|
||||||
|
:action => 'diff',
|
||||||
|
:id => @project,
|
||||||
|
:path => path_param,
|
||||||
|
:rev => @changeset.revision) + ') ' if c.action == 'M'
|
||||||
|
text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank?
|
||||||
|
output << "<li class='#{style}'>#{text}</li>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
output << '</ul>'
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
def to_utf8(str)
|
def to_utf8(str)
|
||||||
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||||
@encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
|
@encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
|
||||||
@@ -47,12 +127,12 @@ module RepositoriesHelper
|
|||||||
|
|
||||||
def repository_field_tags(form, repository)
|
def repository_field_tags(form, repository)
|
||||||
method = repository.class.name.demodulize.underscore + "_field_tags"
|
method = repository.class.name.demodulize.underscore + "_field_tags"
|
||||||
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
|
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags'
|
||||||
end
|
end
|
||||||
|
|
||||||
def scm_select_tag(repository)
|
def scm_select_tag(repository)
|
||||||
scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
|
scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
|
||||||
REDMINE_SUPPORTED_SCM.each do |scm|
|
Redmine::Scm::Base.all.each do |scm|
|
||||||
scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm)
|
scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -73,7 +153,7 @@ module RepositoriesHelper
|
|||||||
|
|
||||||
def subversion_field_tags(form, repository)
|
def subversion_field_tags(form, repository)
|
||||||
content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) +
|
content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) +
|
||||||
'<br />(http://, https://, svn://, file:///)') +
|
'<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
|
||||||
content_tag('p', form.text_field(:login, :size => 30)) +
|
content_tag('p', form.text_field(:login, :size => 30)) +
|
||||||
content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore',
|
content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore',
|
||||||
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
|
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ module SearchHelper
|
|||||||
result << '...'
|
result << '...'
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
words = words.mb_chars
|
||||||
if i.even?
|
if i.even?
|
||||||
result << h(words.length > 100 ? "#{words[0..44]} ... #{words[-45..-1]}" : words)
|
result << h(words.length > 100 ? "#{words.slice(0..44)} ... #{words.slice(-45..-1)}" : words)
|
||||||
else
|
else
|
||||||
t = (tokens.index(words.downcase) || 0) % 4
|
t = (tokens.index(words.downcase) || 0) % 4
|
||||||
result << content_tag('span', h(words), :class => "highlight token-#{t}")
|
result << content_tag('span', h(words), :class => "highlight token-#{t}")
|
||||||
@@ -44,7 +45,7 @@ module SearchHelper
|
|||||||
def project_select_tag
|
def project_select_tag
|
||||||
options = [[l(:label_project_all), 'all']]
|
options = [[l(:label_project_all), 'all']]
|
||||||
options << [l(:label_my_projects), 'my_projects'] unless User.current.memberships.empty?
|
options << [l(:label_my_projects), 'my_projects'] unless User.current.memberships.empty?
|
||||||
options << [l(:label_and_its_subprojects, @project.name), 'subprojects'] unless @project.nil? || @project.active_children.empty?
|
options << [l(:label_and_its_subprojects, @project.name), 'subprojects'] unless @project.nil? || @project.descendants.active.empty?
|
||||||
options << [@project.name, ''] unless @project.nil?
|
options << [@project.name, ''] unless @project.nil?
|
||||||
select_tag('scope', options_for_select(options, params[:scope].to_s)) if options.size > 1
|
select_tag('scope', options_for_select(options, params[:scope].to_s)) if options.size > 1
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -18,11 +18,57 @@
|
|||||||
module SettingsHelper
|
module SettingsHelper
|
||||||
def administration_settings_tabs
|
def administration_settings_tabs
|
||||||
tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
|
tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
|
||||||
|
{:name => 'display', :partial => 'settings/display', :label => :label_display},
|
||||||
{:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication},
|
{:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication},
|
||||||
|
{:name => 'projects', :partial => 'settings/projects', :label => :label_project_plural},
|
||||||
{:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
|
{:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
|
||||||
{:name => 'notifications', :partial => 'settings/notifications', :label => l(:field_mail_notification)},
|
{:name => 'notifications', :partial => 'settings/notifications', :label => :field_mail_notification},
|
||||||
{:name => 'mail_handler', :partial => 'settings/mail_handler', :label => l(:label_incoming_emails)},
|
{:name => 'mail_handler', :partial => 'settings/mail_handler', :label => :label_incoming_emails},
|
||||||
{:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
|
{:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def setting_select(setting, choices, options={})
|
||||||
|
if blank_text = options.delete(:blank)
|
||||||
|
choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
|
||||||
|
end
|
||||||
|
setting_label(setting, options) +
|
||||||
|
select_tag("settings[#{setting}]", options_for_select(choices, Setting.send(setting).to_s), options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def setting_multiselect(setting, choices, options={})
|
||||||
|
setting_values = Setting.send(setting)
|
||||||
|
setting_values = [] unless setting_values.is_a?(Array)
|
||||||
|
|
||||||
|
setting_label(setting, options) +
|
||||||
|
hidden_field_tag("settings[#{setting}][]", '') +
|
||||||
|
choices.collect do |choice|
|
||||||
|
text, value = (choice.is_a?(Array) ? choice : [choice, choice])
|
||||||
|
content_tag('label',
|
||||||
|
check_box_tag("settings[#{setting}][]", value, Setting.send(setting).include?(value)) + text.to_s,
|
||||||
|
:class => 'block'
|
||||||
|
)
|
||||||
|
end.join
|
||||||
|
end
|
||||||
|
|
||||||
|
def setting_text_field(setting, options={})
|
||||||
|
setting_label(setting, options) +
|
||||||
|
text_field_tag("settings[#{setting}]", Setting.send(setting), options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def setting_text_area(setting, options={})
|
||||||
|
setting_label(setting, options) +
|
||||||
|
text_area_tag("settings[#{setting}]", Setting.send(setting), options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def setting_check_box(setting, options={})
|
||||||
|
setting_label(setting, options) +
|
||||||
|
hidden_field_tag("settings[#{setting}]", 0) +
|
||||||
|
check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def setting_label(setting, options={})
|
||||||
|
label = options.delete(:label)
|
||||||
|
label != false ? content_tag("label", l(label || "setting_#{setting}")) : ''
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+140
-65
@@ -1,11 +1,12 @@
|
|||||||
# Helpers to sort tables using clickable column headers.
|
# Helpers to sort tables using clickable column headers.
|
||||||
#
|
#
|
||||||
# Author: Stuart Rackham <srackham@methods.co.nz>, March 2005.
|
# Author: Stuart Rackham <srackham@methods.co.nz>, March 2005.
|
||||||
|
# Jean-Philippe Lang, 2009
|
||||||
# License: This source code is released under the MIT license.
|
# License: This source code is released under the MIT license.
|
||||||
#
|
#
|
||||||
# - Consecutive clicks toggle the column's sort order.
|
# - Consecutive clicks toggle the column's sort order.
|
||||||
# - Sort state is maintained by a session hash entry.
|
# - Sort state is maintained by a session hash entry.
|
||||||
# - Icon image identifies sort column and state.
|
# - CSS classes identify sort column and state.
|
||||||
# - Typically used in conjunction with the Pagination module.
|
# - Typically used in conjunction with the Pagination module.
|
||||||
#
|
#
|
||||||
# Example code snippets:
|
# Example code snippets:
|
||||||
@@ -17,7 +18,7 @@
|
|||||||
#
|
#
|
||||||
# def list
|
# def list
|
||||||
# sort_init 'last_name'
|
# sort_init 'last_name'
|
||||||
# sort_update
|
# sort_update %w(first_name last_name)
|
||||||
# @items = Contact.find_all nil, sort_clause
|
# @items = Contact.find_all nil, sort_clause
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
@@ -28,7 +29,7 @@
|
|||||||
#
|
#
|
||||||
# def list
|
# def list
|
||||||
# sort_init 'last_name'
|
# sort_init 'last_name'
|
||||||
# sort_update
|
# sort_update %w(first_name last_name)
|
||||||
# @contact_pages, @items = paginate :contacts,
|
# @contact_pages, @items = paginate :contacts,
|
||||||
# :order_by => sort_clause,
|
# :order_by => sort_clause,
|
||||||
# :per_page => 10
|
# :per_page => 10
|
||||||
@@ -45,77 +46,170 @@
|
|||||||
# </tr>
|
# </tr>
|
||||||
# </thead>
|
# </thead>
|
||||||
#
|
#
|
||||||
# - The ascending and descending sort icon images are sort_asc.png and
|
# - Introduces instance variables: @sort_default, @sort_criteria
|
||||||
# sort_desc.png and reside in the application's images directory.
|
# - Introduces param :sort
|
||||||
# - Introduces instance variables: @sort_name, @sort_default.
|
|
||||||
# - Introduces params :sort_key and :sort_order.
|
|
||||||
#
|
#
|
||||||
module SortHelper
|
|
||||||
|
|
||||||
# Initializes the default sort column (default_key) and sort order
|
module SortHelper
|
||||||
# (default_order).
|
class SortCriteria
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@criteria = []
|
||||||
|
end
|
||||||
|
|
||||||
|
def available_criteria=(criteria)
|
||||||
|
unless criteria.is_a?(Hash)
|
||||||
|
criteria = criteria.inject({}) {|h,k| h[k] = k; h}
|
||||||
|
end
|
||||||
|
@available_criteria = criteria
|
||||||
|
end
|
||||||
|
|
||||||
|
def from_param(param)
|
||||||
|
@criteria = param.to_s.split(',').collect {|s| s.split(':')[0..1]}
|
||||||
|
normalize!
|
||||||
|
end
|
||||||
|
|
||||||
|
def criteria=(arg)
|
||||||
|
@criteria = arg
|
||||||
|
normalize!
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_param
|
||||||
|
@criteria.collect {|k,o| k + (o ? '' : ':desc')}.join(',')
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_sql
|
||||||
|
sql = @criteria.collect do |k,o|
|
||||||
|
if s = @available_criteria[k]
|
||||||
|
(o ? s.to_a : s.to_a.collect {|c| append_desc(c)}).join(', ')
|
||||||
|
end
|
||||||
|
end.compact.join(', ')
|
||||||
|
sql.blank? ? nil : sql
|
||||||
|
end
|
||||||
|
|
||||||
|
def add!(key, asc)
|
||||||
|
@criteria.delete_if {|k,o| k == key}
|
||||||
|
@criteria = [[key, asc]] + @criteria
|
||||||
|
normalize!
|
||||||
|
end
|
||||||
|
|
||||||
|
def add(*args)
|
||||||
|
r = self.class.new.from_param(to_param)
|
||||||
|
r.add!(*args)
|
||||||
|
r
|
||||||
|
end
|
||||||
|
|
||||||
|
def first_key
|
||||||
|
@criteria.first && @criteria.first.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def first_asc?
|
||||||
|
@criteria.first && @criteria.first.last
|
||||||
|
end
|
||||||
|
|
||||||
|
def empty?
|
||||||
|
@criteria.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def normalize!
|
||||||
|
@criteria ||= []
|
||||||
|
@criteria = @criteria.collect {|s| s = s.to_a; [s.first, (s.last == false || s.last == 'desc') ? false : true]}
|
||||||
|
@criteria = @criteria.select {|k,o| @available_criteria.has_key?(k)} if @available_criteria
|
||||||
|
@criteria.slice!(3)
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
# Appends DESC to the sort criterion unless it has a fixed order
|
||||||
|
def append_desc(criterion)
|
||||||
|
if criterion =~ / (asc|desc)$/i
|
||||||
|
criterion
|
||||||
|
else
|
||||||
|
"#{criterion} DESC"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def sort_name
|
||||||
|
controller_name + '_' + action_name + '_sort'
|
||||||
|
end
|
||||||
|
|
||||||
|
# Initializes the default sort.
|
||||||
|
# Examples:
|
||||||
|
#
|
||||||
|
# sort_init 'name'
|
||||||
|
# sort_init 'id', 'desc'
|
||||||
|
# sort_init ['name', ['id', 'desc']]
|
||||||
|
# sort_init [['name', 'desc'], ['id', 'desc']]
|
||||||
#
|
#
|
||||||
# - default_key is a column attribute name.
|
def sort_init(*args)
|
||||||
# - default_order is 'asc' or 'desc'.
|
case args.size
|
||||||
# - name is the name of the session hash entry that stores the sort state,
|
when 1
|
||||||
# defaults to '<controller_name>_sort'.
|
@sort_default = args.first.is_a?(Array) ? args.first : [[args.first]]
|
||||||
#
|
when 2
|
||||||
def sort_init(default_key, default_order='asc', name=nil)
|
@sort_default = [[args.first, args.last]]
|
||||||
@sort_name = name || params[:controller] + params[:action] + '_sort'
|
else
|
||||||
@sort_default = {:key => default_key, :order => default_order}
|
raise ArgumentError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Updates the sort state. Call this in the controller prior to calling
|
# Updates the sort state. Call this in the controller prior to calling
|
||||||
# sort_clause.
|
# sort_clause.
|
||||||
|
# - criteria can be either an array or a hash of allowed keys
|
||||||
#
|
#
|
||||||
def sort_update()
|
def sort_update(criteria)
|
||||||
if params[:sort_key]
|
@sort_criteria = SortCriteria.new
|
||||||
sort = {:key => params[:sort_key], :order => params[:sort_order]}
|
@sort_criteria.available_criteria = criteria
|
||||||
elsif session[@sort_name]
|
@sort_criteria.from_param(params[:sort] || session[sort_name])
|
||||||
sort = session[@sort_name] # Previous sort.
|
@sort_criteria.criteria = @sort_default if @sort_criteria.empty?
|
||||||
else
|
session[sort_name] = @sort_criteria.to_param
|
||||||
sort = @sort_default
|
end
|
||||||
end
|
|
||||||
session[@sort_name] = sort
|
# Clears the sort criteria session data
|
||||||
|
#
|
||||||
|
def sort_clear
|
||||||
|
session[sort_name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an SQL sort clause corresponding to the current sort state.
|
# Returns an SQL sort clause corresponding to the current sort state.
|
||||||
# Use this to sort the controller's table items collection.
|
# Use this to sort the controller's table items collection.
|
||||||
#
|
#
|
||||||
def sort_clause()
|
def sort_clause()
|
||||||
session[@sort_name][:key] + ' ' + (session[@sort_name][:order] || 'ASC')
|
@sort_criteria.to_sql
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a link which sorts by the named column.
|
# Returns a link which sorts by the named column.
|
||||||
#
|
#
|
||||||
# - column is the name of an attribute in the sorted record collection.
|
# - column is the name of an attribute in the sorted record collection.
|
||||||
# - The optional caption explicitly specifies the displayed link text.
|
# - the optional caption explicitly specifies the displayed link text.
|
||||||
# - A sort icon image is positioned to the right of the sort link.
|
# - 2 CSS classes reflect the state of the link: sort and asc or desc
|
||||||
#
|
#
|
||||||
def sort_link(column, caption, default_order)
|
def sort_link(column, caption, default_order)
|
||||||
key, order = session[@sort_name][:key], session[@sort_name][:order]
|
css, order = nil, default_order
|
||||||
if key == column
|
|
||||||
if order.downcase == 'asc'
|
if column.to_s == @sort_criteria.first_key
|
||||||
icon = 'sort_asc.png'
|
if @sort_criteria.first_asc?
|
||||||
|
css = 'sort asc'
|
||||||
order = 'desc'
|
order = 'desc'
|
||||||
else
|
else
|
||||||
icon = 'sort_desc.png'
|
css = 'sort desc'
|
||||||
order = 'asc'
|
order = 'asc'
|
||||||
end
|
end
|
||||||
else
|
|
||||||
icon = nil
|
|
||||||
order = default_order
|
|
||||||
end
|
end
|
||||||
caption = titleize(Inflector::humanize(column)) unless caption
|
caption = column.to_s.humanize unless caption
|
||||||
|
|
||||||
sort_options = { :sort_key => column, :sort_order => order }
|
sort_options = { :sort => @sort_criteria.add(column.to_s, order).to_param }
|
||||||
# don't reuse params if filters are present
|
# don't reuse params if filters are present
|
||||||
url_options = params.has_key?(:set_filter) ? sort_options : params.merge(sort_options)
|
url_options = params.has_key?(:set_filter) ? sort_options : params.merge(sort_options)
|
||||||
|
|
||||||
|
# Add project_id to url_options
|
||||||
|
url_options = url_options.merge(:project_id => params[:project_id]) if params.has_key?(:project_id)
|
||||||
|
|
||||||
link_to_remote(caption,
|
link_to_remote(caption,
|
||||||
{:update => "content", :url => url_options},
|
{:update => "content", :url => url_options, :method => :get},
|
||||||
{:href => url_for(url_options)}) +
|
{:href => url_for(url_options),
|
||||||
(icon ? nbsp(2) + image_tag(icon) : '')
|
:class => css})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a table header <th> tag with a sort link for the named column
|
# Returns a table header <th> tag with a sort link for the named column
|
||||||
@@ -131,30 +225,11 @@ module SortHelper
|
|||||||
#
|
#
|
||||||
# <%= sort_header_tag('id', :title => 'Sort by contact ID', :width => 40) %>
|
# <%= sort_header_tag('id', :title => 'Sort by contact ID', :width => 40) %>
|
||||||
#
|
#
|
||||||
# Renders:
|
|
||||||
#
|
|
||||||
# <th title="Sort by contact ID" width="40">
|
|
||||||
# <a href="/contact/list?sort_order=desc&sort_key=id">Id</a>
|
|
||||||
# <img alt="Sort_asc" src="/images/sort_asc.png" />
|
|
||||||
# </th>
|
|
||||||
#
|
|
||||||
def sort_header_tag(column, options = {})
|
def sort_header_tag(column, options = {})
|
||||||
caption = options.delete(:caption) || titleize(Inflector::humanize(column))
|
caption = options.delete(:caption) || column.to_s.humanize
|
||||||
default_order = options.delete(:default_order) || 'asc'
|
default_order = options.delete(:default_order) || 'asc'
|
||||||
options[:title]= l(:label_sort_by, "\"#{caption}\"") unless options[:title]
|
options[:title] = l(:label_sort_by, "\"#{caption}\"") unless options[:title]
|
||||||
content_tag('th', sort_link(column, caption, default_order), options)
|
content_tag('th', sort_link(column, caption, default_order), options)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# Return n non-breaking spaces.
|
|
||||||
def nbsp(n)
|
|
||||||
' ' * n
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return capitalized title.
|
|
||||||
def titleize(title)
|
|
||||||
title.split.map {|w| w.capitalize }.join(' ')
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -16,16 +16,49 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module TimelogHelper
|
module TimelogHelper
|
||||||
def activity_collection_for_select_options
|
include ApplicationHelper
|
||||||
activities = Enumeration::get_values('ACTI')
|
|
||||||
|
def render_timelog_breadcrumb
|
||||||
|
links = []
|
||||||
|
links << link_to(l(:label_project_all), {:project_id => nil, :issue_id => nil})
|
||||||
|
links << link_to(h(@project), {:project_id => @project, :issue_id => nil}) if @project
|
||||||
|
if @issue
|
||||||
|
if @issue.visible?
|
||||||
|
links << link_to_issue(@issue, :subject => false)
|
||||||
|
else
|
||||||
|
links << "##{@issue.id}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
breadcrumb links
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a collection of activities for a select field. time_entry
|
||||||
|
# is optional and will be used to check if the selected TimeEntryActivity
|
||||||
|
# is active.
|
||||||
|
def activity_collection_for_select_options(time_entry=nil, project=nil)
|
||||||
|
project ||= @project
|
||||||
|
if project.nil?
|
||||||
|
activities = TimeEntryActivity.shared.active
|
||||||
|
else
|
||||||
|
activities = project.activities
|
||||||
|
end
|
||||||
|
|
||||||
collection = []
|
collection = []
|
||||||
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default)
|
if time_entry && time_entry.activity && !time_entry.activity.active?
|
||||||
|
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ]
|
||||||
|
else
|
||||||
|
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default)
|
||||||
|
end
|
||||||
activities.each { |a| collection << [a.name, a.id] }
|
activities.each { |a| collection << [a.name, a.id] }
|
||||||
collection
|
collection
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_hours(data, criteria, value)
|
def select_hours(data, criteria, value)
|
||||||
data.select {|row| row[criteria] == value}
|
if value.to_s.empty?
|
||||||
|
data.select {|row| row[criteria].blank? }
|
||||||
|
else
|
||||||
|
data.select {|row| row[criteria].to_s == value.to_s}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sum_hours(data)
|
def sum_hours(data)
|
||||||
@@ -54,8 +87,7 @@ module TimelogHelper
|
|||||||
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||||
decimal_separator = l(:general_csv_decimal_separator)
|
decimal_separator = l(:general_csv_decimal_separator)
|
||||||
custom_fields = TimeEntryCustomField.find(:all)
|
custom_fields = TimeEntryCustomField.find(:all)
|
||||||
export = StringIO.new
|
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
|
||||||
# csv header fields
|
# csv header fields
|
||||||
headers = [l(:field_spent_on),
|
headers = [l(:field_spent_on),
|
||||||
l(:field_user),
|
l(:field_user),
|
||||||
@@ -73,7 +105,7 @@ module TimelogHelper
|
|||||||
csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||||||
# csv lines
|
# csv lines
|
||||||
entries.each do |entry|
|
entries.each do |entry|
|
||||||
fields = [l_date(entry.spent_on),
|
fields = [format_date(entry.spent_on),
|
||||||
entry.user,
|
entry.user,
|
||||||
entry.activity,
|
entry.activity,
|
||||||
entry.project,
|
entry.project,
|
||||||
@@ -88,17 +120,26 @@ module TimelogHelper
|
|||||||
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
export.rewind
|
|
||||||
export
|
export
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_criteria_value(criteria, value)
|
def format_criteria_value(criteria, value)
|
||||||
value.blank? ? l(:label_none) : ((k = @available_criterias[criteria][:klass]) ? k.find_by_id(value.to_i) : format_value(value, @available_criterias[criteria][:format]))
|
if value.blank?
|
||||||
|
l(:label_none)
|
||||||
|
elsif k = @available_criterias[criteria][:klass]
|
||||||
|
obj = k.find_by_id(value.to_i)
|
||||||
|
if obj.is_a?(Issue)
|
||||||
|
obj.visible? ? "#{obj.tracker} ##{obj.id}: #{obj.subject}" : "##{obj.id}"
|
||||||
|
else
|
||||||
|
obj
|
||||||
|
end
|
||||||
|
else
|
||||||
|
format_value(value, @available_criterias[criteria][:format])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def report_to_csv(criterias, periods, hours)
|
def report_to_csv(criterias, periods, hours)
|
||||||
export = StringIO.new
|
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
|
||||||
# Column headers
|
# Column headers
|
||||||
headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
|
headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
|
||||||
headers += periods
|
headers += periods
|
||||||
@@ -117,7 +158,6 @@ module TimelogHelper
|
|||||||
row << "%.2f" %total
|
row << "%.2f" %total
|
||||||
csv << row
|
csv << row
|
||||||
end
|
end
|
||||||
export.rewind
|
|
||||||
export
|
export
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -16,29 +16,25 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module UsersHelper
|
module UsersHelper
|
||||||
def status_options_for_select(selected)
|
def users_status_options_for_select(selected)
|
||||||
|
user_count_by_status = User.count(:group => 'status').to_hash
|
||||||
options_for_select([[l(:label_all), ''],
|
options_for_select([[l(:label_all), ''],
|
||||||
[l(:status_active), 1],
|
["#{l(:status_active)} (#{user_count_by_status[1].to_i})", 1],
|
||||||
[l(:status_registered), 2],
|
["#{l(:status_registered)} (#{user_count_by_status[2].to_i})", 2],
|
||||||
[l(:status_locked), 3]], selected)
|
["#{l(:status_locked)} (#{user_count_by_status[3].to_i})", 3]], selected)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Options for the new membership projects combo-box
|
# Options for the new membership projects combo-box
|
||||||
def projects_options_for_select(projects)
|
def options_for_membership_project_select(user, projects)
|
||||||
options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---")
|
options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---")
|
||||||
projects_by_root = projects.group_by(&:root)
|
options << project_tree_options_for_select(projects) do |p|
|
||||||
projects_by_root.keys.sort.each do |root|
|
{:disabled => (user.projects.include?(p))}
|
||||||
options << content_tag('option', h(root.name), :value => root.id, :disabled => (!projects.include?(root)))
|
|
||||||
projects_by_root[root].sort.each do |project|
|
|
||||||
next if project == root
|
|
||||||
options << content_tag('option', '» ' + h(project.name), :value => project.id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_status_link(user)
|
def change_status_link(user)
|
||||||
url = {:action => 'edit', :id => user, :page => params[:page], :status => params[:status]}
|
url = {:controller => 'users', :action => 'edit', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
|
||||||
|
|
||||||
if user.locked?
|
if user.locked?
|
||||||
link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
|
link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
|
||||||
@@ -53,5 +49,9 @@ module UsersHelper
|
|||||||
tabs = [{:name => 'general', :partial => 'users/general', :label => :label_general},
|
tabs = [{:name => 'general', :partial => 'users/general', :label => :label_general},
|
||||||
{:name => 'memberships', :partial => 'users/memberships', :label => :label_project_plural}
|
{:name => 'memberships', :partial => 'users/memberships', :label => :label_project_plural}
|
||||||
]
|
]
|
||||||
|
if Group.all.any?
|
||||||
|
tabs.insert 1, {:name => 'groups', :partial => 'users/groups', :label => :label_group_plural}
|
||||||
|
end
|
||||||
|
tabs
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,21 +16,54 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module WatchersHelper
|
module WatchersHelper
|
||||||
def watcher_tag(object, user)
|
|
||||||
content_tag("span", watcher_link(object, user), :id => 'watcher')
|
# Valid options
|
||||||
|
# * :id - the element id
|
||||||
|
# * :replace - a string or array of element ids that will be
|
||||||
|
# replaced
|
||||||
|
def watcher_tag(object, user, options={:replace => 'watcher'})
|
||||||
|
id = options[:id]
|
||||||
|
id ||= options[:replace] if options[:replace].is_a? String
|
||||||
|
content_tag("span", watcher_link(object, user, options), :id => id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def watcher_link(object, user)
|
# Valid options
|
||||||
|
# * :replace - a string or array of element ids that will be
|
||||||
|
# replaced
|
||||||
|
def watcher_link(object, user, options={:replace => 'watcher'})
|
||||||
return '' unless user && user.logged? && object.respond_to?('watched_by?')
|
return '' unless user && user.logged? && object.respond_to?('watched_by?')
|
||||||
watched = object.watched_by?(user)
|
watched = object.watched_by?(user)
|
||||||
url = {:controller => 'watchers',
|
url = {:controller => 'watchers',
|
||||||
:action => (watched ? 'remove' : 'add'),
|
:action => (watched ? 'unwatch' : 'watch'),
|
||||||
:object_type => object.class.to_s.underscore,
|
:object_type => object.class.to_s.underscore,
|
||||||
:object_id => object.id}
|
:object_id => object.id,
|
||||||
|
:replace => options[:replace]}
|
||||||
link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
|
link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
|
||||||
{:url => url},
|
{:url => url},
|
||||||
:href => url_for(url),
|
:href => url_for(url),
|
||||||
:class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
|
:class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a comma separated list of users watching the given object
|
||||||
|
def watchers_list(object)
|
||||||
|
remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
|
||||||
|
lis = object.watcher_users.collect do |user|
|
||||||
|
s = avatar(user, :size => "16").to_s + link_to_user(user, :class => 'user').to_s
|
||||||
|
if remove_allowed
|
||||||
|
url = {:controller => 'watchers',
|
||||||
|
:action => 'destroy',
|
||||||
|
:object_type => object.class.to_s.underscore,
|
||||||
|
:object_id => object.id,
|
||||||
|
:user_id => user}
|
||||||
|
s += ' ' + link_to_remote(image_tag('delete.png'),
|
||||||
|
{:url => url},
|
||||||
|
:href => url_for(url),
|
||||||
|
:style => "vertical-align: middle",
|
||||||
|
:class => "delete")
|
||||||
|
end
|
||||||
|
"<li>#{ s }</li>"
|
||||||
|
end
|
||||||
|
lis.empty? ? "" : "<ul>#{ lis.join("\n") }</ul>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+12
-15
@@ -16,21 +16,18 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module WikiHelper
|
module WikiHelper
|
||||||
|
|
||||||
def render_page_hierarchy(pages, node=nil)
|
def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
|
||||||
content = ''
|
s = ''
|
||||||
if pages[node]
|
pages.select {|p| p.parent == parent}.each do |page|
|
||||||
content << "<ul class=\"pages-hierarchy\">\n"
|
attrs = "value='#{page.id}'"
|
||||||
pages[node].each do |page|
|
attrs << " selected='selected'" if selected == page
|
||||||
content << "<li>"
|
indent = (level > 0) ? (' ' * level * 2 + '» ') : nil
|
||||||
content << link_to(h(page.pretty_title), {:action => 'index', :page => page.title},
|
|
||||||
:title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
|
s << "<option value='#{page.id}'>#{indent}#{h page.pretty_title}</option>\n" +
|
||||||
content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
|
wiki_page_options_for_select(pages, selected, page, level + 1)
|
||||||
content << "</li>\n"
|
|
||||||
end
|
|
||||||
content << "</ul>\n"
|
|
||||||
end
|
end
|
||||||
content
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_diff(wdiff)
|
def html_diff(wdiff)
|
||||||
@@ -52,7 +49,7 @@ module WikiHelper
|
|||||||
words_add += 1
|
words_add += 1
|
||||||
else
|
else
|
||||||
del_at = pos unless del_at
|
del_at = pos unless del_at
|
||||||
deleted << ' ' + change[2]
|
deleted << ' ' + h(change[2])
|
||||||
words_del += 1
|
words_del += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
module WorkflowsHelper
|
||||||
|
end
|
||||||
+67
-10
@@ -30,12 +30,14 @@ class Attachment < ActiveRecord::Base
|
|||||||
|
|
||||||
acts_as_activity_provider :type => 'files',
|
acts_as_activity_provider :type => 'files',
|
||||||
:permission => :view_files,
|
:permission => :view_files,
|
||||||
|
:author_key => :author_id,
|
||||||
:find_options => {:select => "#{Attachment.table_name}.*",
|
:find_options => {:select => "#{Attachment.table_name}.*",
|
||||||
:joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
|
:joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
|
||||||
"LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id"}
|
"LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id OR ( #{Attachment.table_name}.container_type='Project' AND #{Attachment.table_name}.container_id = #{Project.table_name}.id )"}
|
||||||
|
|
||||||
acts_as_activity_provider :type => 'documents',
|
acts_as_activity_provider :type => 'documents',
|
||||||
:permission => :view_documents,
|
:permission => :view_documents,
|
||||||
|
:author_key => :author_id,
|
||||||
:find_options => {:select => "#{Attachment.table_name}.*",
|
:find_options => {:select => "#{Attachment.table_name}.*",
|
||||||
:joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
|
:joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
|
||||||
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id"}
|
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id"}
|
||||||
@@ -44,7 +46,9 @@ class Attachment < ActiveRecord::Base
|
|||||||
@@storage_path = "#{RAILS_ROOT}/files"
|
@@storage_path = "#{RAILS_ROOT}/files"
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
errors.add_to_base :too_long if self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
if self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
||||||
|
errors.add(:base, :too_long, :count => Setting.attachment_max_size.to_i.kilobytes)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def file=(incoming_file)
|
def file=(incoming_file)
|
||||||
@@ -54,6 +58,9 @@ class Attachment < ActiveRecord::Base
|
|||||||
self.filename = sanitize_filename(@temp_file.original_filename)
|
self.filename = sanitize_filename(@temp_file.original_filename)
|
||||||
self.disk_filename = Attachment.disk_filename(filename)
|
self.disk_filename = Attachment.disk_filename(filename)
|
||||||
self.content_type = @temp_file.content_type.to_s.chomp
|
self.content_type = @temp_file.content_type.to_s.chomp
|
||||||
|
if content_type.blank?
|
||||||
|
self.content_type = Redmine::MimeType.of(filename)
|
||||||
|
end
|
||||||
self.filesize = @temp_file.size
|
self.filesize = @temp_file.size
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -63,14 +70,20 @@ class Attachment < ActiveRecord::Base
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Copy temp file to its final location
|
# Copies the temporary file to its final location
|
||||||
|
# and computes its MD5 hash
|
||||||
def before_save
|
def before_save
|
||||||
if @temp_file && (@temp_file.size > 0)
|
if @temp_file && (@temp_file.size > 0)
|
||||||
logger.debug("saving '#{self.diskfile}'")
|
logger.debug("saving '#{self.diskfile}'")
|
||||||
|
md5 = Digest::MD5.new
|
||||||
File.open(diskfile, "wb") do |f|
|
File.open(diskfile, "wb") do |f|
|
||||||
f.write(@temp_file.read)
|
buffer = ""
|
||||||
|
while (buffer = @temp_file.read(8192))
|
||||||
|
f.write(buffer)
|
||||||
|
md5.update(buffer)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
self.digest = Digest::MD5.hexdigest(File.read(diskfile))
|
self.digest = md5.hexdigest
|
||||||
end
|
end
|
||||||
# Don't save the content type if it's longer than the authorized length
|
# Don't save the content type if it's longer than the authorized length
|
||||||
if self.content_type && self.content_type.length > 255
|
if self.content_type && self.content_type.length > 255
|
||||||
@@ -96,6 +109,14 @@ class Attachment < ActiveRecord::Base
|
|||||||
container.project
|
container.project
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def visible?(user=User.current)
|
||||||
|
container.attachments_visible?(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def deletable?(user=User.current)
|
||||||
|
container.attachments_deletable?(user)
|
||||||
|
end
|
||||||
|
|
||||||
def image?
|
def image?
|
||||||
self.filename =~ /\.(jpe?g|gif|png)$/i
|
self.filename =~ /\.(jpe?g|gif|png)$/i
|
||||||
end
|
end
|
||||||
@@ -108,6 +129,38 @@ class Attachment < ActiveRecord::Base
|
|||||||
self.filename =~ /\.(patch|diff)$/i
|
self.filename =~ /\.(patch|diff)$/i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns true if the file is readable
|
||||||
|
def readable?
|
||||||
|
File.readable?(diskfile)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Bulk attaches a set of files to an object
|
||||||
|
#
|
||||||
|
# Returns a Hash of the results:
|
||||||
|
# :files => array of the attached files
|
||||||
|
# :unsaved => array of the files that could not be attached
|
||||||
|
def self.attach_files(obj, attachments)
|
||||||
|
attached = []
|
||||||
|
if attachments && attachments.is_a?(Hash)
|
||||||
|
attachments.each_value do |attachment|
|
||||||
|
file = attachment['file']
|
||||||
|
next unless file && file.size > 0
|
||||||
|
a = Attachment.create(:container => obj,
|
||||||
|
:file => file,
|
||||||
|
:description => attachment['description'].to_s.strip,
|
||||||
|
:author => User.current)
|
||||||
|
|
||||||
|
if a.new_record?
|
||||||
|
obj.unsaved_attachments ||= []
|
||||||
|
obj.unsaved_attachments << a
|
||||||
|
else
|
||||||
|
attached << a
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
{:files => attached, :unsaved => obj.unsaved_attachments}
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def sanitize_filename(value)
|
def sanitize_filename(value)
|
||||||
# get only the filename, not the whole path
|
# get only the filename, not the whole path
|
||||||
@@ -121,14 +174,18 @@ private
|
|||||||
|
|
||||||
# Returns an ASCII or hashed filename
|
# Returns an ASCII or hashed filename
|
||||||
def self.disk_filename(filename)
|
def self.disk_filename(filename)
|
||||||
df = DateTime.now.strftime("%y%m%d%H%M%S") + "_"
|
timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
|
||||||
|
ascii = ''
|
||||||
if filename =~ %r{^[a-zA-Z0-9_\.\-]*$}
|
if filename =~ %r{^[a-zA-Z0-9_\.\-]*$}
|
||||||
df << filename
|
ascii = filename
|
||||||
else
|
else
|
||||||
df << Digest::MD5.hexdigest(filename)
|
ascii = Digest::MD5.hexdigest(filename)
|
||||||
# keep the extension if any
|
# keep the extension if any
|
||||||
df << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
|
ascii << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
|
||||||
end
|
end
|
||||||
df
|
while File.exist?(File.join(@@storage_path, "#{timestamp}_#{ascii}"))
|
||||||
|
timestamp.succ!
|
||||||
|
end
|
||||||
|
"#{timestamp}_#{ascii}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,13 +32,23 @@ class AuthSource < ActiveRecord::Base
|
|||||||
"Abstract"
|
"Abstract"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def allow_password_changes?
|
||||||
|
self.class.allow_password_changes?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Does this auth source backend allow password changes?
|
||||||
|
def self.allow_password_changes?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
# Try to authenticate a user not yet registered against available sources
|
# Try to authenticate a user not yet registered against available sources
|
||||||
def self.authenticate(login, password)
|
def self.authenticate(login, password)
|
||||||
AuthSource.find(:all, :conditions => ["onthefly_register=?", true]).each do |source|
|
AuthSource.find(:all, :conditions => ["onthefly_register=?", true]).each do |source|
|
||||||
begin
|
begin
|
||||||
logger.debug "Authenticating '#{login}' against '#{source.name}'" if logger && logger.debug?
|
logger.debug "Authenticating '#{login}' against '#{source.name}'" if logger && logger.debug?
|
||||||
attrs = source.authenticate(login, password)
|
attrs = source.authenticate(login, password)
|
||||||
rescue
|
rescue => e
|
||||||
|
logger.error "Error during authentication: #{e.message}"
|
||||||
attrs = nil
|
attrs = nil
|
||||||
end
|
end
|
||||||
return attrs if attrs
|
return attrs if attrs
|
||||||
|
|||||||
@@ -25,36 +25,20 @@ class AuthSourceLdap < AuthSource
|
|||||||
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true
|
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true
|
||||||
validates_numericality_of :port, :only_integer => true
|
validates_numericality_of :port, :only_integer => true
|
||||||
|
|
||||||
|
before_validation :strip_ldap_attributes
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
self.port = 389 if self.port == 0
|
self.port = 389 if self.port == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate(login, password)
|
def authenticate(login, password)
|
||||||
return nil if login.blank? || password.blank?
|
return nil if login.blank? || password.blank?
|
||||||
attrs = []
|
attrs = get_user_dn(login)
|
||||||
# get user's DN
|
|
||||||
ldap_con = initialize_ldap_con(self.account, self.account_password)
|
if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password)
|
||||||
login_filter = Net::LDAP::Filter.eq( self.attr_login, login )
|
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
|
||||||
object_filter = Net::LDAP::Filter.eq( "objectClass", "*" )
|
return attrs.except(:dn)
|
||||||
dn = String.new
|
|
||||||
ldap_con.search( :base => self.base_dn,
|
|
||||||
:filter => object_filter & login_filter,
|
|
||||||
# only ask for the DN if on-the-fly registration is disabled
|
|
||||||
:attributes=> (onthefly_register? ? ['dn', self.attr_firstname, self.attr_lastname, self.attr_mail] : ['dn'])) do |entry|
|
|
||||||
dn = entry.dn
|
|
||||||
attrs = [:firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname),
|
|
||||||
:lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname),
|
|
||||||
:mail => AuthSourceLdap.get_attr(entry, self.attr_mail),
|
|
||||||
:auth_source_id => self.id ] if onthefly_register?
|
|
||||||
end
|
end
|
||||||
return nil if dn.empty?
|
|
||||||
logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug?
|
|
||||||
# authenticate user
|
|
||||||
ldap_con = initialize_ldap_con(dn, password)
|
|
||||||
return nil unless ldap_con.bind
|
|
||||||
# return user's attributes
|
|
||||||
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
|
|
||||||
attrs
|
|
||||||
rescue Net::LDAP::LdapError => text
|
rescue Net::LDAP::LdapError => text
|
||||||
raise "LdapError: " + text
|
raise "LdapError: " + text
|
||||||
end
|
end
|
||||||
@@ -71,7 +55,14 @@ class AuthSourceLdap < AuthSource
|
|||||||
"LDAP"
|
"LDAP"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def strip_ldap_attributes
|
||||||
|
[:attr_login, :attr_firstname, :attr_lastname, :attr_mail].each do |attr|
|
||||||
|
write_attribute(attr, read_attribute(attr).strip) unless read_attribute(attr).nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def initialize_ldap_con(ldap_user, ldap_password)
|
def initialize_ldap_con(ldap_user, ldap_password)
|
||||||
options = { :host => self.host,
|
options = { :host => self.host,
|
||||||
:port => self.port,
|
:port => self.port,
|
||||||
@@ -80,8 +71,60 @@ private
|
|||||||
options.merge!(:auth => { :method => :simple, :username => ldap_user, :password => ldap_password }) unless ldap_user.blank? && ldap_password.blank?
|
options.merge!(:auth => { :method => :simple, :username => ldap_user, :password => ldap_password }) unless ldap_user.blank? && ldap_password.blank?
|
||||||
Net::LDAP.new options
|
Net::LDAP.new options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_user_attributes_from_ldap_entry(entry)
|
||||||
|
{
|
||||||
|
:dn => entry.dn,
|
||||||
|
:firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname),
|
||||||
|
:lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname),
|
||||||
|
:mail => AuthSourceLdap.get_attr(entry, self.attr_mail),
|
||||||
|
:auth_source_id => self.id
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return the attributes needed for the LDAP search. It will only
|
||||||
|
# include the user attributes if on-the-fly registration is enabled
|
||||||
|
def search_attributes
|
||||||
|
if onthefly_register?
|
||||||
|
['dn', self.attr_firstname, self.attr_lastname, self.attr_mail]
|
||||||
|
else
|
||||||
|
['dn']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check if a DN (user record) authenticates with the password
|
||||||
|
def authenticate_dn(dn, password)
|
||||||
|
if dn.present? && password.present?
|
||||||
|
initialize_ldap_con(dn, password).bind
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get the user's dn and any attributes for them, given their login
|
||||||
|
def get_user_dn(login)
|
||||||
|
ldap_con = initialize_ldap_con(self.account, self.account_password)
|
||||||
|
login_filter = Net::LDAP::Filter.eq( self.attr_login, login )
|
||||||
|
object_filter = Net::LDAP::Filter.eq( "objectClass", "*" )
|
||||||
|
attrs = {}
|
||||||
|
|
||||||
|
ldap_con.search( :base => self.base_dn,
|
||||||
|
:filter => object_filter & login_filter,
|
||||||
|
:attributes=> search_attributes) do |entry|
|
||||||
|
|
||||||
|
if onthefly_register?
|
||||||
|
attrs = get_user_attributes_from_ldap_entry(entry)
|
||||||
|
else
|
||||||
|
attrs = {:dn => entry.dn}
|
||||||
|
end
|
||||||
|
|
||||||
|
logger.debug "DN found for #{login}: #{attrs[:dn]}" if logger && logger.debug?
|
||||||
|
end
|
||||||
|
|
||||||
|
attrs
|
||||||
|
end
|
||||||
|
|
||||||
def self.get_attr(entry, attr_name)
|
def self.get_attr(entry, attr_name)
|
||||||
entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name]
|
if !attr_name.blank?
|
||||||
|
entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,4 +26,25 @@ class Board < ActiveRecord::Base
|
|||||||
validates_presence_of :name, :description
|
validates_presence_of :name, :description
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
validates_length_of :description, :maximum => 255
|
validates_length_of :description, :maximum => 255
|
||||||
|
|
||||||
|
def visible?(user=User.current)
|
||||||
|
!user.nil? && user.allowed_to?(:view_messages, project)
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
name
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset_counters!
|
||||||
|
self.class.reset_counters!(id)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Updates topics_count, messages_count and last_message_id attributes for +board_id+
|
||||||
|
def self.reset_counters!(board_id)
|
||||||
|
board_id = board_id.to_i
|
||||||
|
update_all("topics_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id} AND parent_id IS NULL)," +
|
||||||
|
" messages_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id})," +
|
||||||
|
" last_message_id = (SELECT MAX(id) FROM #{Message.table_name} WHERE board_id=#{board_id})",
|
||||||
|
["id = ?", board_id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,4 +23,8 @@ class Change < ActiveRecord::Base
|
|||||||
def relative_path
|
def relative_path
|
||||||
changeset.repository.relative_path(path)
|
changeset.repository.relative_path(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def before_save
|
||||||
|
path ||= ""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+96
-29
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2010 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -15,16 +15,18 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
require 'iconv'
|
||||||
|
|
||||||
class Changeset < ActiveRecord::Base
|
class Changeset < ActiveRecord::Base
|
||||||
belongs_to :repository
|
belongs_to :repository
|
||||||
|
belongs_to :user
|
||||||
has_many :changes, :dependent => :delete_all
|
has_many :changes, :dependent => :delete_all
|
||||||
has_and_belongs_to_many :issues
|
has_and_belongs_to_many :issues
|
||||||
|
|
||||||
acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.revision}" + (o.comments.blank? ? '' : (': ' + o.comments))},
|
acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.revision}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments))},
|
||||||
:description => :comments,
|
:description => :long_comments,
|
||||||
:datetime => :committed_on,
|
:datetime => :committed_on,
|
||||||
:author => :committer,
|
:url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project, :rev => o.revision}}
|
||||||
:url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project_id, :rev => o.revision}}
|
|
||||||
|
|
||||||
acts_as_searchable :columns => 'comments',
|
acts_as_searchable :columns => 'comments',
|
||||||
:include => {:repository => :project},
|
:include => {:repository => :project},
|
||||||
@@ -32,18 +34,22 @@ class Changeset < ActiveRecord::Base
|
|||||||
:date_column => 'committed_on'
|
:date_column => 'committed_on'
|
||||||
|
|
||||||
acts_as_activity_provider :timestamp => "#{table_name}.committed_on",
|
acts_as_activity_provider :timestamp => "#{table_name}.committed_on",
|
||||||
:find_options => {:include => {:repository => :project}}
|
:author_key => :user_id,
|
||||||
|
:find_options => {:include => [:user, {:repository => :project}]}
|
||||||
|
|
||||||
validates_presence_of :repository_id, :revision, :committed_on, :commit_date
|
validates_presence_of :repository_id, :revision, :committed_on, :commit_date
|
||||||
validates_uniqueness_of :revision, :scope => :repository_id
|
validates_uniqueness_of :revision, :scope => :repository_id
|
||||||
validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
|
validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
|
||||||
|
|
||||||
|
named_scope :visible, lambda {|*args| { :include => {:repository => :project},
|
||||||
|
:conditions => Project.allowed_to_condition(args.first || User.current, :view_changesets) } }
|
||||||
|
|
||||||
def revision=(r)
|
def revision=(r)
|
||||||
write_attribute :revision, (r.nil? ? nil : r.to_s)
|
write_attribute :revision, (r.nil? ? nil : r.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def comments=(comment)
|
def comments=(comment)
|
||||||
write_attribute(:comments, comment.strip)
|
write_attribute(:comments, Changeset.normalize_comments(comment))
|
||||||
end
|
end
|
||||||
|
|
||||||
def committed_on=(date)
|
def committed_on=(date)
|
||||||
@@ -51,10 +57,22 @@ class Changeset < ActiveRecord::Base
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def committer=(arg)
|
||||||
|
write_attribute(:committer, self.class.to_utf8(arg.to_s))
|
||||||
|
end
|
||||||
|
|
||||||
def project
|
def project
|
||||||
repository.project
|
repository.project
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def author
|
||||||
|
user || committer.to_s.split('<').first
|
||||||
|
end
|
||||||
|
|
||||||
|
def before_create
|
||||||
|
self.user = repository.find_committer_user(committer)
|
||||||
|
end
|
||||||
|
|
||||||
def after_create
|
def after_create
|
||||||
scan_comment_for_issue_ids
|
scan_comment_for_issue_ids
|
||||||
end
|
end
|
||||||
@@ -66,9 +84,6 @@ class Changeset < ActiveRecord::Base
|
|||||||
ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip)
|
ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip)
|
||||||
# keywords used to fix issues
|
# keywords used to fix issues
|
||||||
fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip)
|
fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip)
|
||||||
# status and optional done ratio applied
|
|
||||||
fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id)
|
|
||||||
done_ratio = Setting.commit_fix_done_ratio.blank? ? nil : Setting.commit_fix_done_ratio.to_i
|
|
||||||
|
|
||||||
kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
|
kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
|
||||||
return if kw_regexp.blank?
|
return if kw_regexp.blank?
|
||||||
@@ -78,15 +93,15 @@ class Changeset < ActiveRecord::Base
|
|||||||
if ref_keywords.delete('*')
|
if ref_keywords.delete('*')
|
||||||
# find any issue ID in the comments
|
# find any issue ID in the comments
|
||||||
target_issue_ids = []
|
target_issue_ids = []
|
||||||
comments.scan(%r{([\s\(,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] }
|
comments.scan(%r{([\s\(\[,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] }
|
||||||
referenced_issues += repository.project.issues.find_all_by_id(target_issue_ids)
|
referenced_issues += find_referenced_issues_by_id(target_issue_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match|
|
comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match|
|
||||||
action = match[0]
|
action = match[0]
|
||||||
target_issue_ids = match[1].scan(/\d+/)
|
target_issue_ids = match[1].scan(/\d+/)
|
||||||
target_issues = repository.project.issues.find_all_by_id(target_issue_ids)
|
target_issues = find_referenced_issues_by_id(target_issue_ids)
|
||||||
if fix_status && fix_keywords.include?(action.downcase)
|
if fix_keywords.include?(action.downcase) && fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id)
|
||||||
# update status of issues
|
# update status of issues
|
||||||
logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug?
|
logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug?
|
||||||
target_issues.each do |issue|
|
target_issues.each do |issue|
|
||||||
@@ -94,32 +109,33 @@ class Changeset < ActiveRecord::Base
|
|||||||
issue.reload
|
issue.reload
|
||||||
# don't change the status is the issue is closed
|
# don't change the status is the issue is closed
|
||||||
next if issue.status.is_closed?
|
next if issue.status.is_closed?
|
||||||
user = committer_user || User.anonymous
|
|
||||||
csettext = "r#{self.revision}"
|
csettext = "r#{self.revision}"
|
||||||
if self.scmid && (! (csettext =~ /^r[0-9]+$/))
|
if self.scmid && (! (csettext =~ /^r[0-9]+$/))
|
||||||
csettext = "commit:\"#{self.scmid}\""
|
csettext = "commit:\"#{self.scmid}\""
|
||||||
end
|
end
|
||||||
journal = issue.init_journal(user, l(:text_status_changed_by_changeset, csettext))
|
journal = issue.init_journal(user || User.anonymous, ll(Setting.default_language, :text_status_changed_by_changeset, csettext))
|
||||||
issue.status = fix_status
|
issue.status = fix_status
|
||||||
issue.done_ratio = done_ratio if done_ratio
|
unless Setting.commit_fix_done_ratio.blank?
|
||||||
|
issue.done_ratio = Setting.commit_fix_done_ratio.to_i
|
||||||
|
end
|
||||||
|
Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update,
|
||||||
|
{ :changeset => self, :issue => issue })
|
||||||
issue.save
|
issue.save
|
||||||
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
referenced_issues += target_issues
|
referenced_issues += target_issues
|
||||||
end
|
end
|
||||||
|
|
||||||
self.issues = referenced_issues.uniq
|
referenced_issues.uniq!
|
||||||
|
self.issues = referenced_issues unless referenced_issues.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the Redmine User corresponding to the committer
|
def short_comments
|
||||||
def committer_user
|
@short_comments || split_comments.first
|
||||||
if committer && committer.strip =~ /^([^<]+)(<(.*)>)?$/
|
end
|
||||||
username, email = $1.strip, $3
|
|
||||||
u = User.find_by_login(username)
|
def long_comments
|
||||||
u ||= User.find_by_mail(email) unless email.blank?
|
@long_comments || split_comments.last
|
||||||
u
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the previous changeset
|
# Returns the previous changeset
|
||||||
@@ -131,4 +147,55 @@ class Changeset < ActiveRecord::Base
|
|||||||
def next
|
def next
|
||||||
@next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC')
|
@next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Strips and reencodes a commit log before insertion into the database
|
||||||
|
def self.normalize_comments(str)
|
||||||
|
to_utf8(str.to_s.strip)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Creates a new Change from it's common parameters
|
||||||
|
def create_change(change)
|
||||||
|
Change.create(:changeset => self,
|
||||||
|
:action => change[:action],
|
||||||
|
:path => change[:path],
|
||||||
|
:from_path => change[:from_path],
|
||||||
|
:from_revision => change[:from_revision])
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Finds issues that can be referenced by the commit message
|
||||||
|
# i.e. issues that belong to the repository project, a subproject or a parent project
|
||||||
|
def find_referenced_issues_by_id(ids)
|
||||||
|
return [] if ids.compact.empty?
|
||||||
|
Issue.find_all_by_id(ids, :include => :project).select {|issue|
|
||||||
|
project == issue.project || project.is_ancestor_of?(issue.project) || project.is_descendant_of?(issue.project)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def split_comments
|
||||||
|
comments =~ /\A(.+?)\r?\n(.*)$/m
|
||||||
|
@short_comments = $1 || comments
|
||||||
|
@long_comments = $2.to_s.strip
|
||||||
|
return @short_comments, @long_comments
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.to_utf8(str)
|
||||||
|
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||||
|
encoding = Setting.commit_logs_encoding.to_s.strip
|
||||||
|
unless encoding.blank? || encoding == 'UTF-8'
|
||||||
|
begin
|
||||||
|
str = Iconv.conv('UTF-8', encoding, str)
|
||||||
|
rescue Iconv::Failure
|
||||||
|
# do nothing here
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# removes invalid UTF8 sequences
|
||||||
|
begin
|
||||||
|
Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]
|
||||||
|
rescue Iconv::InvalidEncoding
|
||||||
|
# "UTF-8//IGNORE" is not supported on some OS
|
||||||
|
str
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+64
-18
@@ -20,20 +20,11 @@ class CustomField < ActiveRecord::Base
|
|||||||
acts_as_list :scope => 'type = \'#{self.class}\''
|
acts_as_list :scope => 'type = \'#{self.class}\''
|
||||||
serialize :possible_values
|
serialize :possible_values
|
||||||
|
|
||||||
FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 },
|
|
||||||
"text" => { :name => :label_text, :order => 2 },
|
|
||||||
"int" => { :name => :label_integer, :order => 3 },
|
|
||||||
"float" => { :name => :label_float, :order => 4 },
|
|
||||||
"list" => { :name => :label_list, :order => 5 },
|
|
||||||
"date" => { :name => :label_date, :order => 6 },
|
|
||||||
"bool" => { :name => :label_boolean, :order => 7 }
|
|
||||||
}.freeze
|
|
||||||
|
|
||||||
validates_presence_of :name, :field_format
|
validates_presence_of :name, :field_format
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name, :scope => :type
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
validates_format_of :name, :with => /^[\w\s\.\'\-]*$/i
|
||||||
validates_inclusion_of :field_format, :in => FIELD_FORMATS.keys
|
validates_inclusion_of :field_format, :in => Redmine::CustomFieldFormat.available_formats
|
||||||
|
|
||||||
def initialize(attributes = nil)
|
def initialize(attributes = nil)
|
||||||
super
|
super
|
||||||
@@ -41,8 +32,6 @@ class CustomField < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def before_validation
|
def before_validation
|
||||||
# remove empty values
|
|
||||||
self.possible_values = self.possible_values.collect{|v| v unless v.empty?}.compact
|
|
||||||
# make sure these fields are not searchable
|
# make sure these fields are not searchable
|
||||||
self.searchable = false if %w(int float date bool).include?(field_format)
|
self.searchable = false if %w(int float date bool).include?(field_format)
|
||||||
true
|
true
|
||||||
@@ -50,23 +39,80 @@ class CustomField < ActiveRecord::Base
|
|||||||
|
|
||||||
def validate
|
def validate
|
||||||
if self.field_format == "list"
|
if self.field_format == "list"
|
||||||
errors.add(:possible_values, :activerecord_error_blank) if self.possible_values.nil? || self.possible_values.empty?
|
errors.add(:possible_values, :blank) if self.possible_values.nil? || self.possible_values.empty?
|
||||||
errors.add(:possible_values, :activerecord_error_invalid) unless self.possible_values.is_a? Array
|
errors.add(:possible_values, :invalid) unless self.possible_values.is_a? Array
|
||||||
end
|
end
|
||||||
|
|
||||||
# validate default value
|
# validate default value
|
||||||
v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil)
|
v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil)
|
||||||
v.custom_field.is_required = false
|
v.custom_field.is_required = false
|
||||||
errors.add(:default_value, :activerecord_error_invalid) unless v.valid?
|
errors.add(:default_value, :invalid) unless v.valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Makes possible_values accept a multiline string
|
||||||
|
def possible_values=(arg)
|
||||||
|
if arg.is_a?(Array)
|
||||||
|
write_attribute(:possible_values, arg.compact.collect(&:strip).select {|v| !v.blank?})
|
||||||
|
else
|
||||||
|
self.possible_values = arg.to_s.split(/[\n\r]+/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def cast_value(value)
|
||||||
|
casted = nil
|
||||||
|
unless value.blank?
|
||||||
|
case field_format
|
||||||
|
when 'string', 'text', 'list'
|
||||||
|
casted = value
|
||||||
|
when 'date'
|
||||||
|
casted = begin; value.to_date; rescue; nil end
|
||||||
|
when 'bool'
|
||||||
|
casted = (value == '1' ? true : false)
|
||||||
|
when 'int'
|
||||||
|
casted = value.to_i
|
||||||
|
when 'float'
|
||||||
|
casted = value.to_f
|
||||||
|
end
|
||||||
|
end
|
||||||
|
casted
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a ORDER BY clause that can used to sort customized
|
||||||
|
# objects by their value of the custom field.
|
||||||
|
# Returns false, if the custom field can not be used for sorting.
|
||||||
|
def order_statement
|
||||||
|
case field_format
|
||||||
|
when 'string', 'text', 'list', 'date', 'bool'
|
||||||
|
# COALESCE is here to make sure that blank and NULL values are sorted equally
|
||||||
|
"COALESCE((SELECT cv_sort.value FROM #{CustomValue.table_name} cv_sort" +
|
||||||
|
" WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" +
|
||||||
|
" AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" +
|
||||||
|
" AND cv_sort.custom_field_id=#{id} LIMIT 1), '')"
|
||||||
|
when 'int', 'float'
|
||||||
|
# Make the database cast values into numeric
|
||||||
|
# Postgresql will raise an error if a value can not be casted!
|
||||||
|
# CustomValue validations should ensure that it doesn't occur
|
||||||
|
"(SELECT CAST(cv_sort.value AS decimal(60,3)) FROM #{CustomValue.table_name} cv_sort" +
|
||||||
|
" WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" +
|
||||||
|
" AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" +
|
||||||
|
" AND cv_sort.custom_field_id=#{id} AND cv_sort.value <> '' AND cv_sort.value IS NOT NULL LIMIT 1)"
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def <=>(field)
|
def <=>(field)
|
||||||
position <=> field.position
|
position <=> field.position
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.customized_class
|
||||||
|
self.name =~ /^(.+)CustomField$/
|
||||||
|
begin; $1.constantize; rescue nil; end
|
||||||
|
end
|
||||||
|
|
||||||
# to move in project_custom_field
|
# to move in project_custom_field
|
||||||
def self.for_all
|
def self.for_all
|
||||||
find(:all, :conditions => ["is_for_all=?", true])
|
find(:all, :conditions => ["is_for_all=?", true], :order => 'position')
|
||||||
end
|
end
|
||||||
|
|
||||||
def type_name
|
def type_name
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class CustomValue < ActiveRecord::Base
|
|||||||
belongs_to :customized, :polymorphic => true
|
belongs_to :customized, :polymorphic => true
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
if custom_field && new_record? && (customized_type.blank? || (customized && customized.new_record?))
|
if new_record? && custom_field && (customized_type.blank? || (customized && customized.new_record?))
|
||||||
self.value ||= custom_field.default_value
|
self.value ||= custom_field.default_value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -30,25 +30,37 @@ class CustomValue < ActiveRecord::Base
|
|||||||
self.value == '1'
|
self.value == '1'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def editable?
|
||||||
|
custom_field.editable?
|
||||||
|
end
|
||||||
|
|
||||||
|
def required?
|
||||||
|
custom_field.is_required?
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
value.to_s
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def validate
|
def validate
|
||||||
if value.blank?
|
if value.blank?
|
||||||
errors.add(:value, :activerecord_error_blank) if custom_field.is_required? and value.blank?
|
errors.add(:value, :blank) if custom_field.is_required? and value.blank?
|
||||||
else
|
else
|
||||||
errors.add(:value, :activerecord_error_invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
|
errors.add(:value, :invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
|
||||||
errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length
|
errors.add(:value, :too_short, :count => custom_field.min_length) if custom_field.min_length > 0 and value.length < custom_field.min_length
|
||||||
errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
|
errors.add(:value, :too_long, :count => custom_field.max_length) if custom_field.max_length > 0 and value.length > custom_field.max_length
|
||||||
|
|
||||||
# Format specific validations
|
# Format specific validations
|
||||||
case custom_field.field_format
|
case custom_field.field_format
|
||||||
when 'int'
|
when 'int'
|
||||||
errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[+-]?\d+$/
|
errors.add(:value, :not_a_number) unless value =~ /^[+-]?\d+$/
|
||||||
when 'float'
|
when 'float'
|
||||||
begin; Kernel.Float(value); rescue; errors.add(:value, :activerecord_error_invalid) end
|
begin; Kernel.Float(value); rescue; errors.add(:value, :invalid) end
|
||||||
when 'date'
|
when 'date'
|
||||||
errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/
|
errors.add(:value, :not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/
|
||||||
when 'list'
|
when 'list'
|
||||||
errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include?(value)
|
errors.add(:value, :inclusion) unless custom_field.possible_values.include?(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+20
-2
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
class Document < ActiveRecord::Base
|
class Document < ActiveRecord::Base
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :category, :class_name => "Enumeration", :foreign_key => "category_id"
|
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
|
||||||
has_many :attachments, :as => :container, :dependent => :destroy
|
acts_as_attachable :delete_permission => :manage_documents
|
||||||
|
|
||||||
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
||||||
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
|
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
|
||||||
@@ -28,4 +28,22 @@ class Document < ActiveRecord::Base
|
|||||||
|
|
||||||
validates_presence_of :project, :title, :category
|
validates_presence_of :project, :title, :category
|
||||||
validates_length_of :title, :maximum => 60
|
validates_length_of :title, :maximum => 60
|
||||||
|
|
||||||
|
def visible?(user=User.current)
|
||||||
|
!user.nil? && user.allowed_to?(:view_documents, project)
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_initialize
|
||||||
|
if new_record?
|
||||||
|
self.category ||= DocumentCategory.default
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def updated_on
|
||||||
|
unless @updated_on
|
||||||
|
a = attachments.find(:first, :order => 'created_on DESC')
|
||||||
|
@updated_on = (a && a.created_on) || created_on
|
||||||
|
end
|
||||||
|
@updated_on
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# redMine - project management software
|
||||||
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class DocumentCategory < Enumeration
|
||||||
|
has_many :documents, :foreign_key => 'category_id'
|
||||||
|
|
||||||
|
OptionName = :enumeration_doc_categories
|
||||||
|
|
||||||
|
def option_name
|
||||||
|
OptionName
|
||||||
|
end
|
||||||
|
|
||||||
|
def objects_count
|
||||||
|
documents.count
|
||||||
|
end
|
||||||
|
|
||||||
|
def transfer_relations(to)
|
||||||
|
documents.update_all("category_id = #{to.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# redMine - project management software
|
||||||
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class DocumentCategoryCustomField < CustomField
|
||||||
|
def type_name
|
||||||
|
:enumeration_doc_categories
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@@ -15,11 +15,8 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class SysApi < ActionWebService::API::Base
|
class DocumentObserver < ActiveRecord::Observer
|
||||||
api_method :projects,
|
def after_create(document)
|
||||||
:expects => [],
|
Mailer.deliver_document_added(document) if Setting.notified_events.include?('document_added')
|
||||||
:returns => [[Project]]
|
end
|
||||||
api_method :repository_created,
|
|
||||||
:expects => [:string, :string],
|
|
||||||
:returns => [:int]
|
|
||||||
end
|
end
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -20,4 +20,19 @@ class EnabledModule < ActiveRecord::Base
|
|||||||
|
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
validates_uniqueness_of :name, :scope => :project_id
|
validates_uniqueness_of :name, :scope => :project_id
|
||||||
|
|
||||||
|
after_create :module_enabled
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# after_create callback used to do things when a module is enabled
|
||||||
|
def module_enabled
|
||||||
|
case name
|
||||||
|
when 'wiki'
|
||||||
|
# Create a wiki with a default start page
|
||||||
|
if project && project.wiki.nil?
|
||||||
|
Wiki.create(:project => project, :start_page => 'Wiki')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+76
-21
@@ -16,44 +16,59 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class Enumeration < ActiveRecord::Base
|
class Enumeration < ActiveRecord::Base
|
||||||
acts_as_list :scope => 'opt = \'#{opt}\''
|
default_scope :order => "#{Enumeration.table_name}.position ASC"
|
||||||
|
|
||||||
|
belongs_to :project
|
||||||
|
|
||||||
|
acts_as_list :scope => 'type = \'#{type}\''
|
||||||
|
acts_as_customizable
|
||||||
|
acts_as_tree :order => 'position ASC'
|
||||||
|
|
||||||
before_destroy :check_integrity
|
before_destroy :check_integrity
|
||||||
|
|
||||||
validates_presence_of :opt, :name
|
validates_presence_of :name
|
||||||
validates_uniqueness_of :name, :scope => [:opt]
|
validates_uniqueness_of :name, :scope => [:type, :project_id]
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
|
|
||||||
# Single table inheritance would be an option
|
named_scope :shared, :conditions => { :project_id => nil }
|
||||||
OPTIONS = {
|
named_scope :active, :conditions => { :active => true }
|
||||||
"IPRI" => {:label => :enumeration_issue_priorities, :model => Issue, :foreign_key => :priority_id},
|
|
||||||
"DCAT" => {:label => :enumeration_doc_categories, :model => Document, :foreign_key => :category_id},
|
|
||||||
"ACTI" => {:label => :enumeration_activities, :model => TimeEntry, :foreign_key => :activity_id}
|
|
||||||
}.freeze
|
|
||||||
|
|
||||||
def self.get_values(option)
|
|
||||||
find(:all, :conditions => {:opt => option}, :order => 'position')
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.default(option)
|
|
||||||
find(:first, :conditions => {:opt => option, :is_default => true}, :order => 'position')
|
|
||||||
end
|
|
||||||
|
|
||||||
|
def self.default
|
||||||
|
# Creates a fake default scope so Enumeration.default will check
|
||||||
|
# it's type. STI subclasses will automatically add their own
|
||||||
|
# types to the finder.
|
||||||
|
if self.descends_from_active_record?
|
||||||
|
find(:first, :conditions => { :is_default => true, :type => 'Enumeration' })
|
||||||
|
else
|
||||||
|
# STI classes are
|
||||||
|
find(:first, :conditions => { :is_default => true })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Overloaded on concrete classes
|
||||||
def option_name
|
def option_name
|
||||||
OPTIONS[self.opt][:label]
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_save
|
def before_save
|
||||||
Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) if is_default?
|
if is_default? && is_default_changed?
|
||||||
|
Enumeration.update_all("is_default = #{connection.quoted_false}", {:type => type})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Overloaded on concrete classes
|
||||||
def objects_count
|
def objects_count
|
||||||
OPTIONS[self.opt][:model].count(:conditions => "#{OPTIONS[self.opt][:foreign_key]} = #{id}")
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
def in_use?
|
def in_use?
|
||||||
self.objects_count != 0
|
self.objects_count != 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Is this enumeration overiding a system level enumeration?
|
||||||
|
def is_override?
|
||||||
|
!self.parent.nil?
|
||||||
|
end
|
||||||
|
|
||||||
alias :destroy_without_reassign :destroy
|
alias :destroy_without_reassign :destroy
|
||||||
|
|
||||||
@@ -61,7 +76,7 @@ class Enumeration < ActiveRecord::Base
|
|||||||
# If a enumeration is specified, objects are reassigned
|
# If a enumeration is specified, objects are reassigned
|
||||||
def destroy(reassign_to = nil)
|
def destroy(reassign_to = nil)
|
||||||
if reassign_to && reassign_to.is_a?(Enumeration)
|
if reassign_to && reassign_to.is_a?(Enumeration)
|
||||||
OPTIONS[self.opt][:model].update_all("#{OPTIONS[self.opt][:foreign_key]} = #{reassign_to.id}", "#{OPTIONS[self.opt][:foreign_key]} = #{id}")
|
self.transfer_relations(reassign_to)
|
||||||
end
|
end
|
||||||
destroy_without_reassign
|
destroy_without_reassign
|
||||||
end
|
end
|
||||||
@@ -71,9 +86,49 @@ class Enumeration < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s; name end
|
def to_s; name end
|
||||||
|
|
||||||
|
# Returns the Subclasses of Enumeration. Each Subclass needs to be
|
||||||
|
# required in development mode.
|
||||||
|
#
|
||||||
|
# Note: subclasses is protected in ActiveRecord
|
||||||
|
def self.get_subclasses
|
||||||
|
@@subclasses[Enumeration]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Does the +new+ Hash override the previous Enumeration?
|
||||||
|
def self.overridding_change?(new, previous)
|
||||||
|
if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new,previous)
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Does the +new+ Hash have the same custom values as the previous Enumeration?
|
||||||
|
def self.same_custom_values?(new, previous)
|
||||||
|
previous.custom_field_values.each do |custom_value|
|
||||||
|
if custom_value.value != new["custom_field_values"][custom_value.custom_field_id.to_s]
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
# Are the new and previous fields equal?
|
||||||
|
def self.same_active_state?(new, previous)
|
||||||
|
new = (new == "1" ? true : false)
|
||||||
|
return new == previous
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def check_integrity
|
def check_integrity
|
||||||
raise "Can't delete enumeration" if self.in_use?
|
raise "Can't delete enumeration" if self.in_use?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Force load the subclasses in development mode
|
||||||
|
require_dependency 'time_entry_activity'
|
||||||
|
require_dependency 'document_category'
|
||||||
|
require_dependency 'issue_priority'
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class Group < Principal
|
||||||
|
has_and_belongs_to_many :users, :after_add => :user_added,
|
||||||
|
:after_remove => :user_removed
|
||||||
|
|
||||||
|
acts_as_customizable
|
||||||
|
|
||||||
|
validates_presence_of :lastname
|
||||||
|
validates_uniqueness_of :lastname, :case_sensitive => false
|
||||||
|
validates_length_of :lastname, :maximum => 30
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
lastname.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_added(user)
|
||||||
|
members.each do |member|
|
||||||
|
user_member = Member.find_by_project_id_and_user_id(member.project_id, user.id) || Member.new(:project_id => member.project_id, :user_id => user.id)
|
||||||
|
member.member_roles.each do |member_role|
|
||||||
|
user_member.member_roles << MemberRole.new(:role => member_role.role, :inherited_from => member_role.id)
|
||||||
|
end
|
||||||
|
user_member.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_removed(user)
|
||||||
|
members.each do |member|
|
||||||
|
MemberRole.find(:all, :include => :member,
|
||||||
|
:conditions => ["#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids]).each(&:destroy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class GroupCustomField < CustomField
|
||||||
|
def type_name
|
||||||
|
:label_group_plural
|
||||||
|
end
|
||||||
|
end
|
||||||
+676
-104
@@ -22,38 +22,67 @@ class Issue < ActiveRecord::Base
|
|||||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||||
belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
|
belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
|
||||||
belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
|
belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
|
||||||
belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id'
|
belongs_to :priority, :class_name => 'IssuePriority', :foreign_key => 'priority_id'
|
||||||
belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
|
belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
|
||||||
|
|
||||||
has_many :journals, :as => :journalized, :dependent => :destroy
|
has_many :journals, :as => :journalized, :dependent => :destroy
|
||||||
has_many :attachments, :as => :container, :dependent => :destroy
|
|
||||||
has_many :time_entries, :dependent => :delete_all
|
has_many :time_entries, :dependent => :delete_all
|
||||||
has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC"
|
has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC"
|
||||||
|
|
||||||
has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
|
has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
|
||||||
has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
|
has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
|
||||||
|
|
||||||
|
acts_as_nested_set :scope => 'root_id'
|
||||||
|
acts_as_attachable :after_remove => :attachment_removed
|
||||||
acts_as_customizable
|
acts_as_customizable
|
||||||
acts_as_watchable
|
acts_as_watchable
|
||||||
acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
|
acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
|
||||||
:include => [:project, :journals],
|
:include => [:project, :journals],
|
||||||
# sort by id so that limited eager loading doesn't break with postgresql
|
# sort by id so that limited eager loading doesn't break with postgresql
|
||||||
:order_column => "#{table_name}.id"
|
:order_column => "#{table_name}.id"
|
||||||
acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"},
|
acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"},
|
||||||
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}}
|
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}},
|
||||||
|
:type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') }
|
||||||
|
|
||||||
acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]}
|
acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]},
|
||||||
|
:author_key => :author_id
|
||||||
validates_presence_of :subject, :description, :priority, :project, :tracker, :author, :status
|
|
||||||
|
DONE_RATIO_OPTIONS = %w(issue_field issue_status)
|
||||||
|
|
||||||
|
attr_reader :current_journal
|
||||||
|
|
||||||
|
validates_presence_of :subject, :priority, :project, :tracker, :author, :status
|
||||||
|
|
||||||
validates_length_of :subject, :maximum => 255
|
validates_length_of :subject, :maximum => 255
|
||||||
validates_inclusion_of :done_ratio, :in => 0..100
|
validates_inclusion_of :done_ratio, :in => 0..100
|
||||||
validates_numericality_of :estimated_hours, :allow_nil => true
|
validates_numericality_of :estimated_hours, :allow_nil => true
|
||||||
|
|
||||||
|
named_scope :visible, lambda {|*args| { :include => :project,
|
||||||
|
:conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
|
||||||
|
|
||||||
|
named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status
|
||||||
|
|
||||||
|
named_scope :recently_updated, :order => "#{self.table_name}.updated_on DESC"
|
||||||
|
named_scope :with_limit, lambda { |limit| { :limit => limit} }
|
||||||
|
named_scope :on_active_project, :include => [:status, :project, :tracker],
|
||||||
|
:conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
|
||||||
|
|
||||||
|
before_create :default_assign
|
||||||
|
before_save :reschedule_following_issues, :close_duplicates, :update_done_ratio_from_issue_status
|
||||||
|
after_save :update_nested_set_attributes, :update_parent_attributes, :create_journal
|
||||||
|
after_destroy :destroy_children
|
||||||
|
after_destroy :update_parent_attributes
|
||||||
|
|
||||||
|
# Returns true if usr or current user is allowed to view the issue
|
||||||
|
def visible?(usr=nil)
|
||||||
|
(usr || User.current).allowed_to?(:view_issues, self.project)
|
||||||
|
end
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
if new_record?
|
if new_record?
|
||||||
# set default values for new records only
|
# set default values for new records only
|
||||||
self.status ||= IssueStatus.default
|
self.status ||= IssueStatus.default
|
||||||
self.priority ||= Enumeration.default('IPRI')
|
self.priority ||= IssuePriority.default
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -63,119 +92,225 @@ class Issue < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def copy_from(arg)
|
def copy_from(arg)
|
||||||
issue = arg.is_a?(Issue) ? arg : Issue.find(arg)
|
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
|
||||||
self.attributes = issue.attributes.dup
|
self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on")
|
||||||
self.custom_values = issue.custom_values.collect {|v| v.clone}
|
self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
||||||
|
self.status = issue.status
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# Move an issue to a new project and tracker
|
# Moves/copies an issue to a new project and tracker
|
||||||
def move_to(new_project, new_tracker = nil)
|
# Returns the moved/copied issue on success, false on failure
|
||||||
transaction do
|
def move_to_project(*args)
|
||||||
if new_project && project_id != new_project.id
|
ret = Issue.transaction do
|
||||||
# delete issue relations
|
move_to_project_without_transaction(*args) || raise(ActiveRecord::Rollback)
|
||||||
unless Setting.cross_project_issue_relations?
|
end || false
|
||||||
self.relations_from.clear
|
end
|
||||||
self.relations_to.clear
|
|
||||||
end
|
def move_to_project_without_transaction(new_project, new_tracker = nil, options = {})
|
||||||
# issue is moved to another project
|
options ||= {}
|
||||||
# reassign to the category with same name if any
|
issue = options[:copy] ? self.class.new.copy_from(self) : self
|
||||||
new_category = category.nil? ? nil : new_project.issue_categories.find_by_name(category.name)
|
|
||||||
self.category = new_category
|
if new_project && issue.project_id != new_project.id
|
||||||
self.fixed_version = nil
|
# delete issue relations
|
||||||
self.project = new_project
|
unless Setting.cross_project_issue_relations?
|
||||||
|
issue.relations_from.clear
|
||||||
|
issue.relations_to.clear
|
||||||
end
|
end
|
||||||
if new_tracker
|
# issue is moved to another project
|
||||||
self.tracker = new_tracker
|
# reassign to the category with same name if any
|
||||||
|
new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name)
|
||||||
|
issue.category = new_category
|
||||||
|
# Keep the fixed_version if it's still valid in the new_project
|
||||||
|
unless new_project.shared_versions.include?(issue.fixed_version)
|
||||||
|
issue.fixed_version = nil
|
||||||
end
|
end
|
||||||
if save
|
issue.project = new_project
|
||||||
# Manually update project_id on related time entries
|
if issue.parent && issue.parent.project_id != issue.project_id
|
||||||
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
|
issue.parent_issue_id = nil
|
||||||
else
|
|
||||||
rollback_db_transaction
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
if new_tracker
|
||||||
|
issue.tracker = new_tracker
|
||||||
|
issue.reset_custom_values!
|
||||||
|
end
|
||||||
|
if options[:copy]
|
||||||
|
issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
||||||
|
issue.status = if options[:attributes] && options[:attributes][:status_id]
|
||||||
|
IssueStatus.find_by_id(options[:attributes][:status_id])
|
||||||
|
else
|
||||||
|
self.status
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# Allow bulk setting of attributes on the issue
|
||||||
|
if options[:attributes]
|
||||||
|
issue.attributes = options[:attributes]
|
||||||
|
end
|
||||||
|
if issue.save
|
||||||
|
unless options[:copy]
|
||||||
|
# Manually update project_id on related time entries
|
||||||
|
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
|
||||||
|
|
||||||
|
issue.children.each do |child|
|
||||||
|
unless child.move_to_project_without_transaction(new_project)
|
||||||
|
# Move failed and transaction was rollback'd
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
issue
|
||||||
|
end
|
||||||
|
|
||||||
|
def status_id=(sid)
|
||||||
|
self.status = nil
|
||||||
|
write_attribute(:status_id, sid)
|
||||||
end
|
end
|
||||||
|
|
||||||
def priority_id=(pid)
|
def priority_id=(pid)
|
||||||
self.priority = nil
|
self.priority = nil
|
||||||
write_attribute(:priority_id, pid)
|
write_attribute(:priority_id, pid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tracker_id=(tid)
|
||||||
|
self.tracker = nil
|
||||||
|
result = write_attribute(:tracker_id, tid)
|
||||||
|
@custom_field_values = nil
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
# Overrides attributes= so that tracker_id gets assigned first
|
||||||
|
def attributes_with_tracker_first=(new_attributes, *args)
|
||||||
|
return if new_attributes.nil?
|
||||||
|
new_tracker_id = new_attributes['tracker_id'] || new_attributes[:tracker_id]
|
||||||
|
if new_tracker_id
|
||||||
|
self.tracker_id = new_tracker_id
|
||||||
|
end
|
||||||
|
send :attributes_without_tracker_first=, new_attributes, *args
|
||||||
|
end
|
||||||
|
# Do not redefine alias chain on reload (see #4838)
|
||||||
|
alias_method_chain(:attributes=, :tracker_first) unless method_defined?(:attributes_without_tracker_first=)
|
||||||
|
|
||||||
def estimated_hours=(h)
|
def estimated_hours=(h)
|
||||||
write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
|
write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
SAFE_ATTRIBUTES = %w(
|
||||||
|
tracker_id
|
||||||
|
status_id
|
||||||
|
parent_issue_id
|
||||||
|
category_id
|
||||||
|
assigned_to_id
|
||||||
|
priority_id
|
||||||
|
fixed_version_id
|
||||||
|
subject
|
||||||
|
description
|
||||||
|
start_date
|
||||||
|
due_date
|
||||||
|
done_ratio
|
||||||
|
estimated_hours
|
||||||
|
custom_field_values
|
||||||
|
lock_version
|
||||||
|
) unless const_defined?(:SAFE_ATTRIBUTES)
|
||||||
|
|
||||||
|
# Safely sets attributes
|
||||||
|
# Should be called from controllers instead of #attributes=
|
||||||
|
# attr_accessible is too rough because we still want things like
|
||||||
|
# Issue.new(:project => foo) to work
|
||||||
|
# TODO: move workflow/permission checks from controllers to here
|
||||||
|
def safe_attributes=(attrs, user=User.current)
|
||||||
|
return if attrs.nil?
|
||||||
|
attrs = attrs.reject {|k,v| !SAFE_ATTRIBUTES.include?(k)}
|
||||||
|
if attrs['status_id']
|
||||||
|
unless new_statuses_allowed_to(user).collect(&:id).include?(attrs['status_id'].to_i)
|
||||||
|
attrs.delete('status_id')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
unless leaf?
|
||||||
|
attrs.reject! {|k,v| %w(priority_id done_ratio start_date due_date estimated_hours).include?(k)}
|
||||||
|
end
|
||||||
|
|
||||||
|
if attrs.has_key?('parent_issue_id')
|
||||||
|
if !user.allowed_to?(:manage_subtasks, project)
|
||||||
|
attrs.delete('parent_issue_id')
|
||||||
|
elsif !attrs['parent_issue_id'].blank?
|
||||||
|
attrs.delete('parent_issue_id') unless Issue.visible(user).exists?(attrs['parent_issue_id'])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.attributes = attrs
|
||||||
|
end
|
||||||
|
|
||||||
|
def done_ratio
|
||||||
|
if Issue.use_status_for_done_ratio? && status && status.default_done_ratio?
|
||||||
|
status.default_done_ratio
|
||||||
|
else
|
||||||
|
read_attribute(:done_ratio)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.use_status_for_done_ratio?
|
||||||
|
Setting.issue_done_ratio == 'issue_status'
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.use_field_for_done_ratio?
|
||||||
|
Setting.issue_done_ratio == 'issue_field'
|
||||||
|
end
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
|
if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
|
||||||
errors.add :due_date, :activerecord_error_not_a_date
|
errors.add :due_date, :not_a_date
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.due_date and self.start_date and self.due_date < self.start_date
|
if self.due_date and self.start_date and self.due_date < self.start_date
|
||||||
errors.add :due_date, :activerecord_error_greater_than_start_date
|
errors.add :due_date, :greater_than_start_date
|
||||||
end
|
end
|
||||||
|
|
||||||
if start_date && soonest_start && start_date < soonest_start
|
if start_date && soonest_start && start_date < soonest_start
|
||||||
errors.add :start_date, :activerecord_error_invalid
|
errors.add :start_date, :invalid
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def validate_on_create
|
|
||||||
errors.add :tracker_id, :activerecord_error_invalid unless project.trackers.include?(tracker)
|
|
||||||
end
|
|
||||||
|
|
||||||
def before_create
|
|
||||||
# default assignment based on category
|
|
||||||
if assigned_to.nil? && category && category.assigned_to
|
|
||||||
self.assigned_to = category.assigned_to
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def before_save
|
|
||||||
if @current_journal
|
|
||||||
# attributes changes
|
|
||||||
(Issue.column_names - %w(id description)).each {|c|
|
|
||||||
@current_journal.details << JournalDetail.new(:property => 'attr',
|
|
||||||
:prop_key => c,
|
|
||||||
:old_value => @issue_before_change.send(c),
|
|
||||||
:value => send(c)) unless send(c)==@issue_before_change.send(c)
|
|
||||||
}
|
|
||||||
# custom fields changes
|
|
||||||
custom_values.each {|c|
|
|
||||||
next if (@custom_values_before_change[c.custom_field_id]==c.value ||
|
|
||||||
(@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
|
|
||||||
@current_journal.details << JournalDetail.new(:property => 'cf',
|
|
||||||
:prop_key => c.custom_field_id,
|
|
||||||
:old_value => @custom_values_before_change[c.custom_field_id],
|
|
||||||
:value => c.value)
|
|
||||||
}
|
|
||||||
@current_journal.save
|
|
||||||
end
|
|
||||||
# Save the issue even if the journal is not saved (because empty)
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_save
|
|
||||||
# Reload is needed in order to get the right status
|
|
||||||
reload
|
|
||||||
|
|
||||||
# Update start/due dates of following issues
|
if fixed_version
|
||||||
relations_from.each(&:set_issue_to_dates)
|
if !assignable_versions.include?(fixed_version)
|
||||||
|
errors.add :fixed_version_id, :inclusion
|
||||||
# Close duplicates if the issue was closed
|
elsif reopened? && fixed_version.closed?
|
||||||
if @issue_before_change && !@issue_before_change.closed? && self.closed?
|
errors.add_to_base I18n.t(:error_can_not_reopen_issue_on_closed_version)
|
||||||
duplicates.each do |duplicate|
|
|
||||||
# Reload is need in case the duplicate was updated by a previous duplicate
|
|
||||||
duplicate.reload
|
|
||||||
# Don't re-close it if it's already closed
|
|
||||||
next if duplicate.closed?
|
|
||||||
# Same user and notes
|
|
||||||
duplicate.init_journal(@current_journal.user, @current_journal.notes)
|
|
||||||
duplicate.update_attribute :status, self.status
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Checks that the issue can not be added/moved to a disabled tracker
|
||||||
|
if project && (tracker_id_changed? || project_id_changed?)
|
||||||
|
unless project.trackers.include?(tracker)
|
||||||
|
errors.add :tracker_id, :inclusion
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Checks parent issue assignment
|
||||||
|
if @parent_issue
|
||||||
|
if @parent_issue.project_id != project_id
|
||||||
|
errors.add :parent_issue_id, :not_same_project
|
||||||
|
elsif !new_record?
|
||||||
|
# moving an existing issue
|
||||||
|
if @parent_issue.root_id != root_id
|
||||||
|
# we can always move to another tree
|
||||||
|
elsif move_possible?(@parent_issue)
|
||||||
|
# move accepted inside tree
|
||||||
|
else
|
||||||
|
errors.add :parent_issue_id, :not_a_valid_parent
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Set the done_ratio using the status if that setting is set. This will keep the done_ratios
|
||||||
|
# even if the user turns off the setting later
|
||||||
|
def update_done_ratio_from_issue_status
|
||||||
|
if Issue.use_status_for_done_ratio? && status && status.default_done_ratio?
|
||||||
|
self.done_ratio = status.default_done_ratio
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_journal(user, notes = "")
|
def init_journal(user, notes = "")
|
||||||
@@ -184,6 +319,8 @@ class Issue < ActiveRecord::Base
|
|||||||
@issue_before_change.status = self.status
|
@issue_before_change.status = self.status
|
||||||
@custom_values_before_change = {}
|
@custom_values_before_change = {}
|
||||||
self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
|
self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
|
||||||
|
# Make sure updated_on is updated when adding a note.
|
||||||
|
updated_on_will_change!
|
||||||
@current_journal
|
@current_journal
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -192,29 +329,78 @@ class Issue < ActiveRecord::Base
|
|||||||
self.status.is_closed?
|
self.status.is_closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return true if the issue is being reopened
|
||||||
|
def reopened?
|
||||||
|
if !new_record? && status_id_changed?
|
||||||
|
status_was = IssueStatus.find_by_id(status_id_was)
|
||||||
|
status_new = IssueStatus.find_by_id(status_id)
|
||||||
|
if status_was && status_new && status_was.is_closed? && !status_new.is_closed?
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return true if the issue is being closed
|
||||||
|
def closing?
|
||||||
|
if !new_record? && status_id_changed?
|
||||||
|
status_was = IssueStatus.find_by_id(status_id_was)
|
||||||
|
status_new = IssueStatus.find_by_id(status_id)
|
||||||
|
if status_was && status_new && !status_was.is_closed? && status_new.is_closed?
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns true if the issue is overdue
|
||||||
|
def overdue?
|
||||||
|
!due_date.nil? && (due_date < Date.today) && !status.is_closed?
|
||||||
|
end
|
||||||
|
|
||||||
# Users the issue can be assigned to
|
# Users the issue can be assigned to
|
||||||
def assignable_users
|
def assignable_users
|
||||||
project.assignable_users
|
project.assignable_users
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Versions that the issue can be assigned to
|
||||||
|
def assignable_versions
|
||||||
|
@assignable_versions ||= (project.shared_versions.open + [Version.find_by_id(fixed_version_id_was)]).compact.uniq.sort
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns true if this issue is blocked by another issue that is still open
|
||||||
|
def blocked?
|
||||||
|
!relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil?
|
||||||
|
end
|
||||||
|
|
||||||
# Returns an array of status that user is able to apply
|
# Returns an array of status that user is able to apply
|
||||||
def new_statuses_allowed_to(user)
|
def new_statuses_allowed_to(user, include_default=false)
|
||||||
statuses = status.find_new_statuses_allowed_to(user.role_for_project(project), tracker)
|
statuses = status.find_new_statuses_allowed_to(user.roles_for_project(project), tracker)
|
||||||
statuses << status unless statuses.empty?
|
statuses << status unless statuses.empty?
|
||||||
statuses.uniq.sort
|
statuses << IssueStatus.default if include_default
|
||||||
|
statuses = statuses.uniq.sort
|
||||||
|
blocked? ? statuses.reject {|s| s.is_closed?} : statuses
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the mail adresses of users that should be notified for the issue
|
# Returns the mail adresses of users that should be notified
|
||||||
def recipients
|
def recipients
|
||||||
recipients = project.recipients
|
notified = project.notified_users
|
||||||
# Author and assignee are always notified unless they have been locked
|
# Author and assignee are always notified unless they have been locked
|
||||||
recipients << author.mail if author && author.active?
|
notified << author if author && author.active?
|
||||||
recipients << assigned_to.mail if assigned_to && assigned_to.active?
|
notified << assigned_to if assigned_to && assigned_to.active?
|
||||||
recipients.compact.uniq
|
notified.uniq!
|
||||||
|
# Remove users that can not view the issue
|
||||||
|
notified.reject! {|user| !visible?(user)}
|
||||||
|
notified.collect(&:mail)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the total number of hours spent on this issue and its descendants
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# spent_hours => 0.0
|
||||||
|
# spent_hours => 50.2
|
||||||
def spent_hours
|
def spent_hours
|
||||||
@spent_hours ||= time_entries.sum(:hours) || 0
|
@spent_hours ||= self_and_descendants.sum("#{TimeEntry.table_name}.hours", :include => :time_entries).to_f || 0.0
|
||||||
end
|
end
|
||||||
|
|
||||||
def relations
|
def relations
|
||||||
@@ -241,21 +427,407 @@ class Issue < ActiveRecord::Base
|
|||||||
due_date || (fixed_version ? fixed_version.effective_date : nil)
|
due_date || (fixed_version ? fixed_version.effective_date : nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the time scheduled for this issue.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# Start Date: 2/26/09, End Date: 3/04/09
|
||||||
|
# duration => 6
|
||||||
def duration
|
def duration
|
||||||
(start_date && due_date) ? due_date - start_date : 0
|
(start_date && due_date) ? due_date - start_date : 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def soonest_start
|
def soonest_start
|
||||||
@soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min
|
@soonest_start ||= (
|
||||||
|
relations_to.collect{|relation| relation.successor_soonest_start} +
|
||||||
|
ancestors.collect(&:soonest_start)
|
||||||
|
).compact.max
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.visible_by(usr)
|
def reschedule_after(date)
|
||||||
with_scope(:find => { :conditions => Project.visible_by(usr) }) do
|
return if date.nil?
|
||||||
yield
|
if leaf?
|
||||||
|
if start_date.nil? || start_date < date
|
||||||
|
self.start_date, self.due_date = date, date + duration
|
||||||
|
save
|
||||||
|
end
|
||||||
|
else
|
||||||
|
leaves.each do |leaf|
|
||||||
|
leaf.reschedule_after(date)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def <=>(issue)
|
||||||
|
if issue.nil?
|
||||||
|
-1
|
||||||
|
elsif root_id != issue.root_id
|
||||||
|
(root_id || 0) <=> (issue.root_id || 0)
|
||||||
|
else
|
||||||
|
(lft || 0) <=> (issue.lft || 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#{tracker} ##{id}: #{subject}"
|
"#{tracker} ##{id}: #{subject}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a string of css classes that apply to the issue
|
||||||
|
def css_classes
|
||||||
|
s = "issue status-#{status.position} priority-#{priority.position}"
|
||||||
|
s << ' closed' if closed?
|
||||||
|
s << ' overdue' if overdue?
|
||||||
|
s << ' created-by-me' if User.current.logged? && author_id == User.current.id
|
||||||
|
s << ' assigned-to-me' if User.current.logged? && assigned_to_id == User.current.id
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
|
# Saves an issue, time_entry, attachments, and a journal from the parameters
|
||||||
|
# Returns false if save fails
|
||||||
|
def save_issue_with_child_records(params, existing_time_entry=nil)
|
||||||
|
Issue.transaction do
|
||||||
|
if params[:time_entry] && params[:time_entry][:hours].present? && User.current.allowed_to?(:log_time, project)
|
||||||
|
@time_entry = existing_time_entry || TimeEntry.new
|
||||||
|
@time_entry.project = project
|
||||||
|
@time_entry.issue = self
|
||||||
|
@time_entry.user = User.current
|
||||||
|
@time_entry.spent_on = Date.today
|
||||||
|
@time_entry.attributes = params[:time_entry]
|
||||||
|
self.time_entries << @time_entry
|
||||||
|
end
|
||||||
|
|
||||||
|
if valid?
|
||||||
|
attachments = Attachment.attach_files(self, params[:attachments])
|
||||||
|
|
||||||
|
attachments[:files].each {|a| @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
|
||||||
|
# TODO: Rename hook
|
||||||
|
Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
|
||||||
|
begin
|
||||||
|
if save
|
||||||
|
# TODO: Rename hook
|
||||||
|
Redmine::Hook.call_hook(:controller_issues_edit_after_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
|
||||||
|
else
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
rescue ActiveRecord::StaleObjectError
|
||||||
|
attachments[:files].each(&:destroy)
|
||||||
|
errors.add_to_base l(:notice_locking_conflict)
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Unassigns issues from +version+ if it's no longer shared with issue's project
|
||||||
|
def self.update_versions_from_sharing_change(version)
|
||||||
|
# Update issues assigned to the version
|
||||||
|
update_versions(["#{Issue.table_name}.fixed_version_id = ?", version.id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Unassigns issues from versions that are no longer shared
|
||||||
|
# after +project+ was moved
|
||||||
|
def self.update_versions_from_hierarchy_change(project)
|
||||||
|
moved_project_ids = project.self_and_descendants.reload.collect(&:id)
|
||||||
|
# Update issues of the moved projects and issues assigned to a version of a moved project
|
||||||
|
Issue.update_versions(["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)", moved_project_ids, moved_project_ids])
|
||||||
|
end
|
||||||
|
|
||||||
|
def parent_issue_id=(arg)
|
||||||
|
parent_issue_id = arg.blank? ? nil : arg.to_i
|
||||||
|
if parent_issue_id && @parent_issue = Issue.find_by_id(parent_issue_id)
|
||||||
|
@parent_issue.id
|
||||||
|
else
|
||||||
|
@parent_issue = nil
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def parent_issue_id
|
||||||
|
if instance_variable_defined? :@parent_issue
|
||||||
|
@parent_issue.nil? ? nil : @parent_issue.id
|
||||||
|
else
|
||||||
|
parent_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Extracted from the ReportsController.
|
||||||
|
def self.by_tracker(project)
|
||||||
|
count_and_group_by(:project => project,
|
||||||
|
:field => 'tracker_id',
|
||||||
|
:joins => Tracker.table_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.by_version(project)
|
||||||
|
count_and_group_by(:project => project,
|
||||||
|
:field => 'fixed_version_id',
|
||||||
|
:joins => Version.table_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.by_priority(project)
|
||||||
|
count_and_group_by(:project => project,
|
||||||
|
:field => 'priority_id',
|
||||||
|
:joins => IssuePriority.table_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.by_category(project)
|
||||||
|
count_and_group_by(:project => project,
|
||||||
|
:field => 'category_id',
|
||||||
|
:joins => IssueCategory.table_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.by_assigned_to(project)
|
||||||
|
count_and_group_by(:project => project,
|
||||||
|
:field => 'assigned_to_id',
|
||||||
|
:joins => User.table_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.by_author(project)
|
||||||
|
count_and_group_by(:project => project,
|
||||||
|
:field => 'author_id',
|
||||||
|
:joins => User.table_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.by_subproject(project)
|
||||||
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||||
|
s.is_closed as closed,
|
||||||
|
i.project_id as project_id,
|
||||||
|
count(i.id) as total
|
||||||
|
from
|
||||||
|
#{Issue.table_name} i, #{IssueStatus.table_name} s
|
||||||
|
where
|
||||||
|
i.status_id=s.id
|
||||||
|
and i.project_id IN (#{project.descendants.active.collect{|p| p.id}.join(',')})
|
||||||
|
group by s.id, s.is_closed, i.project_id") if project.descendants.active.any?
|
||||||
|
end
|
||||||
|
# End ReportsController extraction
|
||||||
|
|
||||||
|
# Returns an array of projects that current user can move issues to
|
||||||
|
def self.allowed_target_projects_on_move
|
||||||
|
projects = []
|
||||||
|
if User.current.admin?
|
||||||
|
# admin is allowed to move issues to any active (visible) project
|
||||||
|
projects = Project.visible.all
|
||||||
|
elsif User.current.logged?
|
||||||
|
if Role.non_member.allowed_to?(:move_issues)
|
||||||
|
projects = Project.visible.all
|
||||||
|
else
|
||||||
|
User.current.memberships.each {|m| projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
projects
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def update_nested_set_attributes
|
||||||
|
if root_id.nil?
|
||||||
|
# issue was just created
|
||||||
|
self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id)
|
||||||
|
set_default_left_and_right
|
||||||
|
Issue.update_all("root_id = #{root_id}, lft = #{lft}, rgt = #{rgt}", ["id = ?", id])
|
||||||
|
if @parent_issue
|
||||||
|
move_to_child_of(@parent_issue)
|
||||||
|
end
|
||||||
|
reload
|
||||||
|
elsif parent_issue_id != parent_id
|
||||||
|
former_parent_id = parent_id
|
||||||
|
# moving an existing issue
|
||||||
|
if @parent_issue && @parent_issue.root_id == root_id
|
||||||
|
# inside the same tree
|
||||||
|
move_to_child_of(@parent_issue)
|
||||||
|
else
|
||||||
|
# to another tree
|
||||||
|
unless root?
|
||||||
|
move_to_right_of(root)
|
||||||
|
reload
|
||||||
|
end
|
||||||
|
old_root_id = root_id
|
||||||
|
self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id )
|
||||||
|
target_maxright = nested_set_scope.maximum(right_column_name) || 0
|
||||||
|
offset = target_maxright + 1 - lft
|
||||||
|
Issue.update_all("root_id = #{root_id}, lft = lft + #{offset}, rgt = rgt + #{offset}",
|
||||||
|
["root_id = ? AND lft >= ? AND rgt <= ? ", old_root_id, lft, rgt])
|
||||||
|
self[left_column_name] = lft + offset
|
||||||
|
self[right_column_name] = rgt + offset
|
||||||
|
if @parent_issue
|
||||||
|
move_to_child_of(@parent_issue)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
reload
|
||||||
|
# delete invalid relations of all descendants
|
||||||
|
self_and_descendants.each do |issue|
|
||||||
|
issue.relations.each do |relation|
|
||||||
|
relation.destroy unless relation.valid?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# update former parent
|
||||||
|
recalculate_attributes_for(former_parent_id) if former_parent_id
|
||||||
|
end
|
||||||
|
remove_instance_variable(:@parent_issue) if instance_variable_defined?(:@parent_issue)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_parent_attributes
|
||||||
|
recalculate_attributes_for(parent_id) if parent_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def recalculate_attributes_for(issue_id)
|
||||||
|
if issue_id && p = Issue.find_by_id(issue_id)
|
||||||
|
# priority = highest priority of children
|
||||||
|
if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :include => :priority)
|
||||||
|
p.priority = IssuePriority.find_by_position(priority_position)
|
||||||
|
end
|
||||||
|
|
||||||
|
# start/due dates = lowest/highest dates of children
|
||||||
|
p.start_date = p.children.minimum(:start_date)
|
||||||
|
p.due_date = p.children.maximum(:due_date)
|
||||||
|
if p.start_date && p.due_date && p.due_date < p.start_date
|
||||||
|
p.start_date, p.due_date = p.due_date, p.start_date
|
||||||
|
end
|
||||||
|
|
||||||
|
# done ratio = weighted average ratio of leaves
|
||||||
|
unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio?
|
||||||
|
leaves_count = p.leaves.count
|
||||||
|
if leaves_count > 0
|
||||||
|
average = p.leaves.average(:estimated_hours).to_f
|
||||||
|
if average == 0
|
||||||
|
average = 1
|
||||||
|
end
|
||||||
|
done = p.leaves.sum("COALESCE(estimated_hours, #{average}) * (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :include => :status).to_f
|
||||||
|
progress = done / (average * leaves_count)
|
||||||
|
p.done_ratio = progress.round
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# estimate = sum of leaves estimates
|
||||||
|
p.estimated_hours = p.leaves.sum(:estimated_hours).to_f
|
||||||
|
p.estimated_hours = nil if p.estimated_hours == 0.0
|
||||||
|
|
||||||
|
# ancestors will be recursively updated
|
||||||
|
p.save(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy_children
|
||||||
|
unless leaf?
|
||||||
|
children.each do |child|
|
||||||
|
child.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Update issues so their versions are not pointing to a
|
||||||
|
# fixed_version that is not shared with the issue's project
|
||||||
|
def self.update_versions(conditions=nil)
|
||||||
|
# Only need to update issues with a fixed_version from
|
||||||
|
# a different project and that is not systemwide shared
|
||||||
|
Issue.all(:conditions => merge_conditions("#{Issue.table_name}.fixed_version_id IS NOT NULL" +
|
||||||
|
" AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" +
|
||||||
|
" AND #{Version.table_name}.sharing <> 'system'",
|
||||||
|
conditions),
|
||||||
|
:include => [:project, :fixed_version]
|
||||||
|
).each do |issue|
|
||||||
|
next if issue.project.nil? || issue.fixed_version.nil?
|
||||||
|
unless issue.project.shared_versions.include?(issue.fixed_version)
|
||||||
|
issue.init_journal(User.current)
|
||||||
|
issue.fixed_version = nil
|
||||||
|
issue.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Callback on attachment deletion
|
||||||
|
def attachment_removed(obj)
|
||||||
|
journal = init_journal(User.current)
|
||||||
|
journal.details << JournalDetail.new(:property => 'attachment',
|
||||||
|
:prop_key => obj.id,
|
||||||
|
:old_value => obj.filename)
|
||||||
|
journal.save
|
||||||
|
end
|
||||||
|
|
||||||
|
# Default assignment based on category
|
||||||
|
def default_assign
|
||||||
|
if assigned_to.nil? && category && category.assigned_to
|
||||||
|
self.assigned_to = category.assigned_to
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Updates start/due dates of following issues
|
||||||
|
def reschedule_following_issues
|
||||||
|
if start_date_changed? || due_date_changed?
|
||||||
|
relations_from.each do |relation|
|
||||||
|
relation.set_issue_to_dates
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Closes duplicates if the issue is being closed
|
||||||
|
def close_duplicates
|
||||||
|
if closing?
|
||||||
|
duplicates.each do |duplicate|
|
||||||
|
# Reload is need in case the duplicate was updated by a previous duplicate
|
||||||
|
duplicate.reload
|
||||||
|
# Don't re-close it if it's already closed
|
||||||
|
next if duplicate.closed?
|
||||||
|
# Same user and notes
|
||||||
|
if @current_journal
|
||||||
|
duplicate.init_journal(@current_journal.user, @current_journal.notes)
|
||||||
|
end
|
||||||
|
duplicate.update_attribute :status, self.status
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Saves the changes in a Journal
|
||||||
|
# Called after_save
|
||||||
|
def create_journal
|
||||||
|
if @current_journal
|
||||||
|
# attributes changes
|
||||||
|
(Issue.column_names - %w(id description root_id lft rgt lock_version created_on updated_on)).each {|c|
|
||||||
|
@current_journal.details << JournalDetail.new(:property => 'attr',
|
||||||
|
:prop_key => c,
|
||||||
|
:old_value => @issue_before_change.send(c),
|
||||||
|
:value => send(c)) unless send(c)==@issue_before_change.send(c)
|
||||||
|
}
|
||||||
|
# custom fields changes
|
||||||
|
custom_values.each {|c|
|
||||||
|
next if (@custom_values_before_change[c.custom_field_id]==c.value ||
|
||||||
|
(@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
|
||||||
|
@current_journal.details << JournalDetail.new(:property => 'cf',
|
||||||
|
:prop_key => c.custom_field_id,
|
||||||
|
:old_value => @custom_values_before_change[c.custom_field_id],
|
||||||
|
:value => c.value)
|
||||||
|
}
|
||||||
|
@current_journal.save
|
||||||
|
# reset current journal
|
||||||
|
init_journal @current_journal.user, @current_journal.notes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Query generator for selecting groups of issue counts for a project
|
||||||
|
# based on specific criteria
|
||||||
|
#
|
||||||
|
# Options
|
||||||
|
# * project - Project to search in.
|
||||||
|
# * field - String. Issue field to key off of in the grouping.
|
||||||
|
# * joins - String. The table name to join against.
|
||||||
|
def self.count_and_group_by(options)
|
||||||
|
project = options.delete(:project)
|
||||||
|
select_field = options.delete(:field)
|
||||||
|
joins = options.delete(:joins)
|
||||||
|
|
||||||
|
where = "i.#{select_field}=j.id"
|
||||||
|
|
||||||
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||||
|
s.is_closed as closed,
|
||||||
|
j.id as #{select_field},
|
||||||
|
count(i.id) as total
|
||||||
|
from
|
||||||
|
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{joins} as j
|
||||||
|
where
|
||||||
|
i.status_id=s.id
|
||||||
|
and #{where}
|
||||||
|
and i.project_id=#{project.id}
|
||||||
|
group by s.id, s.is_closed, j.id")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# redMine - project management software
|
||||||
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class IssueObserver < ActiveRecord::Observer
|
||||||
|
def after_create(issue)
|
||||||
|
Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added')
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# redMine - project management software
|
||||||
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class IssuePriority < Enumeration
|
||||||
|
has_many :issues, :foreign_key => 'priority_id'
|
||||||
|
|
||||||
|
OptionName = :enumeration_issue_priorities
|
||||||
|
|
||||||
|
def option_name
|
||||||
|
OptionName
|
||||||
|
end
|
||||||
|
|
||||||
|
def objects_count
|
||||||
|
issues.count
|
||||||
|
end
|
||||||
|
|
||||||
|
def transfer_relations(to)
|
||||||
|
issues.update_all("priority_id = #{to.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# redMine - project management software
|
||||||
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class IssuePriorityCustomField < CustomField
|
||||||
|
def type_name
|
||||||
|
:enumeration_issue_priorities
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@@ -21,13 +21,19 @@ class IssueRelation < ActiveRecord::Base
|
|||||||
|
|
||||||
TYPE_RELATES = "relates"
|
TYPE_RELATES = "relates"
|
||||||
TYPE_DUPLICATES = "duplicates"
|
TYPE_DUPLICATES = "duplicates"
|
||||||
|
TYPE_DUPLICATED = "duplicated"
|
||||||
TYPE_BLOCKS = "blocks"
|
TYPE_BLOCKS = "blocks"
|
||||||
|
TYPE_BLOCKED = "blocked"
|
||||||
TYPE_PRECEDES = "precedes"
|
TYPE_PRECEDES = "precedes"
|
||||||
|
TYPE_FOLLOWS = "follows"
|
||||||
|
|
||||||
TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 },
|
TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1, :sym => TYPE_RELATES },
|
||||||
TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 },
|
TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2, :sym => TYPE_DUPLICATED },
|
||||||
TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 },
|
TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES },
|
||||||
TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 4 },
|
TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 4, :sym => TYPE_BLOCKED },
|
||||||
|
TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS },
|
||||||
|
TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 6, :sym => TYPE_FOLLOWS },
|
||||||
|
TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES }
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
validates_presence_of :issue_from, :issue_to, :relation_type
|
validates_presence_of :issue_from, :issue_to, :relation_type
|
||||||
@@ -35,11 +41,14 @@ class IssueRelation < ActiveRecord::Base
|
|||||||
validates_numericality_of :delay, :allow_nil => true
|
validates_numericality_of :delay, :allow_nil => true
|
||||||
validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
|
validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
|
||||||
|
|
||||||
|
attr_protected :issue_from_id, :issue_to_id
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
if issue_from && issue_to
|
if issue_from && issue_to
|
||||||
errors.add :issue_to_id, :activerecord_error_invalid if issue_from_id == issue_to_id
|
errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
|
||||||
errors.add :issue_to_id, :activerecord_error_not_same_project unless issue_from.project_id == issue_to.project_id || Setting.cross_project_issue_relations?
|
errors.add :issue_to_id, :not_same_project unless issue_from.project_id == issue_to.project_id || Setting.cross_project_issue_relations?
|
||||||
errors.add_to_base :activerecord_error_circular_dependency if issue_to.all_dependent_issues.include? issue_from
|
errors.add_to_base :circular_dependency if issue_to.all_dependent_issues.include? issue_from
|
||||||
|
errors.add_to_base :cant_link_an_issue_with_a_descendant if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(issue_to)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -47,11 +56,24 @@ class IssueRelation < ActiveRecord::Base
|
|||||||
(self.issue_from_id == issue.id) ? issue_to : issue_from
|
(self.issue_from_id == issue.id) ? issue_to : issue_from
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the relation type for +issue+
|
||||||
|
def relation_type_for(issue)
|
||||||
|
if TYPES[relation_type]
|
||||||
|
if self.issue_from_id == issue.id
|
||||||
|
relation_type
|
||||||
|
else
|
||||||
|
TYPES[relation_type][:sym]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def label_for(issue)
|
def label_for(issue)
|
||||||
TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow
|
TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_save
|
def before_save
|
||||||
|
reverse_if_needed
|
||||||
|
|
||||||
if TYPE_PRECEDES == relation_type
|
if TYPE_PRECEDES == relation_type
|
||||||
self.delay ||= 0
|
self.delay ||= 0
|
||||||
else
|
else
|
||||||
@@ -62,9 +84,8 @@ class IssueRelation < ActiveRecord::Base
|
|||||||
|
|
||||||
def set_issue_to_dates
|
def set_issue_to_dates
|
||||||
soonest_start = self.successor_soonest_start
|
soonest_start = self.successor_soonest_start
|
||||||
if soonest_start && (!issue_to.start_date || issue_to.start_date < soonest_start)
|
if soonest_start
|
||||||
issue_to.start_date, issue_to.due_date = successor_soonest_start, successor_soonest_start + issue_to.duration
|
issue_to.reschedule_after(soonest_start)
|
||||||
issue_to.save
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -76,4 +97,16 @@ class IssueRelation < ActiveRecord::Base
|
|||||||
def <=>(relation)
|
def <=>(relation)
|
||||||
TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order]
|
TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Reverses the relation if needed so that it gets stored in the proper way
|
||||||
|
def reverse_if_needed
|
||||||
|
if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse]
|
||||||
|
issue_tmp = issue_to
|
||||||
|
self.issue_to = issue_from
|
||||||
|
self.issue_from = issue_tmp
|
||||||
|
self.relation_type = TYPES[relation_type][:reverse]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+36
-13
@@ -24,36 +24,59 @@ class IssueStatus < ActiveRecord::Base
|
|||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
||||||
|
validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
|
||||||
|
|
||||||
def before_save
|
def after_save
|
||||||
IssueStatus.update_all "is_default=#{connection.quoted_false}" if self.is_default?
|
IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the default status for new issues
|
# Returns the default status for new issues
|
||||||
def self.default
|
def self.default
|
||||||
find(:first, :conditions =>["is_default=?", true])
|
find(:first, :conditions =>["is_default=?", true])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+
|
||||||
|
def self.update_issue_done_ratios
|
||||||
|
if Issue.use_status_for_done_ratio?
|
||||||
|
IssueStatus.find(:all, :conditions => ["default_done_ratio >= 0"]).each do |status|
|
||||||
|
Issue.update_all(["done_ratio = ?", status.default_done_ratio],
|
||||||
|
["status_id = ?", status.id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return Issue.use_status_for_done_ratio?
|
||||||
|
end
|
||||||
|
|
||||||
# Returns an array of all statuses the given role can switch to
|
# Returns an array of all statuses the given role can switch to
|
||||||
# Uses association cache when called more than one time
|
# Uses association cache when called more than one time
|
||||||
def new_statuses_allowed_to(role, tracker)
|
def new_statuses_allowed_to(roles, tracker)
|
||||||
new_statuses = workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status} if role && tracker
|
if roles && tracker
|
||||||
new_statuses ? new_statuses.compact.sort{|x, y| x.position <=> y.position } : []
|
role_ids = roles.collect(&:id)
|
||||||
|
new_statuses = workflows.select {|w| role_ids.include?(w.role_id) && w.tracker_id == tracker.id}.collect{|w| w.new_status}.compact.sort
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Same thing as above but uses a database query
|
# Same thing as above but uses a database query
|
||||||
# More efficient than the previous method if called just once
|
# More efficient than the previous method if called just once
|
||||||
def find_new_statuses_allowed_to(role, tracker)
|
def find_new_statuses_allowed_to(roles, tracker)
|
||||||
new_statuses = workflows.find(:all,
|
if roles && tracker
|
||||||
:include => :new_status,
|
workflows.find(:all,
|
||||||
:conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status }.compact if role && tracker
|
:include => :new_status,
|
||||||
new_statuses ? new_statuses.sort{|x, y| x.position <=> y.position } : []
|
:conditions => { :role_id => roles.collect(&:id),
|
||||||
|
:tracker_id => tracker.id}).collect{ |w| w.new_status }.compact.sort
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_status_allowed_to?(status, role, tracker)
|
def new_status_allowed_to?(status, roles, tracker)
|
||||||
status && role && tracker ?
|
if status && roles && tracker
|
||||||
!workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => role.id, :tracker_id => tracker.id}).nil? :
|
!workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => roles.collect(&:id), :tracker_id => tracker.id}).nil?
|
||||||
|
else
|
||||||
false
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def <=>(status)
|
def <=>(status)
|
||||||
|
|||||||
@@ -33,11 +33,12 @@ class Journal < ActiveRecord::Base
|
|||||||
|
|
||||||
acts_as_activity_provider :type => 'issues',
|
acts_as_activity_provider :type => 'issues',
|
||||||
:permission => :view_issues,
|
:permission => :view_issues,
|
||||||
|
:author_key => :user_id,
|
||||||
:find_options => {:include => [{:issue => :project}, :details, :user],
|
:find_options => {:include => [{:issue => :project}, :details, :user],
|
||||||
:conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
|
:conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
|
||||||
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
|
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
|
||||||
|
|
||||||
def save
|
def save(*args)
|
||||||
# Do not save an empty journal
|
# Do not save an empty journal
|
||||||
(details.empty? && notes.blank?) ? false : super
|
(details.empty? && notes.blank?) ? false : super
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# redMine - project management software
|
||||||
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class JournalObserver < ActiveRecord::Observer
|
||||||
|
def after_create(journal)
|
||||||
|
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
||||||
|
end
|
||||||
|
end
|
||||||
+222
-31
@@ -16,6 +16,7 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class MailHandler < ActionMailer::Base
|
class MailHandler < ActionMailer::Base
|
||||||
|
include ActionView::Helpers::SanitizeHelper
|
||||||
|
|
||||||
class UnauthorizedAction < StandardError; end
|
class UnauthorizedAction < StandardError; end
|
||||||
class MissingInformation < StandardError; end
|
class MissingInformation < StandardError; end
|
||||||
@@ -31,30 +32,72 @@ class MailHandler < ActionMailer::Base
|
|||||||
@@handler_options[:allow_override] ||= []
|
@@handler_options[:allow_override] ||= []
|
||||||
# Project needs to be overridable if not specified
|
# Project needs to be overridable if not specified
|
||||||
@@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project)
|
@@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project)
|
||||||
|
# Status overridable by default
|
||||||
|
@@handler_options[:allow_override] << 'status' unless @@handler_options[:issue].has_key?(:status)
|
||||||
|
|
||||||
|
@@handler_options[:no_permission_check] = (@@handler_options[:no_permission_check].to_s == '1' ? true : false)
|
||||||
super email
|
super email
|
||||||
end
|
end
|
||||||
|
|
||||||
# Processes incoming emails
|
# Processes incoming emails
|
||||||
|
# Returns the created object (eg. an issue, a message) or false
|
||||||
def receive(email)
|
def receive(email)
|
||||||
@email = email
|
@email = email
|
||||||
@user = User.find_active(:first, :conditions => {:mail => email.from.first})
|
sender_email = email.from.to_a.first.to_s.strip
|
||||||
unless @user
|
# Ignore emails received from the application emission address to avoid hell cycles
|
||||||
# Unknown user => the email is ignored
|
if sender_email.downcase == Setting.mail_from.to_s.strip.downcase
|
||||||
# TODO: ability to create the user's account
|
logger.info "MailHandler: ignoring email from Redmine emission address [#{sender_email}]" if logger && logger.info
|
||||||
logger.info "MailHandler: email submitted by unknown user [#{email.from.first}]" if logger && logger.info
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@user = User.find_by_mail(sender_email) if sender_email.present?
|
||||||
|
if @user && !@user.active?
|
||||||
|
logger.info "MailHandler: ignoring email from non-active user [#{@user.login}]" if logger && logger.info
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if @user.nil?
|
||||||
|
# Email was submitted by an unknown user
|
||||||
|
case @@handler_options[:unknown_user]
|
||||||
|
when 'accept'
|
||||||
|
@user = User.anonymous
|
||||||
|
when 'create'
|
||||||
|
@user = MailHandler.create_user_from_email(email)
|
||||||
|
if @user
|
||||||
|
logger.info "MailHandler: [#{@user.login}] account created" if logger && logger.info
|
||||||
|
Mailer.deliver_account_information(@user, @user.password)
|
||||||
|
else
|
||||||
|
logger.error "MailHandler: could not create account for [#{sender_email}]" if logger && logger.error
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# Default behaviour, emails from unknown users are ignored
|
||||||
|
logger.info "MailHandler: ignoring email from unknown user [#{sender_email}]" if logger && logger.info
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
User.current = @user
|
User.current = @user
|
||||||
dispatch
|
dispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
|
MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
|
||||||
|
ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]*#(\d+)\]}
|
||||||
|
MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]*msg(\d+)\]}
|
||||||
|
|
||||||
def dispatch
|
def dispatch
|
||||||
if m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
|
headers = [email.in_reply_to, email.references].flatten.compact
|
||||||
receive_issue_update(m[1].to_i)
|
if headers.detect {|h| h.to_s =~ MESSAGE_ID_RE}
|
||||||
|
klass, object_id = $1, $2.to_i
|
||||||
|
method_name = "receive_#{klass}_reply"
|
||||||
|
if self.class.private_instance_methods.collect(&:to_s).include?(method_name)
|
||||||
|
send method_name, object_id
|
||||||
|
else
|
||||||
|
# ignoring it
|
||||||
|
end
|
||||||
|
elsif m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
|
||||||
|
receive_issue_reply(m[1].to_i)
|
||||||
|
elsif m = email.subject.match(MESSAGE_REPLY_SUBJECT_RE)
|
||||||
|
receive_message_reply(m[1].to_i)
|
||||||
else
|
else
|
||||||
receive_issue
|
receive_issue
|
||||||
end
|
end
|
||||||
@@ -75,17 +118,39 @@ class MailHandler < ActionMailer::Base
|
|||||||
project = target_project
|
project = target_project
|
||||||
tracker = (get_keyword(:tracker) && project.trackers.find_by_name(get_keyword(:tracker))) || project.trackers.find(:first)
|
tracker = (get_keyword(:tracker) && project.trackers.find_by_name(get_keyword(:tracker))) || project.trackers.find(:first)
|
||||||
category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category)))
|
category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category)))
|
||||||
priority = (get_keyword(:priority) && Enumeration.find_by_opt_and_name('IPRI', get_keyword(:priority)))
|
priority = (get_keyword(:priority) && IssuePriority.find_by_name(get_keyword(:priority)))
|
||||||
|
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
|
||||||
|
assigned_to = (get_keyword(:assigned_to, :override => true) && find_user_from_keyword(get_keyword(:assigned_to, :override => true)))
|
||||||
|
due_date = get_keyword(:due_date, :override => true)
|
||||||
|
start_date = get_keyword(:start_date, :override => true)
|
||||||
|
|
||||||
# check permission
|
# check permission
|
||||||
raise UnauthorizedAction unless user.allowed_to?(:add_issues, project)
|
unless @@handler_options[:no_permission_check]
|
||||||
issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority)
|
raise UnauthorizedAction unless user.allowed_to?(:add_issues, project)
|
||||||
issue.subject = email.subject.chomp
|
end
|
||||||
issue.description = email.plain_text_body.chomp
|
|
||||||
|
issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority, :due_date => due_date, :start_date => start_date, :assigned_to => assigned_to)
|
||||||
|
# check workflow
|
||||||
|
if status && issue.new_statuses_allowed_to(user).include?(status)
|
||||||
|
issue.status = status
|
||||||
|
end
|
||||||
|
issue.subject = email.subject.chomp[0,255]
|
||||||
|
if issue.subject.blank?
|
||||||
|
issue.subject = '(no subject)'
|
||||||
|
end
|
||||||
|
# custom fields
|
||||||
|
issue.custom_field_values = issue.available_custom_fields.inject({}) do |h, c|
|
||||||
|
if value = get_keyword(c.name, :override => true)
|
||||||
|
h[c.id] = value
|
||||||
|
end
|
||||||
|
h
|
||||||
|
end
|
||||||
|
issue.description = cleaned_up_text_body
|
||||||
|
# add To and Cc as watchers before saving so the watchers can reply to Redmine
|
||||||
|
add_watchers(issue)
|
||||||
issue.save!
|
issue.save!
|
||||||
add_attachments(issue)
|
add_attachments(issue)
|
||||||
logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info
|
logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info
|
||||||
Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added')
|
|
||||||
issue
|
issue
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -99,20 +164,68 @@ class MailHandler < ActionMailer::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Adds a note to an existing issue
|
# Adds a note to an existing issue
|
||||||
def receive_issue_update(issue_id)
|
def receive_issue_reply(issue_id)
|
||||||
|
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
|
||||||
|
due_date = get_keyword(:due_date, :override => true)
|
||||||
|
start_date = get_keyword(:start_date, :override => true)
|
||||||
|
assigned_to = (get_keyword(:assigned_to, :override => true) && find_user_from_keyword(get_keyword(:assigned_to, :override => true)))
|
||||||
|
|
||||||
issue = Issue.find_by_id(issue_id)
|
issue = Issue.find_by_id(issue_id)
|
||||||
return unless issue
|
return unless issue
|
||||||
# check permission
|
# check permission
|
||||||
raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project)
|
unless @@handler_options[:no_permission_check]
|
||||||
|
raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project)
|
||||||
|
raise UnauthorizedAction unless status.nil? || user.allowed_to?(:edit_issues, issue.project)
|
||||||
|
end
|
||||||
|
|
||||||
# add the note
|
# add the note
|
||||||
journal = issue.init_journal(user, email.plain_text_body.chomp)
|
journal = issue.init_journal(user, cleaned_up_text_body)
|
||||||
add_attachments(issue)
|
add_attachments(issue)
|
||||||
|
# check workflow
|
||||||
|
if status && issue.new_statuses_allowed_to(user).include?(status)
|
||||||
|
issue.status = status
|
||||||
|
end
|
||||||
|
issue.start_date = start_date if start_date
|
||||||
|
issue.due_date = due_date if due_date
|
||||||
|
issue.assigned_to = assigned_to if assigned_to
|
||||||
|
|
||||||
issue.save!
|
issue.save!
|
||||||
logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
|
logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
|
||||||
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
|
||||||
journal
|
journal
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Reply will be added to the issue
|
||||||
|
def receive_journal_reply(journal_id)
|
||||||
|
journal = Journal.find_by_id(journal_id)
|
||||||
|
if journal && journal.journalized_type == 'Issue'
|
||||||
|
receive_issue_reply(journal.journalized_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Receives a reply to a forum message
|
||||||
|
def receive_message_reply(message_id)
|
||||||
|
message = Message.find_by_id(message_id)
|
||||||
|
if message
|
||||||
|
message = message.root
|
||||||
|
|
||||||
|
unless @@handler_options[:no_permission_check]
|
||||||
|
raise UnauthorizedAction unless user.allowed_to?(:add_messages, message.project)
|
||||||
|
end
|
||||||
|
|
||||||
|
if !message.locked?
|
||||||
|
reply = Message.new(:subject => email.subject.gsub(%r{^.*msg\d+\]}, '').strip,
|
||||||
|
:content => cleaned_up_text_body)
|
||||||
|
reply.author = user
|
||||||
|
reply.board = message.board
|
||||||
|
message.children << reply
|
||||||
|
add_attachments(reply)
|
||||||
|
reply
|
||||||
|
else
|
||||||
|
logger.info "MailHandler: ignoring reply from [#{sender_email}] to a locked topic" if logger && logger.info
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def add_attachments(obj)
|
def add_attachments(obj)
|
||||||
if email.has_attachments?
|
if email.has_attachments?
|
||||||
email.attachments.each do |attachment|
|
email.attachments.each do |attachment|
|
||||||
@@ -124,22 +237,100 @@ class MailHandler < ActionMailer::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_keyword(attr)
|
# Adds To and Cc as watchers of the given object if the sender has the
|
||||||
if @@handler_options[:allow_override].include?(attr.to_s) && email.plain_text_body =~ /^#{attr}:[ \t]*(.+)$/i
|
# appropriate permission
|
||||||
$1.strip
|
def add_watchers(obj)
|
||||||
elsif !@@handler_options[:issue][attr].blank?
|
if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
|
||||||
@@handler_options[:issue][attr]
|
addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
|
||||||
|
unless addresses.empty?
|
||||||
|
watchers = User.active.find(:all, :conditions => ['LOWER(mail) IN (?)', addresses])
|
||||||
|
watchers.each {|w| obj.add_watcher(w)}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
def get_keyword(attr, options={})
|
||||||
class TMail::Mail
|
@keywords ||= {}
|
||||||
# Returns body of the first plain text part found if any
|
if @keywords.has_key?(attr)
|
||||||
|
@keywords[attr]
|
||||||
|
else
|
||||||
|
@keywords[attr] = begin
|
||||||
|
if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body.gsub!(/^#{attr.to_s.humanize}[ \t]*:[ \t]*(.+)\s*$/i, '')
|
||||||
|
$1.strip
|
||||||
|
elsif !@@handler_options[:issue][attr].blank?
|
||||||
|
@@handler_options[:issue][attr]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the text/plain part of the email
|
||||||
|
# If not found (eg. HTML-only email), returns the body with tags removed
|
||||||
def plain_text_body
|
def plain_text_body
|
||||||
return @plain_text_body unless @plain_text_body.nil?
|
return @plain_text_body unless @plain_text_body.nil?
|
||||||
p = self.parts.collect {|c| (c.respond_to?(:parts) && !c.parts.empty?) ? c.parts : c}.flatten
|
parts = @email.parts.collect {|c| (c.respond_to?(:parts) && !c.parts.empty?) ? c.parts : c}.flatten
|
||||||
plain = p.detect {|c| c.content_type == 'text/plain'}
|
if parts.empty?
|
||||||
@plain_text_body = plain.nil? ? self.body : plain.body
|
parts << @email
|
||||||
|
end
|
||||||
|
plain_text_part = parts.detect {|p| p.content_type == 'text/plain'}
|
||||||
|
if plain_text_part.nil?
|
||||||
|
# no text/plain part found, assuming html-only email
|
||||||
|
# strip html tags and remove doctype directive
|
||||||
|
@plain_text_body = strip_tags(@email.body.to_s)
|
||||||
|
@plain_text_body.gsub! %r{^<!DOCTYPE .*$}, ''
|
||||||
|
else
|
||||||
|
@plain_text_body = plain_text_part.body.to_s
|
||||||
|
end
|
||||||
|
@plain_text_body.strip!
|
||||||
|
@plain_text_body
|
||||||
|
end
|
||||||
|
|
||||||
|
def cleaned_up_text_body
|
||||||
|
cleanup_body(plain_text_body)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.full_sanitizer
|
||||||
|
@full_sanitizer ||= HTML::FullSanitizer.new
|
||||||
|
end
|
||||||
|
|
||||||
|
# Creates a user account for the +email+ sender
|
||||||
|
def self.create_user_from_email(email)
|
||||||
|
addr = email.from_addrs.to_a.first
|
||||||
|
if addr && !addr.spec.blank?
|
||||||
|
user = User.new
|
||||||
|
user.mail = addr.spec
|
||||||
|
|
||||||
|
names = addr.name.blank? ? addr.spec.gsub(/@.*$/, '').split('.') : addr.name.split
|
||||||
|
user.firstname = names.shift
|
||||||
|
user.lastname = names.join(' ')
|
||||||
|
user.lastname = '-' if user.lastname.blank?
|
||||||
|
|
||||||
|
user.login = user.mail
|
||||||
|
user.password = ActiveSupport::SecureRandom.hex(5)
|
||||||
|
user.language = Setting.default_language
|
||||||
|
user.save ? user : nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Removes the email body of text after the truncation configurations.
|
||||||
|
def cleanup_body(body)
|
||||||
|
delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)}
|
||||||
|
unless delimiters.empty?
|
||||||
|
regex = Regexp.new("^(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE)
|
||||||
|
body = body.gsub(regex, '')
|
||||||
|
end
|
||||||
|
body.strip
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_user_from_keyword(keyword)
|
||||||
|
user ||= User.find_by_mail(keyword)
|
||||||
|
user ||= User.find_by_login(keyword)
|
||||||
|
if user.nil? && keyword.match(/ /)
|
||||||
|
firstname, lastname = *(keyword.split) # "First Last Throwaway"
|
||||||
|
user ||= User.find_by_firstname_and_lastname(firstname, lastname)
|
||||||
|
end
|
||||||
|
user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+254
-44
@@ -5,40 +5,64 @@
|
|||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class Mailer < ActionMailer::Base
|
class Mailer < ActionMailer::Base
|
||||||
|
layout 'mailer'
|
||||||
helper :application
|
helper :application
|
||||||
helper :issues
|
helper :issues
|
||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
|
|
||||||
include ActionController::UrlWriter
|
include ActionController::UrlWriter
|
||||||
|
include Redmine::I18n
|
||||||
|
|
||||||
|
def self.default_url_options
|
||||||
|
h = Setting.host_name
|
||||||
|
h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
|
||||||
|
{ :host => h, :protocol => Setting.protocol }
|
||||||
|
end
|
||||||
|
|
||||||
def issue_add(issue)
|
# Builds a tmail object used to email recipients of the added issue.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# issue_add(issue) => tmail object
|
||||||
|
# Mailer.deliver_issue_add(issue) => sends an email to issue recipients
|
||||||
|
def issue_add(issue)
|
||||||
redmine_headers 'Project' => issue.project.identifier,
|
redmine_headers 'Project' => issue.project.identifier,
|
||||||
'Issue-Id' => issue.id,
|
'Issue-Id' => issue.id,
|
||||||
'Issue-Author' => issue.author.login
|
'Issue-Author' => issue.author.login
|
||||||
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
|
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
|
||||||
recipients issue.recipients
|
message_id issue
|
||||||
|
recipients issue.recipients
|
||||||
|
cc(issue.watcher_recipients - @recipients)
|
||||||
subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
|
subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
|
||||||
body :issue => issue,
|
body :issue => issue,
|
||||||
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
|
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
|
||||||
|
render_multipart('issue_add', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Builds a tmail object used to email recipients of the edited issue.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# issue_edit(journal) => tmail object
|
||||||
|
# Mailer.deliver_issue_edit(journal) => sends an email to issue recipients
|
||||||
def issue_edit(journal)
|
def issue_edit(journal)
|
||||||
issue = journal.journalized
|
issue = journal.journalized.reload
|
||||||
redmine_headers 'Project' => issue.project.identifier,
|
redmine_headers 'Project' => issue.project.identifier,
|
||||||
'Issue-Id' => issue.id,
|
'Issue-Id' => issue.id,
|
||||||
'Issue-Author' => issue.author.login
|
'Issue-Author' => issue.author.login
|
||||||
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
|
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
|
||||||
|
message_id journal
|
||||||
|
references issue
|
||||||
|
@author = journal.user
|
||||||
recipients issue.recipients
|
recipients issue.recipients
|
||||||
# Watchers in cc
|
# Watchers in cc
|
||||||
cc(issue.watcher_recipients - @recipients)
|
cc(issue.watcher_recipients - @recipients)
|
||||||
@@ -49,62 +73,138 @@ class Mailer < ActionMailer::Base
|
|||||||
body :issue => issue,
|
body :issue => issue,
|
||||||
:journal => journal,
|
:journal => journal,
|
||||||
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
|
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
|
||||||
|
|
||||||
|
render_multipart('issue_edit', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reminder(user, issues, days)
|
def reminder(user, issues, days)
|
||||||
set_language_if_valid user.language
|
set_language_if_valid user.language
|
||||||
recipients user.mail
|
recipients user.mail
|
||||||
subject l(:mail_subject_reminder, issues.size)
|
subject l(:mail_subject_reminder, issues.size)
|
||||||
body :issues => issues,
|
body :issues => issues,
|
||||||
:days => days,
|
:days => days,
|
||||||
:issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'issues.due_date', :sort_order => 'asc')
|
:issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'due_date', :sort_order => 'asc')
|
||||||
|
render_multipart('reminder', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Builds a tmail object used to email users belonging to the added document's project.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# document_added(document) => tmail object
|
||||||
|
# Mailer.deliver_document_added(document) => sends an email to the document's project recipients
|
||||||
def document_added(document)
|
def document_added(document)
|
||||||
redmine_headers 'Project' => document.project.identifier
|
redmine_headers 'Project' => document.project.identifier
|
||||||
recipients document.project.recipients
|
recipients document.recipients
|
||||||
subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
|
subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
|
||||||
body :document => document,
|
body :document => document,
|
||||||
:document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
|
:document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
|
||||||
|
render_multipart('document_added', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Builds a tmail object used to email recipients of a project when an attachements are added.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# attachments_added(attachments) => tmail object
|
||||||
|
# Mailer.deliver_attachments_added(attachments) => sends an email to the project's recipients
|
||||||
def attachments_added(attachments)
|
def attachments_added(attachments)
|
||||||
container = attachments.first.container
|
container = attachments.first.container
|
||||||
added_to = ''
|
added_to = ''
|
||||||
added_to_url = ''
|
added_to_url = ''
|
||||||
case container.class.name
|
case container.class.name
|
||||||
|
when 'Project'
|
||||||
|
added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container)
|
||||||
|
added_to = "#{l(:label_project)}: #{container}"
|
||||||
|
recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
|
||||||
when 'Version'
|
when 'Version'
|
||||||
added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
|
added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
|
||||||
added_to = "#{l(:label_version)}: #{container.name}"
|
added_to = "#{l(:label_version)}: #{container.name}"
|
||||||
|
recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
|
||||||
when 'Document'
|
when 'Document'
|
||||||
added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
|
added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
|
||||||
added_to = "#{l(:label_document)}: #{container.title}"
|
added_to = "#{l(:label_document)}: #{container.title}"
|
||||||
|
recipients container.recipients
|
||||||
end
|
end
|
||||||
redmine_headers 'Project' => container.project.identifier
|
redmine_headers 'Project' => container.project.identifier
|
||||||
recipients container.project.recipients
|
|
||||||
subject "[#{container.project.name}] #{l(:label_attachment_new)}"
|
subject "[#{container.project.name}] #{l(:label_attachment_new)}"
|
||||||
body :attachments => attachments,
|
body :attachments => attachments,
|
||||||
:added_to => added_to,
|
:added_to => added_to,
|
||||||
:added_to_url => added_to_url
|
:added_to_url => added_to_url
|
||||||
|
render_multipart('attachments_added', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Builds a tmail object used to email recipients of a news' project when a news item is added.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# news_added(news) => tmail object
|
||||||
|
# Mailer.deliver_news_added(news) => sends an email to the news' project recipients
|
||||||
def news_added(news)
|
def news_added(news)
|
||||||
redmine_headers 'Project' => news.project.identifier
|
redmine_headers 'Project' => news.project.identifier
|
||||||
recipients news.project.recipients
|
message_id news
|
||||||
|
recipients news.recipients
|
||||||
subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
|
subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
|
||||||
body :news => news,
|
body :news => news,
|
||||||
:news_url => url_for(:controller => 'news', :action => 'show', :id => news)
|
:news_url => url_for(:controller => 'news', :action => 'show', :id => news)
|
||||||
|
render_multipart('news_added', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_posted(message, recipients)
|
# Builds a tmail object used to email the recipients of the specified message that was posted.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# message_posted(message) => tmail object
|
||||||
|
# Mailer.deliver_message_posted(message) => sends an email to the recipients
|
||||||
|
def message_posted(message)
|
||||||
redmine_headers 'Project' => message.project.identifier,
|
redmine_headers 'Project' => message.project.identifier,
|
||||||
'Topic-Id' => (message.parent_id || message.id)
|
'Topic-Id' => (message.parent_id || message.id)
|
||||||
recipients(recipients)
|
message_id message
|
||||||
subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
|
references message.parent unless message.parent.nil?
|
||||||
|
recipients(message.recipients)
|
||||||
|
cc((message.root.watcher_recipients + message.board.watcher_recipients).uniq - @recipients)
|
||||||
|
subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
|
||||||
body :message => message,
|
body :message => message,
|
||||||
:message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
|
:message_url => url_for(message.event_url)
|
||||||
|
render_multipart('message_posted', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Builds a tmail object used to email the recipients of a project of the specified wiki content was added.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# wiki_content_added(wiki_content) => tmail object
|
||||||
|
# Mailer.deliver_wiki_content_added(wiki_content) => sends an email to the project's recipients
|
||||||
|
def wiki_content_added(wiki_content)
|
||||||
|
redmine_headers 'Project' => wiki_content.project.identifier,
|
||||||
|
'Wiki-Page-Id' => wiki_content.page.id
|
||||||
|
message_id wiki_content
|
||||||
|
recipients wiki_content.recipients
|
||||||
|
cc(wiki_content.page.wiki.watcher_recipients - recipients)
|
||||||
|
subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :page => wiki_content.page.pretty_title)}"
|
||||||
|
body :wiki_content => wiki_content,
|
||||||
|
:wiki_content_url => url_for(:controller => 'wiki', :action => 'index', :id => wiki_content.project, :page => wiki_content.page.title)
|
||||||
|
render_multipart('wiki_content_added', body)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Builds a tmail object used to email the recipients of a project of the specified wiki content was updated.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# wiki_content_updated(wiki_content) => tmail object
|
||||||
|
# Mailer.deliver_wiki_content_updated(wiki_content) => sends an email to the project's recipients
|
||||||
|
def wiki_content_updated(wiki_content)
|
||||||
|
redmine_headers 'Project' => wiki_content.project.identifier,
|
||||||
|
'Wiki-Page-Id' => wiki_content.page.id
|
||||||
|
message_id wiki_content
|
||||||
|
recipients wiki_content.recipients
|
||||||
|
cc(wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients)
|
||||||
|
subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :page => wiki_content.page.pretty_title)}"
|
||||||
|
body :wiki_content => wiki_content,
|
||||||
|
:wiki_content_url => url_for(:controller => 'wiki', :action => 'index', :id => wiki_content.project, :page => wiki_content.page.title),
|
||||||
|
:wiki_diff_url => url_for(:controller => 'wiki', :action => 'diff', :id => wiki_content.project, :page => wiki_content.page.title, :version => wiki_content.version)
|
||||||
|
render_multipart('wiki_content_updated', body)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Builds a tmail object used to email the specified user their account information.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# account_information(user, password) => tmail object
|
||||||
|
# Mailer.deliver_account_information(user, password) => sends account information to the user
|
||||||
def account_information(user, password)
|
def account_information(user, password)
|
||||||
set_language_if_valid user.language
|
set_language_if_valid user.language
|
||||||
recipients user.mail
|
recipients user.mail
|
||||||
@@ -112,14 +212,35 @@ class Mailer < ActionMailer::Base
|
|||||||
body :user => user,
|
body :user => user,
|
||||||
:password => password,
|
:password => password,
|
||||||
:login_url => url_for(:controller => 'account', :action => 'login')
|
:login_url => url_for(:controller => 'account', :action => 'login')
|
||||||
|
render_multipart('account_information', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Builds a tmail object used to email all active administrators of an account activation request.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# account_activation_request(user) => tmail object
|
||||||
|
# Mailer.deliver_account_activation_request(user)=> sends an email to all active administrators
|
||||||
def account_activation_request(user)
|
def account_activation_request(user)
|
||||||
# Send the email to all active administrators
|
# Send the email to all active administrators
|
||||||
recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
|
recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
|
||||||
subject l(:mail_subject_account_activation_request, Setting.app_title)
|
subject l(:mail_subject_account_activation_request, Setting.app_title)
|
||||||
body :user => user,
|
body :user => user,
|
||||||
:url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
|
:url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
|
||||||
|
render_multipart('account_activation_request', body)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Builds a tmail object used to email the specified user that their account was activated by an administrator.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# account_activated(user) => tmail object
|
||||||
|
# Mailer.deliver_account_activated(user) => sends an email to the registered user
|
||||||
|
def account_activated(user)
|
||||||
|
set_language_if_valid user.language
|
||||||
|
recipients user.mail
|
||||||
|
subject l(:mail_subject_register, Setting.app_title)
|
||||||
|
body :user => user,
|
||||||
|
:login_url => url_for(:controller => 'account', :action => 'login')
|
||||||
|
render_multipart('account_activated', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def lost_password(token)
|
def lost_password(token)
|
||||||
@@ -128,7 +249,8 @@ class Mailer < ActionMailer::Base
|
|||||||
subject l(:mail_subject_lost_password, Setting.app_title)
|
subject l(:mail_subject_lost_password, Setting.app_title)
|
||||||
body :token => token,
|
body :token => token,
|
||||||
:url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
|
:url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
|
||||||
end
|
render_multipart('lost_password', body)
|
||||||
|
end
|
||||||
|
|
||||||
def register(token)
|
def register(token)
|
||||||
set_language_if_valid(token.user.language)
|
set_language_if_valid(token.user.language)
|
||||||
@@ -136,24 +258,49 @@ class Mailer < ActionMailer::Base
|
|||||||
subject l(:mail_subject_register, Setting.app_title)
|
subject l(:mail_subject_register, Setting.app_title)
|
||||||
body :token => token,
|
body :token => token,
|
||||||
:url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
|
:url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
|
||||||
|
render_multipart('register', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(user)
|
def test(user)
|
||||||
set_language_if_valid(user.language)
|
set_language_if_valid(user.language)
|
||||||
recipients user.mail
|
recipients user.mail
|
||||||
subject 'Redmine test'
|
subject 'Redmine test'
|
||||||
body :url => url_for(:controller => 'welcome')
|
body :url => url_for(:controller => 'welcome')
|
||||||
|
render_multipart('test', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overrides default deliver! method to prevent from sending an email
|
# Overrides default deliver! method to prevent from sending an email
|
||||||
# with no recipient, cc or bcc
|
# with no recipient, cc or bcc
|
||||||
def deliver!(mail = @mail)
|
def deliver!(mail = @mail)
|
||||||
return false if (recipients.nil? || recipients.empty?) &&
|
set_language_if_valid @initial_language
|
||||||
|
return false if (recipients.nil? || recipients.empty?) &&
|
||||||
(cc.nil? || cc.empty?) &&
|
(cc.nil? || cc.empty?) &&
|
||||||
(bcc.nil? || bcc.empty?)
|
(bcc.nil? || bcc.empty?)
|
||||||
super
|
|
||||||
|
# Set Message-Id and References
|
||||||
|
if @message_id_object
|
||||||
|
mail.message_id = self.class.message_id_for(@message_id_object)
|
||||||
|
end
|
||||||
|
if @references_objects
|
||||||
|
mail.references = @references_objects.collect {|o| self.class.message_id_for(o)}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Log errors when raise_delivery_errors is set to false, Rails does not
|
||||||
|
raise_errors = self.class.raise_delivery_errors
|
||||||
|
self.class.raise_delivery_errors = true
|
||||||
|
begin
|
||||||
|
return super(mail)
|
||||||
|
rescue Exception => e
|
||||||
|
if raise_errors
|
||||||
|
raise e
|
||||||
|
elsif mylogger
|
||||||
|
mylogger.error "The following error occured while sending email notification: \"#{e.message}\". Check your configuration in config/email.yml."
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
self.class.raise_delivery_errors = raise_errors
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sends reminders to issue assignees
|
# Sends reminders to issue assignees
|
||||||
# Available options:
|
# Available options:
|
||||||
# * :days => how many days in the future to remind about (defaults to 7)
|
# * :days => how many days in the future to remind about (defaults to 7)
|
||||||
@@ -163,13 +310,13 @@ class Mailer < ActionMailer::Base
|
|||||||
days = options[:days] || 7
|
days = options[:days] || 7
|
||||||
project = options[:project] ? Project.find(options[:project]) : nil
|
project = options[:project] ? Project.find(options[:project]) : nil
|
||||||
tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
|
tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
|
||||||
|
|
||||||
s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date]
|
s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date]
|
||||||
s << "#{Issue.table_name}.assigned_to_id IS NOT NULL"
|
s << "#{Issue.table_name}.assigned_to_id IS NOT NULL"
|
||||||
s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
|
s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
|
||||||
s << "#{Issue.table_name}.project_id = #{project.id}" if project
|
s << "#{Issue.table_name}.project_id = #{project.id}" if project
|
||||||
s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker
|
s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker
|
||||||
|
|
||||||
issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker],
|
issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker],
|
||||||
:conditions => s.conditions
|
:conditions => s.conditions
|
||||||
).group_by(&:assigned_to)
|
).group_by(&:assigned_to)
|
||||||
@@ -177,51 +324,114 @@ class Mailer < ActionMailer::Base
|
|||||||
deliver_reminder(assignee, issues, days) unless assignee.nil?
|
deliver_reminder(assignee, issues, days) unless assignee.nil?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Activates/desactivates email deliveries during +block+
|
||||||
|
def self.with_deliveries(enabled = true, &block)
|
||||||
|
was_enabled = ActionMailer::Base.perform_deliveries
|
||||||
|
ActionMailer::Base.perform_deliveries = !!enabled
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
ActionMailer::Base.perform_deliveries = was_enabled
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def initialize_defaults(method_name)
|
def initialize_defaults(method_name)
|
||||||
super
|
super
|
||||||
|
@initial_language = current_language
|
||||||
set_language_if_valid Setting.default_language
|
set_language_if_valid Setting.default_language
|
||||||
from Setting.mail_from
|
from Setting.mail_from
|
||||||
default_url_options[:host] = Setting.host_name
|
|
||||||
default_url_options[:protocol] = Setting.protocol
|
|
||||||
# Common headers
|
# Common headers
|
||||||
headers 'X-Mailer' => 'Redmine',
|
headers 'X-Mailer' => 'Redmine',
|
||||||
'X-Redmine-Host' => Setting.host_name,
|
'X-Redmine-Host' => Setting.host_name,
|
||||||
'X-Redmine-Site' => Setting.app_title
|
'X-Redmine-Site' => Setting.app_title,
|
||||||
|
'Precedence' => 'bulk',
|
||||||
|
'Auto-Submitted' => 'auto-generated'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Appends a Redmine header field (name is prepended with 'X-Redmine-')
|
# Appends a Redmine header field (name is prepended with 'X-Redmine-')
|
||||||
def redmine_headers(h)
|
def redmine_headers(h)
|
||||||
h.each { |k,v| headers["X-Redmine-#{k}"] = v }
|
h.each { |k,v| headers["X-Redmine-#{k}"] = v }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overrides the create_mail method
|
# Overrides the create_mail method
|
||||||
def create_mail
|
def create_mail
|
||||||
# Removes the current user from the recipients and cc
|
# Removes the current user from the recipients and cc
|
||||||
# if he doesn't want to receive notifications about what he does
|
# if he doesn't want to receive notifications about what he does
|
||||||
if User.current.pref[:no_self_notified]
|
@author ||= User.current
|
||||||
recipients.delete(User.current.mail) if recipients
|
if @author.pref[:no_self_notified]
|
||||||
cc.delete(User.current.mail) if cc
|
recipients.delete(@author.mail) if recipients
|
||||||
|
cc.delete(@author.mail) if cc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
notified_users = [recipients, cc].flatten.compact.uniq
|
||||||
|
# Rails would log recipients only, not cc and bcc
|
||||||
|
mylogger.info "Sending email notification to: #{notified_users.join(', ')}" if mylogger
|
||||||
|
|
||||||
# Blind carbon copy recipients
|
# Blind carbon copy recipients
|
||||||
if Setting.bcc_recipients?
|
if Setting.bcc_recipients?
|
||||||
bcc([recipients, cc].flatten.compact.uniq)
|
bcc(notified_users)
|
||||||
recipients []
|
recipients []
|
||||||
cc []
|
cc []
|
||||||
end
|
end
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Rails 2.3 has problems rendering implicit multipart messages with
|
||||||
|
# layouts so this method will wrap an multipart messages with
|
||||||
|
# explicit parts.
|
||||||
|
#
|
||||||
|
# https://rails.lighthouseapp.com/projects/8994/tickets/2338-actionmailer-mailer-views-and-content-type
|
||||||
|
# https://rails.lighthouseapp.com/projects/8994/tickets/1799-actionmailer-doesnt-set-template_format-when-rendering-layouts
|
||||||
|
|
||||||
# Renders a message with the corresponding layout
|
def render_multipart(method_name, body)
|
||||||
def render_message(method_name, body)
|
if Setting.plain_text_mail?
|
||||||
layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
|
content_type "text/plain"
|
||||||
body[:content_for_layout] = render(:file => method_name, :body => body)
|
body render(:file => "#{method_name}.text.plain.rhtml", :body => body, :layout => 'mailer.text.plain.erb')
|
||||||
ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}")
|
else
|
||||||
|
content_type "multipart/alternative"
|
||||||
|
part :content_type => "text/plain", :body => render(:file => "#{method_name}.text.plain.rhtml", :body => body, :layout => 'mailer.text.plain.erb')
|
||||||
|
part :content_type => "text/html", :body => render_message("#{method_name}.text.html.rhtml", body)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Makes partial rendering work with Rails 1.2 (retro-compatibility)
|
# Makes partial rendering work with Rails 1.2 (retro-compatibility)
|
||||||
def self.controller_path
|
def self.controller_path
|
||||||
''
|
''
|
||||||
end unless respond_to?('controller_path')
|
end unless respond_to?('controller_path')
|
||||||
|
|
||||||
|
# Returns a predictable Message-Id for the given object
|
||||||
|
def self.message_id_for(object)
|
||||||
|
# id + timestamp should reduce the odds of a collision
|
||||||
|
# as far as we don't send multiple emails for the same object
|
||||||
|
timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on)
|
||||||
|
hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{timestamp.strftime("%Y%m%d%H%M%S")}"
|
||||||
|
host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
|
||||||
|
host = "#{::Socket.gethostname}.redmine" if host.empty?
|
||||||
|
"<#{hash}@#{host}>"
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def message_id(object)
|
||||||
|
@message_id_object = object
|
||||||
|
end
|
||||||
|
|
||||||
|
def references(object)
|
||||||
|
@references_objects ||= []
|
||||||
|
@references_objects << object
|
||||||
|
end
|
||||||
|
|
||||||
|
def mylogger
|
||||||
|
RAILS_DEFAULT_LOGGER
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Patch TMail so that message_id is not overwritten
|
||||||
|
module TMail
|
||||||
|
class Mail
|
||||||
|
def add_message_id( fqdn = nil )
|
||||||
|
self.message_id ||= ::TMail::new_message_id(fqdn)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+64
-10
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -17,26 +17,80 @@
|
|||||||
|
|
||||||
class Member < ActiveRecord::Base
|
class Member < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :role
|
belongs_to :principal, :foreign_key => 'user_id'
|
||||||
|
has_many :member_roles, :dependent => :destroy
|
||||||
|
has_many :roles, :through => :member_roles
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
validates_presence_of :role, :user, :project
|
validates_presence_of :principal, :project
|
||||||
validates_uniqueness_of :user_id, :scope => :project_id
|
validates_uniqueness_of :user_id, :scope => :project_id
|
||||||
|
|
||||||
def validate
|
after_destroy :unwatch_from_permission_change
|
||||||
errors.add :role_id, :activerecord_error_invalid if role && !role.member?
|
|
||||||
end
|
|
||||||
|
|
||||||
def name
|
def name
|
||||||
self.user.name
|
self.user.name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias :base_role_ids= :role_ids=
|
||||||
|
def role_ids=(arg)
|
||||||
|
ids = (arg || []).collect(&:to_i) - [0]
|
||||||
|
# Keep inherited roles
|
||||||
|
ids += member_roles.select {|mr| !mr.inherited_from.nil?}.collect(&:role_id)
|
||||||
|
|
||||||
|
new_role_ids = ids - role_ids
|
||||||
|
# Add new roles
|
||||||
|
new_role_ids.each {|id| member_roles << MemberRole.new(:role_id => id) }
|
||||||
|
# Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy)
|
||||||
|
member_roles_to_destroy = member_roles.select {|mr| !ids.include?(mr.role_id)}
|
||||||
|
if member_roles_to_destroy.any?
|
||||||
|
member_roles_to_destroy.each(&:destroy)
|
||||||
|
unwatch_from_permission_change
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def <=>(member)
|
def <=>(member)
|
||||||
role == member.role ? (user <=> member.user) : (role <=> member.role)
|
a, b = roles.sort.first, member.roles.sort.first
|
||||||
|
a == b ? (principal <=> member.principal) : (a <=> b)
|
||||||
|
end
|
||||||
|
|
||||||
|
def deletable?
|
||||||
|
member_roles.detect {|mr| mr.inherited_from}.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def include?(user)
|
||||||
|
if principal.is_a?(Group)
|
||||||
|
!user.nil? && user.groups.include?(principal)
|
||||||
|
else
|
||||||
|
self.user == user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_destroy
|
def before_destroy
|
||||||
# remove category based auto assignments for this member
|
if user
|
||||||
IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id]
|
# remove category based auto assignments for this member
|
||||||
|
IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Find or initilize a Member with an id, attributes, and for a Principal
|
||||||
|
def self.edit_membership(id, new_attributes, principal=nil)
|
||||||
|
@membership = id.present? ? Member.find(id) : Member.new(:principal => principal)
|
||||||
|
@membership.attributes = new_attributes
|
||||||
|
@membership
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def validate
|
||||||
|
errors.add_to_base "Role can't be blank" if member_roles.empty? && roles.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Unwatch things that the user is no longer allowed to view inside project
|
||||||
|
def unwatch_from_permission_change
|
||||||
|
if user
|
||||||
|
Watcher.prune(:user => user, :project => project)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class MemberRole < ActiveRecord::Base
|
||||||
|
belongs_to :member
|
||||||
|
belongs_to :role
|
||||||
|
|
||||||
|
after_destroy :remove_member_if_empty
|
||||||
|
|
||||||
|
after_create :add_role_to_group_users
|
||||||
|
after_destroy :remove_role_from_group_users
|
||||||
|
|
||||||
|
validates_presence_of :role
|
||||||
|
|
||||||
|
def validate
|
||||||
|
errors.add :role_id, :invalid if role && !role.member?
|
||||||
|
end
|
||||||
|
|
||||||
|
def inherited?
|
||||||
|
!inherited_from.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def remove_member_if_empty
|
||||||
|
if member.roles.empty?
|
||||||
|
member.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_role_to_group_users
|
||||||
|
if member.principal.is_a?(Group)
|
||||||
|
member.principal.users.each do |user|
|
||||||
|
user_member = Member.find_by_project_id_and_user_id(member.project_id, user.id) || Member.new(:project_id => member.project_id, :user_id => user.id)
|
||||||
|
user_member.member_roles << MemberRole.new(:role => role, :inherited_from => id)
|
||||||
|
user_member.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_role_from_group_users
|
||||||
|
MemberRole.find(:all, :conditions => { :inherited_from => id }).group_by(&:member).each do |member, member_roles|
|
||||||
|
member_roles.each(&:destroy)
|
||||||
|
if member && member.user
|
||||||
|
Watcher.prune(:user => member.user, :project => member.project)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
+41
-14
@@ -19,46 +19,59 @@ class Message < ActiveRecord::Base
|
|||||||
belongs_to :board
|
belongs_to :board
|
||||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||||
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
|
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
|
||||||
has_many :attachments, :as => :container, :dependent => :destroy
|
acts_as_attachable
|
||||||
belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id'
|
belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id'
|
||||||
|
|
||||||
acts_as_searchable :columns => ['subject', 'content'],
|
acts_as_searchable :columns => ['subject', 'content'],
|
||||||
:include => {:board, :project},
|
:include => {:board => :project},
|
||||||
:project_key => 'project_id',
|
:project_key => 'project_id',
|
||||||
:date_column => "#{table_name}.created_on"
|
:date_column => "#{table_name}.created_on"
|
||||||
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
|
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
|
||||||
:description => :content,
|
:description => :content,
|
||||||
:type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
|
:type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
|
||||||
:url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} :
|
:url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} :
|
||||||
{:id => o.parent_id, :anchor => "message-#{o.id}"})}
|
{:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})}
|
||||||
|
|
||||||
acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}
|
acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
|
||||||
|
:author_key => :author_id
|
||||||
|
acts_as_watchable
|
||||||
|
|
||||||
attr_protected :locked, :sticky
|
attr_protected :locked, :sticky
|
||||||
validates_presence_of :subject, :content
|
validates_presence_of :board, :subject, :content
|
||||||
validates_length_of :subject, :maximum => 255
|
validates_length_of :subject, :maximum => 255
|
||||||
|
|
||||||
|
after_create :add_author_as_watcher
|
||||||
|
|
||||||
|
def visible?(user=User.current)
|
||||||
|
!user.nil? && user.allowed_to?(:view_messages, project)
|
||||||
|
end
|
||||||
|
|
||||||
def validate_on_create
|
def validate_on_create
|
||||||
# Can not reply to a locked topic
|
# Can not reply to a locked topic
|
||||||
errors.add_to_base 'Topic is locked' if root.locked? && self != root
|
errors.add_to_base 'Topic is locked' if root.locked? && self != root
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_create
|
def after_create
|
||||||
board.update_attribute(:last_message_id, self.id)
|
|
||||||
board.increment! :messages_count
|
|
||||||
if parent
|
if parent
|
||||||
parent.reload.update_attribute(:last_reply_id, self.id)
|
parent.reload.update_attribute(:last_reply_id, self.id)
|
||||||
else
|
end
|
||||||
board.increment! :topics_count
|
board.reset_counters!
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_update
|
||||||
|
if board_id_changed?
|
||||||
|
Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id])
|
||||||
|
Board.reset_counters!(board_id_was)
|
||||||
|
Board.reset_counters!(board_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_destroy
|
def after_destroy
|
||||||
# The following line is required so that the previous counter
|
board.reset_counters!
|
||||||
# updates (due to children removal) are not overwritten
|
end
|
||||||
board.reload
|
|
||||||
board.decrement! :messages_count
|
def sticky=(arg)
|
||||||
board.decrement! :topics_count unless parent
|
write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sticky?
|
def sticky?
|
||||||
@@ -68,4 +81,18 @@ class Message < ActiveRecord::Base
|
|||||||
def project
|
def project
|
||||||
board.project
|
board.project
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def editable_by?(usr)
|
||||||
|
usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroyable_by?(usr)
|
||||||
|
usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project)))
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def add_author_as_watcher
|
||||||
|
Watcher.create(:watchable => self.root, :user => author)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,13 +17,6 @@
|
|||||||
|
|
||||||
class MessageObserver < ActiveRecord::Observer
|
class MessageObserver < ActiveRecord::Observer
|
||||||
def after_create(message)
|
def after_create(message)
|
||||||
# send notification to the authors of the thread
|
Mailer.deliver_message_posted(message) if Setting.notified_events.include?('message_posted')
|
||||||
recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author && m.author.active?}
|
|
||||||
# send notification to the board watchers
|
|
||||||
recipients += message.board.watcher_recipients
|
|
||||||
# send notification to project members who want to be notified
|
|
||||||
recipients += message.board.project.recipients
|
|
||||||
recipients = recipients.compact.uniq
|
|
||||||
Mailer.deliver_message_posted(message, recipients) if !recipients.empty? && Setting.notified_events.include?('message_posted')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+11
-6
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006 Jean-Philippe Lang
|
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -24,12 +24,17 @@ class News < ActiveRecord::Base
|
|||||||
validates_length_of :title, :maximum => 60
|
validates_length_of :title, :maximum => 60
|
||||||
validates_length_of :summary, :maximum => 255
|
validates_length_of :summary, :maximum => 255
|
||||||
|
|
||||||
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :project
|
||||||
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
||||||
acts_as_activity_provider :find_options => {:include => [:project, :author]}
|
acts_as_activity_provider :find_options => {:include => [:project, :author]},
|
||||||
|
:author_key => :author_id
|
||||||
|
|
||||||
|
def visible?(user=User.current)
|
||||||
|
!user.nil? && user.allowed_to?(:view_news, project)
|
||||||
|
end
|
||||||
|
|
||||||
# returns latest news for projects visible by user
|
# returns latest news for projects visible by user
|
||||||
def self.latest(user=nil, count=5)
|
def self.latest(user = User.current, count = 5)
|
||||||
find(:all, :limit => count, :conditions => Project.visible_by(user), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# redMine - project management software
|
||||||
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class NewsObserver < ActiveRecord::Observer
|
||||||
|
def after_create(news)
|
||||||
|
Mailer.deliver_news_added(news) if Setting.notified_events.include?('news_added')
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program 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, USA.
|
||||||
|
|
||||||
|
class Principal < ActiveRecord::Base
|
||||||
|
set_table_name "#{table_name_prefix}users#{table_name_suffix}"
|
||||||
|
|
||||||
|
has_many :members, :foreign_key => 'user_id', :dependent => :destroy
|
||||||
|
has_many :memberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :project, :roles ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name"
|
||||||
|
has_many :projects, :through => :memberships
|
||||||
|
|
||||||
|
# Groups and active users
|
||||||
|
named_scope :active, :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status = 1)"
|
||||||
|
|
||||||
|
named_scope :like, lambda {|q|
|
||||||
|
s = "%#{q.to_s.strip.downcase}%"
|
||||||
|
{:conditions => ["LOWER(login) LIKE :s OR LOWER(firstname) LIKE :s OR LOWER(lastname) LIKE :s OR LOWER(mail) LIKE :s", {:s => s}],
|
||||||
|
:order => 'type, login, lastname, firstname, mail'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
before_create :set_default_empty_values
|
||||||
|
|
||||||
|
def <=>(principal)
|
||||||
|
if self.class.name == principal.class.name
|
||||||
|
self.to_s.downcase <=> principal.to_s.downcase
|
||||||
|
else
|
||||||
|
# groups after users
|
||||||
|
principal.class.name <=> self.class.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
# Make sure we don't try to insert NULL values (see #4632)
|
||||||
|
def set_default_empty_values
|
||||||
|
self.login ||= ''
|
||||||
|
self.hashed_password ||= ''
|
||||||
|
self.firstname ||= ''
|
||||||
|
self.lastname ||= ''
|
||||||
|
self.mail ||= ''
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
+507
-54
@@ -20,8 +20,16 @@ class Project < ActiveRecord::Base
|
|||||||
STATUS_ACTIVE = 1
|
STATUS_ACTIVE = 1
|
||||||
STATUS_ARCHIVED = 9
|
STATUS_ARCHIVED = 9
|
||||||
|
|
||||||
has_many :members, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
|
# Specific overidden Activities
|
||||||
|
has_many :time_entry_activities
|
||||||
|
has_many :members, :include => [:user, :roles], :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}"
|
||||||
|
has_many :memberships, :class_name => 'Member'
|
||||||
|
has_many :member_principals, :class_name => 'Member',
|
||||||
|
:include => :principal,
|
||||||
|
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{User::STATUS_ACTIVE})"
|
||||||
has_many :users, :through => :members
|
has_many :users, :through => :members
|
||||||
|
has_many :principals, :through => :member_principals, :source => :principal
|
||||||
|
|
||||||
has_many :enabled_modules, :dependent => :delete_all
|
has_many :enabled_modules, :dependent => :delete_all
|
||||||
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
|
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
|
||||||
has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
|
has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
|
||||||
@@ -43,12 +51,14 @@ class Project < ActiveRecord::Base
|
|||||||
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
|
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
|
||||||
:association_foreign_key => 'custom_field_id'
|
:association_foreign_key => 'custom_field_id'
|
||||||
|
|
||||||
acts_as_tree :order => "name", :counter_cache => true
|
acts_as_nested_set :order => 'name'
|
||||||
|
acts_as_attachable :view_permission => :view_files,
|
||||||
|
:delete_permission => :manage_files
|
||||||
|
|
||||||
acts_as_customizable
|
acts_as_customizable
|
||||||
acts_as_searchable :columns => ['name', 'description'], :project_key => 'id', :permission => nil
|
acts_as_searchable :columns => ['name', 'identifier', 'description'], :project_key => 'id', :permission => nil
|
||||||
acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
|
acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
|
||||||
:url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}},
|
:url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o}},
|
||||||
:author => nil
|
:author => nil
|
||||||
|
|
||||||
attr_protected :status, :enabled_module_names
|
attr_protected :status, :enabled_module_names
|
||||||
@@ -58,10 +68,18 @@ class Project < ActiveRecord::Base
|
|||||||
validates_associated :repository, :wiki
|
validates_associated :repository, :wiki
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
validates_length_of :homepage, :maximum => 255
|
validates_length_of :homepage, :maximum => 255
|
||||||
validates_length_of :identifier, :in => 3..20
|
validates_length_of :identifier, :in => 1..20
|
||||||
validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
|
# donwcase letters, digits, dashes but not digits only
|
||||||
|
validates_format_of :identifier, :with => /^(?!\d+$)[a-z0-9\-]*$/, :if => Proc.new { |p| p.identifier_changed? }
|
||||||
before_destroy :delete_all_members
|
# reserved words
|
||||||
|
validates_exclusion_of :identifier, :in => %w( new )
|
||||||
|
|
||||||
|
before_destroy :delete_all_members, :destroy_children
|
||||||
|
|
||||||
|
named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
|
||||||
|
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
|
||||||
|
named_scope :all_public, { :conditions => { :is_public => true } }
|
||||||
|
named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
|
||||||
|
|
||||||
def identifier=(identifier)
|
def identifier=(identifier)
|
||||||
super unless identifier_frozen?
|
super unless identifier_frozen?
|
||||||
@@ -70,21 +88,6 @@ class Project < ActiveRecord::Base
|
|||||||
def identifier_frozen?
|
def identifier_frozen?
|
||||||
errors[:identifier].nil? && !(new_record? || identifier.blank?)
|
errors[:identifier].nil? && !(new_record? || identifier.blank?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def issues_with_subprojects(include_subprojects=false)
|
|
||||||
conditions = nil
|
|
||||||
if include_subprojects
|
|
||||||
ids = [id] + child_ids
|
|
||||||
conditions = ["#{Project.table_name}.id IN (#{ids.join(',')}) AND #{Project.visible_by}"]
|
|
||||||
end
|
|
||||||
conditions ||= ["#{Project.table_name}.id = ?", id]
|
|
||||||
# Quick and dirty fix for Rails 2 compatibility
|
|
||||||
Issue.send(:with_scope, :find => { :conditions => conditions }) do
|
|
||||||
Version.send(:with_scope, :find => { :conditions => conditions }) do
|
|
||||||
yield
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# returns latest created projects
|
# returns latest created projects
|
||||||
# non public projects will be returned only if user is a member of those
|
# non public projects will be returned only if user is a member of those
|
||||||
@@ -92,6 +95,11 @@ class Project < ActiveRecord::Base
|
|||||||
find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
|
find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a SQL :conditions string used to find all active projects for the specified user.
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# Projects.visible_by(admin) => "projects.status = 1"
|
||||||
|
# Projects.visible_by(normal_user) => "projects.status = 1 AND projects.is_public = 1"
|
||||||
def self.visible_by(user=nil)
|
def self.visible_by(user=nil)
|
||||||
user ||= User.current
|
user ||= User.current
|
||||||
if user && user.admin?
|
if user && user.admin?
|
||||||
@@ -106,9 +114,15 @@ class Project < ActiveRecord::Base
|
|||||||
def self.allowed_to_condition(user, permission, options={})
|
def self.allowed_to_condition(user, permission, options={})
|
||||||
statements = []
|
statements = []
|
||||||
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
||||||
|
if perm = Redmine::AccessControl.permission(permission)
|
||||||
|
unless perm.project_module.nil?
|
||||||
|
# If the permission belongs to a project module, make sure the module is enabled
|
||||||
|
base_statement << " AND #{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}')"
|
||||||
|
end
|
||||||
|
end
|
||||||
if options[:project]
|
if options[:project]
|
||||||
project_statement = "#{Project.table_name}.id = #{options[:project].id}"
|
project_statement = "#{Project.table_name}.id = #{options[:project].id}"
|
||||||
project_statement << " OR #{Project.table_name}.parent_id = #{options[:project].id}" if options[:with_subprojects]
|
project_statement << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects]
|
||||||
base_statement = "(#{project_statement}) AND (#{base_statement})"
|
base_statement = "(#{project_statement}) AND (#{base_statement})"
|
||||||
end
|
end
|
||||||
if user.admin?
|
if user.admin?
|
||||||
@@ -116,22 +130,74 @@ class Project < ActiveRecord::Base
|
|||||||
else
|
else
|
||||||
statements << "1=0"
|
statements << "1=0"
|
||||||
if user.logged?
|
if user.logged?
|
||||||
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission)
|
if Role.non_member.allowed_to?(permission) && !options[:member]
|
||||||
allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id}
|
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
|
||||||
|
end
|
||||||
|
allowed_project_ids = user.memberships.select {|m| m.roles.detect {|role| role.allowed_to?(permission)}}.collect {|m| m.project_id}
|
||||||
statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any?
|
statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any?
|
||||||
elsif Role.anonymous.allowed_to?(permission)
|
|
||||||
# anonymous user allowed on public project
|
|
||||||
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
|
|
||||||
else
|
else
|
||||||
# anonymous user is not authorized
|
if Role.anonymous.allowed_to?(permission) && !options[:member]
|
||||||
|
# anonymous user allowed on public project
|
||||||
|
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))"
|
statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the Systemwide and project specific activities
|
||||||
|
def activities(include_inactive=false)
|
||||||
|
if include_inactive
|
||||||
|
return all_activities
|
||||||
|
else
|
||||||
|
return active_activities
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Will create a new Project specific Activity or update an existing one
|
||||||
|
#
|
||||||
|
# This will raise a ActiveRecord::Rollback if the TimeEntryActivity
|
||||||
|
# does not successfully save.
|
||||||
|
def update_or_create_time_entry_activity(id, activity_hash)
|
||||||
|
if activity_hash.respond_to?(:has_key?) && activity_hash.has_key?('parent_id')
|
||||||
|
self.create_time_entry_activity_if_needed(activity_hash)
|
||||||
|
else
|
||||||
|
activity = project.time_entry_activities.find_by_id(id.to_i)
|
||||||
|
activity.update_attributes(activity_hash) if activity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Create a new TimeEntryActivity if it overrides a system TimeEntryActivity
|
||||||
|
#
|
||||||
|
# This will raise a ActiveRecord::Rollback if the TimeEntryActivity
|
||||||
|
# does not successfully save.
|
||||||
|
def create_time_entry_activity_if_needed(activity)
|
||||||
|
if activity['parent_id']
|
||||||
|
|
||||||
|
parent_activity = TimeEntryActivity.find(activity['parent_id'])
|
||||||
|
activity['name'] = parent_activity.name
|
||||||
|
activity['position'] = parent_activity.position
|
||||||
|
|
||||||
|
if Enumeration.overridding_change?(activity, parent_activity)
|
||||||
|
project_activity = self.time_entry_activities.create(activity)
|
||||||
|
|
||||||
|
if project_activity.new_record?
|
||||||
|
raise ActiveRecord::Rollback, "Overridding TimeEntryActivity was not successfully saved"
|
||||||
|
else
|
||||||
|
self.time_entries.update_all("activity_id = #{project_activity.id}", ["activity_id = ?", parent_activity.id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a :conditions SQL string that can be used to find the issues associated with this project.
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# project.project_condition(true) => "(projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 10))"
|
||||||
|
# project.project_condition(false) => "projects.id = 1"
|
||||||
def project_condition(with_subprojects)
|
def project_condition(with_subprojects)
|
||||||
cond = "#{Project.table_name}.id = #{id}"
|
cond = "#{Project.table_name}.id = #{id}"
|
||||||
cond = "(#{cond} OR #{Project.table_name}.parent_id = #{id})" if with_subprojects
|
cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects
|
||||||
cond
|
cond
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -154,40 +220,164 @@ class Project < ActiveRecord::Base
|
|||||||
self.status == STATUS_ACTIVE
|
self.status == STATUS_ACTIVE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Archives the project and its descendants
|
||||||
def archive
|
def archive
|
||||||
# Archive subprojects if any
|
# Check that there is no issue of a non descendant project that is assigned
|
||||||
children.each do |subproject|
|
# to one of the project or descendant versions
|
||||||
subproject.archive
|
v_ids = self_and_descendants.collect {|p| p.version_ids}.flatten
|
||||||
|
if v_ids.any? && Issue.find(:first, :include => :project,
|
||||||
|
:conditions => ["(#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?)" +
|
||||||
|
" AND #{Issue.table_name}.fixed_version_id IN (?)", lft, rgt, v_ids])
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
update_attribute :status, STATUS_ARCHIVED
|
Project.transaction do
|
||||||
|
archive!
|
||||||
|
end
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Unarchives the project
|
||||||
|
# All its ancestors must be active
|
||||||
def unarchive
|
def unarchive
|
||||||
return false if parent && !parent.active?
|
return false if ancestors.detect {|a| !a.active?}
|
||||||
update_attribute :status, STATUS_ACTIVE
|
update_attribute :status, STATUS_ACTIVE
|
||||||
end
|
end
|
||||||
|
|
||||||
def active_children
|
# Returns an array of projects the project can be moved to
|
||||||
children.select {|child| child.active?}
|
# by the current user
|
||||||
|
def allowed_parents
|
||||||
|
return @allowed_parents if @allowed_parents
|
||||||
|
@allowed_parents = Project.find(:all, :conditions => Project.allowed_to_condition(User.current, :add_subprojects))
|
||||||
|
@allowed_parents = @allowed_parents - self_and_descendants
|
||||||
|
if User.current.allowed_to?(:add_project, nil, :global => true) || (!new_record? && parent.nil?)
|
||||||
|
@allowed_parents << nil
|
||||||
|
end
|
||||||
|
unless parent.nil? || @allowed_parents.empty? || @allowed_parents.include?(parent)
|
||||||
|
@allowed_parents << parent
|
||||||
|
end
|
||||||
|
@allowed_parents
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of the trackers used by the project and its sub projects
|
# Sets the parent of the project with authorization check
|
||||||
|
def set_allowed_parent!(p)
|
||||||
|
unless p.nil? || p.is_a?(Project)
|
||||||
|
if p.to_s.blank?
|
||||||
|
p = nil
|
||||||
|
else
|
||||||
|
p = Project.find_by_id(p)
|
||||||
|
return false unless p
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if p.nil?
|
||||||
|
if !new_record? && allowed_parents.empty?
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
elsif !allowed_parents.include?(p)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
set_parent!(p)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sets the parent of the project
|
||||||
|
# Argument can be either a Project, a String, a Fixnum or nil
|
||||||
|
def set_parent!(p)
|
||||||
|
unless p.nil? || p.is_a?(Project)
|
||||||
|
if p.to_s.blank?
|
||||||
|
p = nil
|
||||||
|
else
|
||||||
|
p = Project.find_by_id(p)
|
||||||
|
return false unless p
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if p == parent && !p.nil?
|
||||||
|
# Nothing to do
|
||||||
|
true
|
||||||
|
elsif p.nil? || (p.active? && move_possible?(p))
|
||||||
|
# Insert the project so that target's children or root projects stay alphabetically sorted
|
||||||
|
sibs = (p.nil? ? self.class.roots : p.children)
|
||||||
|
to_be_inserted_before = sibs.detect {|c| c.name.to_s.downcase > name.to_s.downcase }
|
||||||
|
if to_be_inserted_before
|
||||||
|
move_to_left_of(to_be_inserted_before)
|
||||||
|
elsif p.nil?
|
||||||
|
if sibs.empty?
|
||||||
|
# move_to_root adds the project in first (ie. left) position
|
||||||
|
move_to_root
|
||||||
|
else
|
||||||
|
move_to_right_of(sibs.last) unless self == sibs.last
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# move_to_child_of adds the project in last (ie.right) position
|
||||||
|
move_to_child_of(p)
|
||||||
|
end
|
||||||
|
Issue.update_versions_from_hierarchy_change(self)
|
||||||
|
true
|
||||||
|
else
|
||||||
|
# Can not move to the given target
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns an array of the trackers used by the project and its active sub projects
|
||||||
def rolled_up_trackers
|
def rolled_up_trackers
|
||||||
@rolled_up_trackers ||=
|
@rolled_up_trackers ||=
|
||||||
Tracker.find(:all, :include => :projects,
|
Tracker.find(:all, :include => :projects,
|
||||||
:select => "DISTINCT #{Tracker.table_name}.*",
|
:select => "DISTINCT #{Tracker.table_name}.*",
|
||||||
:conditions => ["#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?", id, id],
|
:conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt],
|
||||||
:order => "#{Tracker.table_name}.position")
|
:order => "#{Tracker.table_name}.position")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Closes open and locked project versions that are completed
|
||||||
|
def close_completed_versions
|
||||||
|
Version.transaction do
|
||||||
|
versions.find(:all, :conditions => {:status => %w(open locked)}).each do |version|
|
||||||
|
if version.completed?
|
||||||
|
version.update_attribute(:status, 'closed')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a scope of the Versions on subprojects
|
||||||
|
def rolled_up_versions
|
||||||
|
@rolled_up_versions ||=
|
||||||
|
Version.scoped(:include => :project,
|
||||||
|
:conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a scope of the Versions used by the project
|
||||||
|
def shared_versions
|
||||||
|
@shared_versions ||=
|
||||||
|
Version.scoped(:include => :project,
|
||||||
|
:conditions => "#{Project.table_name}.id = #{id}" +
|
||||||
|
" OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" +
|
||||||
|
" #{Version.table_name}.sharing = 'system'" +
|
||||||
|
" OR (#{Project.table_name}.lft >= #{root.lft} AND #{Project.table_name}.rgt <= #{root.rgt} AND #{Version.table_name}.sharing = 'tree')" +
|
||||||
|
" OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" +
|
||||||
|
" OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
|
||||||
|
"))")
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a hash of project users grouped by role
|
||||||
|
def users_by_role
|
||||||
|
members.find(:all, :include => [:user, :roles]).inject({}) do |h, m|
|
||||||
|
m.roles.each do |r|
|
||||||
|
h[r] ||= []
|
||||||
|
h[r] << m.user
|
||||||
|
end
|
||||||
|
h
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Deletes all project's members
|
# Deletes all project's members
|
||||||
def delete_all_members
|
def delete_all_members
|
||||||
|
me, mr = Member.table_name, MemberRole.table_name
|
||||||
|
connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})")
|
||||||
Member.delete_all(['project_id = ?', id])
|
Member.delete_all(['project_id = ?', id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Users issues can be assigned to
|
# Users issues can be assigned to
|
||||||
def assignable_users
|
def assignable_users
|
||||||
members.select {|m| m.role.assignable?}.collect {|m| m.user}.sort
|
members.select {|m| m.roles.detect {|role| role.assignable?}}.collect {|m| m.user}.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the mail adresses of users that should be always notified on project events
|
# Returns the mail adresses of users that should be always notified on project events
|
||||||
@@ -195,10 +385,15 @@ class Project < ActiveRecord::Base
|
|||||||
members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
|
members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the users that should be notified on project events
|
||||||
|
def notified_users
|
||||||
|
members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user}
|
||||||
|
end
|
||||||
|
|
||||||
# Returns an array of all custom fields enabled for project issues
|
# Returns an array of all custom fields enabled for project issues
|
||||||
# (explictly associated custom fields and custom fields enabled for all projects)
|
# (explictly associated custom fields and custom fields enabled for all projects)
|
||||||
def all_issue_custom_fields
|
def all_issue_custom_fields
|
||||||
@all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq
|
@all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def project
|
def project
|
||||||
@@ -215,9 +410,13 @@ class Project < ActiveRecord::Base
|
|||||||
|
|
||||||
# Returns a short description of the projects (first lines)
|
# Returns a short description of the projects (first lines)
|
||||||
def short_description(length = 255)
|
def short_description(length = 255)
|
||||||
description.gsub(/^(.{#{length}}[^\n]*).*$/m, '\1').strip if description
|
description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return true if this project is allowed to do the specified action.
|
||||||
|
# action can be:
|
||||||
|
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
|
||||||
|
# * a permission Symbol (eg. :edit_project)
|
||||||
def allows_to?(action)
|
def allows_to?(action)
|
||||||
if action.is_a? Hash
|
if action.is_a? Hash
|
||||||
allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
|
allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
|
||||||
@@ -232,24 +431,232 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def enabled_module_names=(module_names)
|
def enabled_module_names=(module_names)
|
||||||
enabled_modules.clear
|
if module_names && module_names.is_a?(Array)
|
||||||
module_names = [] unless module_names && module_names.is_a?(Array)
|
module_names = module_names.collect(&:to_s)
|
||||||
module_names.each do |name|
|
# remove disabled modules
|
||||||
enabled_modules << EnabledModule.new(:name => name.to_s)
|
enabled_modules.each {|mod| mod.destroy unless module_names.include?(mod.name)}
|
||||||
|
# add new modules
|
||||||
|
module_names.reject {|name| module_enabled?(name)}.each {|name| enabled_modules << EnabledModule.new(:name => name)}
|
||||||
|
else
|
||||||
|
enabled_modules.clear
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns an auto-generated project identifier based on the last identifier used
|
||||||
|
def self.next_identifier
|
||||||
|
p = Project.find(:first, :order => 'created_on DESC')
|
||||||
|
p.nil? ? nil : p.identifier.to_s.succ
|
||||||
|
end
|
||||||
|
|
||||||
|
# Copies and saves the Project instance based on the +project+.
|
||||||
|
# Duplicates the source project's:
|
||||||
|
# * Wiki
|
||||||
|
# * Versions
|
||||||
|
# * Categories
|
||||||
|
# * Issues
|
||||||
|
# * Members
|
||||||
|
# * Queries
|
||||||
|
#
|
||||||
|
# Accepts an +options+ argument to specify what to copy
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# project.copy(1) # => copies everything
|
||||||
|
# project.copy(1, :only => 'members') # => copies members only
|
||||||
|
# project.copy(1, :only => ['members', 'versions']) # => copies members and versions
|
||||||
|
def copy(project, options={})
|
||||||
|
project = project.is_a?(Project) ? project : Project.find(project)
|
||||||
|
|
||||||
|
to_be_copied = %w(wiki versions issue_categories issues members queries boards)
|
||||||
|
to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil?
|
||||||
|
|
||||||
|
Project.transaction do
|
||||||
|
if save
|
||||||
|
reload
|
||||||
|
to_be_copied.each do |name|
|
||||||
|
send "copy_#{name}", project
|
||||||
|
end
|
||||||
|
Redmine::Hook.call_hook(:model_project_copy_before_save, :source_project => project, :destination_project => self)
|
||||||
|
save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
def validate
|
# Copies +project+ and returns the new instance. This will not save
|
||||||
errors.add(parent_id, " must be a root project") if parent and parent.parent
|
# the copy
|
||||||
errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0
|
def self.copy_from(project)
|
||||||
errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/)
|
begin
|
||||||
|
project = project.is_a?(Project) ? project : Project.find(project)
|
||||||
|
if project
|
||||||
|
# clear unique attributes
|
||||||
|
attributes = project.attributes.dup.except('id', 'name', 'identifier', 'status', 'parent_id', 'lft', 'rgt')
|
||||||
|
copy = Project.new(attributes)
|
||||||
|
copy.enabled_modules = project.enabled_modules
|
||||||
|
copy.trackers = project.trackers
|
||||||
|
copy.custom_values = project.custom_values.collect {|v| v.clone}
|
||||||
|
copy.issue_custom_fields = project.issue_custom_fields
|
||||||
|
return copy
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Destroys children before destroying self
|
||||||
|
def destroy_children
|
||||||
|
children.each do |child|
|
||||||
|
child.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Copies wiki from +project+
|
||||||
|
def copy_wiki(project)
|
||||||
|
# Check that the source project has a wiki first
|
||||||
|
unless project.wiki.nil?
|
||||||
|
self.wiki ||= Wiki.new
|
||||||
|
wiki.attributes = project.wiki.attributes.dup.except("id", "project_id")
|
||||||
|
wiki_pages_map = {}
|
||||||
|
project.wiki.pages.each do |page|
|
||||||
|
# Skip pages without content
|
||||||
|
next if page.content.nil?
|
||||||
|
new_wiki_content = WikiContent.new(page.content.attributes.dup.except("id", "page_id", "updated_on"))
|
||||||
|
new_wiki_page = WikiPage.new(page.attributes.dup.except("id", "wiki_id", "created_on", "parent_id"))
|
||||||
|
new_wiki_page.content = new_wiki_content
|
||||||
|
wiki.pages << new_wiki_page
|
||||||
|
wiki_pages_map[page.id] = new_wiki_page
|
||||||
|
end
|
||||||
|
wiki.save
|
||||||
|
# Reproduce page hierarchy
|
||||||
|
project.wiki.pages.each do |page|
|
||||||
|
if page.parent_id && wiki_pages_map[page.id]
|
||||||
|
wiki_pages_map[page.id].parent = wiki_pages_map[page.parent_id]
|
||||||
|
wiki_pages_map[page.id].save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Copies versions from +project+
|
||||||
|
def copy_versions(project)
|
||||||
|
project.versions.each do |version|
|
||||||
|
new_version = Version.new
|
||||||
|
new_version.attributes = version.attributes.dup.except("id", "project_id", "created_on", "updated_on")
|
||||||
|
self.versions << new_version
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Copies issue categories from +project+
|
||||||
|
def copy_issue_categories(project)
|
||||||
|
project.issue_categories.each do |issue_category|
|
||||||
|
new_issue_category = IssueCategory.new
|
||||||
|
new_issue_category.attributes = issue_category.attributes.dup.except("id", "project_id")
|
||||||
|
self.issue_categories << new_issue_category
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Copies issues from +project+
|
||||||
|
def copy_issues(project)
|
||||||
|
# Stores the source issue id as a key and the copied issues as the
|
||||||
|
# value. Used to map the two togeather for issue relations.
|
||||||
|
issues_map = {}
|
||||||
|
|
||||||
|
# Get issues sorted by root_id, lft so that parent issues
|
||||||
|
# get copied before their children
|
||||||
|
project.issues.find(:all, :order => 'root_id, lft').each do |issue|
|
||||||
|
new_issue = Issue.new
|
||||||
|
new_issue.copy_from(issue)
|
||||||
|
new_issue.project = self
|
||||||
|
# Reassign fixed_versions by name, since names are unique per
|
||||||
|
# project and the versions for self are not yet saved
|
||||||
|
if issue.fixed_version
|
||||||
|
new_issue.fixed_version = self.versions.select {|v| v.name == issue.fixed_version.name}.first
|
||||||
|
end
|
||||||
|
# Reassign the category by name, since names are unique per
|
||||||
|
# project and the categories for self are not yet saved
|
||||||
|
if issue.category
|
||||||
|
new_issue.category = self.issue_categories.select {|c| c.name == issue.category.name}.first
|
||||||
|
end
|
||||||
|
# Parent issue
|
||||||
|
if issue.parent_id
|
||||||
|
if copied_parent = issues_map[issue.parent_id]
|
||||||
|
new_issue.parent_issue_id = copied_parent.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.issues << new_issue
|
||||||
|
issues_map[issue.id] = new_issue
|
||||||
|
end
|
||||||
|
|
||||||
|
# Relations after in case issues related each other
|
||||||
|
project.issues.each do |issue|
|
||||||
|
new_issue = issues_map[issue.id]
|
||||||
|
|
||||||
|
# Relations
|
||||||
|
issue.relations_from.each do |source_relation|
|
||||||
|
new_issue_relation = IssueRelation.new
|
||||||
|
new_issue_relation.attributes = source_relation.attributes.dup.except("id", "issue_from_id", "issue_to_id")
|
||||||
|
new_issue_relation.issue_to = issues_map[source_relation.issue_to_id]
|
||||||
|
if new_issue_relation.issue_to.nil? && Setting.cross_project_issue_relations?
|
||||||
|
new_issue_relation.issue_to = source_relation.issue_to
|
||||||
|
end
|
||||||
|
new_issue.relations_from << new_issue_relation
|
||||||
|
end
|
||||||
|
|
||||||
|
issue.relations_to.each do |source_relation|
|
||||||
|
new_issue_relation = IssueRelation.new
|
||||||
|
new_issue_relation.attributes = source_relation.attributes.dup.except("id", "issue_from_id", "issue_to_id")
|
||||||
|
new_issue_relation.issue_from = issues_map[source_relation.issue_from_id]
|
||||||
|
if new_issue_relation.issue_from.nil? && Setting.cross_project_issue_relations?
|
||||||
|
new_issue_relation.issue_from = source_relation.issue_from
|
||||||
|
end
|
||||||
|
new_issue.relations_to << new_issue_relation
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Copies members from +project+
|
||||||
|
def copy_members(project)
|
||||||
|
project.memberships.each do |member|
|
||||||
|
new_member = Member.new
|
||||||
|
new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
|
||||||
|
# only copy non inherited roles
|
||||||
|
# inherited roles will be added when copying the group membership
|
||||||
|
role_ids = member.member_roles.reject(&:inherited?).collect(&:role_id)
|
||||||
|
next if role_ids.empty?
|
||||||
|
new_member.role_ids = role_ids
|
||||||
|
new_member.project = self
|
||||||
|
self.members << new_member
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Copies queries from +project+
|
||||||
|
def copy_queries(project)
|
||||||
|
project.queries.each do |query|
|
||||||
|
new_query = Query.new
|
||||||
|
new_query.attributes = query.attributes.dup.except("id", "project_id", "sort_criteria")
|
||||||
|
new_query.sort_criteria = query.sort_criteria if query.sort_criteria
|
||||||
|
new_query.project = self
|
||||||
|
self.queries << new_query
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Copies boards from +project+
|
||||||
|
def copy_boards(project)
|
||||||
|
project.boards.each do |board|
|
||||||
|
new_board = Board.new
|
||||||
|
new_board.attributes = board.attributes.dup.except("id", "project_id", "topics_count", "messages_count", "last_message_id")
|
||||||
|
new_board.project = self
|
||||||
|
self.boards << new_board
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
def allowed_permissions
|
def allowed_permissions
|
||||||
@allowed_permissions ||= begin
|
@allowed_permissions ||= begin
|
||||||
module_names = enabled_modules.collect {|m| m.name}
|
module_names = enabled_modules.all(:select => :name).collect {|m| m.name}
|
||||||
Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
|
Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -257,4 +664,50 @@ private
|
|||||||
def allowed_actions
|
def allowed_actions
|
||||||
@actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
|
@actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns all the active Systemwide and project specific activities
|
||||||
|
def active_activities
|
||||||
|
overridden_activity_ids = self.time_entry_activities.collect(&:parent_id)
|
||||||
|
|
||||||
|
if overridden_activity_ids.empty?
|
||||||
|
return TimeEntryActivity.shared.active
|
||||||
|
else
|
||||||
|
return system_activities_and_project_overrides
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns all the Systemwide and project specific activities
|
||||||
|
# (inactive and active)
|
||||||
|
def all_activities
|
||||||
|
overridden_activity_ids = self.time_entry_activities.collect(&:parent_id)
|
||||||
|
|
||||||
|
if overridden_activity_ids.empty?
|
||||||
|
return TimeEntryActivity.shared
|
||||||
|
else
|
||||||
|
return system_activities_and_project_overrides(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the systemwide active activities merged with the project specific overrides
|
||||||
|
def system_activities_and_project_overrides(include_inactive=false)
|
||||||
|
if include_inactive
|
||||||
|
return TimeEntryActivity.shared.
|
||||||
|
find(:all,
|
||||||
|
:conditions => ["id NOT IN (?)", self.time_entry_activities.collect(&:parent_id)]) +
|
||||||
|
self.time_entry_activities
|
||||||
|
else
|
||||||
|
return TimeEntryActivity.shared.active.
|
||||||
|
find(:all,
|
||||||
|
:conditions => ["id NOT IN (?)", self.time_entry_activities.collect(&:parent_id)]) +
|
||||||
|
self.time_entry_activities.active
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Archives subprojects recursively
|
||||||
|
def archive!
|
||||||
|
children.each do |subproject|
|
||||||
|
subproject.send :archive!
|
||||||
|
end
|
||||||
|
update_attribute :status, STATUS_ARCHIVED
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+303
-96
@@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,18 +16,31 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class QueryColumn
|
class QueryColumn
|
||||||
attr_accessor :name, :sortable, :default_order
|
attr_accessor :name, :sortable, :groupable, :default_order
|
||||||
include GLoc
|
include Redmine::I18n
|
||||||
|
|
||||||
def initialize(name, options={})
|
def initialize(name, options={})
|
||||||
self.name = name
|
self.name = name
|
||||||
self.sortable = options[:sortable]
|
self.sortable = options[:sortable]
|
||||||
|
self.groupable = options[:groupable] || false
|
||||||
|
if groupable == true
|
||||||
|
self.groupable = name.to_s
|
||||||
|
end
|
||||||
self.default_order = options[:default_order]
|
self.default_order = options[:default_order]
|
||||||
|
@caption_key = options[:caption] || "field_#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def caption
|
def caption
|
||||||
set_language_if_valid(User.current.language)
|
l(@caption_key)
|
||||||
l("field_#{name}")
|
end
|
||||||
|
|
||||||
|
# Returns true if the column is sortable, otherwise false
|
||||||
|
def sortable?
|
||||||
|
!sortable.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def value(issue)
|
||||||
|
issue.send name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -35,7 +48,11 @@ class QueryCustomFieldColumn < QueryColumn
|
|||||||
|
|
||||||
def initialize(custom_field)
|
def initialize(custom_field)
|
||||||
self.name = "cf_#{custom_field.id}".to_sym
|
self.name = "cf_#{custom_field.id}".to_sym
|
||||||
self.sortable = false
|
self.sortable = custom_field.order_statement || false
|
||||||
|
if %w(list date bool int).include?(custom_field.field_format)
|
||||||
|
self.groupable = custom_field.order_statement
|
||||||
|
end
|
||||||
|
self.groupable ||= false
|
||||||
@cf = custom_field
|
@cf = custom_field
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -46,13 +63,22 @@ class QueryCustomFieldColumn < QueryColumn
|
|||||||
def custom_field
|
def custom_field
|
||||||
@cf
|
@cf
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def value(issue)
|
||||||
|
cv = issue.custom_values.detect {|v| v.custom_field_id == @cf.id}
|
||||||
|
cv && @cf.cast_value(cv.value)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Query < ActiveRecord::Base
|
class Query < ActiveRecord::Base
|
||||||
|
class StatementInvalid < ::ActiveRecord::StatementInvalid
|
||||||
|
end
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
serialize :filters
|
serialize :filters
|
||||||
serialize :column_names
|
serialize :column_names
|
||||||
|
serialize :sort_criteria, Array
|
||||||
|
|
||||||
attr_protected :project_id, :user_id
|
attr_protected :project_id, :user_id
|
||||||
|
|
||||||
@@ -65,8 +91,8 @@ class Query < ActiveRecord::Base
|
|||||||
"c" => :label_closed_issues,
|
"c" => :label_closed_issues,
|
||||||
"!*" => :label_none,
|
"!*" => :label_none,
|
||||||
"*" => :label_all,
|
"*" => :label_all,
|
||||||
">=" => '>=',
|
">=" => :label_greater_or_equal,
|
||||||
"<=" => '<=',
|
"<=" => :label_less_or_equal,
|
||||||
"<t+" => :label_in_less_than,
|
"<t+" => :label_in_less_than,
|
||||||
">t+" => :label_in_more_than,
|
">t+" => :label_in_more_than,
|
||||||
"t+" => :label_in,
|
"t+" => :label_in,
|
||||||
@@ -93,19 +119,21 @@ class Query < ActiveRecord::Base
|
|||||||
cattr_reader :operators_by_filter_type
|
cattr_reader :operators_by_filter_type
|
||||||
|
|
||||||
@@available_columns = [
|
@@available_columns = [
|
||||||
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position"),
|
QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
|
||||||
QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position"),
|
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true),
|
||||||
QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position", :default_order => 'desc'),
|
QueryColumn.new(:parent, :sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"], :default_order => 'desc', :caption => :field_parent_issue),
|
||||||
|
QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :groupable => true),
|
||||||
|
QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.position", :default_order => 'desc', :groupable => true),
|
||||||
QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
|
QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
|
||||||
QueryColumn.new(:author),
|
QueryColumn.new(:author),
|
||||||
QueryColumn.new(:assigned_to, :sortable => "#{User.table_name}.lastname"),
|
QueryColumn.new(:assigned_to, :sortable => ["#{User.table_name}.lastname", "#{User.table_name}.firstname", "#{User.table_name}.id"], :groupable => true),
|
||||||
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
|
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
|
||||||
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"),
|
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true),
|
||||||
QueryColumn.new(:fixed_version, :sortable => "#{Version.table_name}.effective_date", :default_order => 'desc'),
|
QueryColumn.new(:fixed_version, :sortable => ["#{Version.table_name}.effective_date", "#{Version.table_name}.name"], :default_order => 'desc', :groupable => true),
|
||||||
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
|
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
|
||||||
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
|
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
|
||||||
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
|
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
|
||||||
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"),
|
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio", :groupable => true),
|
||||||
QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'),
|
QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'),
|
||||||
]
|
]
|
||||||
cattr_reader :available_columns
|
cattr_reader :available_columns
|
||||||
@@ -113,7 +141,6 @@ class Query < ActiveRecord::Base
|
|||||||
def initialize(attributes = nil)
|
def initialize(attributes = nil)
|
||||||
super attributes
|
super attributes
|
||||||
self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
|
self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
|
||||||
set_language_if_valid(User.current.language)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
@@ -123,7 +150,7 @@ class Query < ActiveRecord::Base
|
|||||||
|
|
||||||
def validate
|
def validate
|
||||||
filters.each_key do |field|
|
filters.each_key do |field|
|
||||||
errors.add label_for(field), :activerecord_error_blank unless
|
errors.add label_for(field), :blank unless
|
||||||
# filter requires one or more values
|
# filter requires one or more values
|
||||||
(values_for(field) and !values_for(field).first.blank?) or
|
(values_for(field) and !values_for(field).first.blank?) or
|
||||||
# filter doesn't require any value
|
# filter doesn't require any value
|
||||||
@@ -146,7 +173,7 @@ class Query < ActiveRecord::Base
|
|||||||
|
|
||||||
@available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
|
@available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
|
||||||
"tracker_id" => { :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] } },
|
"tracker_id" => { :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] } },
|
||||||
"priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI'], :order => 'position').collect{|s| [s.name, s.id.to_s] } },
|
"priority_id" => { :type => :list, :order => 3, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s] } },
|
||||||
"subject" => { :type => :text, :order => 8 },
|
"subject" => { :type => :text, :order => 8 },
|
||||||
"created_on" => { :type => :date_past, :order => 9 },
|
"created_on" => { :type => :date_past, :order => 9 },
|
||||||
"updated_on" => { :type => :date_past, :order => 10 },
|
"updated_on" => { :type => :date_past, :order => 10 },
|
||||||
@@ -160,26 +187,37 @@ class Query < ActiveRecord::Base
|
|||||||
if project
|
if project
|
||||||
user_values += project.users.sort.collect{|s| [s.name, s.id.to_s] }
|
user_values += project.users.sort.collect{|s| [s.name, s.id.to_s] }
|
||||||
else
|
else
|
||||||
# members of the user's projects
|
project_ids = User.current.projects.collect(&:id)
|
||||||
user_values += User.current.projects.collect(&:users).flatten.uniq.sort.collect{|s| [s.name, s.id.to_s] }
|
if project_ids.any?
|
||||||
|
# members of the user's projects
|
||||||
|
user_values += User.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", project_ids]).sort.collect{|s| [s.name, s.id.to_s] }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
|
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
|
||||||
@available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
|
@available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
|
||||||
|
|
||||||
|
if User.current.logged?
|
||||||
|
@available_filters["watcher_id"] = { :type => :list, :order => 15, :values => [["<< #{l(:label_me)} >>", "me"]] }
|
||||||
|
end
|
||||||
|
|
||||||
if project
|
if project
|
||||||
# project specific filters
|
# project specific filters
|
||||||
unless @project.issue_categories.empty?
|
unless @project.issue_categories.empty?
|
||||||
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
|
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
|
||||||
end
|
end
|
||||||
unless @project.versions.empty?
|
unless @project.shared_versions.empty?
|
||||||
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
|
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.shared_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
|
||||||
end
|
end
|
||||||
unless @project.active_children.empty?
|
unless @project.descendants.active.empty?
|
||||||
@available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
|
@available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.descendants.visible.collect{|s| [s.name, s.id.to_s] } }
|
||||||
end
|
end
|
||||||
add_custom_fields_filters(@project.all_issue_custom_fields)
|
add_custom_fields_filters(@project.all_issue_custom_fields)
|
||||||
else
|
else
|
||||||
# global filters for cross project issue list
|
# global filters for cross project issue list
|
||||||
|
system_shared_versions = Version.visible.find_all_by_sharing('system')
|
||||||
|
unless system_shared_versions.empty?
|
||||||
|
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => system_shared_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
|
||||||
|
end
|
||||||
add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
|
add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
|
||||||
end
|
end
|
||||||
@available_filters
|
@available_filters
|
||||||
@@ -202,9 +240,16 @@ class Query < ActiveRecord::Base
|
|||||||
|
|
||||||
def add_short_filter(field, expression)
|
def add_short_filter(field, expression)
|
||||||
return unless expression
|
return unless expression
|
||||||
parms = expression.scan(/^(o|c|\!|\*)?(.*)$/).first
|
parms = expression.scan(/^(o|c|!\*|!|\*)?(.*)$/).first
|
||||||
add_filter field, (parms[0] || "="), [parms[1] || ""]
|
add_filter field, (parms[0] || "="), [parms[1] || ""]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add multiple filters using +add_filter+
|
||||||
|
def add_filters(fields, operators, values)
|
||||||
|
fields.each do |field|
|
||||||
|
add_filter(field, operators[field], values[field])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def has_filter?(field)
|
def has_filter?(field)
|
||||||
filters and filters[field]
|
filters and filters[field]
|
||||||
@@ -228,13 +273,37 @@ class Query < ActiveRecord::Base
|
|||||||
@available_columns = Query.available_columns
|
@available_columns = Query.available_columns
|
||||||
@available_columns += (project ?
|
@available_columns += (project ?
|
||||||
project.all_issue_custom_fields :
|
project.all_issue_custom_fields :
|
||||||
IssueCustomField.find(:all, :conditions => {:is_for_all => true})
|
IssueCustomField.find(:all)
|
||||||
).collect {|cf| QueryCustomFieldColumn.new(cf) }
|
).collect {|cf| QueryCustomFieldColumn.new(cf) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.available_columns=(v)
|
||||||
|
self.available_columns = (v)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.add_available_column(column)
|
||||||
|
self.available_columns << (column) if column.is_a?(QueryColumn)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns an array of columns that can be used to group the results
|
||||||
|
def groupable_columns
|
||||||
|
available_columns.select {|c| c.groupable}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a Hash of columns and the key for sorting
|
||||||
|
def sortable_columns
|
||||||
|
{'id' => "#{Issue.table_name}.id"}.merge(available_columns.inject({}) {|h, column|
|
||||||
|
h[column.name.to_s] = column.sortable
|
||||||
|
h
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
def columns
|
def columns
|
||||||
if has_default_columns?
|
if has_default_columns?
|
||||||
available_columns.select {|c| Setting.issue_list_default_columns.include?(c.name.to_s) }
|
available_columns.select do |c|
|
||||||
|
# Adds the project column by default for cross-project lists
|
||||||
|
Setting.issue_list_default_columns.include?(c.name.to_s) || (c.name == :project && project.nil?)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
# preserve the column_names order
|
# preserve the column_names order
|
||||||
column_names.collect {|name| available_columns.find {|col| col.name == name}}.compact
|
column_names.collect {|name| available_columns.find {|col| col.name == name}}.compact
|
||||||
@@ -242,8 +311,14 @@ class Query < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def column_names=(names)
|
def column_names=(names)
|
||||||
names = names.select {|n| n.is_a?(Symbol) || !n.blank? } if names
|
if names
|
||||||
names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym } if names
|
names = names.select {|n| n.is_a?(Symbol) || !n.blank? }
|
||||||
|
names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym }
|
||||||
|
# Set column_names to nil if default columns
|
||||||
|
if names.map(&:to_s) == Setting.issue_list_default_columns
|
||||||
|
names = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
write_attribute(:column_names, names)
|
write_attribute(:column_names, names)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -254,11 +329,53 @@ class Query < ActiveRecord::Base
|
|||||||
def has_default_columns?
|
def has_default_columns?
|
||||||
column_names.nil? || column_names.empty?
|
column_names.nil? || column_names.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def statement
|
def sort_criteria=(arg)
|
||||||
# project/subprojects clause
|
c = []
|
||||||
|
if arg.is_a?(Hash)
|
||||||
|
arg = arg.keys.sort.collect {|k| arg[k]}
|
||||||
|
end
|
||||||
|
c = arg.select {|k,o| !k.to_s.blank?}.slice(0,3).collect {|k,o| [k.to_s, o == 'desc' ? o : 'asc']}
|
||||||
|
write_attribute(:sort_criteria, c)
|
||||||
|
end
|
||||||
|
|
||||||
|
def sort_criteria
|
||||||
|
read_attribute(:sort_criteria) || []
|
||||||
|
end
|
||||||
|
|
||||||
|
def sort_criteria_key(arg)
|
||||||
|
sort_criteria && sort_criteria[arg] && sort_criteria[arg].first
|
||||||
|
end
|
||||||
|
|
||||||
|
def sort_criteria_order(arg)
|
||||||
|
sort_criteria && sort_criteria[arg] && sort_criteria[arg].last
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the SQL sort order that should be prepended for grouping
|
||||||
|
def group_by_sort_order
|
||||||
|
if grouped? && (column = group_by_column)
|
||||||
|
column.sortable.is_a?(Array) ?
|
||||||
|
column.sortable.collect {|s| "#{s} #{column.default_order}"}.join(',') :
|
||||||
|
"#{column.sortable} #{column.default_order}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns true if the query is a grouped query
|
||||||
|
def grouped?
|
||||||
|
!group_by.blank?
|
||||||
|
end
|
||||||
|
|
||||||
|
def group_by_column
|
||||||
|
groupable_columns.detect {|c| c.name.to_s == group_by}
|
||||||
|
end
|
||||||
|
|
||||||
|
def group_by_statement
|
||||||
|
group_by_column.groupable
|
||||||
|
end
|
||||||
|
|
||||||
|
def project_statement
|
||||||
project_clauses = []
|
project_clauses = []
|
||||||
if project && !@project.active_children.empty?
|
if project && !@project.descendants.active.empty?
|
||||||
ids = [project.id]
|
ids = [project.id]
|
||||||
if has_filter?("subproject_id")
|
if has_filter?("subproject_id")
|
||||||
case operator_for("subproject_id")
|
case operator_for("subproject_id")
|
||||||
@@ -269,98 +386,176 @@ class Query < ActiveRecord::Base
|
|||||||
# main project only
|
# main project only
|
||||||
else
|
else
|
||||||
# all subprojects
|
# all subprojects
|
||||||
ids += project.child_ids
|
ids += project.descendants.collect(&:id)
|
||||||
end
|
end
|
||||||
elsif Setting.display_subprojects_issues?
|
elsif Setting.display_subprojects_issues?
|
||||||
ids += project.child_ids
|
ids += project.descendants.collect(&:id)
|
||||||
end
|
end
|
||||||
project_clauses << "#{Issue.table_name}.project_id IN (%s)" % ids.join(',')
|
project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
|
||||||
elsif project
|
elsif project
|
||||||
project_clauses << "#{Issue.table_name}.project_id = %d" % project.id
|
project_clauses << "#{Project.table_name}.id = %d" % project.id
|
||||||
end
|
end
|
||||||
project_clauses << Project.visible_by(User.current)
|
project_clauses << Project.allowed_to_condition(User.current, :view_issues)
|
||||||
|
project_clauses.join(' AND ')
|
||||||
|
end
|
||||||
|
|
||||||
|
def statement
|
||||||
# filters clauses
|
# filters clauses
|
||||||
filters_clauses = []
|
filters_clauses = []
|
||||||
filters.each_key do |field|
|
filters.each_key do |field|
|
||||||
next if field == "subproject_id"
|
next if field == "subproject_id"
|
||||||
v = values_for(field).clone
|
v = values_for(field).clone
|
||||||
next unless v and !v.empty?
|
next unless v and !v.empty?
|
||||||
|
operator = operator_for(field)
|
||||||
|
|
||||||
|
# "me" value subsitution
|
||||||
|
if %w(assigned_to_id author_id watcher_id).include?(field)
|
||||||
|
v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me")
|
||||||
|
end
|
||||||
|
|
||||||
sql = ''
|
sql = ''
|
||||||
is_custom_filter = false
|
|
||||||
if field =~ /^cf_(\d+)$/
|
if field =~ /^cf_(\d+)$/
|
||||||
# custom field
|
# custom field
|
||||||
db_table = CustomValue.table_name
|
db_table = CustomValue.table_name
|
||||||
db_field = 'value'
|
db_field = 'value'
|
||||||
is_custom_filter = true
|
is_custom_filter = true
|
||||||
sql << "#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} WHERE "
|
sql << "#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} WHERE "
|
||||||
|
sql << sql_for_field(field, operator, v, db_table, db_field, true) + ')'
|
||||||
|
elsif field == 'watcher_id'
|
||||||
|
db_table = Watcher.table_name
|
||||||
|
db_field = 'user_id'
|
||||||
|
sql << "#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='Issue' AND "
|
||||||
|
sql << sql_for_field(field, '=', v, db_table, db_field) + ')'
|
||||||
else
|
else
|
||||||
# regular field
|
# regular field
|
||||||
db_table = Issue.table_name
|
db_table = Issue.table_name
|
||||||
db_field = field
|
db_field = field
|
||||||
sql << '('
|
sql << '(' + sql_for_field(field, operator, v, db_table, db_field) + ')'
|
||||||
end
|
end
|
||||||
|
|
||||||
# "me" value subsitution
|
|
||||||
if %w(assigned_to_id author_id).include?(field)
|
|
||||||
v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me")
|
|
||||||
end
|
|
||||||
|
|
||||||
case operator_for field
|
|
||||||
when "="
|
|
||||||
sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
|
|
||||||
when "!"
|
|
||||||
sql = sql + "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
|
|
||||||
when "!*"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} IS NULL"
|
|
||||||
sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter
|
|
||||||
when "*"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} IS NOT NULL"
|
|
||||||
sql << " AND #{db_table}.#{db_field} <> ''" if is_custom_filter
|
|
||||||
when ">="
|
|
||||||
sql = sql + "#{db_table}.#{db_field} >= #{v.first.to_i}"
|
|
||||||
when "<="
|
|
||||||
sql = sql + "#{db_table}.#{db_field} <= #{v.first.to_i}"
|
|
||||||
when "o"
|
|
||||||
sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
|
|
||||||
when "c"
|
|
||||||
sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
|
|
||||||
when ">t-"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today + 1).to_time)]
|
|
||||||
when "<t-"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} <= '%s'" % connection.quoted_date((Date.today - v.first.to_i).to_time)
|
|
||||||
when "t-"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today - v.first.to_i + 1).to_time)]
|
|
||||||
when ">t+"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} >= '%s'" % connection.quoted_date((Date.today + v.first.to_i).to_time)
|
|
||||||
when "<t+"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)]
|
|
||||||
when "t+"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today + v.first.to_i).to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)]
|
|
||||||
when "t"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today+1).to_time)]
|
|
||||||
when "w"
|
|
||||||
from = l(:general_first_day_of_week) == '7' ?
|
|
||||||
# week starts on sunday
|
|
||||||
((Date.today.cwday == 7) ? Time.now.at_beginning_of_day : Time.now.at_beginning_of_week - 1.day) :
|
|
||||||
# week starts on monday (Rails default)
|
|
||||||
Time.now.at_beginning_of_week
|
|
||||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
|
|
||||||
when "~"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'"
|
|
||||||
when "!~"
|
|
||||||
sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
|
|
||||||
end
|
|
||||||
sql << ')'
|
|
||||||
filters_clauses << sql
|
filters_clauses << sql
|
||||||
|
|
||||||
end if filters and valid?
|
end if filters and valid?
|
||||||
|
|
||||||
(project_clauses + filters_clauses).join(' AND ')
|
(filters_clauses << project_statement).join(' AND ')
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the issue count
|
||||||
|
def issue_count
|
||||||
|
Issue.count(:include => [:status, :project], :conditions => statement)
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
|
raise StatementInvalid.new(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the issue count by group or nil if query is not grouped
|
||||||
|
def issue_count_by_group
|
||||||
|
r = nil
|
||||||
|
if grouped?
|
||||||
|
begin
|
||||||
|
# Rails will raise an (unexpected) RecordNotFound if there's only a nil group value
|
||||||
|
r = Issue.count(:group => group_by_statement, :include => [:status, :project], :conditions => statement)
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
r = {nil => issue_count}
|
||||||
|
end
|
||||||
|
c = group_by_column
|
||||||
|
if c.is_a?(QueryCustomFieldColumn)
|
||||||
|
r = r.keys.inject({}) {|h, k| h[c.custom_field.cast_value(k)] = r[k]; h}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
r
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
|
raise StatementInvalid.new(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the issues
|
||||||
|
# Valid options are :order, :offset, :limit, :include, :conditions
|
||||||
|
def issues(options={})
|
||||||
|
order_option = [group_by_sort_order, options[:order]].reject {|s| s.blank?}.join(',')
|
||||||
|
order_option = nil if order_option.blank?
|
||||||
|
|
||||||
|
Issue.find :all, :include => ([:status, :project] + (options[:include] || [])).uniq,
|
||||||
|
:conditions => Query.merge_conditions(statement, options[:conditions]),
|
||||||
|
:order => order_option,
|
||||||
|
:limit => options[:limit],
|
||||||
|
:offset => options[:offset]
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
|
raise StatementInvalid.new(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the journals
|
||||||
|
# Valid options are :order, :offset, :limit
|
||||||
|
def journals(options={})
|
||||||
|
Journal.find :all, :include => [:details, :user, {:issue => [:project, :author, :tracker, :status]}],
|
||||||
|
:conditions => statement,
|
||||||
|
:order => options[:order],
|
||||||
|
:limit => options[:limit],
|
||||||
|
:offset => options[:offset]
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
|
raise StatementInvalid.new(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the versions
|
||||||
|
# Valid options are :conditions
|
||||||
|
def versions(options={})
|
||||||
|
Version.find :all, :include => :project,
|
||||||
|
:conditions => Query.merge_conditions(project_statement, options[:conditions])
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
|
raise StatementInvalid.new(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Helper method to generate the WHERE sql for a +field+, +operator+ and a +value+
|
||||||
|
def sql_for_field(field, operator, value, db_table, db_field, is_custom_filter=false)
|
||||||
|
sql = ''
|
||||||
|
case operator
|
||||||
|
when "="
|
||||||
|
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
|
||||||
|
when "!"
|
||||||
|
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
|
||||||
|
when "!*"
|
||||||
|
sql = "#{db_table}.#{db_field} IS NULL"
|
||||||
|
sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter
|
||||||
|
when "*"
|
||||||
|
sql = "#{db_table}.#{db_field} IS NOT NULL"
|
||||||
|
sql << " AND #{db_table}.#{db_field} <> ''" if is_custom_filter
|
||||||
|
when ">="
|
||||||
|
sql = "#{db_table}.#{db_field} >= #{value.first.to_i}"
|
||||||
|
when "<="
|
||||||
|
sql = "#{db_table}.#{db_field} <= #{value.first.to_i}"
|
||||||
|
when "o"
|
||||||
|
sql = "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
|
||||||
|
when "c"
|
||||||
|
sql = "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
|
||||||
|
when ">t-"
|
||||||
|
sql = date_range_clause(db_table, db_field, - value.first.to_i, 0)
|
||||||
|
when "<t-"
|
||||||
|
sql = date_range_clause(db_table, db_field, nil, - value.first.to_i)
|
||||||
|
when "t-"
|
||||||
|
sql = date_range_clause(db_table, db_field, - value.first.to_i, - value.first.to_i)
|
||||||
|
when ">t+"
|
||||||
|
sql = date_range_clause(db_table, db_field, value.first.to_i, nil)
|
||||||
|
when "<t+"
|
||||||
|
sql = date_range_clause(db_table, db_field, 0, value.first.to_i)
|
||||||
|
when "t+"
|
||||||
|
sql = date_range_clause(db_table, db_field, value.first.to_i, value.first.to_i)
|
||||||
|
when "t"
|
||||||
|
sql = date_range_clause(db_table, db_field, 0, 0)
|
||||||
|
when "w"
|
||||||
|
from = l(:general_first_day_of_week) == '7' ?
|
||||||
|
# week starts on sunday
|
||||||
|
((Date.today.cwday == 7) ? Time.now.at_beginning_of_day : Time.now.at_beginning_of_week - 1.day) :
|
||||||
|
# week starts on monday (Rails default)
|
||||||
|
Time.now.at_beginning_of_week
|
||||||
|
sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
|
||||||
|
when "~"
|
||||||
|
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
|
||||||
|
when "!~"
|
||||||
|
sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
|
||||||
|
end
|
||||||
|
|
||||||
|
return sql
|
||||||
|
end
|
||||||
|
|
||||||
def add_custom_fields_filters(custom_fields)
|
def add_custom_fields_filters(custom_fields)
|
||||||
@available_filters ||= {}
|
@available_filters ||= {}
|
||||||
|
|
||||||
@@ -380,4 +575,16 @@ class Query < ActiveRecord::Base
|
|||||||
@available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
|
@available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a SQL clause for a date or datetime field.
|
||||||
|
def date_range_clause(table, field, from, to)
|
||||||
|
s = []
|
||||||
|
if from
|
||||||
|
s << ("#{table}.#{field} > '%s'" % [connection.quoted_date((Date.yesterday + from).to_time.end_of_day)])
|
||||||
|
end
|
||||||
|
if to
|
||||||
|
s << ("#{table}.#{field} <= '%s'" % [connection.quoted_date((Date.today + to).to_time.end_of_day)])
|
||||||
|
end
|
||||||
|
s.join(' AND ')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+90
-14
@@ -25,7 +25,7 @@ class Repository < ActiveRecord::Base
|
|||||||
before_destroy :clear_changesets
|
before_destroy :clear_changesets
|
||||||
|
|
||||||
# Checks if the SCM is enabled when creating a repository
|
# Checks if the SCM is enabled when creating a repository
|
||||||
validate_on_create { |r| r.errors.add(:type, :activerecord_error_invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) }
|
validate_on_create { |r| r.errors.add(:type, :invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) }
|
||||||
|
|
||||||
# Removes leading and trailing whitespace
|
# Removes leading and trailing whitespace
|
||||||
def url=(arg)
|
def url=(arg)
|
||||||
@@ -62,6 +62,18 @@ class Repository < ActiveRecord::Base
|
|||||||
def entries(path=nil, identifier=nil)
|
def entries(path=nil, identifier=nil)
|
||||||
scm.entries(path, identifier)
|
scm.entries(path, identifier)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def branches
|
||||||
|
scm.branches
|
||||||
|
end
|
||||||
|
|
||||||
|
def tags
|
||||||
|
scm.tags
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_branch
|
||||||
|
scm.default_branch
|
||||||
|
end
|
||||||
|
|
||||||
def properties(path, identifier=nil)
|
def properties(path, identifier=nil)
|
||||||
scm.properties(path, identifier)
|
scm.properties(path, identifier)
|
||||||
@@ -75,32 +87,94 @@ class Repository < ActiveRecord::Base
|
|||||||
scm.diff(path, rev, rev_to)
|
scm.diff(path, rev, rev_to)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Default behaviour: we search in cached changesets
|
|
||||||
def changesets_for_path(path)
|
|
||||||
path = "/#{path}" unless path.starts_with?('/')
|
|
||||||
Change.find(:all, :include => :changeset,
|
|
||||||
:conditions => ["repository_id = ? AND path = ?", id, path],
|
|
||||||
:order => "committed_on DESC, #{Changeset.table_name}.id DESC").collect(&:changeset)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a path relative to the url of the repository
|
# Returns a path relative to the url of the repository
|
||||||
def relative_path(path)
|
def relative_path(path)
|
||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Finds and returns a revision with a number or the beginning of a hash
|
||||||
|
def find_changeset_by_name(name)
|
||||||
|
changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
|
||||||
|
end
|
||||||
|
|
||||||
def latest_changeset
|
def latest_changeset
|
||||||
@latest_changeset ||= changesets.find(:first)
|
@latest_changeset ||= changesets.find(:first)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the latest changesets for +path+
|
||||||
|
# Default behaviour is to search in cached changesets
|
||||||
|
def latest_changesets(path, rev, limit=10)
|
||||||
|
if path.blank?
|
||||||
|
changesets.find(:all, :include => :user,
|
||||||
|
:order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
|
||||||
|
:limit => limit)
|
||||||
|
else
|
||||||
|
changes.find(:all, :include => {:changeset => :user},
|
||||||
|
:conditions => ["path = ?", path.with_leading_slash],
|
||||||
|
:order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
|
||||||
|
:limit => limit).collect(&:changeset)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def scan_changesets_for_issue_ids
|
def scan_changesets_for_issue_ids
|
||||||
self.changesets.each(&:scan_comment_for_issue_ids)
|
self.changesets.each(&:scan_comment_for_issue_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns an array of committers usernames and associated user_id
|
||||||
|
def committers
|
||||||
|
@committers ||= Changeset.connection.select_rows("SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}")
|
||||||
|
end
|
||||||
|
|
||||||
# fetch new changesets for all repositories
|
# Maps committers username to a user ids
|
||||||
# can be called periodically by an external script
|
def committer_ids=(h)
|
||||||
|
if h.is_a?(Hash)
|
||||||
|
committers.each do |committer, user_id|
|
||||||
|
new_user_id = h[committer]
|
||||||
|
if new_user_id && (new_user_id.to_i != user_id.to_i)
|
||||||
|
new_user_id = (new_user_id.to_i > 0 ? new_user_id.to_i : nil)
|
||||||
|
Changeset.update_all("user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }", ["repository_id = ? AND committer = ?", id, committer])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@committers = nil
|
||||||
|
@found_committer_users = nil
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the Redmine User corresponding to the given +committer+
|
||||||
|
# It will return nil if the committer is not yet mapped and if no User
|
||||||
|
# with the same username or email was found
|
||||||
|
def find_committer_user(committer)
|
||||||
|
unless committer.blank?
|
||||||
|
@found_committer_users ||= {}
|
||||||
|
return @found_committer_users[committer] if @found_committer_users.has_key?(committer)
|
||||||
|
|
||||||
|
user = nil
|
||||||
|
c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
|
||||||
|
if c && c.user
|
||||||
|
user = c.user
|
||||||
|
elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/
|
||||||
|
username, email = $1.strip, $3
|
||||||
|
u = User.find_by_login(username)
|
||||||
|
u ||= User.find_by_mail(email) unless email.blank?
|
||||||
|
user = u
|
||||||
|
end
|
||||||
|
@found_committer_users[committer] = user
|
||||||
|
user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Fetches new changesets for all repositories of active projects
|
||||||
|
# Can be called periodically by an external script
|
||||||
# eg. ruby script/runner "Repository.fetch_changesets"
|
# eg. ruby script/runner "Repository.fetch_changesets"
|
||||||
def self.fetch_changesets
|
def self.fetch_changesets
|
||||||
find(:all).each(&:fetch_changesets)
|
Project.active.has_module(:repository).find(:all, :include => :repository).each do |project|
|
||||||
|
if project.repository
|
||||||
|
project.repository.fetch_changesets
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# scan changeset comments to find related and fixed issues for all repositories
|
# scan changeset comments to find related and fixed issues for all repositories
|
||||||
@@ -133,7 +207,9 @@ class Repository < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def clear_changesets
|
def clear_changesets
|
||||||
connection.delete("DELETE FROM changes WHERE changes.changeset_id IN (SELECT changesets.id FROM changesets WHERE changesets.repository_id = #{id})")
|
cs, ch, ci = Changeset.table_name, Change.table_name, "#{table_name_prefix}changesets_issues#{table_name_suffix}"
|
||||||
connection.delete("DELETE FROM changesets WHERE changesets.repository_id = #{id}")
|
connection.delete("DELETE FROM #{ch} WHERE #{ch}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
|
||||||
|
connection.delete("DELETE FROM #{ci} WHERE #{ci}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
|
||||||
|
connection.delete("DELETE FROM #{cs} WHERE #{cs}.repository_id = #{id}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class Repository::Cvs < Repository
|
|||||||
cs = changesets.find(:first, :conditions=>{
|
cs = changesets.find(:first, :conditions=>{
|
||||||
:committed_on=>revision.time-time_delta..revision.time+time_delta,
|
:committed_on=>revision.time-time_delta..revision.time+time_delta,
|
||||||
:committer=>revision.author,
|
:committer=>revision.author,
|
||||||
:comments=>revision.message
|
:comments=>Changeset.normalize_comments(revision.message)
|
||||||
})
|
})
|
||||||
|
|
||||||
# create a new changeset....
|
# create a new changeset....
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user