From 1e1435be14514be461a4e83d17f56080232bc589 Mon Sep 17 00:00:00 2001 From: Andre D Date: Mon, 20 May 2013 22:35:49 -0700 Subject: [PATCH] banning: Add an endpoint to add a note to banned users. --- r2/r2/config/routing.py | 3 +++ r2/r2/controllers/api.py | 7 +++++++ r2/r2/models/subreddit.py | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/r2/r2/config/routing.py b/r2/r2/config/routing.py index 38f306189..2f4d7cbf9 100644 --- a/r2/r2/config/routing.py +++ b/r2/r2/config/routing.py @@ -303,6 +303,9 @@ def make_map(): "add_roadblock|rm_roadblock"))) mc('/api/:action', controller='apiminimal', requirements=dict(action="new_captcha")) + mc('/api/:type', controller='api', + requirements=dict(type='wikibannednote|bannednote'), + action='relnote') mc('/api/:action', controller='api') mc("/api/v1/:action", controller="oauth2frontend", diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 2e490a05f..b9f9fcec5 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -813,6 +813,13 @@ class ApiController(RedditController, OAuth2ResourceController): c.user.add_friend_note(friend, note) form.set_html('.status', _("saved")) + @validatedForm(type = VOneOf('type', ('bannednote', 'wikibannednote')), + user = VExistingUname('name'), + note = VLength('note', 300)) + def POST_relnote(self, form, jquery, type, user, note): + c.site.add_rel_note(type[:-4], user, note) + form.set_html('.status', _("saved")) + @validatedForm(VUser(), VModhash(), ip=ValidIP()) diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 6e85aa8de..b4ef81776 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -883,6 +883,12 @@ class Subreddit(Thing, Printable): rel.update_permissions(**kwargs) rel._commit() + def add_rel_note(self, type, user, note): + rel = getattr(self, "get_%s" % type)(user) + if not rel: + raise ValueError("User is not %s." % type) + rel.note = note + rel._commit() class FakeSubreddit(Subreddit): over_18 = False