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

Commit

Permalink
Restricted authors to developer accounts (bug 719224)
Browse files Browse the repository at this point in the history
  • Loading branch information
robhudson committed Feb 28, 2012
1 parent edb7cfa commit c2210d3
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 20 deletions.
3 changes: 2 additions & 1 deletion apps/amo/fixtures/base/addon_3615.json
Expand Up @@ -307,7 +307,8 @@
"created": "2007-03-05 13:09:56",
"notes": null,
"modified": "2010-05-19 16:41:22",
"notifyevents": true
"notifyevents": true,
"read_dev_agreement": 1
}
},
{
Expand Down
11 changes: 8 additions & 3 deletions apps/amo/fixtures/base/users.json
Expand Up @@ -44,7 +44,8 @@
"created": "2009-02-02 11:50:31",
"notes": "",
"modified": "2010-01-12 17:01:41",
"notifyevents": 1
"notifyevents": 1,
"read_dev_agreement": 1
},
"model": "users.userprofile",
"pk": 999
Expand Down Expand Up @@ -97,7 +98,8 @@
"created": "2007-03-05 13:09:38",
"notes": "",
"modified": "2010-03-19 13:50:38",
"notifyevents": 1
"notifyevents": 1,
"read_dev_agreement": 1
}
},
{
Expand Down Expand Up @@ -146,7 +148,8 @@
"created": "2009-02-02 11:50:31",
"notes": "",
"modified": "2010-01-12 17:01:41",
"notifyevents": 1
"notifyevents": 1,
"read_dev_agreement": 1
},
"model": "users.userprofile",
"pk": 4043307
Expand Down Expand Up @@ -189,6 +192,7 @@
"modified": "2010-11-16 10:51:34",
"last_login_ip": "127.0.0.1",
"notifyevents": false,
"read_dev_agreement": 1,
"user": 5497308
}
},
Expand Down Expand Up @@ -244,6 +248,7 @@
"modified": "2011-12-01 16:20:56",
"last_login_ip": "",
"notifyevents": true,
"read_dev_agreement": 1,
"user": 20
}
},
Expand Down
2 changes: 0 additions & 2 deletions apps/devhub/tests/test_views_ownership.py
@@ -1,13 +1,11 @@
"""Tests related to the ``devhub.addons.owner`` view."""
import mock
from nose.tools import eq_
from pyquery import PyQuery as pq
import waffle

import amo
import amo.tests
from amo.tests import formset
from amo.urlresolvers import reverse
from addons.models import Addon, AddonUser
from devhub.forms import LicenseForm
from devhub.models import ActivityLog
Expand Down
3 changes: 2 additions & 1 deletion apps/users/fixtures/users/test_backends.json
Expand Up @@ -102,7 +102,8 @@
"created": "2007-03-05 13:09:37",
"notes": "",
"modified": "2009-09-24 20:11:30",
"notifyevents": 1
"notifyevents": 1,
"read_dev_agreement": 1
}
},
{
Expand Down
13 changes: 12 additions & 1 deletion apps/users/tests/test_views.py
Expand Up @@ -82,10 +82,11 @@ def test_ajax_xss(self):
assert '<script>' in self.user_profile.display_name, (
'Expected <script> to be in display name')
r = self.client.get(reverse('users.ajax'),
{'q': self.user_profile.email})
{'q': self.user_profile.email, 'dev': 0})
assert '<script>' not in r.content
assert '&lt;script&gt;' in r.content

@patch.object(settings, 'MARKETPLACE', False)
def test_ajax_failure_incorrect_email(self):
r = self.client.get(reverse('users.ajax'), {'q': 'incorrect'},
follow=True)
Expand All @@ -94,6 +95,16 @@ def test_ajax_failure_incorrect_email(self):
{'status': 0,
'message': 'A user with that email address does not exist.'})

@patch.object(settings, 'MARKETPLACE', True)
def test_ajax_failure_incorrect_email_mkt(self):
r = self.client.get(reverse('users.ajax'), {'q': 'incorrect'},
follow=True)
data = json.loads(r.content)
eq_(data,
{'status': 0,
'message': 'A user with that email address does not exist, or the '
'user has not yet accepted the developer agreement.'})

def test_ajax_failure_no_email(self):
r = self.client.get(reverse('users.ajax'), {'q': ''}, follow=True)
data = json.loads(r.content)
Expand Down
3 changes: 1 addition & 2 deletions apps/users/urls.py
Expand Up @@ -5,8 +5,7 @@

from . import forms, views
from .models import UserProfile
from addons.urls import ADDON_ID
from amo.decorators import modal_view


