Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2011.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace `getAdapter(context, ISecuritySchema)` with `registry.forInterface(ISecuritySchema, prefix="plone")` in user services.
9 changes: 6 additions & 3 deletions src/plone/restapi/services/users/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
except ImportError:
# BBB: plone.app.users without standalone generators (Plone < 6.2)
HAS_STANDALONE_GENERATORS = False
from plone.registry.interfaces import IRegistry
from plone.restapi import _
from plone.restapi.bbb import ISecuritySchema
from plone.restapi.deserializer import json_body
Expand All @@ -23,8 +24,8 @@
from Products.CMFPlone.RegistrationTool import get_member_by_login_name
from zExceptions import BadRequest
from zExceptions import Forbidden
from zope.component import getAdapter
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.component import queryMultiAdapter
from zope.component.hooks import getSite
from zope.i18n import translate
Expand Down Expand Up @@ -69,7 +70,8 @@ def translate_fieldname(self, fieldname):

def validate_input_data(self, portal, original_data):
"""Returns a tuple of (required_fields, allowed_fields)"""
security = getAdapter(portal, ISecuritySchema)
registry = getUtility(IRegistry)
security = registry.forInterface(ISecuritySchema, prefix="plone")

# remove data we don't want to check for
data = {}
Expand Down Expand Up @@ -227,7 +229,8 @@ def reply(self):

def _add_user(self, data, location=True):
portal = getSite()
security = getAdapter(self.context, ISecuritySchema)
registry = getUtility(IRegistry)
security = registry.forInterface(ISecuritySchema, prefix="plone")
registration = getToolByName(portal, "portal_registration")

username = data.pop("username", None)
Expand Down
6 changes: 4 additions & 2 deletions src/plone/restapi/services/users/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from Acquisition import aq_inner
from io import BytesIO
from OFS.Image import Image
from plone.registry.interfaces import IRegistry
from plone.restapi import _
from plone.restapi.bbb import ISecuritySchema
from plone.restapi.permissions import PloneManageUsers
Expand All @@ -12,7 +13,7 @@
from Products.CMFPlone.utils import set_own_login_name
from Products.PlonePAS.tools.membership import default_portrait
from Products.PlonePAS.utils import scale_image
from zope.component import getAdapter
from zope.component import getUtility
from zope.component.hooks import getSite
from zope.i18n import translate
from zope.interface import alsoProvides
Expand Down Expand Up @@ -80,7 +81,8 @@ def reply(self):
if "IDisableCSRFProtection" in dir(plone.protect.interfaces):
alsoProvides(self.request, plone.protect.interfaces.IDisableCSRFProtection)

security = getAdapter(self.context, ISecuritySchema)
registry = getUtility(IRegistry)
security = registry.forInterface(ISecuritySchema, prefix="plone")

if self.can_manage_users:
current_roles = user.getRoles()
Expand Down
71 changes: 47 additions & 24 deletions src/plone/restapi/tests/test_services_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
from plone.app.testing import SITE_OWNER_PASSWORD
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_PASSWORD
from plone.registry.interfaces import IRegistry
from plone.restapi.bbb import ISecuritySchema
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from plone.restapi.testing import RelativeSession
from Products.CMFCore.permissions import SetOwnPassword
from Products.CMFCore.utils import getToolByName
from Products.MailHost.interfaces import IMailHost
from zope.component import getAdapter
from zope.component import getUtility

import base64
Expand Down Expand Up @@ -212,7 +212,8 @@ def test_add_user_password_is_required(self):

