mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-25 06:48:01 -05:00
Modify /api/subscribe to accept "sr_name" param to support subscribing subreddits by name.
This commit is contained in:
@@ -1747,7 +1747,7 @@ class ApiController(RedditController):
|
||||
@noresponse(VUser(),
|
||||
VModhash(),
|
||||
action = VOneOf('action', ('sub', 'unsub')),
|
||||
sr = VByName('sr'))
|
||||
sr = VSubscribeSR('sr', 'sr_name'))
|
||||
def POST_subscribe(self, action, sr):
|
||||
# only users who can make edits are allowed to subscribe.
|
||||
# Anyone can leave.
|
||||
|
||||
@@ -826,6 +826,24 @@ class VSubmitSR(Validator):
|
||||
|
||||
return sr
|
||||
|
||||
class VSubscribeSR(VByName):
|
||||
def __init__(self, srid_param, srname_param):
|
||||
VByName.__init__(self, (srid_param, srname_param))
|
||||
|
||||
def run(self, sr_id, sr_name):
|
||||
if sr_id:
|
||||
return VByName.run(self, sr_id)
|
||||
elif not sr_name:
|
||||
return
|
||||
|
||||
try:
|
||||
sr = Subreddit._by_name(str(sr_name).strip())
|
||||
except (NotFound, AttributeError, UnicodeEncodeError):
|
||||
self.set_error(errors.SUBREDDIT_NOEXIST)
|
||||
return
|
||||
|
||||
return sr
|
||||
|
||||
MIN_PASSWORD_LENGTH = 3
|
||||
|
||||
class VPassword(Validator):
|
||||
|
||||
Reference in New Issue
Block a user