def test_checkin_without_comment_portal_action_not_rendered_for_locked_documents(
            self, browser):
        self.login(self.regular_user, browser)

        browser.open(self.document, view='tabbedview_view-overview')
        browser.find('Checkout and edit').click()

        lockable = IRefreshableLockable(self.document)
        lockable.lock()

        browser.open(self.document)

        document_portal_actions = [
            'Edit metadata',
            u'Actions \u25bc',
            'Properties',
            u'Checkin \u25bc',
            'with comment',
        ]

        self.assertEquals(document_portal_actions,
                          browser.css('#edit-bar a').text)
示例#2
0
    def is_cancel_allowed(self):
        """Checks whether the user is able to cancel a checkout."""
        current_user_id = getSecurityManager().getUser().getId()
        current_checkout_id = self.get_checked_out_by()

        # is the document checked out?
        # is the document not locked?
        # is it versionable?
        # is the user allowed to cancel?
        # is the user either the one who owns the checkout or a manager?
        if (
                current_checkout_id
                and not IRefreshableLockable(self.context).locked()
                and self.versioner.is_versionable()
                and self.check_permission('opengever.document: Cancel')
                and bool(
                    current_checkout_id == current_user_id
                    or self.check_permission('Manage portal')
                    )
            ):
            return True

        return False
示例#3
0
    def test_checkin_without_comment_action_button_not_rendered_for_locked_documents(self, browser):  # noqa
        self.login(self.regular_user, browser)

        browser.open(self.document, view='tabbedview_view-overview')
        browser.find('Checkout and edit').click()

        lockable = IRefreshableLockable(self.document)
        lockable.lock()

        # Tabbedview gets in the way of the redirect so we'll have to revisit
        browser.open(self.document, view='tabbedview_view-overview')

        file_actions = [
            'Checkout and edit',
            'Checkin with comment',
            'Download copy',
            'PDF Preview',
            ]

        self.assertEquals(
            file_actions,
            browser.css('.file-action-buttons a').text,
            )
示例#4
0
    def test_checkout_when_locked(self):
        """Test that it's not possible to check out the document if its locked
        by another user.
        """
        old_sm = getSecurityManager()

        # Change security context to 'other_user' to lock the document
        user = self.portal.acl_users.getUser('other_user')
        user = user.__of__(self.portal.acl_users)
        newSecurityManager(self.portal, user)

        # Let user 'other_user' lock the document
        lockable = IRefreshableLockable(self.document4)
        lockable.lock()

        # Restore previous security context (test_user_1)
        setSecurityManager(old_sm)
        transaction.commit()

        self.browser.open('%s/tabbedview_view-overview' %
                          self.document4.absolute_url())

        # Editing the document shouldn't be possible
        self.assertNotIn('editing_document', self.browser.contents)
示例#5
0
 def is_document_locked(self):
     return IRefreshableLockable(self.context).locked()
示例#6
0
def isLocked(context):
    lockable = IRefreshableLockable(context)
    lockable.locked()
示例#7
0
def unlockContext(context):
    lockable = IRefreshableLockable(context)
    lockable.unlock(STRUCTURALCONTENT_LOCK)
示例#8
0
def lockContext(context):
    lockable = IRefreshableLockable(context)
    lockable.lock(STRUCTURALCONTENT_LOCK)
    token = lockable.lock_info()[0]["token"]
    lock = lockable.context.wl_getLock(token)
    lock.setTimeout(MAXTIMEOUT)
示例#9
0
 def refresh_lock(self):
     """Reset the lock start time
     """
     lockable = IRefreshableLockable(self.context, None)
     if lockable is not None:
         lockable.refresh_lock()
示例#10
0
 def create_lock(self):
     """Lock the object if it is unlocked
     """
     lockable = IRefreshableLockable(self.context, None)
     if lockable is not None:
         lockable.lock()
示例#11
0
    def test_api(self):
        # create a defaultfolder
        pr = getToolByName(self.portal, 'portal_repository')

        # create a document, and get the CheckinCheckoutManager for the document
        mok_file1 = NamedBlobFile('bla bla', filename=u'test.txt')
        mok_file2 = NamedBlobFile('bla bla', filename=u'test.txt')
        doc1 = createContentInContainer(self.portal,
                                        'opengever.document.document',
                                        title=u'Doc \xf6ne',
                                        document_author=u'Hugo Boss',
                                        document_date=datetime.date(
                                            2011, 1, 1),
                                        file=mok_file1)
        doc2 = createContentInContainer(self.portal,
                                        'opengever.document.document',
                                        title=u"Doc three",
                                        file=mok_file2)
        manager = getMultiAdapter((doc1, self.portal.REQUEST),
                                  ICheckinCheckoutManager)
        manager2 = getMultiAdapter((doc2, self.portal.REQUEST),
                                   ICheckinCheckoutManager)

        # Checkout:
        # checkout should now allowed, but just for a user with authorization
        self.assertTrue(manager.is_checkout_allowed())

        # the annotations should be still empty
        self.assertEquals(None, manager.checked_out())

        # checkout the document
        manager.checkout()
        self.assertEquals('test_user_1_', manager.checked_out())

        # cancelling and checkin should be allowed for the 'test_user_1_'
        self.assertTrue(manager.is_checkin_allowed())
        self.assertTrue(manager.is_cancel_allowed())

        self.assertFalse(manager.is_checkout_allowed())

        # Checkout when locked by another user:

        # Create a second user to test locking and checkout
        self.portal.acl_users.userFolderAddUser('other_user', 'secret',
                                                ['Member'], [])

        # Checkout should first be allowed
        self.assertTrue(manager2.is_checkout_allowed())

        # Switch to different user and lock the document
        logout()
        login(self.portal, 'other_user')
        setRoles(self.portal, 'other_user',
                 ['Manager', 'Editor', 'Contributor'])
        lockable = IRefreshableLockable(doc2)
        lockable.lock()

        # Log back in as the regular test user
        logout()
        login(self.portal, TEST_USER_NAME)
        setRoles(self.portal, TEST_USER_ID,
                 ['Manager', 'Editor', 'Contributor'])

        # Checkout should not be allowed since the document is locked by another user
        self.assertFalse(manager2.is_checkout_allowed())

        # checkin and cancelling:
        mok_file2 = NamedBlobFile('blubb blubb', filename=u"blubb.txt")
        doc1.file = mok_file2
        manager.checkin(comment="Test commit Nr. 1")

        transaction.commit()

        # document isn't checked out and the old object is in the history
        self.assertEquals(None, manager.checked_out())

        self.assertEquals(u'doc-one.txt',
                          pr.retrieve(doc1, 0).object.file.filename)
        self.assertEquals(u'blubb.txt', doc1.file.filename)

        manager.checkout()
        self.assertEquals('test_user_1_', manager.checked_out())

        manager.cancel()
        pr.getHistoryMetadata(doc1).retrieve(2)

        self.assertEquals(None, manager.checked_out())
    def test_file_upload_is_disallowed_when_document_is_locked(self):
        doc = create(Builder('document').checked_out())
        IRefreshableLockable(doc).lock()

        self.assertFalse(self.get_manager(doc).is_file_upload_allowed())
 def test_revert_disallowed_when_locked(self):
     IRefreshableLockable(self.document).lock()
     self.assertFalse(self.manager.is_revert_allowed())
    def test_clear_locks(self):
        IRefreshableLockable(self.document).lock()
        self.assertTrue(IRefreshableLockable(self.document).locked())

        self.manager.checkin()
        self.assertFalse(IRefreshableLockable(self.document).locked())