diff --git a/caravel/controllers/listings.py b/caravel/controllers/listings.py index 52d1451..5b58c4b 100644 --- a/caravel/controllers/listings.py +++ b/caravel/controllers/listings.py @@ -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") diff --git a/caravel/templates/listings/fullpage.html b/caravel/templates/listings/fullpage.html index 8cbf3e5..5a5ccf6 100644 --- a/caravel/templates/listings/fullpage.html +++ b/caravel/templates/listings/fullpage.html @@ -32,6 +32,13 @@

{{ listing.title }}

{%- endif -%}. Price: {{ '${:,.2f}'.format(listing.price) }}

+ {% if is_admin %} +

+ {{ listing.principal.explain() }}. Originally posted by + {{ listing.principal.device.ip_address }} with + {{ listing.principal.device.user_agent }}. +

+ {% endif %}

{{ listing.body }}

{% if not is_from_tor() %} diff --git a/caravel/tests/test_listings.py b/caravel/tests/test_listings.py index 23a645a..bcca058 100644 --- a/caravel/tests/test_listings.py +++ b/caravel/tests/test_listings.py @@ -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. @@ -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. @@ -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" ) diff --git a/caravel/utils/principals.py b/caravel/utils/principals.py index c815516..3ce47fd 100644 --- a/caravel/utils/principals.py +++ b/caravel/utils/principals.py @@ -1,4 +1,5 @@ import uuid +import user_agents class Device(object): @classmethod @@ -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.