-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from RedTurtle/read_field
Add 'read' field to the comment
- Loading branch information
Showing
21 changed files
with
289 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,4 @@ report.html | |
reports/ | ||
venv/ | ||
# excludes | ||
.python-version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,4 @@ | |
"""Init and utils.""" | ||
from zope.i18nmessageid import MessageFactory | ||
|
||
|
||
_ = MessageFactory("collective.feedback") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from plone.protect.interfaces import IDisableCSRFProtection | ||
from plone.restapi.deserializer import json_body | ||
from plone.restapi.services import Service | ||
from zExceptions import BadRequest, NotFound | ||
from zope.component import getUtility | ||
from zope.interface import alsoProvides, implementer | ||
from zope.publisher.interfaces import IPublishTraverse | ||
|
||
from collective.feedback.interfaces import ICollectiveFeedbackStore | ||
|
||
|
||
@implementer(IPublishTraverse) | ||
class FeedbackUpdate(Service): | ||
""" | ||
Service for update feedback to object, you can only update `read` field | ||
""" | ||
|
||
def __init__(self, context, request): | ||
super().__init__(context, request) | ||
self.params = [] | ||
|
||
def publishTraverse(self, request, id): | ||
# Consume any path segments after /@users as parameters | ||
self.params.append(id) | ||
return self | ||
|
||
def reply(self): | ||
alsoProvides(self.request, IDisableCSRFProtection) | ||
|
||
tool = getUtility(ICollectiveFeedbackStore) | ||
|
||
if self.params: | ||
try: | ||
id = int(self.params[0]) | ||
except ValueError: | ||
raise BadRequest(f"Bad id={self.params[0]} format provided") | ||
|
||
comment = tool.get(id) | ||
|
||
if comment.get("error", "") == "NotFound": | ||
raise NotFound() | ||
|
||
form_data = json_body(self.request) | ||
|
||
self.validate_form(form_data=form_data) | ||
|
||
form_data = self.extract_data(form_data) | ||
|
||
try: | ||
res = tool.update(id, form_data) | ||
except ValueError as e: | ||
self.request.response.setStatus(500) | ||
return dict( | ||
error=dict( | ||
type="InternalServerError", | ||
message=getattr(e, "message", e.__str__()), | ||
) | ||
) | ||
|
||
if res is None: | ||
return self.reply_no_content() | ||
|
||
self.request.response.setStatus(500) | ||
|
||
return dict( | ||
error=dict( | ||
type="InternalServerError", | ||
message="Unable to add. Contact site manager.", | ||
) | ||
) | ||
|
||
def extract_data(sefl, form_data): | ||
return {"read": form_data.get("read")} | ||
|
||
def validate_form(self, form_data): | ||
""" | ||
check all required fields and parameters | ||
""" | ||
for field in ["read"]: | ||
value = form_data.get(field, None) | ||
if value is None: | ||
raise BadRequest("Campo obbligatorio mancante: {}".format(field)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.