push more data into users
This commit is contained in:
Родитель
34db64e7ac
Коммит
884ea995e7
|
@ -81,3 +81,10 @@ def user_report_abuse(context, hide, profile):
|
|||
@register.filter
|
||||
def contribution_type(type):
|
||||
return amo.CONTRIB_TYPES[type]
|
||||
|
||||
|
||||
@register.function
|
||||
def user_data(amo_user):
|
||||
return {'anonymous': amo_user.is_anonymous(),
|
||||
'pre_auth': False if amo_user.is_anonymous()
|
||||
else amo_user.has_preapproval_key()}
|
||||
|
|
|
@ -472,6 +472,9 @@ class RequestUser(UserProfile):
|
|||
keys = super(RequestUser, self)._cache_keys()
|
||||
return keys + (UserProfile(id=self.id).cache_key,)
|
||||
|
||||
def is_anonymous(self):
|
||||
return False
|
||||
|
||||
|
||||
class BlacklistedUsername(amo.models.ModelBase):
|
||||
"""Blacklisted user usernames."""
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
|
||||
import mock
|
||||
from nose.tools import eq_
|
||||
|
||||
from amo.urlresolvers import reverse
|
||||
from users.helpers import emaillink, user_link, users_list
|
||||
from users.models import UserProfile
|
||||
from users.helpers import emaillink, user_link, users_list, user_data
|
||||
from users.models import UserProfile, RequestUser
|
||||
|
||||
|
||||
def test_emaillink():
|
||||
|
@ -78,3 +81,23 @@ def test_user_link_unicode():
|
|||
url = reverse('users.profile', args=[1])
|
||||
eq_(user_link(u),
|
||||
u'<a href="%s">%s</a>' % (url, u.username))
|
||||
|
||||
|
||||
def test_user_data():
|
||||
u = user_data(RequestUser(username='foo', pk=1))
|
||||
eq_(u['anonymous'], False)
|
||||
eq_(u['pre_auth'], False)
|
||||
|
||||
|
||||
@mock.patch('users.models.RequestUser.has_preapproval_key')
|
||||
def test_user_data_approved(has_preapproval_key):
|
||||
has_preapproval_key.return_value = True
|
||||
u = user_data(RequestUser(username='foo', pk=1))
|
||||
eq_(u['anonymous'], False)
|
||||
eq_(u['pre_auth'], True)
|
||||
|
||||
|
||||
def test_anonymous_user_data():
|
||||
u = user_data(AnonymousUser())
|
||||
eq_(u['anonymous'], True)
|
||||
eq_(u['pre_auth'], False)
|
||||
|
|
|
@ -17,6 +17,11 @@ $(document).ready(function() {
|
|||
'a little later.'))
|
||||
.find('button, input, select, textarea').attr('disabled', true).addClass('disabled');
|
||||
}
|
||||
var data_user = $('body').data('user');
|
||||
_.extend(z, {
|
||||
anonymous: data_user.anonymous,
|
||||
pre_auth: data_user.pre_auth
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
@ -82,4 +87,4 @@ function escape_(s) {
|
|||
z.anonymous = JSON.parse(document.body.getAttribute('data-anonymous'))
|
||||
z.media_url = document.body.getAttribute('data-media-url');
|
||||
z.readonly = JSON.parse(document.body.getAttribute('data-readonly'));
|
||||
z.apps = true;
|
||||
z.apps = true;
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
var z = {};
|
||||
|
||||
$(document).ready(function() {
|
||||
// Initialize email links.
|
||||
$('span.emaillink').each(function() {
|
||||
var $this = $(this);
|
||||
$this.find('.i').remove();
|
||||
var em = $this.text().split('').reverse().join('');
|
||||
$this.prev('a').attr('href', 'mailto:' + em);
|
||||
});
|
||||
if (z.readonly) {
|
||||
$('form[method=post]')
|
||||
.before(gettext('This feature is temporarily disabled while we ' +
|
||||
'perform website maintenance. Please check back ' +
|
||||
'a little later.'))
|
||||
.find('button, input, select, textarea').attr('disabled', true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function _pd(func) {
|
||||
// Prevent-default function wrapper.
|
||||
return function(e) {
|
||||
e.preventDefault();
|
||||
func.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function escape_(s) {
|
||||
if (typeof s === undefined) {
|
||||
return;
|
||||
}
|
||||
return s.replace(/&/g, '&').replace(/>/g, '>').replace(/</g, '<')
|
||||
.replace(/'/g, ''').replace(/"/g, '"');
|
||||
}
|
||||
|
||||
|
||||
z.anonymous = JSON.parse(document.body.getAttribute('data-anonymous'))
|
||||
z.media_url = document.body.getAttribute('data-media-url');
|
||||
z.readonly = JSON.parse(document.body.getAttribute('data-readonly'));
|
|
@ -1,6 +1,5 @@
|
|||
var z = {
|
||||
page: $('#page'),
|
||||
anonymous: $('body').data('anonymous')
|
||||
};
|
||||
|
||||
|
||||
|
@ -20,6 +19,11 @@ $(document).ready(function() {
|
|||
.find('button, input, select, textarea').attr('disabled', true)
|
||||
.addClass('disabled');
|
||||
}
|
||||
var data_user = $('body').data('user');
|
||||
_.extend(z, {
|
||||
anonymous: data_user.anonymous,
|
||||
pre_auth: data_user.pre_auth
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
data-app="{{ request.APP.short }}"
|
||||
data-appname="{{ request.APP.pretty }}"
|
||||
data-appid="{{ request.APP.id }}"
|
||||
data-anonymous="{{ (not request.user.is_authenticated())|json }}"
|
||||
data-user="{{ user_data(amo_user)|json }}"
|
||||
data-readonly="{{ settings.READ_ONLY|json }}"
|
||||
data-media-url="{{ MEDIA_URL }}"
|
||||
data-collect-timings="{{ url('amo.timing.record') }}:{{ collect_timings_percent }}"
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
{% endif %}
|
||||
</head>
|
||||
<body class="html-{{ DIR }} {% block bodyclass %}{% endblock %}"
|
||||
data-anonymous="{{ (not request.user.is_authenticated())|json }}"
|
||||
data-user="{{ user_data(amo_user)|json }}"
|
||||
data-readonly="{{ settings.READ_ONLY|json }}"
|
||||
data-media-url="{{ MEDIA_URL }}"
|
||||
data-login-url="{{ url('users.browserid_login') }}"
|
||||
|
|
Загрузка…
Ссылка в новой задаче