@@ 2523-2682 (lines=160) @@ | ||
2520 | api2.save(content2) |
|
2521 | transaction.commit() |
|
2522 | ||
2523 | def test_archive_unarchive(self): |
|
2524 | uapi = UserApi( |
|
2525 | session=self.session, |
|
2526 | config=self.app_config, |
|
2527 | current_user=None, |
|
2528 | ) |
|
2529 | group_api = GroupApi( |
|
2530 | current_user=None, |
|
2531 | session=self.session, |
|
2532 | config=self.app_config, |
|
2533 | ) |
|
2534 | groups = [group_api.get_one(Group.TIM_USER), |
|
2535 | group_api.get_one(Group.TIM_MANAGER), |
|
2536 | group_api.get_one(Group.TIM_ADMIN)] |
|
2537 | ||
2538 | user1 = uapi.create_minimal_user( |
|
2539 | email='this.is@user', |
|
2540 | groups=groups, |
|
2541 | save_now=True |
|
2542 | ) |
|
2543 | u1id = user1.user_id |
|
2544 | ||
2545 | workspace_api = WorkspaceApi( |
|
2546 | current_user=user1, |
|
2547 | session=self.session, |
|
2548 | config=self.app_config, |
|
2549 | ) |
|
2550 | workspace = workspace_api.create_workspace( |
|
2551 | 'test workspace', |
|
2552 | save_now=True |
|
2553 | ) |
|
2554 | wid = workspace.workspace_id |
|
2555 | ||
2556 | user2 = uapi.create_minimal_user('[email protected]') |
|
2557 | uapi.save(user2) |
|
2558 | ||
2559 | RoleApi( |
|
2560 | current_user=user1, |
|
2561 | session=self.session, |
|
2562 | config=self.app_config, |
|
2563 | ).create_one( |
|
2564 | user2, |
|
2565 | workspace, |
|
2566 | UserRoleInWorkspace.CONTENT_MANAGER, |
|
2567 | with_notif=True, |
|
2568 | flush=True |
|
2569 | ) |
|
2570 | ||
2571 | # show archived is used at the top end of the test |
|
2572 | api = ContentApi( |
|
2573 | current_user=user1, |
|
2574 | session=self.session, |
|
2575 | show_archived=True, |
|
2576 | config=self.app_config, |
|
2577 | ) |
|
2578 | p = api.create( |
|
2579 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2580 | workspace=workspace, |
|
2581 | parent=None, |
|
2582 | label='this_is_a_page', |
|
2583 | do_save=True |
|
2584 | ) |
|
2585 | ||
2586 | u1id = user1.user_id |
|
2587 | u2id = user2.user_id |
|
2588 | pcid = p.content_id |
|
2589 | poid = p.owner_id |
|
2590 | ||
2591 | transaction.commit() |
|
2592 | ||
2593 | #### |
|
2594 | ||
2595 | # refresh after commit |
|
2596 | user1 = UserApi( |
|
2597 | current_user=None, |
|
2598 | config=self.app_config, |
|
2599 | session=self.session |
|
2600 | ).get_one(u1id) |
|
2601 | workspace = WorkspaceApi( |
|
2602 | current_user=user1, |
|
2603 | session=self.session, |
|
2604 | config=self.app_config, |
|
2605 | ).get_one(wid) |
|
2606 | ||
2607 | content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2608 | eq_(u1id, content.owner_id) |
|
2609 | eq_(poid, content.owner_id) |
|
2610 | ||
2611 | u2api = UserApi( |
|
2612 | session=self.session, |
|
2613 | config=self.app_config, |
|
2614 | current_user=None, |
|
2615 | ) |
|
2616 | u2 = u2api.get_one(u2id) |
|
2617 | api2 = ContentApi( |
|
2618 | current_user=u2, |
|
2619 | session=self.session, |
|
2620 | config=self.app_config, |
|
2621 | show_archived=True, |
|
2622 | ) |
|
2623 | content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2624 | with new_revision( |
|
2625 | session=self.session, |
|
2626 | tm=transaction.manager, |
|
2627 | content=content2, |
|
2628 | ): |
|
2629 | api2.archive(content2) |
|
2630 | api2.save(content2) |
|
2631 | transaction.commit() |
|
2632 | ||
2633 | # refresh after commit |
|
2634 | user1 = UserApi( |
|
2635 | current_user=None, |
|
2636 | session=self.session, |
|
2637 | config=self.app_config, |
|
2638 | ).get_one(u1id) |
|
2639 | workspace = WorkspaceApi( |
|
2640 | current_user=user1, |
|
2641 | session=self.session, |
|
2642 | config=self.app_config, |
|
2643 | ).get_one(wid) |
|
2644 | u2 = UserApi( |
|
2645 | current_user=None, |
|
2646 | session=self.session, |
|
2647 | config=self.app_config, |
|
2648 | ).get_one(u2id) |
|
2649 | api = ContentApi( |
|
2650 | current_user=user1, |
|
2651 | session=self.session, |
|
2652 | config=self.app_config, |
|
2653 | show_archived=True, |
|
2654 | ) |
|
2655 | api2 = ContentApi( |
|
2656 | current_user=u2, |
|
2657 | session=self.session, |
|
2658 | config=self.app_config, |
|
2659 | show_archived=True, |
|
2660 | ) |
|
2661 | ||
2662 | updated = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2663 | eq_(u2id, updated.owner_id, |
|
2664 | 'the owner id should be {} (found {})'.format(u2id, |
|
2665 | updated.owner_id)) |
|
2666 | eq_(True, updated.is_archived) |
|
2667 | eq_(ActionDescription.ARCHIVING, updated.revision_type) |
|
2668 | ||
2669 | #### |
|
2670 | ||
2671 | updated2 = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2672 | with new_revision( |
|
2673 | session=self.session, |
|
2674 | tm=transaction.manager, |
|
2675 | content=updated, |
|
2676 | ||
2677 | ): |
|
2678 | api.unarchive(updated) |
|
2679 | api.save(updated2) |
|
2680 | eq_(False, updated2.is_archived) |
|
2681 | eq_(ActionDescription.UNARCHIVING, updated2.revision_type) |
|
2682 | eq_(u1id, updated2.owner_id) |
|
2683 | ||
2684 | def test_delete_undelete(self): |
|
2685 | uapi = UserApi( |
|
@@ 2684-2841 (lines=158) @@ | ||
2681 | eq_(ActionDescription.UNARCHIVING, updated2.revision_type) |
|
2682 | eq_(u1id, updated2.owner_id) |
|
2683 | ||
2684 | def test_delete_undelete(self): |
|
2685 | uapi = UserApi( |
|
2686 | session=self.session, |
|
2687 | config=self.app_config, |
|
2688 | current_user=None, |
|
2689 | ) |
|
2690 | group_api = GroupApi( |
|
2691 | current_user=None, |
|
2692 | session=self.session, |
|
2693 | config=self.app_config, |
|
2694 | ) |
|
2695 | groups = [group_api.get_one(Group.TIM_USER), |
|
2696 | group_api.get_one(Group.TIM_MANAGER), |
|
2697 | group_api.get_one(Group.TIM_ADMIN)] |
|
2698 | ||
2699 | user1 = uapi.create_minimal_user( |
|
2700 | email='this.is@user', |
|
2701 | groups=groups, |
|
2702 | save_now=True |
|
2703 | ) |
|
2704 | u1id = user1.user_id |
|
2705 | ||
2706 | workspace_api = WorkspaceApi( |
|
2707 | current_user=user1, |
|
2708 | session=self.session, |
|
2709 | config=self.app_config, |
|
2710 | ) |
|
2711 | workspace = workspace_api.create_workspace( |
|
2712 | 'test workspace', |
|
2713 | save_now=True |
|
2714 | ) |
|
2715 | wid = workspace.workspace_id |
|
2716 | ||
2717 | user2 = uapi.create_minimal_user('[email protected]') |
|
2718 | uapi.save(user2) |
|
2719 | ||
2720 | RoleApi( |
|
2721 | current_user=user1, |
|
2722 | session=self.session, |
|
2723 | config=self.app_config, |
|
2724 | ).create_one( |
|
2725 | user2, |
|
2726 | workspace, |
|
2727 | UserRoleInWorkspace.CONTENT_MANAGER, |
|
2728 | with_notif=True, |
|
2729 | flush=True |
|
2730 | ) |
|
2731 | ||
2732 | # show archived is used at the top end of the test |
|
2733 | api = ContentApi( |
|
2734 | current_user=user1, |
|
2735 | session=self.session, |
|
2736 | config=self.app_config, |
|
2737 | show_deleted=True, |
|
2738 | ) |
|
2739 | p = api.create( |
|
2740 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2741 | workspace=workspace, |
|
2742 | parent=None, |
|
2743 | label='this_is_a_page', |
|
2744 | do_save=True |
|
2745 | ) |
|
2746 | ||
2747 | u1id = user1.user_id |
|
2748 | u2id = user2.user_id |
|
2749 | pcid = p.content_id |
|
2750 | poid = p.owner_id |
|
2751 | ||
2752 | transaction.commit() |
|
2753 | ||
2754 | #### |
|
2755 | user1 = UserApi( |
|
2756 | current_user=None, |
|
2757 | session=self.session, |
|
2758 | config=self.app_config, |
|
2759 | ).get_one(u1id) |
|
2760 | workspace = WorkspaceApi( |
|
2761 | current_user=user1, |
|
2762 | session=self.session, |
|
2763 | config=self.app_config, |
|
2764 | ).get_one(wid) |
|
2765 | ||
2766 | content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2767 | eq_(u1id, content.owner_id) |
|
2768 | eq_(poid, content.owner_id) |
|
2769 | ||
2770 | u2 = UserApi( |
|
2771 | current_user=None, |
|
2772 | session=self.session, |
|
2773 | config=self.app_config, |
|
2774 | ).get_one(u2id) |
|
2775 | api2 = ContentApi( |
|
2776 | current_user=u2, |
|
2777 | session=self.session, |
|
2778 | config=self.app_config, |
|
2779 | show_deleted=True, |
|
2780 | ) |
|
2781 | content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2782 | with new_revision( |
|
2783 | session=self.session, |
|
2784 | tm=transaction.manager, |
|
2785 | content=content2, |
|
2786 | ): |
|
2787 | api2.delete(content2) |
|
2788 | api2.save(content2) |
|
2789 | transaction.commit() |
|
2790 | ||
2791 | #### |
|
2792 | ||
2793 | user1 = UserApi( |
|
2794 | current_user=None, |
|
2795 | session=self.session, |
|
2796 | config=self.app_config, |
|
2797 | ).get_one(u1id) |
|
2798 | workspace = WorkspaceApi( |
|
2799 | current_user=user1, |
|
2800 | session=self.session, |
|
2801 | config=self.app_config, |
|
2802 | ).get_one(wid) |
|
2803 | # show archived is used at the top end of the test |
|
2804 | api = ContentApi( |
|
2805 | current_user=user1, |
|
2806 | session=self.session, |
|
2807 | config=self.app_config, |
|
2808 | show_deleted=True, |
|
2809 | ) |
|
2810 | u2 = UserApi( |
|
2811 | current_user=None, |
|
2812 | session=self.session, |
|
2813 | config=self.app_config, |
|
2814 | ).get_one(u2id) |
|
2815 | api2 = ContentApi( |
|
2816 | current_user=u2, |
|
2817 | session=self.session, |
|
2818 | config=self.app_config, |
|
2819 | show_deleted=True |
|
2820 | ) |
|
2821 | ||
2822 | updated = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2823 | eq_(u2id, updated.owner_id, |
|
2824 | 'the owner id should be {} (found {})'.format(u2id, |
|
2825 | updated.owner_id)) |
|
2826 | eq_(True, updated.is_deleted) |
|
2827 | eq_(ActionDescription.DELETION, updated.revision_type) |
|
2828 | ||
2829 | #### |
|
2830 | ||
2831 | updated2 = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2832 | with new_revision( |
|
2833 | tm=transaction.manager, |
|
2834 | session=self.session, |
|
2835 | content=updated2, |
|
2836 | ): |
|
2837 | api.undelete(updated2) |
|
2838 | api.save(updated2) |
|
2839 | eq_(False, updated2.is_deleted) |
|
2840 | eq_(ActionDescription.UNDELETION, updated2.revision_type) |
|
2841 | eq_(u1id, updated2.owner_id) |
|
2842 | ||
2843 | def test_unit__get_last_active__ok__nominal_case(self): |
|
2844 | uapi = UserApi( |