Skip to content

JSON access to the moderation log #371

Closed
wants to merge 3 commits into from

5 participants

@yole
yole commented Mar 13, 2012

No description provided.

@spladug spladug commented on the diff Mar 13, 2012
r2/r2/lib/jsontemplates.py
+
+class ModActionJsonTemplate(ThingJsonTemplate):
+ _data_attrs_ = dict(date="date",
+ moderator="moderator",
+ subreddit="subreddit",
+ action="action",
+ target="target",
+ details="details",
+ description="description")
+
+ def thing_attr(self, thing, attr):
+ from r2.models.account import Account
+ from r2.models.subreddit import Subreddit
+
+ if attr == "moderator":
+ return Account._byID36(thing.mod_id36).name
@spladug
reddit member
spladug added a note Mar 13, 2012

I think this will leak the names of deleted accounts. Possibly need to use Wrapped here?

@yole
yole added a note Mar 13, 2012

Is that really a concern that one moderator will be able to see the deleted account of another moderator?

@kemitche
kemitche added a note Mar 13, 2012

Most things should be Wrapped() before grabbing data to send to the user, as that's the primary (though not sole) method used to ensure that data access is restricted to those with appropriate permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@chromakode chromakode commented on the diff Mar 13, 2012
r2/r2/lib/jsontemplates.py
+ details="details",
+ description="description")
+
+ def thing_attr(self, thing, attr):
+ from r2.models.account import Account
+ from r2.models.subreddit import Subreddit
+
+ if attr == "moderator":
+ return Account._byID36(thing.mod_id36).name
+ elif attr == "subreddit":
+ return Subreddit._byID36(thing.sr_id36).name
+ elif attr == "date":
+ return time.mktime(thing.date.timetuple())
+ elif attr == "target":
+ result = dict((key, getattr(thing.target, key, None))
+ for key in ["_fullname", "name", "url", "author", "title"])
@chromakode
chromakode added a note Mar 13, 2012

Upon further inspection, can we grab all of these by using getattr(thing, 'target_'+key, None) instead of involving the target?

Should the "url" key be permalink (similar to thing.target_path)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bboe bboe commented on the diff Mar 13, 2012
r2/r2/lib/jsontemplates.py
@@ -543,3 +543,42 @@ def row_to_json(row):
class FlairCsvJsonTemplate(JsonTemplate):
def render(self, thing, *a, **kw):
return ObjectTemplate([l.__dict__ for l in thing.results_by_line])
+
+
+class ModActionListingJsonTemplate(ListingJsonTemplate):
+ def kind(self, wrapped):
+ return "ModActionListing"
+
+
+class ModActionJsonTemplate(ThingJsonTemplate):
+ _data_attrs_ = dict(date="date",
@bboe
bboe added a note Mar 13, 2012

Perhaps there should be two date fields as with many of the other items which have created and created_utc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@spladug
reddit member
spladug commented Nov 20, 2012

I'm closing this because it was implemented in 1ac5259. Sorry :(

@spladug spladug closed this Nov 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.