Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

JSON access to the moderation log #371

Closed
wants to merge 3 commits into from

5 participants

Dmitry Jemerov Neil Williams Max Goodman Bryce Boe Keith Mitchell
Dmitry Jemerov

No description provided.

Neil Williams spladug commented on the diff
r2/r2/lib/jsontemplates.py
((10 lines not shown))
+
+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
Neil Williams Owner
spladug added a note

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

Dmitry Jemerov
yole added a note

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

Keith Mitchell Collaborator

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
Max Goodman chromakode commented on the diff
r2/r2/lib/jsontemplates.py
((17 lines not shown))
+ 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"])

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
Bryce Boe bboe commented on the diff
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",
Bryce Boe
bboe added a note

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
Neil Williams
Owner

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

Neil Williams spladug closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2012
  1. Dmitry Jemerov

    JSON access to moderator log

    yole authored
  2. Dmitry Jemerov
Commits on Mar 13, 2012
  1. Dmitry Jemerov

    nested attributes for target

    yole authored
This page is out of date. Refresh to see the latest.
3  r2/r2/config/templates.py
View
@@ -57,4 +57,7 @@ def api(type, cls):
api('flairlist', FlairListJsonTemplate)
api('flaircsv', FlairCsvJsonTemplate)
+api('modactionlisting', ModActionListingJsonTemplate)
+api('modaction', ModActionJsonTemplate)
+
tpm.add_handler('usertableitem', 'api-html', UserItemHTMLJsonTemplate())
39 r2/r2/lib/jsontemplates.py
View
@@ -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",
Bryce Boe
bboe added a note

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
+ 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
Neil Williams Owner
spladug added a note

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

Dmitry Jemerov
yole added a note

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

Keith Mitchell Collaborator

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
+ 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"])

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
+ result["author"] = getattr(thing, "target_author", None)
+ return result
+
+ return ThingJsonTemplate.thing_attr(self, thing, attr)
+
+ def rendered_data(self, thing):
+ return self.thing_attr(thing, "things")
+
+ def kind(self, wrapped):
+ return "ModAction"
7 r2/r2/models/modaction.py
View
@@ -237,7 +237,7 @@ def add_props(cls, user, wrapped):
'by': _('by'),
'author': author.name}
path = target.make_permalink(subreddits[target.sr_id])
- target_links[fullname] = (text, path, title)
+ target_links[fullname] = (author.name, text, path, title)
elif isinstance(target, Comment):
author = authors[target.author_id]
link = links[target.link_id]
@@ -253,7 +253,7 @@ def add_props(cls, user, wrapped):
'on': _('on'),
'title': short_title}
path = target.make_permalink(link, subreddits[link.sr_id])
- target_links[fullname] = (text, path, title)
+ target_links[fullname] = (author.name, text, path, title)
elif isinstance(target, Account):
target_accounts[fullname] = WrappedUser(target)
@@ -271,10 +271,11 @@ def add_props(cls, user, wrapped):
if hasattr(item, 'target_fullname') and item.target_fullname:
target = targets[item.target_fullname]
+ item.target = target
if isinstance(target, Account):
item.target_wrapped_user = target_accounts[item.target_fullname]
elif isinstance(target, Link) or isinstance(target, Comment):
- item.target_text, item.target_path, item.target_title = target_links[item.target_fullname]
+ item.target_author, item.target_text, item.target_path, item.target_title = target_links[item.target_fullname]
item.bgcolor = ModAction.get_rgb(item.sr_id)
item.sr_name = subreddits[item.sr_id].name
Something went wrong with that request. Please try again.