Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
add checkmark/pitch depending on pre-approval status (bug 740924)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvan committed Apr 19, 2012
1 parent 6c7e7c2 commit 7facdd2
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
49 changes: 48 additions & 1 deletion media/css/mkt/detail.less
Expand Up @@ -3,6 +3,54 @@
@text-gray: #424f5a;
@link: #2d87ca;

.checkmark {
display: block;
color: @black;
font-weight: bold;
font-size: 12px;
line-height: 20px;
&:before {
.border-radius(10px);
background-color: @green;
color: @white;
content: "\2714"; /* checkmark */
display: inline-block;
font-weight: normal;
height: 20px;
margin-right: 5px;
position: relative;
text-align: center;
width: 20px;
}
}

.actions {
.button {
position: relative;
z-index: 1;
}
.approval {
.border-radius(0 0 5px 5px);
background: fadeOut(@green, 90%);
display: block;
margin-top: -5px;
padding: 15px 5px 10px;
position: relative;
z-index: 0;
}
.approval-pitch {
display: block;
color: @dark-gray;
font-size: 12px;
font-weight: bold;
padding-top: 8px;
text-align: center;
&:hover {
color: @medium-gray;
}
}
}

.icon {
background: @white;
.border-radius(2px);
Expand Down Expand Up @@ -257,7 +305,6 @@
}

.listing .device-list {
padding-top: 3px;
text-align: center;
h4, ul {
display: block;
Expand Down
8 changes: 8 additions & 0 deletions mkt/detail/templates/detail/app.html
Expand Up @@ -61,6 +61,14 @@ <h3 class="hidden">{{ _('Categories') }}</h3>
<div class="actions">
{% if product.is_public() %}
{{ market_button(product) }}
{% if product.can_purchase() %}
{% if request.amo_user and request.amo_user.get_preapproval().paypal_key %}
<span class="approval checkmark">{{ _('PayPal pre-approval') }}</span>
{% else %}
<a class="approval-pitch" href="{{ url('account.payment') }}">
{{ _('Set up purchasing') }}</a>
{% endif %}
{% endif %}
{% endif %}
{% if is_dev %}
<p><a href="{{ product.get_dev_url() }}" class="button developer manage">
Expand Down
35 changes: 35 additions & 0 deletions mkt/detail/tests/test_views.py
Expand Up @@ -13,7 +13,9 @@
from amo.helpers import external_url
import amo.tests
from addons.models import AddonCategory, AddonUpsell, AddonUser, Category
from market.models import PreApprovalUser
from users.models import UserProfile

from mkt.webapps.models import Webapp


Expand All @@ -31,6 +33,9 @@ def setUp(self):
def get_webapp(self):
return Webapp.objects.get(id=337141)

def get_user(self):
return UserProfile.objects.get(email='regular@mozilla.com')

def get_pq(self):
r = self.client.get(self.url)
eq_(r.status_code, 200)
Expand Down Expand Up @@ -153,6 +158,36 @@ def test_has_homepage(self):
eq_(url.find('a').text(), self.webapp.homepage)
eq_(url.find('a').attr('href'), external_url(self.webapp.homepage))

def test_free_no_preapproval(self):
eq_(self.get_pq()('.approval-pitch, .approval.checkmark').length, 0)

def test_free_preapproval_enabled(self):
PreApprovalUser.objects.create(user=self.get_user(), paypal_key='xyz')
eq_(self.get_pq()('.approval-pitch, .approval.checkmark').length, 0)

def test_paid_no_preapproval_anonymous(self):
self.make_premium(self.webapp)
doc = self.get_pq()
eq_(doc('.approval-pitch').length, 1)
eq_(doc('.approval.checkmark').length, 0)

def test_paid_no_preapproval_authenticated(self):
assert self.client.login(username='regular@mozilla.com',
password='password')
self.make_premium(self.webapp)
doc = self.get_pq()
eq_(doc('.approval-pitch').length, 1)
eq_(doc('.approval.checkmark').length, 0)

def test_paid_preapproval_enabled(self):
self.make_premium(self.webapp)
user = self.get_user()
assert self.client.login(username=user.email, password='password')
PreApprovalUser.objects.create(user=user, paypal_key='xyz')
doc = self.get_pq()
eq_(doc('.approval-pitch').length, 0)
eq_(doc('.approval.checkmark').length, 1)


class TestDetailPagePermissions(DetailBase):

Expand Down
5 changes: 4 additions & 1 deletion mkt/webapps/models.py
Expand Up @@ -22,7 +22,7 @@
from addons import query
from addons.models import Addon, update_name_table, update_search_index
from files.models import FileUpload, Platform
from lib.crypto.receipt import sign, cef
from lib.crypto.receipt import sign
from versions.models import Version

import jwt
Expand Down Expand Up @@ -195,6 +195,9 @@ def authors_other_addons(self, app=None):
.filter(addonuser__listed=True,
authors__in=self.listed_authors))

def can_purchase(self):
return self.is_premium() and self.premium and self.is_public()


# Pull all translated_fields from Addon over to Webapp.
Webapp._meta.translated_fields = Addon._meta.translated_fields
Expand Down

0 comments on commit 7facdd2

Please sign in to comment.