Allow limited mods to demod themselves.

This commit is contained in:
Logan Hanks
2013-02-22 10:53:02 -08:00
parent 6a59536f4d
commit c751ff0132
2 changed files with 12 additions and 2 deletions

View File

@@ -592,11 +592,18 @@ class ApiController(RedditController, OAuth2ResourceController):
# The user who made the request must be an admin or a moderator
# for the privilege change to succeed.
# (Exception: a user can remove privilege from oneself)
victim = iuser or nuser
perm = 'wiki' if type.startswith('wiki') else 'access'
required_perms = []
if c.user != victim:
if type.startswith('wiki'):
required_perms.append('wiki')
else:
required_perms.append('access')
if (not c.user_is_admin
and (type in self._sr_friend_types
and not container.is_moderator_with_perms(c.user, perm))):
and not container.is_moderator_with_perms(
c.user, *required_perms))):
abort(403, 'forbidden')
if (type == 'moderator' and not
(c.user_is_admin or container.can_demod(c.user, victim))):

View File

@@ -459,6 +459,9 @@ class Subreddit(Thing, Printable):
def can_demod(self, bully, victim):
bully_rel = self.get_moderator(bully)
if bully_rel is not None and bully == victim:
# mods can always demod themselves
return True
victim_rel = self.get_moderator(victim)
return (
bully_rel is not None