Opened 10 years ago
Last modified 10 years ago
#11477 new enhancement
Extend ITicketManipulator (or similar) - Filter Comments — at Initial Version
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | unscheduled |
Component: | ticket system | Version: | 1.0.1 |
Severity: | normal | Keywords: | comment |
Cc: | olemis+trac@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Example:
Version 1.0.1 code in ticket/web_ui.py
def _get_comment_history(self, req, ticket, cnum): history = [] for version, date, author, comment in ticket.get_comment_history(cnum): history.append({ 'version': version, 'date': date, 'author': author, 'comment': _("''Initial version''") if version == 0 else '', 'value': comment, 'url': self._make_comment_url(req, ticket, cnum, version) }) return history
If ITicketManipulator in ticket/api.py contained a method like:
def comment_filter(self, req, version, date, author, comment): """Validate if a comment can be displayed Must return a 4-tuple corresponding to version, date, author, comment The 4 may be empty or None to "nullify display of the comment """
The code from above in web-ui.py could be rewritten as:
def _get_comment_history(self, req, ticket, cnum): history = [] for version, date, author, comment in ticket.get_comment_history(cnum): for manipulator in self.ticket_manipulators: version, date, author, comment = manipulator.comment_filter(req, version, date, author, comment) if version or date or author or comment: # Only if the comment has not been fully "nullified" add it to the list to display history.append({ 'version': version, 'date': date, 'author': author, 'comment': _("''Initial version''") if version == 0 else '', 'value': comment, 'url': self._make_comment_url(req, ticket, cnum, version) }) return history
This allows filtering of comments by Plugins which can create set of rules (user, group, permission based, …)
The existing PrivateCommentPlugin, http://trac-hacks.org/wiki/PrivateCommentPlugin is broken beyond 0.12 because it filters the Template Stream and needs to adapt to changes in the stream.
The proposed modification allows filtering "objects" rather than content and therefore eases up the creation of a Comment Filtering Plugin.