Files
@ ffd45b185016
Branch filter:
Location: kallithea/rhodecode/model/repo.py - annotation
ffd45b185016
29.6 KiB
text/x-python
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3§14 and other relevant sections of GPLv3.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3§14 and other relevant sections of GPLv3.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 | 2889a4446960 a671db5bdd58 a671db5bdd58 a671db5bdd58 a671db5bdd58 6832ef664673 7e536d1af60d 7e536d1af60d 7e536d1af60d 7e536d1af60d 6832ef664673 7e536d1af60d a671db5bdd58 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 a3efdd61a21f 2889a4446960 2889a4446960 2889a4446960 2889a4446960 7e536d1af60d ffd45b185016 2889a4446960 324ac367a4da a21eab6ff42f ffd45b185016 55dbc440878b f522f4d3bf93 1b275d04ac07 b7563ad4e7ee 2889a4446960 ffd45b185016 ffd45b185016 ffd45b185016 72a91632b731 ffd45b185016 a21eab6ff42f 32f66c839c54 b44979649915 32f66c839c54 87f0800abc7b 7e536d1af60d 7e536d1af60d aa7e45ad0cea 89b9037d68b7 7e536d1af60d 17893d61792a 9d4b80743a2a 17893d61792a 7e3d89d9d3a2 fa6ba6727475 fa6ba6727475 87f0800abc7b ffd45b185016 ffd45b185016 87f0800abc7b 87f0800abc7b 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 a8f520540ab0 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 405b80e4ccd5 405b80e4ccd5 7d1fc253549e a5888ca796b5 405b80e4ccd5 ade3414a8b61 405b80e4ccd5 405b80e4ccd5 d2a840b29858 7e536d1af60d ffd45b185016 dbec976d9975 7e536d1af60d 7e536d1af60d 7e536d1af60d dbec976d9975 7e536d1af60d 7e536d1af60d 14dffcfebb02 d3ac7491a5c8 14dffcfebb02 dbec976d9975 ffd45b185016 dbec976d9975 dbec976d9975 dbec976d9975 dbec976d9975 dbec976d9975 89b9037d68b7 dbec976d9975 28571535dd61 28571535dd61 a5888ca796b5 28571535dd61 28571535dd61 28571535dd61 28571535dd61 28571535dd61 28571535dd61 28571535dd61 28571535dd61 28571535dd61 28571535dd61 28571535dd61 28571535dd61 7e536d1af60d 7e536d1af60d a21eab6ff42f a21eab6ff42f ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 a21eab6ff42f a21eab6ff42f 7e536d1af60d ffd45b185016 ffd45b185016 fa6ba6727475 ffd45b185016 ffd45b185016 ffd45b185016 a21eab6ff42f a21eab6ff42f ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 a21eab6ff42f d2a840b29858 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 b3cf4539d1bd b3cf4539d1bd b3cf4539d1bd b3cf4539d1bd b3cf4539d1bd a6bef3e8a361 b3cf4539d1bd 8f3cc21d83e6 8f3cc21d83e6 0226b6d6b2b5 ff57547c9cf7 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 ffd45b185016 ffd45b185016 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 ffd45b185016 ffd45b185016 ffd45b185016 0226b6d6b2b5 8f3cc21d83e6 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 ffd45b185016 ffd45b185016 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 ffd45b185016 0226b6d6b2b5 0226b6d6b2b5 ffd45b185016 0226b6d6b2b5 0226b6d6b2b5 ffd45b185016 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 0226b6d6b2b5 9dae92a65e40 9dae92a65e40 a5888ca796b5 9dae92a65e40 cf51bbfb120e 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 8087731920d8 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 4cc9bb83ecb4 ffd45b185016 ffd45b185016 ffd45b185016 4cc9bb83ecb4 4cc9bb83ecb4 4cc9bb83ecb4 4cc9bb83ecb4 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 4cc9bb83ecb4 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 ffd45b185016 9dae92a65e40 9dae92a65e40 9dae92a65e40 9dae92a65e40 ffd45b185016 9dae92a65e40 9dae92a65e40 9dae92a65e40 ffd45b185016 7e536d1af60d ffd45b185016 ffd45b185016 4cc9bb83ecb4 4cc9bb83ecb4 4cc9bb83ecb4 4cc9bb83ecb4 4cc9bb83ecb4 ffd45b185016 c32322126fe4 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 4cc9bb83ecb4 4cc9bb83ecb4 4cc9bb83ecb4 4cc9bb83ecb4 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 4cc9bb83ecb4 7e536d1af60d 4cc9bb83ecb4 bd604cf75c5a 802c94bdfc85 bd604cf75c5a 802c94bdfc85 802c94bdfc85 802c94bdfc85 802c94bdfc85 802c94bdfc85 ffd45b185016 ffd45b185016 ffd45b185016 72a91632b731 72a91632b731 72a91632b731 72a91632b731 72a91632b731 7e536d1af60d 7e536d1af60d 4cc9bb83ecb4 a7a772ea7b95 ffd45b185016 7e536d1af60d bd604cf75c5a 10b4e34841a4 7e536d1af60d 7e536d1af60d 7e536d1af60d ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 532ee86cf9b1 ffd45b185016 ffd45b185016 532ee86cf9b1 532ee86cf9b1 e7eef7a1db6a 9c0f5d558789 9d4b80743a2a 9d4b80743a2a ffd45b185016 7e536d1af60d ffd45b185016 ffd45b185016 e7eef7a1db6a e7eef7a1db6a e7eef7a1db6a 40b3a54391f9 9d4b80743a2a 87ca17540603 7e536d1af60d ffd45b185016 f726a939d2d4 9d4b80743a2a 9d4b80743a2a 9d4b80743a2a ffd45b185016 9d4b80743a2a 9d4b80743a2a 9d4b80743a2a 9d4b80743a2a e7eef7a1db6a 6104dfd35b16 6104dfd35b16 6104dfd35b16 6104dfd35b16 ffd45b185016 ffd45b185016 839ee7a774ab 9d4b80743a2a 9d4b80743a2a 7e536d1af60d 7e536d1af60d 7e536d1af60d 7e536d1af60d ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 7e536d1af60d ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 7e536d1af60d ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 da8ee2ef7f6d 7e3d89d9d3a2 7e3d89d9d3a2 f42ee60e673b e7eef7a1db6a 2889a4446960 9d4b80743a2a ffd45b185016 ffd45b185016 ffd45b185016 bd604cf75c5a 10b4e34841a4 7e536d1af60d 7e536d1af60d 7e536d1af60d ffd45b185016 532ee86cf9b1 ffd45b185016 532ee86cf9b1 532ee86cf9b1 532ee86cf9b1 532ee86cf9b1 ffd45b185016 ffd45b185016 9d4b80743a2a ff57547c9cf7 ff57547c9cf7 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 32f66c839c54 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 32f66c839c54 32f66c839c54 ffd45b185016 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 7e3d89d9d3a2 32f66c839c54 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 32f66c839c54 32f66c839c54 7e3d89d9d3a2 7e536d1af60d e7eef7a1db6a e7eef7a1db6a cf51bbfb120e e7eef7a1db6a e7eef7a1db6a e7eef7a1db6a 7e536d1af60d ffd45b185016 7e536d1af60d 55dbc440878b b44979649915 b44979649915 b44979649915 b44979649915 b44979649915 b44979649915 b44979649915 34093903b505 b44979649915 55dbc440878b 727d2a45ec10 d3ac7491a5c8 9d4b80743a2a b44979649915 b44979649915 b44979649915 b44979649915 b44979649915 b44979649915 b44979649915 b44979649915 b44979649915 b44979649915 1b275d04ac07 1b275d04ac07 9d4b80743a2a 9d4b80743a2a 34093903b505 ffd45b185016 34093903b505 34093903b505 1b275d04ac07 55dbc440878b 10b4e34841a4 9d4b80743a2a 9d4b80743a2a 7e536d1af60d 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b d3ac7491a5c8 d3ac7491a5c8 d3ac7491a5c8 87f0800abc7b 87f0800abc7b ffd45b185016 ffd45b185016 ffd45b185016 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b c0cc8f8a71b0 ffd45b185016 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b a21eab6ff42f d3ac7491a5c8 d3ac7491a5c8 87f0800abc7b ffd45b185016 ffd45b185016 ffd45b185016 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 7e536d1af60d ffd45b185016 87f0800abc7b b8f929bff7e3 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b b8f929bff7e3 87f0800abc7b 87f0800abc7b d3ac7491a5c8 7e3d89d9d3a2 d3ac7491a5c8 87f0800abc7b 87f0800abc7b ffd45b185016 ffd45b185016 ffd45b185016 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b fa6ba6727475 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b 87f0800abc7b c0cc8f8a71b0 ffd45b185016 87f0800abc7b ffd45b185016 87f0800abc7b b8f929bff7e3 87f0800abc7b 87f0800abc7b 87f0800abc7b b8f929bff7e3 87f0800abc7b d3ac7491a5c8 7e3d89d9d3a2 87f0800abc7b ffd45b185016 ffd45b185016 ffd45b185016 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 65129c332d37 b9bbc0d6e9f3 e7eef7a1db6a e7eef7a1db6a cf51bbfb120e e7eef7a1db6a e7eef7a1db6a 059efaea23d6 b9bbc0d6e9f3 ffd45b185016 ffd45b185016 059efaea23d6 059efaea23d6 10b4e34841a4 b9bbc0d6e9f3 b9bbc0d6e9f3 b9bbc0d6e9f3 ffd45b185016 ffd45b185016 4502ceec31be 87ca17540603 87ca17540603 87ca17540603 6832ef664673 4502ceec31be 4502ceec31be ffd45b185016 eb489bf9d7c7 ffd45b185016 4502ceec31be ffd45b185016 e1370dcb9908 142a05597cba ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 eb489bf9d7c7 ffd45b185016 ffd45b185016 dc4644865e8b dc4644865e8b dc4644865e8b dc4644865e8b ffd45b185016 dc4644865e8b eb489bf9d7c7 6f468ba37650 6f468ba37650 6f468ba37650 b7563ad4e7ee 6f468ba37650 ffd45b185016 6f468ba37650 9dae92a65e40 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 dc4644865e8b a3efdd61a21f dc4644865e8b 75280665ad1e ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 dc4644865e8b 7e536d1af60d ffd45b185016 4502ceec31be 4502ceec31be 6832ef664673 4502ceec31be 4502ceec31be 4502ceec31be a76e9bacbedc 7e536d1af60d 405b80e4ccd5 405b80e4ccd5 7e536d1af60d 87f0800abc7b 87f0800abc7b 87f0800abc7b 7e536d1af60d 7e536d1af60d ffd45b185016 4502ceec31be 4502ceec31be 4502ceec31be 4502ceec31be 4502ceec31be 6832ef664673 4502ceec31be 4502ceec31be 405b80e4ccd5 ffd45b185016 69b836e383df dff6d5cb8bba 69b836e383df 69b836e383df 69b836e383df ffd45b185016 69b836e383df ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 069e13b4dddc f6800c5e5b2d 069e13b4dddc d37b79ad0ae8 d37b79ad0ae8 d37b79ad0ae8 d37b79ad0ae8 ffd45b185016 ffd45b185016 ffd45b185016 | # -*- coding: utf-8 -*-
# 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 3 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, see <http://www.gnu.org/licenses/>.
"""
rhodecode.model.repo
~~~~~~~~~~~~~~~~~~~~
Repository model for rhodecode
:created_on: Jun 5, 2010
:author: marcink
:copyright: (c) 2013 RhodeCode GmbH.
:license: GPLv3, see LICENSE for more details.
"""
from __future__ import with_statement
import os
import shutil
import logging
import traceback
from datetime import datetime
from rhodecode.lib.utils import make_ui
from rhodecode.lib.vcs.backends import get_backend
from rhodecode.lib.compat import json
from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode, \
remove_prefix, obfuscate_url_pw, get_current_rhodecode_user
from rhodecode.lib.caching_query import FromCache
from rhodecode.lib.hooks import log_create_repository, log_delete_repository
from rhodecode.model import BaseModel
from rhodecode.model.db import Repository, UserRepoToPerm, UserGroupRepoToPerm, \
UserRepoGroupToPerm, UserGroupRepoGroupToPerm, User, Permission, \
Statistics, UserGroup, RhodeCodeUi, RepoGroup, \
RhodeCodeSetting, RepositoryField
from rhodecode.lib import helpers as h
from rhodecode.lib.auth import HasRepoPermissionAny, HasUserGroupPermissionAny
from rhodecode.lib.exceptions import AttachedForksError
from rhodecode.model.scm import UserGroupList
log = logging.getLogger(__name__)
class RepoModel(BaseModel):
cls = Repository
URL_SEPARATOR = Repository.url_sep()
def _get_user_group(self, users_group):
return self._get_instance(UserGroup, users_group,
callback=UserGroup.get_by_group_name)
def _get_repo_group(self, repo_group):
return self._get_instance(RepoGroup, repo_group,
callback=RepoGroup.get_by_group_name)
def _create_default_perms(self, repository, private):
# create default permission
default = 'repository.read'
def_user = User.get_default_user()
for p in def_user.user_perms:
if p.permission.permission_name.startswith('repository.'):
default = p.permission.permission_name
break
default_perm = 'repository.none' if private else default
repo_to_perm = UserRepoToPerm()
repo_to_perm.permission = Permission.get_by_key(default_perm)
repo_to_perm.repository = repository
repo_to_perm.user_id = def_user.user_id
return repo_to_perm
@LazyProperty
def repos_path(self):
"""
Gets the repositories root path from database
"""
q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
return q.ui_value
def get(self, repo_id, cache=False):
repo = self.sa.query(Repository) \
.filter(Repository.repo_id == repo_id)
if cache:
repo = repo.options(FromCache("sql_cache_short",
"get_repo_%s" % repo_id))
return repo.scalar()
def get_repo(self, repository):
return self._get_repo(repository)
def get_by_repo_name(self, repo_name, cache=False):
repo = self.sa.query(Repository) \
.filter(Repository.repo_name == repo_name)
if cache:
repo = repo.options(FromCache("sql_cache_short",
"get_repo_%s" % repo_name))
return repo.scalar()
def get_all_user_repos(self, user):
"""
Gets all repositories that user have at least read access
:param user:
"""
from rhodecode.lib.auth import AuthUser
user = self._get_user(user)
repos = AuthUser(user_id=user.user_id).permissions['repositories']
access_check = lambda r: r[1] in ['repository.read',
'repository.write',
'repository.admin']
repos = [x[0] for x in filter(access_check, repos.items())]
return Repository.query().filter(Repository.repo_name.in_(repos))
def get_users_js(self):
users = self.sa.query(User).filter(User.active == True).all()
return json.dumps([
{
'id': u.user_id,
'fname': u.name,
'lname': u.lastname,
'nname': u.username,
'gravatar_lnk': h.gravatar_url(u.email, 14)
} for u in users]
)
def get_user_groups_js(self):
user_groups = self.sa.query(UserGroup) \
.filter(UserGroup.users_group_active == True).all()
user_groups = UserGroupList(user_groups, perm_set=['usergroup.read',
'usergroup.write',
'usergroup.admin'])
return json.dumps([
{
'id': gr.users_group_id,
'grname': gr.users_group_name,
'grmembers': len(gr.members),
} for gr in user_groups]
)
@classmethod
def _render_datatable(cls, tmpl, *args, **kwargs):
import rhodecode
from pylons import tmpl_context as c
from pylons.i18n.translation import _
_tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup
template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
tmpl = template.get_def(tmpl)
kwargs.update(dict(_=_, h=h, c=c))
return tmpl.render(*args, **kwargs)
@classmethod
def update_repoinfo(cls, repositories=None):
if not repositories:
repositories = Repository.getAll()
for repo in repositories:
repo.update_changeset_cache()
def get_repos_as_dict(self, repos_list=None, admin=False, perm_check=True,
super_user_actions=False):
_render = self._render_datatable
from pylons import tmpl_context as c
def quick_menu(repo_name):
return _render('quick_menu', repo_name)
def repo_lnk(name, rtype, rstate, private, fork_of):
return _render('repo_name', name, rtype, rstate, private, fork_of,
short_name=not admin, admin=False)
def last_change(last_change):
return _render("last_change", last_change)
def rss_lnk(repo_name):
return _render("rss", repo_name)
def atom_lnk(repo_name):
return _render("atom", repo_name)
def last_rev(repo_name, cs_cache):
return _render('revision', repo_name, cs_cache.get('revision'),
cs_cache.get('raw_id'), cs_cache.get('author'),
cs_cache.get('message'))
def desc(desc):
if c.visual.stylify_metatags:
return h.urlify_text(h.desc_stylize(h.truncate(desc, 60)))
else:
return h.urlify_text(h.truncate(desc, 60))
def state(repo_state):
return _render("repo_state", repo_state)
def repo_actions(repo_name):
return _render('repo_actions', repo_name, super_user_actions)
def owner_actions(user_id, username):
return _render('user_name', user_id, username)
repos_data = []
for repo in repos_list:
if perm_check:
# check permission at this level
if not HasRepoPermissionAny(
'repository.read', 'repository.write',
'repository.admin'
)(repo.repo_name, 'get_repos_as_dict check'):
continue
cs_cache = repo.changeset_cache
row = {
"menu": quick_menu(repo.repo_name),
"raw_name": repo.repo_name.lower(),
"name": repo_lnk(repo.repo_name, repo.repo_type,
repo.repo_state, repo.private, repo.fork),
"last_change": last_change(repo.last_db_change),
"last_changeset": last_rev(repo.repo_name, cs_cache),
"last_rev_raw": cs_cache.get('revision'),
"desc": desc(repo.description),
"owner": h.person(repo.user.username),
"state": state(repo.repo_state),
"rss": rss_lnk(repo.repo_name),
"atom": atom_lnk(repo.repo_name),
}
if admin:
row.update({
"action": repo_actions(repo.repo_name),
"owner": owner_actions(repo.user.user_id,
h.person(repo.user.username))
})
repos_data.append(row)
return {
"totalRecords": len(repos_list),
"startIndex": 0,
"sort": "name",
"dir": "asc",
"records": repos_data
}
def _get_defaults(self, repo_name):
"""
Gets information about repository, and returns a dict for
usage in forms
:param repo_name:
"""
repo_info = Repository.get_by_repo_name(repo_name)
if repo_info is None:
return None
defaults = repo_info.get_dict()
group, repo_name, repo_name_full = repo_info.groups_and_repo
defaults['repo_name'] = repo_name
defaults['repo_group'] = getattr(group[-1] if group else None,
'group_id', None)
for strip, k in [(0, 'repo_type'), (1, 'repo_enable_downloads'),
(1, 'repo_description'), (1, 'repo_enable_locking'),
(1, 'repo_landing_rev'), (0, 'clone_uri'),
(1, 'repo_private'), (1, 'repo_enable_statistics')]:
attr = k
if strip:
attr = remove_prefix(k, 'repo_')
val = defaults[attr]
if k == 'repo_landing_rev':
val = ':'.join(defaults[attr])
defaults[k] = val
if k == 'clone_uri':
defaults['clone_uri_hidden'] = repo_info.clone_uri_hidden
# fill owner
if repo_info.user:
defaults.update({'user': repo_info.user.username})
else:
replacement_user = User.query().filter(User.admin ==
True).first().username
defaults.update({'user': replacement_user})
# fill repository users
for p in repo_info.repo_to_perm:
defaults.update({'u_perm_%s' % p.user.username:
p.permission.permission_name})
# fill repository groups
for p in repo_info.users_group_to_perm:
defaults.update({'g_perm_%s' % p.users_group.users_group_name:
p.permission.permission_name})
return defaults
def update(self, repo, **kwargs):
try:
cur_repo = self._get_repo(repo)
org_repo_name = cur_repo.repo_name
if 'user' in kwargs:
cur_repo.user = User.get_by_username(kwargs['user'])
if 'repo_group' in kwargs:
cur_repo.group = RepoGroup.get(kwargs['repo_group'])
log.debug('Updating repo %s with params:%s' % (cur_repo, kwargs))
for strip, k in [(1, 'repo_enable_downloads'),
(1, 'repo_description'),
(1, 'repo_enable_locking'),
(1, 'repo_landing_rev'),
(1, 'repo_private'),
(1, 'repo_enable_statistics'),
(0, 'clone_uri'),]:
if k in kwargs:
val = kwargs[k]
if strip:
k = remove_prefix(k, 'repo_')
if k == 'clone_uri':
from rhodecode.model.validators import Missing
_change = kwargs.get('clone_uri_change')
if _change == Missing:
# we don't change the value, so use original one
val = cur_repo.clone_uri
setattr(cur_repo, k, val)
new_name = cur_repo.get_new_name(kwargs['repo_name'])
cur_repo.repo_name = new_name
#if private flag is set, reset default permission to NONE
if kwargs.get('repo_private'):
EMPTY_PERM = 'repository.none'
RepoModel().grant_user_permission(
repo=cur_repo, user='default', perm=EMPTY_PERM
)
#handle extra fields
for field in filter(lambda k: k.startswith(RepositoryField.PREFIX),
kwargs):
k = RepositoryField.un_prefix_key(field)
ex_field = RepositoryField.get_by_key_name(key=k, repo=cur_repo)
if ex_field:
ex_field.field_value = kwargs[field]
self.sa.add(ex_field)
self.sa.add(cur_repo)
if org_repo_name != new_name:
# rename repository
self._rename_filesystem_repo(old=org_repo_name, new=new_name)
return cur_repo
except Exception:
log.error(traceback.format_exc())
raise
def _create_repo(self, repo_name, repo_type, description, owner,
private=False, clone_uri=None, repo_group=None,
landing_rev='rev:tip', fork_of=None,
copy_fork_permissions=False, enable_statistics=False,
enable_locking=False, enable_downloads=False,
copy_group_permissions=False, state=Repository.STATE_PENDING):
"""
Create repository inside database with PENDING state, this should be
only executed by create() repo. With exception of importing existing repos
"""
from rhodecode.model.scm import ScmModel
owner = self._get_user(owner)
fork_of = self._get_repo(fork_of)
repo_group = self._get_repo_group(repo_group)
try:
repo_name = safe_unicode(repo_name)
description = safe_unicode(description)
# repo name is just a name of repository
# while repo_name_full is a full qualified name that is combined
# with name and path of group
repo_name_full = repo_name
repo_name = repo_name.split(self.URL_SEPARATOR)[-1]
new_repo = Repository()
new_repo.repo_state = state
new_repo.enable_statistics = False
new_repo.repo_name = repo_name_full
new_repo.repo_type = repo_type
new_repo.user = owner
new_repo.group = repo_group
new_repo.description = description or repo_name
new_repo.private = private
new_repo.clone_uri = clone_uri
new_repo.landing_rev = landing_rev
new_repo.enable_statistics = enable_statistics
new_repo.enable_locking = enable_locking
new_repo.enable_downloads = enable_downloads
if repo_group:
new_repo.enable_locking = repo_group.enable_locking
if fork_of:
parent_repo = fork_of
new_repo.fork = parent_repo
self.sa.add(new_repo)
if fork_of and copy_fork_permissions:
repo = fork_of
user_perms = UserRepoToPerm.query() \
.filter(UserRepoToPerm.repository == repo).all()
group_perms = UserGroupRepoToPerm.query() \
.filter(UserGroupRepoToPerm.repository == repo).all()
for perm in user_perms:
UserRepoToPerm.create(perm.user, new_repo, perm.permission)
for perm in group_perms:
UserGroupRepoToPerm.create(perm.users_group, new_repo,
perm.permission)
elif repo_group and copy_group_permissions:
user_perms = UserRepoGroupToPerm.query() \
.filter(UserRepoGroupToPerm.group == repo_group).all()
group_perms = UserGroupRepoGroupToPerm.query() \
.filter(UserGroupRepoGroupToPerm.group == repo_group).all()
for perm in user_perms:
perm_name = perm.permission.permission_name.replace('group.', 'repository.')
perm_obj = Permission.get_by_key(perm_name)
UserRepoToPerm.create(perm.user, new_repo, perm_obj)
for perm in group_perms:
perm_name = perm.permission.permission_name.replace('group.', 'repository.')
perm_obj = Permission.get_by_key(perm_name)
UserGroupRepoToPerm.create(perm.users_group, new_repo, perm_obj)
else:
perm_obj = self._create_default_perms(new_repo, private)
self.sa.add(perm_obj)
# now automatically start following this repository as owner
ScmModel(self.sa).toggle_following_repo(new_repo.repo_id,
owner.user_id)
# we need to flush here, in order to check if database won't
# throw any exceptions, create filesystem dirs at the very end
self.sa.flush()
return new_repo
except Exception:
log.error(traceback.format_exc())
raise
def create(self, form_data, cur_user):
"""
Create repository using celery tasks
:param form_data:
:param cur_user:
"""
from rhodecode.lib.celerylib import tasks, run_task
return run_task(tasks.create_repo, form_data, cur_user)
def _update_permissions(self, repo, perms_new=None, perms_updates=None,
check_perms=True):
if not perms_new:
perms_new = []
if not perms_updates:
perms_updates = []
# update permissions
for member, perm, member_type in perms_updates:
if member_type == 'user':
# this updates existing one
self.grant_user_permission(
repo=repo, user=member, perm=perm
)
else:
#check if we have permissions to alter this usergroup
req_perms = (
'usergroup.read', 'usergroup.write', 'usergroup.admin')
if not check_perms or HasUserGroupPermissionAny(*req_perms)(
member):
self.grant_user_group_permission(
repo=repo, group_name=member, perm=perm
)
# set new permissions
for member, perm, member_type in perms_new:
if member_type == 'user':
self.grant_user_permission(
repo=repo, user=member, perm=perm
)
else:
#check if we have permissions to alter this usergroup
req_perms = (
'usergroup.read', 'usergroup.write', 'usergroup.admin')
if not check_perms or HasUserGroupPermissionAny(*req_perms)(
member):
self.grant_user_group_permission(
repo=repo, group_name=member, perm=perm
)
def create_fork(self, form_data, cur_user):
"""
Simple wrapper into executing celery task for fork creation
:param form_data:
:param cur_user:
"""
from rhodecode.lib.celerylib import tasks, run_task
return run_task(tasks.create_repo_fork, form_data, cur_user)
def delete(self, repo, forks=None, fs_remove=True, cur_user=None):
"""
Delete given repository, forks parameter defines what do do with
attached forks. Throws AttachedForksError if deleted repo has attached
forks
:param repo:
:param forks: str 'delete' or 'detach'
:param fs_remove: remove(archive) repo from filesystem
"""
if not cur_user:
cur_user = getattr(get_current_rhodecode_user(), 'username', None)
repo = self._get_repo(repo)
if repo:
if forks == 'detach':
for r in repo.forks:
r.fork = None
self.sa.add(r)
elif forks == 'delete':
for r in repo.forks:
self.delete(r, forks='delete')
elif [f for f in repo.forks]:
raise AttachedForksError()
old_repo_dict = repo.get_dict()
owner = repo.user
try:
self.sa.delete(repo)
if fs_remove:
self._delete_filesystem_repo(repo)
else:
log.debug('skipping removal from filesystem')
log_delete_repository(old_repo_dict,
deleted_by=cur_user)
except Exception:
log.error(traceback.format_exc())
raise
def grant_user_permission(self, repo, user, perm):
"""
Grant permission for user on given repository, or update existing one
if found
:param repo: Instance of Repository, repository_id, or repository name
:param user: Instance of User, user_id or username
:param perm: Instance of Permission, or permission_name
"""
user = self._get_user(user)
repo = self._get_repo(repo)
permission = self._get_perm(perm)
# check if we have that permission already
obj = self.sa.query(UserRepoToPerm) \
.filter(UserRepoToPerm.user == user) \
.filter(UserRepoToPerm.repository == repo) \
.scalar()
if obj is None:
# create new !
obj = UserRepoToPerm()
obj.repository = repo
obj.user = user
obj.permission = permission
self.sa.add(obj)
log.debug('Granted perm %s to %s on %s' % (perm, user, repo))
return obj
def revoke_user_permission(self, repo, user):
"""
Revoke permission for user on given repository
:param repo: Instance of Repository, repository_id, or repository name
:param user: Instance of User, user_id or username
"""
user = self._get_user(user)
repo = self._get_repo(repo)
obj = self.sa.query(UserRepoToPerm) \
.filter(UserRepoToPerm.repository == repo) \
.filter(UserRepoToPerm.user == user) \
.scalar()
if obj:
self.sa.delete(obj)
log.debug('Revoked perm on %s on %s' % (repo, user))
def grant_user_group_permission(self, repo, group_name, perm):
"""
Grant permission for user group on given repository, or update
existing one if found
:param repo: Instance of Repository, repository_id, or repository name
:param group_name: Instance of UserGroup, users_group_id,
or user group name
:param perm: Instance of Permission, or permission_name
"""
repo = self._get_repo(repo)
group_name = self._get_user_group(group_name)
permission = self._get_perm(perm)
# check if we have that permission already
obj = self.sa.query(UserGroupRepoToPerm) \
.filter(UserGroupRepoToPerm.users_group == group_name) \
.filter(UserGroupRepoToPerm.repository == repo) \
.scalar()
if obj is None:
# create new
obj = UserGroupRepoToPerm()
obj.repository = repo
obj.users_group = group_name
obj.permission = permission
self.sa.add(obj)
log.debug('Granted perm %s to %s on %s' % (perm, group_name, repo))
return obj
def revoke_user_group_permission(self, repo, group_name):
"""
Revoke permission for user group on given repository
:param repo: Instance of Repository, repository_id, or repository name
:param group_name: Instance of UserGroup, users_group_id,
or user group name
"""
repo = self._get_repo(repo)
group_name = self._get_user_group(group_name)
obj = self.sa.query(UserGroupRepoToPerm) \
.filter(UserGroupRepoToPerm.repository == repo) \
.filter(UserGroupRepoToPerm.users_group == group_name) \
.scalar()
if obj:
self.sa.delete(obj)
log.debug('Revoked perm to %s on %s' % (repo, group_name))
def delete_stats(self, repo_name):
"""
removes stats for given repo
:param repo_name:
"""
repo = self._get_repo(repo_name)
try:
obj = self.sa.query(Statistics) \
.filter(Statistics.repository == repo).scalar()
if obj:
self.sa.delete(obj)
except Exception:
log.error(traceback.format_exc())
raise
def _create_filesystem_repo(self, repo_name, repo_type, repo_group,
clone_uri=None, repo_store_location=None):
"""
makes repository on filesystem. It's group aware means it'll create
a repository within a group, and alter the paths accordingly of
group location
:param repo_name:
:param alias:
:param parent:
:param clone_uri:
:param repo_store_location:
"""
from rhodecode.lib.utils import is_valid_repo, is_valid_repo_group
from rhodecode.model.scm import ScmModel
if '/' in repo_name:
raise ValueError('repo_name must not contain groups got `%s`' % repo_name)
if isinstance(repo_group, RepoGroup):
new_parent_path = os.sep.join(repo_group.full_path_splitted)
else:
new_parent_path = repo_group or ''
if repo_store_location:
_paths = [repo_store_location]
else:
_paths = [self.repos_path, new_parent_path, repo_name]
# we need to make it str for mercurial
repo_path = os.path.join(*map(lambda x: safe_str(x), _paths))
# check if this path is not a repository
if is_valid_repo(repo_path, self.repos_path):
raise Exception('This path %s is a valid repository' % repo_path)
# check if this path is a group
if is_valid_repo_group(repo_path, self.repos_path):
raise Exception('This path %s is a valid group' % repo_path)
log.info('creating repo %s in %s from url: `%s`' % (
repo_name, safe_unicode(repo_path),
obfuscate_url_pw(clone_uri)))
backend = get_backend(repo_type)
if repo_type == 'hg':
baseui = make_ui('db', clear_session=False)
# patch and reset hooks section of UI config to not run any
# hooks on creating remote repo
for k, v in baseui.configitems('hooks'):
baseui.setconfig('hooks', k, None)
repo = backend(repo_path, create=True, src_url=clone_uri, baseui=baseui)
elif repo_type == 'git':
repo = backend(repo_path, create=True, src_url=clone_uri, bare=True)
# add rhodecode hook into this repo
ScmModel().install_git_hook(repo=repo)
else:
raise Exception('Not supported repo_type %s expected hg/git' % repo_type)
log.debug('Created repo %s with %s backend'
% (safe_unicode(repo_name), safe_unicode(repo_type)))
return repo
def _rename_filesystem_repo(self, old, new):
"""
renames repository on filesystem
:param old: old name
:param new: new name
"""
log.info('renaming repo from %s to %s' % (old, new))
old_path = os.path.join(self.repos_path, old)
new_path = os.path.join(self.repos_path, new)
if os.path.isdir(new_path):
raise Exception(
'Was trying to rename to already existing dir %s' % new_path
)
shutil.move(old_path, new_path)
def _delete_filesystem_repo(self, repo):
"""
removes repo from filesystem, the removal is acctually made by
added rm__ prefix into dir, and rename internat .hg/.git dirs so this
repository is no longer valid for rhodecode, can be undeleted later on
by reverting the renames on this repository
:param repo: repo object
"""
rm_path = os.path.join(self.repos_path, repo.repo_name)
log.info("Removing repository %s" % (rm_path,))
# disable hg/git internal that it doesn't get detected as repo
alias = repo.repo_type
bare = getattr(repo.scm_instance, 'bare', False)
# skip this for bare git repos
if not bare:
# disable VCS repo
vcs_path = os.path.join(rm_path, '.%s' % alias)
if os.path.exists(vcs_path):
shutil.move(vcs_path, os.path.join(rm_path, 'rm__.%s' % alias))
_now = datetime.now()
_ms = str(_now.microsecond).rjust(6, '0')
_d = 'rm__%s__%s' % (_now.strftime('%Y%m%d_%H%M%S_' + _ms),
repo.just_name)
if repo.group:
args = repo.group.full_path_splitted + [_d]
_d = os.path.join(*args)
if os.path.isdir(rm_path):
shutil.move(rm_path, os.path.join(self.repos_path, _d))
|