def test_add_user_email_is_required_if_email_login_is_enabled(self):
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
transaction.commit()
response = self.api_session.post(
Expand All @@ -225,7 +226,8 @@ def test_add_user_email_is_required_if_email_login_is_enabled(self):

def test_add_user_email_with_email_login_enabled(self):
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
transaction.commit()
response = self.api_session.post(
Expand All @@ -242,7 +244,8 @@ def test_add_user_email_with_email_login_enabled(self):

def test_username_is_not_allowed_with_email_login_enabled(self):
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
transaction.commit()
response = self.api_session.post(
Expand All @@ -260,7 +263,8 @@ def test_username_is_not_allowed_with_email_login_enabled(self):

def test_add_user_with_email_login_enabled(self):
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
transaction.commit()
response = self.api_session.post(
Expand Down Expand Up @@ -313,7 +317,8 @@ def test_add_user_send_properties(self):
self.assertEqual(member.getProperty("fullname"), "Howard Zinn")

def test_add_anon_user_sends_properties_are_saved(self):
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.enable_self_reg = True
transaction.commit()

Expand All @@ -335,7 +340,8 @@ def test_add_anon_no_roles(self):
"""Make sure anonymous users cannot set their own roles.
Allowing so would make them Manager.
"""
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.enable_self_reg = True
transaction.commit()

Expand All @@ -356,7 +362,8 @@ def test_add_anon_no_roles(self):

def test_add_user_with_uuid_as_userid_enabled(self):
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
security_settings.use_uuid_as_userid = True
transaction.commit()
Expand Down Expand Up @@ -844,7 +851,8 @@ def test_reset_with_token_validates_password(self):

def test_reset_with_uuid_as_userid_and_login_email_using_id(self):
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
security_settings.use_uuid_as_userid = True
transaction.commit()
Expand Down Expand Up @@ -877,7 +885,8 @@ def test_reset_with_uuid_as_userid_and_login_email_using_id(self):

def test_reset_with_uuid_as_userid_and_login_email_using_mail(self):
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
security_settings.use_uuid_as_userid = True
transaction.commit()
Expand Down Expand Up @@ -910,7 +919,8 @@ def test_reset_with_uuid_as_userid_and_login_email_using_mail(self):

def test_reset_and_login_email_using_mail(self):
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
transaction.commit()

Expand Down Expand Up @@ -1000,7 +1010,8 @@ def test_delete_non_existing_user(self):
self.assertEqual(response.status_code, 404)

def test_anonymous_requires_enable_self_reg(self):
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.enable_self_reg = False
transaction.commit()

Expand All @@ -1026,7 +1037,8 @@ def test_anonymous_requires_enable_self_reg(self):
self.assertEqual(201, response.status_code)

def test_anonymous_without_enable_user_pwd_choice_sends_mail(self):
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.enable_self_reg = True
transaction.commit()

Expand All @@ -1047,7 +1059,8 @@ def test_anonymous_without_enable_user_pwd_choice_sends_mail(self):
self.assertTrue("To: avram.chomsky@example.com" in msg)

def test_anonymous_with_sendPasswordReset_sends_mail(self):
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.enable_self_reg = True
security_settings.use_email_as_login = True
transaction.commit()
Expand All @@ -1070,7 +1083,8 @@ def test_anonymous_with_sendPasswordReset_sends_mail(self):
self.assertTrue("To: avram.chomsky@example.com" in msg)

def test_anonymous_can_set_password_with_enable_user_pwd_choice(self):
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.enable_self_reg = True
transaction.commit()

Expand Down Expand Up @@ -1103,7 +1117,8 @@ def test_anonymous_can_set_password_with_enable_user_pwd_choice(self):
self.assertEqual(201, response.status_code)

def test_anonymous_with_enable_user_pwd_choice_doent_send_email(self):
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.enable_self_reg = True
security_settings.enable_user_pwd_choice = True
transaction.commit()
Expand All @@ -1122,7 +1137,8 @@ def test_anonymous_with_enable_user_pwd_choice_doent_send_email(self):
self.assertEqual(201, response.status_code)

def test_anonymous_with_enable_user_sets_only_member_role(self):
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.enable_self_reg = True
security_settings.enable_user_pwd_choice = True
transaction.commit()
Expand Down Expand Up @@ -1261,7 +1277,8 @@ def test_get_user_portrait_anonymous(self):

def test_get_user_portrait_if_email_login_enabled(self):
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
transaction.commit()

Expand Down Expand Up @@ -1498,7 +1515,8 @@ def test_manager_changes_email_when_login_with_email(self):
they can log in with the new email
"""
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
transaction.commit()
# Create a user
Expand Down Expand Up @@ -1551,7 +1569,8 @@ def test_user_changes_email_when_login_with_email(self):
they can log in with the new email
"""
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
transaction.commit()
# Create a user
Expand Down Expand Up @@ -1611,7 +1630,8 @@ def test_manager_changes_email_when_login_with_email_and_uuid_userids(self):

"""
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
security_settings.use_uuid_as_userid = True
transaction.commit()
Expand Down Expand Up @@ -1667,7 +1687,8 @@ def test_user_changes_email_when_login_with_email_and_uuid_userids(self):

"""
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
security_settings.use_uuid_as_userid = True

Expand Down Expand Up @@ -1725,7 +1746,8 @@ def test_manager_changes_email_to_existing_when_login_with_email(self):
to a previously existing one
"""
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
transaction.commit()

Expand Down Expand Up @@ -1792,7 +1814,8 @@ def test_user_changes_email_to_existing_one_when_login_with_email(self):
they can log in with the new email
"""
# enable use_email_as_login
security_settings = getAdapter(self.portal, ISecuritySchema)
registry = getUtility(IRegistry)
security_settings = registry.forInterface(ISecuritySchema, prefix="plone")
security_settings.use_email_as_login = True
transaction.commit()

Expand Down
Loading