Skip to content

Commit

Permalink
[refs #134160] fix my view bug
Browse files Browse the repository at this point in the history
  • Loading branch information
david-batranu committed Jun 11, 2021
1 parent 2e6db48 commit c2df14c
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 60 deletions.
4 changes: 4 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

2.5.24 (2021-06-11)

- Task #134160 - MS coordinator MyView bug.

2.5.23 (2021-06-02)

- Task #134554 - Missing fields for Sector Experts creating new observations
Expand Down
22 changes: 20 additions & 2 deletions emrt/necd/content/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from types import TupleType
from types import UnicodeType

import datetime

from zope.schema import getFieldsInOrder

from Products.CMFPlone.utils import safe_unicode
Expand Down Expand Up @@ -238,7 +240,15 @@ def observation_sent_to_msc(context):
winfo = question.workflow_history
was_or_is_pending = False
has_public_questions = False
for witem in winfo.get('esd-question-review-workflow', []):
this_year = datetime.datetime.now().year
# [refs #134160] only count events that happened this year
# as the Observation may be a carry-over.
witems = [
w
for w in winfo.get('esd-question-review-workflow', [])
if w["time"].year == this_year
]
for witem in witems:
if witem.get('review_state', '').endswith('pending'):
was_or_is_pending = True
break
Expand All @@ -259,7 +269,15 @@ def observation_sent_to_mse(context):
if questions:
question = questions[0]
winfo = question.workflow_history
for witem in winfo.get('esd-question-review-workflow', []):
this_year = datetime.datetime.now().year
# [refs #134160] only count events that happened this year
# as the Observation may be a carry-over.
witems = [
w
for w in winfo.get('esd-question-review-workflow', [])
if w["time"].year == this_year
]
for witem in witems:
if witem.get('review_state', '').endswith('expert-comments'):
return True
return False
Expand Down
54 changes: 30 additions & 24 deletions emrt/necd/content/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,19 @@ def validate(self, value, force=False):
category = get_category_ldap_from_nfr_code(value, self.context)
user = api.user.get_current()
groups = user.getGroups()
valid = False
ldap_wrapper = getUtility(IGetLDAPWrapper)(self.context)
ldap_se = ldap_wrapper(LDAP_SECTOREXP)
for group in groups:
if group.startswith('{}-{}-'.format(ldap_se, category)):
valid = True
break
if not valid:
raise Invalid(
u'You are not allowed to add observations '
u'for this sector category.'
)
if "Manager" not in api.user.get_roles(user=user):
valid = False
ldap_wrapper = getUtility(IGetLDAPWrapper)(self.context)
ldap_se = ldap_wrapper(LDAP_SECTOREXP)
for group in groups:
if group.startswith('{}-{}-'.format(ldap_se, category)):
valid = True
break
if not valid:
raise Invalid(
u'You are not allowed to add observations '
u'for this sector category.'
)


validator.WidgetValidatorDiscriminators(
Expand All @@ -349,21 +350,22 @@ class CountryContextValidator(validator.SimpleFieldValidator):
def validate(self, value):
user = api.user.get_current()
groups = user.getGroups()
valid = False
if "Manager" not in api.user.get_roles(user=user):
valid = False

ldap_wrapper = getUtility(IGetLDAPWrapper)(self.context)
ldap_se = ldap_wrapper(LDAP_SECTOREXP)
ldap_wrapper = getUtility(IGetLDAPWrapper)(self.context)
ldap_se = ldap_wrapper(LDAP_SECTOREXP)

for group in groups:
is_se = group.startswith('{}-'.format(ldap_se))
if is_se and group.endswith('-%s' % value):
valid = True
break
for group in groups:
is_se = group.startswith('{}-'.format(ldap_se))
if is_se and group.endswith('-%s' % value):
valid = True
break

if not valid:
raise Invalid(
u'You are not allowed to add observations for this country.'
)
if not valid:
raise Invalid(
u'You are not allowed to add observations for this country.'
)


validator.WidgetValidatorDiscriminators(
Expand Down Expand Up @@ -946,9 +948,13 @@ def observation_already_replied(self):
if questions:
question = questions[0]
winfo = question.workflow_history
this_year = datetime.datetime.now().year
# [refs #134160] only count events that happened this year
# as the Observation may be a carry-over.
states = [
w.get('review_state')
for w in winfo.get('esd-question-review-workflow', [])
if w["time"].year == this_year
]
if states:
sp = { s: idx for idx, s in enumerate(states) }
Expand Down
2 changes: 1 addition & 1 deletion emrt/necd/content/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<metadata>
<version>2.5.23</version>
<version>2.5.24</version>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
<dependency>profile-plone.app.ldap:ldap</dependency>
Expand Down
14 changes: 14 additions & 0 deletions emrt/necd/content/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,18 @@

</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
source="2.5.8"
destination="2.5.24"
profile="emrt.necd.content:default">


<genericsetup:upgradeStep
title="[refs #134160] Correctly index for current year."
description="Reindex 'observation_already_replied', 'observation_sent_to_msc' and 'observation_sent_to_mse'."
handler=".evolve2524.upgrade"
/>

</genericsetup:upgradeSteps>

</configure>
32 changes: 32 additions & 0 deletions emrt/necd/content/upgrades/evolve2524.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import logging
import transaction
import plone.api as api

from Products.CMFCore.utils import getToolByName
from emrt.necd.content.upgrades import portal_workflow as upw


logger = logging.getLogger(__name__)


IDX = "reply_comments_by_mse"


def upgrade(_):
portal = api.portal.get()
rf = ["2021", "2021-projection"]
rf = ["test-reviewfolder"]
for folder in [portal[f] for f in rf]:
for idx, obj in enumerate(folder.objectValues(), start=1):
if obj.portal_type == "Observation":
if idx % 1 == 0:
transaction.savepoint(optimistic=True)
logger.info("[%s] Reindexing %s...", idx, obj.absolute_url(1))
obj.reindexObject(
idxs=[
"observation_already_replied",
"observation_sent_to_msc",
"observation_sent_to_mse",
]
)
transaction.commit()
69 changes: 36 additions & 33 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,60 @@
from setuptools import setup, find_packages
import os

VERSION = '2.5.23'
from setuptools import find_packages
from setuptools import setup

VERSION = "2.5.24"


setup(
name='emrt.necd.content',
name="emrt.necd.content",
version=VERSION,
description="Content-types for EMRT-NECD Review Tool",
long_description=(
open("README.txt").read() + "\n" +
open(os.path.join("docs", "HISTORY.txt")).read()
open("README.txt").read()
+ "\n"
+ open(os.path.join("docs", "HISTORY.txt")).read()
),
# Get more strings from
# http://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
"Framework :: Plone",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords='',
author='Mikel Larreategi',
author_email='mlarreategi@codesyntax.com',
url='https://github.com/eea/emrt.necd.content/',
license='GPL',
packages=find_packages(exclude=['ez_setup']),
namespace_packages=['emrt', 'emrt.necd'],
],
keywords="",
author="Mikel Larreategi",
author_email="mlarreategi@codesyntax.com",
url="https://github.com/eea/emrt.necd.content/",
license="GPL",
packages=find_packages(exclude=["ez_setup"]),
namespace_packages=["emrt", "emrt.necd"],
include_package_data=True,
zip_safe=False,
install_requires=[
'setuptools',
'futures',
'plone.app.dexterity [relations]',
'plone.namedfile [blobs]',
'collective.z3cform.datagridfield',
'plone.api',
'Products.ATVocabularyManager',
'plone.app.versioningbehavior',
'plone.app.workflowmanager',
'plone.app.ldap',
'cs.htmlmailer',
'collective.deletepermission',
'tablib',
'python-docx==0.8.5',
'zc.dict',
'collective.monkeypatcher',
'openpyxl',
'five.pt',
'simplejson',
"setuptools",
"futures",
"plone.app.dexterity [relations]",
"plone.namedfile [blobs]",
"collective.z3cform.datagridfield",
"plone.api",
"Products.ATVocabularyManager",
"plone.app.versioningbehavior",
"plone.app.workflowmanager",
"plone.app.ldap",
"cs.htmlmailer",
"collective.deletepermission",
"tablib",
"python-docx==0.8.5",
"zc.dict",
"collective.monkeypatcher",
"openpyxl",
"five.pt",
"simplejson",
],
entry_points="""
# -*- Entry points: -*-
[z3c.autoinclude.plugin]
target = plone
""",
)
)

0 comments on commit c2df14c

Please sign in to comment.