@@ 1632-1777 (lines=146) @@ | ||
1629 | eq_(ActionDescription.UNARCHIVING, updated2.revision_type) |
|
1630 | eq_(u1id, updated2.owner_id) |
|
1631 | ||
1632 | def test_delete_undelete(self): |
|
1633 | uapi = UserApi( |
|
1634 | session=self.session, |
|
1635 | config=self.app_config, |
|
1636 | current_user=None, |
|
1637 | ) |
|
1638 | group_api = GroupApi( |
|
1639 | current_user=None, |
|
1640 | session=self.session |
|
1641 | ) |
|
1642 | groups = [group_api.get_one(Group.TIM_USER), |
|
1643 | group_api.get_one(Group.TIM_MANAGER), |
|
1644 | group_api.get_one(Group.TIM_ADMIN)] |
|
1645 | ||
1646 | user1 = uapi.create_user( |
|
1647 | email='this.is@user', |
|
1648 | groups=groups, |
|
1649 | save_now=True |
|
1650 | ) |
|
1651 | u1id = user1.user_id |
|
1652 | ||
1653 | workspace_api = WorkspaceApi(current_user=user1, session=self.session) |
|
1654 | workspace = workspace_api.create_workspace( |
|
1655 | 'test workspace', |
|
1656 | save_now=True |
|
1657 | ) |
|
1658 | wid = workspace.workspace_id |
|
1659 | ||
1660 | user2 = uapi.create_user() |
|
1661 | user2.email = '[email protected]' |
|
1662 | uapi.save(user2) |
|
1663 | ||
1664 | RoleApi( |
|
1665 | current_user=user1, |
|
1666 | session=self.session |
|
1667 | ).create_one( |
|
1668 | user2, |
|
1669 | workspace, |
|
1670 | UserRoleInWorkspace.CONTENT_MANAGER, |
|
1671 | with_notif=True, |
|
1672 | flush=True |
|
1673 | ) |
|
1674 | ||
1675 | # show archived is used at the top end of the test |
|
1676 | api = ContentApi( |
|
1677 | current_user=user1, |
|
1678 | session=self.session, |
|
1679 | config=self.app_config, |
|
1680 | show_deleted=True, |
|
1681 | ) |
|
1682 | p = api.create(ContentType.File, workspace, None, |
|
1683 | 'this_is_a_page', True) |
|
1684 | ||
1685 | u1id = user1.user_id |
|
1686 | u2id = user2.user_id |
|
1687 | pcid = p.content_id |
|
1688 | poid = p.owner_id |
|
1689 | ||
1690 | transaction.commit() |
|
1691 | ||
1692 | #### |
|
1693 | user1 = UserApi( |
|
1694 | current_user=None, |
|
1695 | session=self.session, |
|
1696 | config=self.app_config, |
|
1697 | ).get_one(u1id) |
|
1698 | workspace = WorkspaceApi( |
|
1699 | current_user=user1, |
|
1700 | session=self.session, |
|
1701 | ).get_one(wid) |
|
1702 | ||
1703 | content = api.get_one(pcid, ContentType.Any, workspace) |
|
1704 | eq_(u1id, content.owner_id) |
|
1705 | eq_(poid, content.owner_id) |
|
1706 | ||
1707 | u2 = UserApi( |
|
1708 | current_user=None, |
|
1709 | session=self.session, |
|
1710 | config=self.app_config, |
|
1711 | ).get_one(u2id) |
|
1712 | api2 = ContentApi( |
|
1713 | current_user=u2, |
|
1714 | session=self.session, |
|
1715 | config=self.app_config, |
|
1716 | show_deleted=True, |
|
1717 | ) |
|
1718 | content2 = api2.get_one(pcid, ContentType.Any, workspace) |
|
1719 | with new_revision( |
|
1720 | session=self.session, |
|
1721 | tm=transaction.manager, |
|
1722 | content=content2, |
|
1723 | ): |
|
1724 | api2.delete(content2) |
|
1725 | api2.save(content2) |
|
1726 | transaction.commit() |
|
1727 | ||
1728 | #### |
|
1729 | ||
1730 | user1 = UserApi( |
|
1731 | current_user=None, |
|
1732 | session=self.session, |
|
1733 | config=self.app_config, |
|
1734 | ).get_one(u1id) |
|
1735 | workspace = WorkspaceApi( |
|
1736 | current_user=user1, |
|
1737 | session=self.session, |
|
1738 | ).get_one(wid) |
|
1739 | # show archived is used at the top end of the test |
|
1740 | api = ContentApi( |
|
1741 | current_user=user1, |
|
1742 | session=self.session, |
|
1743 | config=self.app_config, |
|
1744 | show_deleted=True, |
|
1745 | ) |
|
1746 | u2 = UserApi( |
|
1747 | current_user=None, |
|
1748 | session=self.session, |
|
1749 | config=self.app_config, |
|
1750 | ).get_one(u2id) |
|
1751 | api2 = ContentApi( |
|
1752 | current_user=u2, |
|
1753 | session=self.session, |
|
1754 | config=self.app_config, |
|
1755 | show_deleted=True |
|
1756 | ) |
|
1757 | ||
1758 | updated = api2.get_one(pcid, ContentType.Any, workspace) |
|
1759 | eq_(u2id, updated.owner_id, |
|
1760 | 'the owner id should be {} (found {})'.format(u2id, |
|
1761 | updated.owner_id)) |
|
1762 | eq_(True, updated.is_deleted) |
|
1763 | eq_(ActionDescription.DELETION, updated.revision_type) |
|
1764 | ||
1765 | #### |
|
1766 | ||
1767 | updated2 = api.get_one(pcid, ContentType.Any, workspace) |
|
1768 | with new_revision( |
|
1769 | tm=transaction.manager, |
|
1770 | session=self.session, |
|
1771 | content=updated2, |
|
1772 | ): |
|
1773 | api.undelete(updated2) |
|
1774 | api.save(updated2) |
|
1775 | eq_(False, updated2.is_deleted) |
|
1776 | eq_(ActionDescription.UNDELETION, updated2.revision_type) |
|
1777 | eq_(u1id, updated2.owner_id) |
|
1778 | ||
1779 | def test_search_in_label(self): |
|
1780 | # HACK - D.A. - 2015-03-09 |
|
@@ 1486-1630 (lines=145) @@ | ||
1483 | api2.save(content2) |
|
1484 | transaction.commit() |
|
1485 | ||
1486 | def test_archive_unarchive(self): |
|
1487 | uapi = UserApi( |
|
1488 | session=self.session, |
|
1489 | config=self.app_config, |
|
1490 | current_user=None, |
|
1491 | ) |
|
1492 | group_api = GroupApi(current_user=None, session=self.session) |
|
1493 | groups = [group_api.get_one(Group.TIM_USER), |
|
1494 | group_api.get_one(Group.TIM_MANAGER), |
|
1495 | group_api.get_one(Group.TIM_ADMIN)] |
|
1496 | ||
1497 | user1 = uapi.create_user( |
|
1498 | email='this.is@user', |
|
1499 | groups=groups, |
|
1500 | save_now=True |
|
1501 | ) |
|
1502 | u1id = user1.user_id |
|
1503 | ||
1504 | workspace_api = WorkspaceApi(current_user=user1, session=self.session) |
|
1505 | workspace = workspace_api.create_workspace( |
|
1506 | 'test workspace', |
|
1507 | save_now=True |
|
1508 | ) |
|
1509 | wid = workspace.workspace_id |
|
1510 | ||
1511 | user2 = uapi.create_user() |
|
1512 | user2.email = '[email protected]' |
|
1513 | uapi.save(user2) |
|
1514 | ||
1515 | RoleApi( |
|
1516 | current_user=user1, |
|
1517 | session=self.session |
|
1518 | ).create_one( |
|
1519 | user2, |
|
1520 | workspace, |
|
1521 | UserRoleInWorkspace.CONTENT_MANAGER, |
|
1522 | with_notif=True, |
|
1523 | flush=True |
|
1524 | ) |
|
1525 | ||
1526 | # show archived is used at the top end of the test |
|
1527 | api = ContentApi( |
|
1528 | current_user=user1, |
|
1529 | session=self.session, |
|
1530 | show_archived=True, |
|
1531 | config=self.app_config, |
|
1532 | ) |
|
1533 | p = api.create(ContentType.File, workspace, None, |
|
1534 | 'this_is_a_page', True) |
|
1535 | ||
1536 | u1id = user1.user_id |
|
1537 | u2id = user2.user_id |
|
1538 | pcid = p.content_id |
|
1539 | poid = p.owner_id |
|
1540 | ||
1541 | transaction.commit() |
|
1542 | ||
1543 | #### |
|
1544 | ||
1545 | # refresh after commit |
|
1546 | user1 = UserApi( |
|
1547 | current_user=None, |
|
1548 | config=self.app_config, |
|
1549 | session=self.session |
|
1550 | ).get_one(u1id) |
|
1551 | workspace = WorkspaceApi( |
|
1552 | current_user=user1, |
|
1553 | session=self.session |
|
1554 | ).get_one(wid) |
|
1555 | ||
1556 | content = api.get_one(pcid, ContentType.Any, workspace) |
|
1557 | eq_(u1id, content.owner_id) |
|
1558 | eq_(poid, content.owner_id) |
|
1559 | ||
1560 | u2api = UserApi( |
|
1561 | session=self.session, |
|
1562 | config=self.app_config, |
|
1563 | current_user=None, |
|
1564 | ) |
|
1565 | u2 = u2api.get_one(u2id) |
|
1566 | api2 = ContentApi( |
|
1567 | current_user=u2, |
|
1568 | session=self.session, |
|
1569 | config=self.app_config, |
|
1570 | show_archived=True, |
|
1571 | ) |
|
1572 | content2 = api2.get_one(pcid, ContentType.Any, workspace) |
|
1573 | with new_revision( |
|
1574 | session=self.session, |
|
1575 | tm=transaction.manager, |
|
1576 | content=content2, |
|
1577 | ): |
|
1578 | api2.archive(content2) |
|
1579 | api2.save(content2) |
|
1580 | transaction.commit() |
|
1581 | ||
1582 | # refresh after commit |
|
1583 | user1 = UserApi( |
|
1584 | current_user=None, |
|
1585 | session=self.session, |
|
1586 | config=self.app_config, |
|
1587 | ).get_one(u1id) |
|
1588 | workspace = WorkspaceApi( |
|
1589 | current_user=user1, |
|
1590 | session=self.session, |
|
1591 | ).get_one(wid) |
|
1592 | u2 = UserApi( |
|
1593 | current_user=None, |
|
1594 | session=self.session, |
|
1595 | config=self.app_config, |
|
1596 | ).get_one(u2id) |
|
1597 | api = ContentApi( |
|
1598 | current_user=user1, |
|
1599 | session=self.session, |
|
1600 | config=self.app_config, |
|
1601 | show_archived=True, |
|
1602 | ) |
|
1603 | api2 = ContentApi( |
|
1604 | current_user=u2, |
|
1605 | session=self.session, |
|
1606 | config=self.app_config, |
|
1607 | show_archived=True, |
|
1608 | ) |
|
1609 | ||
1610 | updated = api2.get_one(pcid, ContentType.Any, workspace) |
|
1611 | eq_(u2id, updated.owner_id, |
|
1612 | 'the owner id should be {} (found {})'.format(u2id, |
|
1613 | updated.owner_id)) |
|
1614 | eq_(True, updated.is_archived) |
|
1615 | eq_(ActionDescription.ARCHIVING, updated.revision_type) |
|
1616 | ||
1617 | #### |
|
1618 | ||
1619 | updated2 = api.get_one(pcid, ContentType.Any, workspace) |
|
1620 | with new_revision( |
|
1621 | session=self.session, |
|
1622 | tm=transaction.manager, |
|
1623 | content=updated, |
|
1624 | ||
1625 | ): |
|
1626 | api.unarchive(updated) |
|
1627 | api.save(updated2) |
|
1628 | eq_(False, updated2.is_archived) |
|
1629 | eq_(ActionDescription.UNARCHIVING, updated2.revision_type) |
|
1630 | eq_(u1id, updated2.owner_id) |
|
1631 | ||
1632 | def test_delete_undelete(self): |
|
1633 | uapi = UserApi( |