Skip to content

Commit

Permalink
Merge branch 'master' into 197-conditional-archetypes
Browse files Browse the repository at this point in the history
* master:
  Support a list of objects in content.delete
  Add local TOCS to main docs pages
  Support Zope users in user.adopt_user

Conflicts:
	docs/CHANGES.rst
  • Loading branch information
jaroel committed Feb 4, 2015
2 parents 4d2943a + 0bc02de commit 93dbf6c
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 8 deletions.
9 changes: 9 additions & 0 deletions docs/CHANGES.rst
Expand Up @@ -7,9 +7,18 @@ Changelog
- Make Products.Archetypes dependency optional. Fixes #197
[jaroel]

- Added local TOCS to main docs pages. Fixes #90.
[jaroel]

- Allow deleting multiple objects. Fixes #198
[jaroel]

- Fixed `make docs`.
[jaroel]

- Support Zope users in user.adopt_user. Fixes #171 and #157.
[jaroel]

- explicit dependencies in setup.py, explicit zcml loading in tests.
[jensens]

Expand Down
3 changes: 3 additions & 0 deletions docs/about.rst
Expand Up @@ -7,6 +7,9 @@
About
=====

.. contents:: :local:


Inspiration
===========

Expand Down
22 changes: 22 additions & 0 deletions docs/content.rst
Expand Up @@ -10,6 +10,8 @@
Content
=======

.. contents:: :local:

.. _content_create_example:

Create content
Expand Down Expand Up @@ -265,6 +267,26 @@ To delete a content object, pass the object to the :meth:`api.content.delete` me
self.assertFalse(portal.get('copy_of_training'))
To delete multiple content objects, pass the objects to the :meth:`api.content.delete` method:

.. invisible-code-block: python
api.content.copy(source=portal['training'], target=portal, safe_id=True)
api.content.copy(source=portal['events']['training'], target=portal['events'], safe_id=True)
.. code-block:: python
from plone import api
portal = api.portal.get()
data = [portal['copy_of_training'], portal['events']['copy_of_training'], ]
api.content.delete(objects=data)
.. invisible-code-block: python
self.assertFalse(portal.get('copy_of_training'))
self.assertFalse(portal.events.get('copy_of_training'))
.. _content_manipulation_with_safe_id_option:

Content manipulation with the `safe_id` option
Expand Down
3 changes: 3 additions & 0 deletions docs/env.rst
Expand Up @@ -10,6 +10,9 @@
Environment
===========

.. contents:: :local:


.. _env_adopt_roles_example:

Switch roles inside a block
Expand Down
3 changes: 3 additions & 0 deletions docs/group.rst
Expand Up @@ -10,6 +10,9 @@
Groups
======

.. contents:: :local:


.. _group_create_example:

Create group
Expand Down
3 changes: 3 additions & 0 deletions docs/portal.rst
Expand Up @@ -10,6 +10,9 @@
Portal
======

.. contents:: :local:


.. _portal_get_example:

Get portal object
Expand Down
3 changes: 3 additions & 0 deletions docs/user.rst
Expand Up @@ -10,6 +10,9 @@
Users
=====

.. contents:: :local:


.. _user_create_example:

Create user
Expand Down
17 changes: 12 additions & 5 deletions src/plone/api/content.py
Expand Up @@ -262,17 +262,24 @@ def copy(source=None, target=None, id=None, safe_id=False):
return target[new_id]


@required_parameters('obj')
def delete(obj=None):
"""Delete the object.
@at_least_one_of('obj', 'objects')
def delete(obj=None, objects=None):
"""Delete the object(s).
:param obj: [required] Object that we want to delete.
:param obj: Object that we want to delete.
:type obj: Content object
:param objects: Objects that we want to delete.
:type objects: List of content objects
:raises:
ValueError
:Example: :ref:`content_delete_example`
"""
obj.aq_parent.manage_delObjects([obj.getId()])
if obj is not None:
obj.aq_parent.manage_delObjects([obj.getId()])
else:
# The objects may have different parents
for obj in objects:
delete(obj=obj)


@required_parameters('obj')
Expand Down
17 changes: 14 additions & 3 deletions src/plone/api/env.py
Expand Up @@ -32,11 +32,22 @@ def adopt_user(username=None, user=None):
# Grab the user object out of acl_users because this function
# accepts 'user' objects that are actually things like MemberData
# objects, which AccessControl isn't so keen on.
acl_users = portal.get().acl_users

unwrapped = None
plone = portal.get()
acls = [plone.acl_users, plone.__parent__.acl_users]

if username is None:
unwrapped = acl_users.getUserById(user.getId())
for acl_users in acls:
unwrapped = acl_users.getUserById(user.getId())
if unwrapped:
break
else:
unwrapped = acl_users.getUser(username)
for acl_users in acls:
unwrapped = acl_users.getUser(username)
if unwrapped:
break

if unwrapped is None:
raise UserNotFoundError

Expand Down
12 changes: 12 additions & 0 deletions src/plone/api/tests/test_content.py
Expand Up @@ -593,6 +593,18 @@ def test_delete(self):
api.content.delete(self.contact)
assert 'contact' not in container['about'].keys()

def test_delete_multiple(self):
"""Test deleting multiple content items."""

container = self.portal
api.content.copy(source=container['about'], target=container)
api.content.copy(source=container['about'], target=container['events'])

api.content.delete(objects=[container['copy_of_about'],
container['events']['about']])
assert 'copy_of_about' not in container
assert 'about' not in container['events']

def test_get_state(self):
"""Test retrieving the workflow state of a content item."""

Expand Down
4 changes: 4 additions & 0 deletions src/plone/api/tests/test_env.py
Expand Up @@ -367,6 +367,10 @@ def test_adopted_nested_ownership(self):
])
# /user worker

def test_adopting_zope_users(self):
api.env.adopt_user(username='admin')
api.env.adopt_user(user=api.user.get(username='admin'))

def test_empty_warning(self):
"""Tests that empty roles lists get warned about."""
from plone.api.exc import InvalidParameterError
Expand Down

0 comments on commit 93dbf6c

Please sign in to comment.