[Python-checkins] r56590 - in tracker/instances: python-dev-spambayes-integration/html/file.item.html python-dev-spambayes-integration/html/issue.item.html python-dev-spambayes-integration/html/msg.item.html python-dev-spambayes-integration/schema.py spambayes_integration/detectors/config.ini.template spambayes_integration/detectors/spambayes.py spambayes_integration/extensions/spambayes.py
erik.forsberg
python-checkins at python.org
Fri Jul 27 22:27:34 CEST 2007
Author: erik.forsberg
Date: Fri Jul 27 22:27:34 2007
New Revision: 56590
Modified:
tracker/instances/python-dev-spambayes-integration/html/file.item.html
tracker/instances/python-dev-spambayes-integration/html/issue.item.html
tracker/instances/python-dev-spambayes-integration/html/msg.item.html
tracker/instances/python-dev-spambayes-integration/schema.py
tracker/instances/spambayes_integration/detectors/config.ini.template
tracker/instances/spambayes_integration/detectors/spambayes.py
tracker/instances/spambayes_integration/extensions/spambayes.py
Log:
Remade spambayes integration, this time using the roundup's built-in
permissions system, which I understand better now, 2 hours later :-).
Modified: tracker/instances/python-dev-spambayes-integration/html/file.item.html
==============================================================================
--- tracker/instances/python-dev-spambayes-integration/html/file.item.html (original)
+++ tracker/instances/python-dev-spambayes-integration/html/file.item.html Fri Jul 27 22:27:34 2007
@@ -56,11 +56,11 @@
<p tal:condition="python:utils.sb_is_spam(context)" class="error-message">
File has been classified as spam.</p>
-<a tal:condition="python:context.id and utils.sb_is_view_ok(context)"
+<a tal:condition="python:context.id and context.content.is_view_ok()"
tal:attributes="href string:file${context/id}/${context/name}"
i18n:translate="">download</a>
-<p tal:condition="python:context.id and not utils.sb_is_view_ok(context)">
+<p tal:condition="python:context.id and not context.content.is_view_ok()">
Files classified as spam are not available for download by
unathorized users. If you think the file has been misclassified,
please login and click on the button for reclassification.
Modified: tracker/instances/python-dev-spambayes-integration/html/issue.item.html
==============================================================================
--- tracker/instances/python-dev-spambayes-integration/html/issue.item.html (original)
+++ tracker/instances/python-dev-spambayes-integration/html/issue.item.html Fri Jul 27 22:27:34 2007
@@ -247,7 +247,7 @@
tal:condition="python:utils.sb_is_spam(msg)">
Message has been classified as spam.
</p>
- <pre tal:condition="python:utils.sb_is_view_ok(msg)"
+ <pre tal:condition="python:msg.content.is_view_ok()"
tal:content="structure msg/content/hyperlinked">content</pre>
</td>
</tr>
Modified: tracker/instances/python-dev-spambayes-integration/html/msg.item.html
==============================================================================
--- tracker/instances/python-dev-spambayes-integration/html/msg.item.html (original)
+++ tracker/instances/python-dev-spambayes-integration/html/msg.item.html Fri Jul 27 22:27:34 2007
@@ -67,7 +67,8 @@
<tr>
<th class="header" i18n:translate="">Content</th>
- <th class="header" tal:condition="python:utils.sb_may_classify(context)">
+ <th class="header"
+ tal:condition="python:request.user.hasPermission('SB: May Classify')">
<form method="POST" onSubmit="return submit_once()"
enctype="multipart/form-data"
tal:attributes="action context/designator">
@@ -82,10 +83,11 @@
<tr>
<td class="content" colspan=2
- tal:condition="python:utils.sb_is_view_ok(context)"><pre
+ tal:condition="python:context.content.is_view_ok()">
+ <pre
tal:content="structure context/content/hyperlinked"></pre></td>
<td class="content" colspan=2
- tal:condition="python:not utils.sb_is_view_ok(context)">
+ tal:condition="python:not context.content.is_view_ok()">
Message has been classified as spam and is therefore not
available to unathorized users. If you think this is
incorrect, please login and report the message as being
Modified: tracker/instances/python-dev-spambayes-integration/schema.py
==============================================================================
--- tracker/instances/python-dev-spambayes-integration/schema.py (original)
+++ tracker/instances/python-dev-spambayes-integration/schema.py Fri Jul 27 22:27:34 2007
@@ -134,6 +134,9 @@
db.security.addRole(name='Developer', description='A developer')
db.security.addRole(name='Coordinator', description='A coordinator')
+sb_may_classify = db.security.addPermission(name="SB: May Classify")
+sb_may_report_misclassified = db.security.addPermission(name="SB: May Report Misclassified")
+
#
# REGULAR USERS
#
@@ -166,15 +169,13 @@
return True
if score > cutoff_score:
- roles = set(db.user.get(userid, "roles").lower().split(","))
- allowed = set(db.config.detectors['SPAMBAYES_MAY_VIEW_SPAM'].lower().split(","))
- return bool(roles.intersection(allowed))
+ return False
return True
for cl in ('file', 'msg'):
p = db.security.addPermission(name='View', klass=cl,
- description="allowed to see metadata of file object regardless of spam status",
+ description="allowed to see metadata object regardless of spam status",
properties=('creation', 'activity',
'creator', 'actor',
'name', 'spambayes_score',
@@ -185,22 +186,25 @@
))
db.security.addPermissionToRole('Anonymous', p)
- db.security.addPermissionToRole('User', p)
+ db.security.addPermissionToRole('User', p)
+
+ db.security.addPermissionToRole('User', 'Create', cl)
+
+ p = db.security.addPermission(name='View', klass=cl,
+ description="Allowed to see content of object regardless of spam status",
+ properties = ('content', 'summary'))
+ db.security.addPermissionToRole('User', p)
spamcheck = db.security.addPermission(name='View', klass=cl,
- description="allowed to see metadata of file object regardless of spam status",
+ description="allowed to see content if not spam",
properties=('content', 'summary'),
check=may_view_spam(cl))
-
- db.security.addPermissionToRole('User', spamcheck)
+
db.security.addPermissionToRole('Anonymous', spamcheck)
-for cl in 'file', 'msg':
- db.security.addPermissionToRole('User', 'Create', cl)
-
p = db.security.addPermission(name='Create', klass='issue',
properties=('title', 'type',
'components', 'versions',
@@ -217,6 +221,9 @@
description='User can report and discuss issues')
db.security.addPermissionToRole('User', p)
+db.security.addPermissionToRole('User', 'SB: May Report Misclassified')
+
+
##########################
# Developer permissions
@@ -240,6 +247,8 @@
db.security.addPermissionToRole('Coordinator', 'Edit', cl)
db.security.addPermissionToRole('Coordinator', 'Create', cl)
+db.security.addPermissionToRole('Coordinator', 'SB: May Classify')
+
# May users view other user information? Comment these lines out
# if you don't want them to
db.security.addPermissionToRole('User', 'View', 'user')
@@ -314,7 +323,10 @@
db.security.addPermissionToRole('Anonymous', 'Create', 'user')
# Allow anonymous users access to view issues (and the related, linked
-# information)
+# information).
+# Note permissions settings for file and msg above (due to spambayes
+# integration).
+
for cl in 'issue', 'severity', 'status', 'resolution':
db.security.addPermissionToRole('Anonymous', 'View', cl)
Modified: tracker/instances/spambayes_integration/detectors/config.ini.template
==============================================================================
--- tracker/instances/spambayes_integration/detectors/config.ini.template (original)
+++ tracker/instances/spambayes_integration/detectors/config.ini.template Fri Jul 27 22:27:34 2007
@@ -5,7 +5,3 @@
# config.
spambayes_ham_cutoff = 0.2
spambayes_spam_cutoff = 0.85
-
-spambayes_may_view_spam = User,Coordinator,Developer
-spambayes_may_classify = Coordinator
-spambayes_may_report_misclassified = User,Coordinator,Developer
Modified: tracker/instances/spambayes_integration/detectors/spambayes.py
==============================================================================
--- tracker/instances/spambayes_integration/detectors/spambayes.py (original)
+++ tracker/instances/spambayes_integration/detectors/spambayes.py Fri Jul 27 22:27:34 2007
@@ -1,13 +1,3 @@
-"""
-spamcheck.py - Auditor that consults a SpamBayes server and scores all form
-submissions. Submissions which are deemed to be spam are rejected. For the
-time being only reject submissions which are assumed to be spam (score >=
-SPAM_CUTOFF). Once a reasonable body of ham and spam submissions have been
-built up you can consider whether to also reject unsure submissions (score >
-HAM_CUTOFF). The current settings make it less likely that you'll reject
-valid submissions at the expense of manual checks to correct spammy items
-which snuck by the screen.
-"""
import xmlrpclib
import socket
@@ -58,8 +48,8 @@
if newvalues.has_key('spambayes_score'):
- if not "coordinator" in [x.lower().strip() for x in db.user.get(db.getuid(), 'roles').split(",")]:
- raise ValueError, "Only Coordinators may explicitly assign spambayes_score"
+ if not db.security.hasPermission('SB: May Classify', db.getuid()):
+ raise ValueError, "You don't have permission to spamclassify messages"
# Don't do anything if we're explicitly setting the score
return
Modified: tracker/instances/spambayes_integration/extensions/spambayes.py
==============================================================================
--- tracker/instances/spambayes_integration/extensions/spambayes.py (original)
+++ tracker/instances/spambayes_integration/extensions/spambayes.py Fri Jul 27 22:27:34 2007
@@ -28,6 +28,8 @@
class SpambayesClassify(Action):
+ permissionType = 'SB: May Classify'
+
def handle(self):
(content, tokens) = extract_classinfo(self.db,
self.classname, self.nodeid)
@@ -61,15 +63,6 @@
klass.set(self.nodeid, **props)
self.db.commit()
- def permission(self):
- roles = set(self.db.user.get(self.userid, 'roles').lower().split(","))
- allowed = set(self.db.config.detectors['SPAMBAYES_MAY_CLASSIFY'].lower().split(","))
-
- if not bool(roles.intersection(allowed)):
- raise Unauthorised("You do not have permission to train spambayes")
- Action.permission(self)
-
-
def sb_is_spam(obj):
cutoff_score = float(obj._db.config.detectors['SPAMBAYES_SPAM_CUTOFF'])
try:
@@ -78,34 +71,7 @@
return False
return score >= cutoff_score
-def sb_is_view_ok(obj):
- if not sb_is_spam(obj):
- return True
- roles = set(obj._db.user.get(obj._client.userid,
- 'roles').lower().split(","))
- allowed = set(obj._db.config.detectors['SPAMBAYES_MAY_VIEW_SPAM'].lower().split(","))
-
- return bool(roles.intersection(allowed))
-
-def sb_may_report_misclassified(obj):
- roles = set(obj._db.user.get(obj._client.userid,
- 'roles').lower().split(","))
- allowed = set(obj._db.config.detectors['SPAMBAYES_MAY_REPORT_MISCLASSIFIED'].lower().split(","))
-
- return bool(roles.intersection(allowed))
-
-def sb_may_classify(obj):
- roles = set(obj._db.user.get(obj._client.userid,
- 'roles').lower().split(","))
- allowed = set(obj._db.config.detectors['SPAMBAYES_MAY_CLASSIFY'].lower().split(","))
-
- return bool(roles.intersection(allowed))
-
def init(instance):
instance.registerAction("spambayes_classify", SpambayesClassify)
instance.registerUtil('sb_is_spam', sb_is_spam)
- instance.registerUtil('sb_is_view_ok', sb_is_view_ok)
- instance.registerUtil('sb_may_report_misclassified',
- sb_may_report_misclassified)
- instance.registerUtil('sb_may_classify', sb_may_classify)
More information about the Python-checkins
mailing list