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