Skip to content
This repository

JSON access to the moderation log #371

Closed
wants to merge 3 commits into from

5 participants

Dmitry Jemerov Neil Williams Keith Mitchell Max Goodman Bryce Boe
Dmitry Jemerov
yole commented March 12, 2012

No description provided.

Neil Williams spladug commented on the diff March 12, 2012
r2/r2/lib/jsontemplates.py
((10 lines not shown))
  552
+
  553
+class ModActionJsonTemplate(ThingJsonTemplate):
  554
+    _data_attrs_ = dict(date="date",
  555
+                        moderator="moderator",
  556
+                        subreddit="subreddit",
  557
+                        action="action",
  558
+                        target="target",
  559
+                        details="details",
  560
+                        description="description")
  561
+
  562
+    def thing_attr(self, thing, attr):
  563
+        from r2.models.account import Account
  564
+        from r2.models.subreddit import Subreddit
  565
+
  566
+        if attr == "moderator":
  567
+            return Account._byID36(thing.mod_id36).name
3
Neil Williams Owner
spladug added a note March 12, 2012

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

Dmitry Jemerov
yole added a note March 12, 2012

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

Keith Mitchell Collaborator
kemitche added a note March 12, 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
Max Goodman chromakode commented on the diff March 12, 2012
r2/r2/lib/jsontemplates.py
((17 lines not shown))
  559
+                        details="details",
  560
+                        description="description")
  561
+
  562
+    def thing_attr(self, thing, attr):
  563
+        from r2.models.account import Account
  564
+        from r2.models.subreddit import Subreddit
  565
+
  566
+        if attr == "moderator":
  567
+            return Account._byID36(thing.mod_id36).name
  568
+        elif attr == "subreddit":
  569
+            return Subreddit._byID36(thing.sr_id36).name
  570
+        elif attr == "date":
  571
+            return time.mktime(thing.date.timetuple())
  572
+        elif attr == "target":
  573
+            result = dict((key, getattr(thing.target, key, None))
  574
+                                for key in ["_fullname", "name", "url", "author", "title"])
1
Max Goodman Owner
chromakode added a note March 12, 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
Bryce Boe bboe commented on the diff March 13, 2012
r2/r2/lib/jsontemplates.py
@@ -543,3 +543,42 @@ def row_to_json(row):
543 543
 class FlairCsvJsonTemplate(JsonTemplate):
544 544
     def render(self, thing, *a, **kw):
545 545
         return ObjectTemplate([l.__dict__ for l in thing.results_by_line])
  546
+
  547
+
  548
+class ModActionListingJsonTemplate(ListingJsonTemplate):
  549
+    def kind(self, wrapped):
  550
+        return "ModActionListing"
  551
+
  552
+
  553
+class ModActionJsonTemplate(ThingJsonTemplate):
  554
+    _data_attrs_ = dict(date="date",
1
Bryce Boe
bboe added a note March 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
Neil Williams
Owner

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

Neil Williams spladug closed this November 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
3  r2/r2/config/templates.py
@@ -57,4 +57,7 @@ def api(type, cls):
57 57
 api('flairlist', FlairListJsonTemplate)
58 58
 api('flaircsv', FlairCsvJsonTemplate)
59 59
 
  60
+api('modactionlisting', ModActionListingJsonTemplate)
  61
+api('modaction', ModActionJsonTemplate)
  62
+
60 63
 tpm.add_handler('usertableitem', 'api-html', UserItemHTMLJsonTemplate())
39  r2/r2/lib/jsontemplates.py
@@ -543,3 +543,42 @@ def row_to_json(row):
543 543
 class FlairCsvJsonTemplate(JsonTemplate):
544 544
     def render(self, thing, *a, **kw):
545 545
         return ObjectTemplate([l.__dict__ for l in thing.results_by_line])
  546
+
  547
+
  548
+class ModActionListingJsonTemplate(ListingJsonTemplate):
  549
+    def kind(self, wrapped):
  550
+        return "ModActionListing"
  551
+
  552
+
  553
+class ModActionJsonTemplate(ThingJsonTemplate):
  554
+    _data_attrs_ = dict(date="date",
  555
+                        moderator="moderator",
  556
+                        subreddit="subreddit",
  557
+                        action="action",
  558
+                        target="target",
  559
+                        details="details",
  560
+                        description="description")
  561
+
  562
+    def thing_attr(self, thing, attr):
  563
+        from r2.models.account import Account
  564
+        from r2.models.subreddit import Subreddit
  565
+
  566
+        if attr == "moderator":
  567
+            return Account._byID36(thing.mod_id36).name
  568
+        elif attr == "subreddit":
  569
+            return Subreddit._byID36(thing.sr_id36).name
  570
+        elif attr == "date":
  571
+            return time.mktime(thing.date.timetuple())
  572
+        elif attr == "target":
  573
+            result = dict((key, getattr(thing.target, key, None))
  574
+                                for key in ["_fullname", "name", "url", "author", "title"])
  575
+            result["author"] = getattr(thing, "target_author", None)
  576
+            return result
  577
+
  578
+        return ThingJsonTemplate.thing_attr(self, thing, attr)
  579
+
  580
+    def rendered_data(self, thing):
  581
+        return self.thing_attr(thing, "things")
  582
+
  583
+    def kind(self, wrapped):
  584
+        return "ModAction"
7  r2/r2/models/modaction.py
@@ -237,7 +237,7 @@ def add_props(cls, user, wrapped):
237 237
                         'by': _('by'),
238 238
                         'author': author.name}
239 239
                 path = target.make_permalink(subreddits[target.sr_id])
240  
-                target_links[fullname] = (text, path, title)
  240
+                target_links[fullname] = (author.name, text, path, title)
241 241
             elif isinstance(target, Comment):
242 242
                 author = authors[target.author_id]
243 243
                 link = links[target.link_id]
@@ -253,7 +253,7 @@ def add_props(cls, user, wrapped):
253 253
                         'on': _('on'),
254 254
                         'title': short_title}
255 255
                 path = target.make_permalink(link, subreddits[link.sr_id])
256  
-                target_links[fullname] = (text, path, title)
  256
+                target_links[fullname] = (author.name, text, path, title)
257 257
             elif isinstance(target, Account):
258 258
                 target_accounts[fullname] = WrappedUser(target)
259 259
 
@@ -271,10 +271,11 @@ def add_props(cls, user, wrapped):
271 271
 
272 272
             if hasattr(item, 'target_fullname') and item.target_fullname:
273 273
                 target = targets[item.target_fullname]
  274
+                item.target = target
274 275
                 if isinstance(target, Account):
275 276
                     item.target_wrapped_user = target_accounts[item.target_fullname]
276 277
                 elif isinstance(target, Link) or isinstance(target, Comment):
277  
-                    item.target_text, item.target_path, item.target_title = target_links[item.target_fullname]
  278
+                    item.target_author, item.target_text, item.target_path, item.target_title = target_links[item.target_fullname]
278 279
 
279 280
             item.bgcolor = ModAction.get_rgb(item.sr_id)
280 281
             item.sr_name = subreddits[item.sr_id].name
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.