# We need Django to use our User model.
auth_views.User = UserProfile
Expand Down
20 changes: 16 additions & 4 deletions apps/users/views.py
Expand Up @@ -73,17 +73,29 @@ def ajax(request):
data = {'status': 0, 'message': ''}

email = request.GET.get('q', '').strip()
dev_only = request.GET.get('dev', '1')
try:
dev_only = int(dev_only)
except ValueError:
dev_only = 1
dev_only = dev_only and settings.MARKETPLACE

if not email:
data.update(message=_('An email address is required.'))
return data

u = UserProfile.objects.filter(email=email)
user = UserProfile.objects.filter(email=email)
if dev_only:
user = user.filter(read_dev_agreement=True)

msg = _('A user with that email address does not exist.')
msg_dev = loc('A user with that email address does not exist, or the user '
'has not yet accepted the developer agreement.')

if u:
data.update(status=1, id=u[0].id, name=u[0].name)
if user:
data.update(status=1, id=user[0].id, name=user[0].name)
else:
data['message'] = _('A user with that email address does not exist.')
data['message'] = msg_dev if dev_only else msg

return escape_all(data)

Expand Down
9 changes: 7 additions & 2 deletions media/js/devreg/devhub.js
Expand Up @@ -830,8 +830,13 @@ function initAuthorFields() {
url: tgt.attr("data-src"),
data: {q: tgt.val()},
success: function(data) {
tgt.removeClass("ui-autocomplete-loading")
.addClass("valid");
tgt.removeClass("ui-autocomplete-loading");
if (data.status == 1) {
tgt.addClass("valid");
} else {
tgt.addClass("invalid tooltip formerror")
.attr('title', data.message);
}
},
error: function() {
tgt.removeClass("ui-autocomplete-loading")
Expand Down
9 changes: 7 additions & 2 deletions media/js/zamboni/devhub.js
Expand Up @@ -1093,8 +1093,13 @@ function initAuthorFields() {
url: tgt.attr("data-src"),
data: {q: tgt.val()},
success: function(data) {
tgt.removeClass("ui-autocomplete-loading")
.addClass("valid");
tgt.removeClass("ui-autocomplete-loading");
if (data.status == 1) {
tgt.addClass("valid");
} else {
tgt.addClass("invalid tooltip formerror")
.attr('title', data.message);
}
},
error: function() {
tgt.removeClass("ui-autocomplete-loading")
Expand Down
9 changes: 9 additions & 0 deletions mkt/developers/forms.py
Expand Up @@ -56,6 +56,15 @@ def __init__(self, *args, **kwargs):
if c != amo.AUTHOR_ROLE_SUPPORT or
waffle.switch_is_active('allow-refund'))

def clean_user(self):
user = self.cleaned_data['user']
if not user.read_dev_agreement:
raise forms.ValidationError(
_('All authors must have read and agreed to the developer '
'agreement.'))

return user

class Meta:
model = AddonUser
exclude = ('addon')
Expand Down
7 changes: 5 additions & 2 deletions mkt/developers/tests/test_views_paypal.py
Expand Up @@ -8,6 +8,7 @@
import amo.tests
from amo.urlresolvers import reverse
from market.models import Price, AddonPaymentData
from users.models import UserProfile


# Testing the payments page.
Expand Down Expand Up @@ -86,6 +87,9 @@ class TestPaypal(amo.tests.TestCase):
def setUp(self):
self.webapp = self.get_webapp()
self.url = self.webapp.get_dev_url('paypal_setup')
user = UserProfile.objects.get(email='admin@mozilla.com')
user.update(read_dev_agreement=False)

self.client.login(username='admin@mozilla.com', password='password')
self.price = Price.objects.all()[0]

Expand All @@ -101,8 +105,7 @@ def test_partial_submit(self):
from mkt.submit.models import AppSubmissionChecklist
AppSubmissionChecklist.objects.create(addon=self.webapp)
self.webapp.update(premium_type=amo.ADDON_PREMIUM)
res = self.client.get(self.url)
eq_(res.status_code, 302)
res = self.client.get(self.url, follow=True)
self.assertRedirects(res, reverse('submit.app.terms'))


Expand Down
2 changes: 2 additions & 0 deletions mkt/submit/tests/test_views.py
Expand Up @@ -73,6 +73,7 @@ class TestTerms(TestSubmit):

def setUp(self):
super(TestTerms, self).setUp()
self.user.update(read_dev_agreement=False)
self.url = reverse('submit.app.terms')

def test_anonymous(self):
Expand Down Expand Up @@ -126,6 +127,7 @@ class TestManifest(TestSubmit):

def setUp(self):
super(TestManifest, self).setUp()
self.user.update(read_dev_agreement=False)
self.url = reverse('submit.app.manifest')

def _step(self):
Expand Down

0 comments on commit c2210d3

Please sign in to comment.