Skip to content

Commit

Permalink
Fixing build.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-batranu committed Jan 17, 2025
1 parent 5d543b6 commit 4c03fdf
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 45 deletions.
4 changes: 2 additions & 2 deletions constraints_plone60.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
#certifi ; platform_system == 'Windows'
tox==4.3.5
isort>=5
black==22.8.0
flake8==5.0.4
black==24.10.0
flake8==7.1.1
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,18 @@ zope = ["App", "zope", "BTrees", "z*", "Acquisition", "DateTime"]
products = ["Products"]
cmf = ["Products.CMF*"]
plone = ["plone", "collective"]


[tool.isort]
profile = "black"
force_single_line = true
line_length = 79
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "ZOPE", "PRODUCTS", "CMF", "PLONE", "FIRSTPARTY", "LOCALFOLDER"]

known_first_party = ["edw", "eea", "pas.plugins.eea"]
known_third_party = ["chameleon", "graphene", "pycountry", "dateutil", "graphql", "reportlab"]

known_zope = ["App", "zope", "BTrees", "z*", "Acquisition", "DateTime"]
known_products = ["Products"]
known_cmf = ["Products.CMF*"]
known_plone = ["plone", "collective"]
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from setuptools import find_packages
from setuptools import setup


long_description = "\n\n".join(
[
open("README.md").read(),
Expand Down
1 change: 0 additions & 1 deletion src/pas/plugins/eea/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
"""Init and utils."""
from zope.i18nmessageid import MessageFactory


_ = MessageFactory("pas.plugins.eea")
19 changes: 11 additions & 8 deletions src/pas/plugins/eea/browser/user_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
from logging import getLogger

import requests
from pas.plugins.authomatic.interfaces import \
DEFAULT_ID as DEFAULT_AUTHOMATIC_ID
from plone import api
from plone import schema
from plone.autoform.form import AutoExtensibleForm
from pas.plugins.authomatic.interfaces import (
DEFAULT_ID as DEFAULT_AUTHOMATIC_ID,
)

from z3c.form import button
from z3c.form import form
from zope.interface import Interface

from plone import api
from plone import schema
from plone.autoform.form import AutoExtensibleForm

from pas.plugins.eea.utils import get_plugin

logger = getLogger(__name__)
Expand Down Expand Up @@ -41,8 +44,7 @@ def handleApply(self, action):

@button.buttonAndHandler("Cancel")
def handleCancel(self, action):
"""User cancelled. Redirect back to the front page.
"""
"""User cancelled. Redirect back to the front page."""
return self.request.response.redirect(api.portal.get().absolute_url())

def do_sync(self):
Expand All @@ -66,7 +68,8 @@ def do_sync(self):

response = plugin.queryApiEndpoint(
f"https://graph.microsoft.com/v1.0/users/{provider_uuid}",
session=session)
session=session,
)

if response.status_code == 200:
info = response.json()
Expand Down
2 changes: 2 additions & 0 deletions src/pas/plugins/eea/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
-->
<!--<includeDependencies package="." />-->

<include package="pas.plugins.authomatic" />

<!-- has to be loaded before permissions are used, so keep above views aso. -->
<include file="permissions.zcml" />

Expand Down
46 changes: 21 additions & 25 deletions src/pas/plugins/eea/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
import requests
from AccessControl import ClassSecurityInfo
from AccessControl.class_init import InitializeClass
from pas.plugins.authomatic.useridentities import UserIdentities
from pas.plugins.authomatic.useridentities import UserIdentity
from pas.plugins.authomatic.utils import authomatic_cfg

from zope.interface import alsoProvides
from zope.interface import implementer

from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.PlonePAS.interfaces.group import IGroupIntrospection
from Products.PlonePAS.interfaces.group import IGroupManagement
from Products.PlonePAS.plugins.autogroup import VirtualGroup
from Products.PluggableAuthService.UserPropertySheet import UserPropertySheet
from Products.PluggableAuthService.interfaces import plugins as pas_interfaces
from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin
from pas.plugins.authomatic.useridentities import UserIdentities
from pas.plugins.authomatic.useridentities import UserIdentity
from pas.plugins.authomatic.utils import authomatic_cfg
from Products.PluggableAuthService.UserPropertySheet import UserPropertySheet

from plone import api
from plone.memoize import ram
from plone.protect.interfaces import IDisableCSRFProtection
from zope.interface import alsoProvides
from zope.interface import implementer

from pas.plugins.eea.utils import get_authomatic_plugin
from pas.plugins.eea.utils import get_provider_name
Expand Down Expand Up @@ -116,9 +119,7 @@ def _getMSAccessToken(self):
domain = cfg.get("domain")

if domain:
url = (
f"https://login.microsoftonline.com/{domain}/oauth2/v2.0/token"
)
url = f"https://login.microsoftonline.com/{domain}/oauth2/v2.0/token"
headers = {"Content-Type": "application/x-www-form-urlencoded"}

data = {
Expand All @@ -131,16 +132,15 @@ def _getMSAccessToken(self):
response = requests.post(url, headers=headers, data=data)
token_data = response.json()

MS_TOKEN_CACHE = {
"expires": time() + token_data["expires_in"] - 60
}
MS_TOKEN_CACHE = {"expires": time() + token_data["expires_in"] - 60}
MS_TOKEN_CACHE.update(token_data)
return MS_TOKEN_CACHE["access_token"]

@security.private
@ram.cache(_cachekey_query_api_endpoint)
def queryApiEndpoint(self, url, consistent=True, extra_headers=None,
session: requests.Session = None):
def queryApiEndpoint(
self, url, consistent=True, extra_headers=None, session: requests.Session = None
):
token = self._getMSAccessToken()

headers = {
Expand All @@ -167,9 +167,7 @@ def queryApiEndpointGetAll(self, url, *args, **kwargs):
yield from data.get("value", [data])
next_url = data.get("@odata.nextLink")
if next_url:
yield from self.queryApiEndpointGetAll(
next_url, *args, **kwargs
)
yield from self.queryApiEndpointGetAll(next_url, *args, **kwargs)

@security.private
def queryMSApiUsers(self, login=""):
Expand Down Expand Up @@ -232,8 +230,10 @@ def getServiceUuid(self, plone_uuid):
provider_name = get_provider_name(authomatic_cfg())
plone_uuid_to_provider_uuid = {
v: provider_uuid
for (name, provider_uuid), v
in authomatic_plugin._userid_by_identityinfo.items()
for (
name,
provider_uuid,
), v in authomatic_plugin._userid_by_identityinfo.items()
if name == provider_name
}
return plone_uuid_to_provider_uuid.get(plone_uuid, plone_uuid)
Expand Down Expand Up @@ -264,9 +264,7 @@ def rememberUsers(self, users):
schema=None,
**{"fullname": user["fullname"], "email": user["email"]},
)
authomatic_plugin._useridentities_by_userid[userid] = (
useridentities
)
authomatic_plugin._useridentities_by_userid[userid] = useridentities
authomatic_plugin._userid_by_identityinfo[user_key] = userid
# replace provider id with internal plone uuid
user["id"] = userid
Expand Down Expand Up @@ -340,9 +338,7 @@ def updateGroup(self, *args, **kw):

@security.private
def setRolesForGroup(self, group_id, roles=()):
rmanagers = self._getPlugins().listPlugins(
pas_interfaces.IRoleAssignerPlugin
)
rmanagers = self._getPlugins().listPlugins(pas_interfaces.IRoleAssignerPlugin)
if not (rmanagers):
raise NotImplementedError(
"There is no plugin that can assign roles to groups"
Expand Down
3 changes: 2 additions & 1 deletion src/pas/plugins/eea/setuphandlers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from plone.base.interfaces import INonInstallable
from zope.interface import implementer

from plone.base.interfaces import INonInstallable

from .interfaces import DEFAULT_ID
from .plugin import EEAEntraPlugin

Expand Down
2 changes: 1 addition & 1 deletion src/pas/plugins/eea/testing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import applyProfile
from plone.testing import z2
Expand Down
12 changes: 9 additions & 3 deletions src/pas/plugins/eea/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from plone.app.testing import TEST_USER_ID
from plone.app.testing import setRoles

from pas.plugins.eea.testing import PAS_PLUGINS_EEA_INTEGRATION_TESTING # noqa: E501
from pas.plugins.eea.testing import ( # noqa: E501
PAS_PLUGINS_EEA_INTEGRATION_TESTING,
)

try:
from Products.CMFPlone.utils import get_installer
Expand All @@ -26,16 +28,19 @@ def setUp(self):
self.installer = get_installer(self.portal, self.layer["request"])
else:
self.installer = api.portal.get_tool("portal_quickinstaller")
self.installer.install_product("pas.plugins.authomatic")
self.installer.install_product("pas.plugins.eea")

def test_product_installed(self):
"""Test if pas.plugins.eea is installed."""
self.assertTrue(self.installer.is_product_installed("pas.plugins.eea"))

def test_browserlayer(self):
"""Test that IPasPluginsEeaLayer is registered."""
from pas.plugins.eea.interfaces import IPasPluginsEeaLayer
from plone.browserlayer import utils

from pas.plugins.eea.interfaces import IPasPluginsEeaLayer

self.assertIn(IPasPluginsEeaLayer, utils.registered_layers())


Expand All @@ -60,7 +65,8 @@ def test_product_uninstalled(self):

def test_browserlayer_removed(self):
"""Test that IPasPluginsEeaLayer is removed."""
from pas.plugins.eea.interfaces import IPasPluginsEeaLayer
from plone.browserlayer import utils

from pas.plugins.eea.interfaces import IPasPluginsEeaLayer

self.assertNotIn(IPasPluginsEeaLayer, utils.registered_layers())
16 changes: 13 additions & 3 deletions src/pas/plugins/eea/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
from pas.plugins.authomatic.interfaces import DEFAULT_ID as DEFAULT_AUTHOMATIC_ID
import typing

from pas.plugins.authomatic.interfaces import (
DEFAULT_ID as DEFAULT_AUTHOMATIC_ID,
)

from plone import api

from .interfaces import DEFAULT_ID

if typing.TYPE_CHECKING:
from pas.plugins.authomatic.plugin import AuthomaticPlugin

from pas.plugins.eea.plugin import EEAEntraPlugin


def get_plugin() -> 'pas.plugins.eea.plugin.EEAEntraPlugin':
def get_plugin() -> "EEAEntraPlugin":
return api.portal.get().acl_users.get(DEFAULT_ID)


def get_authomatic_plugin() -> 'pas.plugins.authomatic.plugin.AuthomaticPlugin':
def get_authomatic_plugin() -> "AuthomaticPlugin":
return api.portal.get().acl_users.get(DEFAULT_AUTHOMATIC_ID)


Expand Down

0 comments on commit 4c03fdf

Please sign in to comment.