Skip to content

Commit

Permalink
Add notice about who posted each listing.
Browse files Browse the repository at this point in the history
  • Loading branch information
fatlotus committed Dec 31, 2015
1 parent b29696c commit ebc5f4f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion caravel/controllers/listings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def inject_globals():
"""Adds the categories and user info into the view."""
return {'categories_list': model.Listing.CATEGORIES_LIST,
'categories_dict': model.Listing.CATEGORIES_DICT,
'current_user': users.get_current_user()}
'current_user': users.get_current_user(),
'is_admin': users.is_current_user_admin()}

# Display the time as "1s" etc.
@app.template_filter("as_duration")
Expand Down
7 changes: 7 additions & 0 deletions caravel/templates/listings/fullpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ <h2>{{ listing.title }}</h2>
{%- endif -%}.
Price: <strong>{{ '${:,.2f}'.format(listing.price) }}</strong>
</p>
{% if is_admin %}
<p class="alert alert-info">
{{ listing.principal.explain() }}. Originally posted by
{{ listing.principal.device.ip_address }} with
{{ listing.principal.device.user_agent }}.
</p>
{% endif %}
<p style="white-space:pre-wrap">{{ listing.body }}</p>
</div>
{% if not is_from_tor() %}
Expand Down
7 changes: 5 additions & 2 deletions caravel/tests/test_listings.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def test_post_inquiry_with_cnetid(self):
"New Listing Logged in as visitor@uchicago.edu My Listings "
"Logout Your inquiry has been sent. Listing \xe2\x98\x86B "
"apartments Posted 2d ago by seller-b@uchicago.edu . Price: "
"$71.10 Body of \xe2\x98\x86B Contact Seller From "
"$71.10 Validated by GOOGLE_APPS. Originally posted by 1.2.3.4 "
"with mozilla. Body of \xe2\x98\x86B Contact Seller From "
"visitor@uchicago.edu ( Logout ) Message")

# Verify that the proper email was sent.
Expand Down Expand Up @@ -239,6 +240,7 @@ def test_new_listing_with_cnetid(self):
"New Listing Logged in as visitor@uchicago.edu My Listings "
"Logout Your listing has been created. Title of \xe2\x98\x86D "
"apartments Posted now by visitor@uchicago.edu . Price: $3.44 "
"Validated by GOOGLE_APPS. Originally posted by None with . "
"Body of \xe2\x98\x86D Manage Listing Edit")

# Make sure the picture shows up.
Expand Down Expand Up @@ -334,7 +336,8 @@ def test_edit_listing(self):
self.assertEqual(self.clean(self.get("/listing_a").data),
"New Listing Logged in as seller-a@uchicago.edu My Listings "
"Logout Your listing has been updated. Title\xe2\x98\x86A cars "
"Posted now by seller-a@uchicago.edu . Price: $2.34 "
"Posted now by seller-a@uchicago.edu . Price: $2.34 Validated "
"by GOOGLE_APPS. Originally posted by None with . "
"Body\xe2\x98\x86A Manage Listing Edit"
)

Expand Down
11 changes: 11 additions & 0 deletions caravel/utils/principals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
import user_agents

class Device(object):
@classmethod
Expand Down Expand Up @@ -51,6 +52,16 @@ def validate(self, reason):

self.validated_by = reason

def explain(self):
"""
Return a string explaining why this Principal is valid or not.
"""

if self.auth_method in (self.GOOGLE_APPS, self.LEGACY):
return "Validated by {}".format(self.auth_method)
else:
return self.validated_by

def __repr__(self):
"""
Returns a readable representation of this Principal.
Expand Down

0 comments on commit ebc5f4f

Please sign in to comment.