Skip to content

Commit

Permalink
URB-3148 Merge pull request #4 from IMIO/2.x
Browse files Browse the repository at this point in the history
2.x - REST API
  • Loading branch information
jimbiscuit authored Oct 10, 2024
2 parents 4b546e7 + 4cfa2c3 commit b924ede
Show file tree
Hide file tree
Showing 33 changed files with 1,869 additions and 786 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Tests

on: [ push ]

jobs:
tests:
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
include:
- python-version: "2.7.18"
plone-version: "4.3"
# - python-version: "3.8.15"
# plone-version: "5.2"
# - python-version: "3.11.2"
# plone-version: "6.0"
services:
libreoffice:
image: imiobe/libreoffice:7.3
ports:
- 2002:2002
volumes:
- /tmp:/tmp
- /var/tmp:/var/tmp
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Env
run: |
mkdir -p -m 777 /tmp/appy/
sudo add-apt-repository ppa:libreoffice/ppa -y
sudo apt update -qq -y
sudo apt-get install -qq -y libreoffice libreoffice-script-provider-python
mkdir -p buildout-cache/{eggs,downloads}
- name: Set up pyenv and Python
uses: "gabrielfalcao/pyenv-action@v17"
with:
default: "${{ matrix.python-version }}"
- name: Setup Python env
run: |
pip install --upgrade pip
pip install -r requirements-${{ matrix.plone-version }}.txt
- name: Cache eggs
uses: actions/cache@v2
env:
cache-name: cache-eggs
with:
path: ~/buildout-cache/eggs
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ matrix.plone-version }}
restore-keys: ${{ runner.os }}-test-${{ env.cache-name }}-${{ matrix.plone-version }}
- name: buildout
run: |
buildout
- name: test
run: |
bin/test -t !robot
24 changes: 20 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
Changelog
=========

1.18 (unreleased)
-----------------

- Nothing changed yet.
2.0.0b2 (unreleased)
--------------------

- Fix translation of overlay title
[mpeeters]
- Avoid an error if the user can not access to meetings
[mpeeters]
- Upgrade config for REST api
[mpeeters]
- Fixed all unit tests.
[aduchene]
- Add a new helper method `_rest_getDecidedMeetingDate` to get the actual decided meeting date.
[aduchene]


2.0.0b1 (2022-11-18)
--------------------

- Migrate to REST api
[mpeeters]


1.17 (2022-06-29)
Expand Down
3 changes: 2 additions & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ parts =
test
coverage
report
omelette

develop = .

Expand All @@ -34,7 +35,6 @@ eggs =
ipdb
Products.PloneMeeting [test]
imio.pm.wsclient [test]
z3c.soap [test]

environment = testenv
initialization =
Expand All @@ -58,3 +58,4 @@ initialization =

[versions]
imio.pm.wsclient =
gnureadline = 8.1.2
2 changes: 2 additions & 0 deletions requirements-4.3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
zc.buildout==2.13.3
setuptools==44.1.1
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# using buildout.pm
#setuptools == 38.2.4
#zc.buildout == 2.13.1
zc.buildout==2.13.3
setuptools==44.1.1
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os

version = '1.18.dev0'
version = '2.0.0b2.dev0'

setup(name='imio.pm.wsclient',
version=version,
Expand All @@ -20,7 +20,7 @@
keywords='',
author='Gauthier Bastien',
author_email='[email protected]',
url='http://svn.communesplone.org/svn/communesplone/imio.pm.wsclient/',
url='https://github.com/IMIO/imio.pm.wsclient',
license='GPL',
packages=find_packages('src'),
package_dir={'': 'src'},
Expand All @@ -32,10 +32,10 @@
'collective.z3cform.datagridfield',
'imio.pm.locales',
'plone.memoize',
# -*- Extra requirements: -*-
'suds-jurko',
'requests',
'six',
],
extras_require={'test': ['plone.app.testing', 'imio.pm.ws', 'mock']},
extras_require={'test': ['plone.app.testing', 'plonemeeting.restapi', 'mock']},
entry_points="""
# -*- Entry points: -*-
""",
Expand Down
17 changes: 4 additions & 13 deletions src/imio/pm/wsclient/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:soap="http://namespaces.zope.org/soap"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="imio.pm.wsclient">

Expand Down Expand Up @@ -45,7 +44,7 @@
layer="imio.pm.wsclient.interfaces.IWS4PMClientLayer"
name="send_to_plonemeeting_form"
class=".forms.SendToPloneMeetingWrapper"
permission="zope2.SOAPClientSend"
permission="ws.client.Send"
/>

<!-- define a specific template for rendering ContentProviders in z3c.form until it is in plone.app.z3cform... -->
Expand All @@ -63,7 +62,7 @@
layer="imio.pm.wsclient.interfaces.IWS4PMClientLayer"
name="generate_document_from_plonemeeting"
class=".views.GenerateItemTemplateView"
permission="zope2.SOAPClientAccess"
permission="ws.client.Access"
/>

<!-- View that downaload an annex of an item -->
Expand All @@ -72,7 +71,7 @@
layer="imio.pm.wsclient.interfaces.IWS4PMClientLayer"
name="download_annex_from_plonemeeting"
class=".views.DownloadAnnexFromItemView"
permission="zope2.SOAPClientAccess"
permission="ws.client.Access"
/>

<!-- Viewlets -->
Expand All @@ -81,7 +80,7 @@
layer="imio.pm.wsclient.interfaces.IWS4PMClientLayer"
manager="plone.app.layout.viewlets.interfaces.IBelowContentTitle"
class=".viewlets.PloneMeetingInfosViewlet"
permission="zope2.SOAPClientAccess"
permission="ws.client.Access"
/>

