Skip to content

Commit

Permalink
Merge branch 'master' into force-uchicago-suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeteo committed Jan 5, 2016
2 parents e555b7a + c29fd65 commit c0a6236
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 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
5 changes: 5 additions & 0 deletions caravel/static/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ form .thumbnail {
float: right;
}

.alert.alert-warning a {
color: black;
font-weight: bold;
}

/* Custom header via media query */
@media (min-width: 992px){
.logo-brand-block{
Expand Down
4 changes: 4 additions & 0 deletions caravel/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<script src="/static/js/continuation.js" type="text/javascript"></script>
{% endblock %}
{% block content %}
<div class="alert alert-warning">
Please read <a href="https://medium.com/@khakimaroon/4f064dabb76a">January
2016 Update to Marketplace</a>.
</div>
<div class="row" id="listings">
{% if not listings %}
{% include "search_fail.html" %}
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
6 changes: 5 additions & 1 deletion caravel/tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from caravel import app, model, utils
from caravel.storage import config


class CaravelTestCase(unittest.TestCase):

def setUp(self):
# FIXME: Remove once everything else is TestCase-ified.
db.delete(db.Query(keys_only=True))
Expand Down Expand Up @@ -91,6 +93,7 @@ def clean(self, markup):
markup = re.sub(r'[ \t\r\n]+', ' ', markup)
markup = re.sub(r'Marketplace is.*lists.uchicago.edu\. ', '', markup)
markup = re.sub(r'(^.*UChicago Marketplace)|(&#169;.*$)', '', markup)
markup = re.sub(r'Please .* Update to Marketplace \. ', '', markup)
return markup.strip()

def extract_photos(self, markup):
Expand All @@ -111,6 +114,7 @@ def post(self, *vargs, **kwargs):
@contextmanager
def google_apps_user(self, email, is_admin=True):
class FakeUser():

def email(self):
return email

Expand All @@ -123,7 +127,7 @@ def email(self):
try:
yield
finally:
users.get_current_user = _current_user
users.get_current_user = _current_user
users.is_current_user_admin = _is_admin

@contextmanager
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):
Expand Down Expand Up @@ -62,6 +63,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 c0a6236

Please sign in to comment.