<!-- Vocabularies -->
Expand Down Expand Up @@ -141,12 +140,4 @@
directory="javascripts"
/>

<genericsetup:upgradeDepends
source="*"
destination="1.13"
title="Upgrade to 1.13"
profile="imio.pm.wsclient:default"
import_steps="plone.app.registry"
/>

</configure>
51 changes: 31 additions & 20 deletions src/imio/pm/wsclient/browser/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def getDisplayableData(self):
res = ['<fieldset><legend>{0}</legend>{1}</fieldset>'.format(
translate('PloneMeeting_label_' + extraAttr['key'],
domain="PloneMeeting",
context=self.request),
context=self.request).encode("utf-8"),
extraAttr['value']) for extraAttr in data[elt]]
data[elt] = '<br />'.join(res)

Expand Down Expand Up @@ -149,12 +149,16 @@ def __init__(self, context, request):
self.portal = self.portal_state.portal()
self.ws4pmSettings = getMultiAdapter((self.portal, self.request), name='ws4pmclient-settings')
# manage the label to display to wich meetingConfig we are sending the element...
self.label = translate('Send to',
domain='imio.pm.wsclient',
mapping={'meetingConfigTitle':
self.ws4pmSettings.getMeetingConfigTitle(self.meetingConfigId),
},
context=self.request)
self.label = translate(
_(
'Send to ${meetingConfigTitle}',
mapping={
'meetingConfigTitle': self.ws4pmSettings.getMeetingConfigTitle(self.meetingConfigId),
},
),
domain='imio.pm.wsclient',
context=self.request,
)

@button.buttonAndHandler(_('Send'), name='send_to_plonemeeting')
def handleSendToPloneMeeting(self, action):
Expand Down Expand Up @@ -187,16 +191,16 @@ def update(self):
# False means that is was not sent, so no connection test is made to PloneMeeting for performance reason
if alreadySent is not None:
# now connect to PloneMeeting
client = self.ws4pmSettings._soap_connectToPloneMeeting()
client = self.ws4pmSettings._rest_connectToPloneMeeting()
if alreadySent is None or not client:
IStatusMessage(self.request).addStatusMessage(_(UNABLE_TO_CONNECT_ERROR), "error")
self._changeFormForErrors()
return

# do not go further if current user can not create an item in
# PloneMeeting with any proposingGroup
userInfos = self.ws4pmSettings._soap_getUserInfos(showGroups=True, suffix='creators')
if not userInfos or 'groups' not in userInfos:
userInfos = self.ws4pmSettings._rest_getUserInfos(showGroups=True, suffix='creators')
if not userInfos or 'extra_include_groups' not in userInfos:
userThatWillCreate = self.ws4pmSettings._getUserIdToUseInTheNameOfWith()
if not userInfos:
IStatusMessage(self.request).addStatusMessage(
Expand Down Expand Up @@ -281,13 +285,13 @@ def _doSendToPloneMeeting(self):
settings.only_one_sending:
return False
# build the creationData
client = self.ws4pmSettings._soap_connectToPloneMeeting()
client = self.ws4pmSettings._rest_connectToPloneMeeting()
creation_data = self._getCreationData(client)

notify(WillbeSendToPMEvent(self.context))

# call the SOAP method actually creating the item
res = self.ws4pmSettings._soap_createItem(self.meetingConfigId,
# call the REST method actually creating the item
res = self.ws4pmSettings._rest_createItem(self.meetingConfigId,
self.proposingGroupId,
creation_data)
if res:
Expand Down Expand Up @@ -319,11 +323,14 @@ def _doSendToPloneMeeting(self):
def _getCreationData(self, client):
"""
Build creationData dict that will be used to actually create
the item in PloneMeeting thru SOAP createItem call
the item in PloneMeeting thru REST createItem call
"""
data = self._buildDataDict()
# now that every values are evaluated, build the CreationData
creation_data = client.factory.create('CreationData')
creation_data = {
k: "" for k in self.ws4pmSettings._rest_getItemCreationAvailableData()
if k in data.keys()
}
for elt in data:
# proposingGroup is managed apart
if elt == u'proposingGroup':
Expand All @@ -336,6 +343,7 @@ def _getCreationData(self, client):
creation_data[elt] = data[elt]
# initialize the externalIdentifier to the context UID
creation_data['externalIdentifier'] = self.context.UID()

return creation_data

def _buildDataDict(self):
Expand All @@ -344,10 +352,10 @@ def _buildDataDict(self):
data = OrderedDict()
settings = self.ws4pmSettings.settings()
# initialize annexes field from the form, not the field_mappings
data['annexes'] = self._buildAnnexesData()
data['__children__'] = self._buildAnnexesData()
data['preferredMeeting'] = self.request.form.get('form.widgets.preferredMeeting', [u'', ])[0]
# if preferredMeeting is '--NOVALUE--', remove it from data to send
if data['preferredMeeting'] == '--NOVALUE--':
if data['preferredMeeting'] in ('--NOVALUE--', ''):
data.pop('preferredMeeting')
# initialize category field in case it is not defined in field_mappings
data['category'] = self.request.form.get('form.widgets.category', [u'', ])[0]
Expand Down Expand Up @@ -395,9 +403,12 @@ def _buildAnnexesData(self):
annex_name = type(annex_file.name) in [unicode] and annex_file.name or annex_file.name.decode('utf-8')
annexes_data.append(
{
'title': unidecode(annex.title.decode('utf-8')),
'filename': unidecode(annex_name),
'file': base64.b64encode(annex_file.read()),
"@type": "annex",
"title": unidecode(annex.title.decode('utf-8')),
"file": {
"filename": unidecode(annex_name),
"data": base64.b64encode(annex_file.read()),
}
}
)
return annexes_data
Expand Down
Loading

0 comments on commit b924ede

Please sign in to comment.