Commit f33d68bd authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Merge branch 'release-0.13' into develop

Conflicts:
	version
parents e99318c8 6646f0ae
......@@ -85,23 +85,6 @@ import astakos.im.messages as astakos_messages
logger = logging.getLogger(__name__)
def logged(func, msg):
@wraps(func)
def with_logging(*args, **kwargs):
email = ''
user = None
try:
request = args[0]
email = request.user.email
except (KeyError, AttributeError), e:
email = ''
r = func(*args, **kwargs)
if LOGGING_LEVEL:
logger.log(LOGGING_LEVEL, msg % email)
return r
return with_logging
def login(request, user):
auth_login(request, user)
from astakos.im.models import SessionCatalog
......@@ -109,9 +92,13 @@ def login(request, user):
session_key=request.session.session_key,
user=user
).save()
logger.info('%s logged in.', user.log_display)
login = logged(login, '%s logged in.')
logout = logged(auth_logout, '%s logged out.')
def logout(request, *args, **kwargs):
user = request.user
auth_logout(request, *args, **kwargs)
logger.info('%s logged out.', user.log_display)
def send_verification(user, template_name='im/activation_email.txt'):
......@@ -168,8 +155,8 @@ def _send_admin_notification(template_name,
logger.exception(e)
raise SendNotificationError()
else:
msg = 'Sent admin notification for user %s' % dictionary.get('email',
None)
msg = 'Sent admin notification for user %s' % \
(dictionary.get('user', {}).get('email', None), )
logger.log(LOGGING_LEVEL, msg)
......
......@@ -115,6 +115,7 @@ class Command(BaseCommand):
@transaction.commit_on_success
def run(self, sync):
try:
self.stderr.write("Calculating all quotas...\n")
return sync_all_users(sync=sync)
except BaseException, e:
logger.exception(e)
......
......@@ -410,6 +410,14 @@ class AstakosUser(User):
def realname(self):
return '%s %s' % (self.first_name, self.last_name)
@property
def log_display(self):
"""
Should be used in all logger.* calls that refer to a user so that
user display is consistent across log entries.
"""
return '%s (%s)' % (self.uuid, self.email)
@realname.setter
def realname(self, value):
parts = value.split(' ')
......
......@@ -44,6 +44,9 @@ from astakos.im import messages as astakos_messages
from astakos.im import auth_providers
from astakos.im.util import prepare_response, get_context
from astakos.im.views import requires_anonymous, render_response
import logging
logger = logging.getLogger(__name__)
def init_third_party_session(request):
......@@ -89,8 +92,12 @@ def handle_third_party_signup(request, userid, provider_module, third_party_key,
provider = auth_providers.get_provider(provider_module)
if not provider.is_available_for_create():
logger.info('%s signup is disabled.' %
(provider_module,))
messages.error(request,
_(astakos_messages.AUTH_PROVIDER_INVALID_LOGIN))
_(astakos_messages.AUTH_PROVIDER_INVALID_LOGIN)
% {'provider_name': provider.get_title_display,
'provider': provider_module})
return HttpResponseRedirect(reverse('login'))
# identifier not stored in astakos models, create pending profile
......@@ -151,6 +158,8 @@ def handle_third_party_login(request, provider_module, identifier,
user = request.user
if not request.user.can_add_auth_provider(provider_module,
identifier=identifier):
logger.info('%s failed to add %s: %r' % \
(user.log_display, provider_module, provider_info))
# TODO: handle existing uuid message separately
messages.error(request, _(astakos_messages.AUTH_PROVIDER_ADD_FAILED) +
u' ' + _(astakos_messages.AUTH_PROVIDER_ADD_EXISTS))
......@@ -159,6 +168,8 @@ def handle_third_party_login(request, provider_module, identifier,
user.add_auth_provider(provider_module, identifier=identifier,
affiliation=affiliation,
provider_info=provider_info)
logger.info('%s added %s: %r' % \
(user.log_display, provider_module, provider_info))
provider = auth_providers.get_provider(provider_module)
message = _(astakos_messages.AUTH_PROVIDER_ADDED) % provider.get_method_prompt_display
messages.success(request, message)
......
......@@ -88,6 +88,14 @@ def login(
tokens = request.META
third_party_key = get_pending_key(request)
shibboleth_headers = {}
for token in dir(Tokens):
if token == token.upper():
shibboleth_headers[token] = tokens.get(token, 'NOT_SET')
# log shibboleth headers
# TODO: info -> debug
logger.info("shibboleth request: %r" % shibboleth_headers)
try:
eppn = tokens.get(Tokens.SHIB_EPPN)
if not eppn:
......@@ -114,10 +122,10 @@ def login(
affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, 'Shibboleth')
email = tokens.get(Tokens.SHIB_MAIL, '')
#eppn, email, realname, affiliation = 'test@grnet-hq.admin.grnet.gr', 'test@grnet.gr', 'sff', None
provider_info = {'eppn': eppn, 'email': email, 'name': realname}
userid = eppn
try:
return handle_third_party_login(request, 'shibboleth',
eppn, provider_info,
......
......@@ -25,4 +25,6 @@
</div>
</form>
<br>
{% if not forloop.last %}
LOGIN using &nbsp;&nbsp;
{% endif %}
......@@ -679,10 +679,10 @@ def activate(request, greeting_email_template_name='im/welcome_email.txt',
except AstakosUser.DoesNotExist:
return HttpResponseBadRequest(_(astakos_messages.ACCOUNT_UNKNOWN))
if user.is_active:
if user.is_active or user.email_verified:
message = _(astakos_messages.ACCOUNT_ALREADY_ACTIVE)
messages.error(request, message)
return index(request)
return HttpResponseRedirect(reverse('index'))
try:
activate_func(user, greeting_email_template_name,
......@@ -918,6 +918,11 @@ def remove_auth_provider(request, pk):
provider.delete()
message = astakos_messages.AUTH_PROVIDER_REMOVED % \
provider.settings.get_method_prompt_display
user = request.user
logger.info("%s deleted %s provider (%d): %r" % (user.log_display,
provider.module,
int(pk),
provider.info))
messages.success(request, message)
return HttpResponseRedirect(reverse('edit_profile'))
else:
......
......@@ -134,8 +134,9 @@ class Command(BaseCommand):
else:
headers.extend(['IPv4 Subnet', 'IPv4 Gateway'])
uuids = list(set([network.userid for network in networks]))
ucache.fetch_names(uuids)
if displayname:
uuids = list(set([network.userid for network in networks]))
ucache.fetch_names(uuids)
table = []
for network in networks.order_by("id"):
......
......@@ -144,8 +144,9 @@ class Command(BaseCommand):
'backend',
])
uuids = list(set([server.userid for server in servers]))
ucache.fetch_names(uuids)
if displayname:
uuids = list(set([server.userid for server in servers]))
ucache.fetch_names(uuids)
table = []
for server in servers.order_by('id'):
......
......@@ -263,11 +263,11 @@ class UserCache(object):
assert(self.split > 0), "split must be positive"
def fetch_names(self, uuid_list):
l = len(uuid_list)
total = len(uuid_list)
split = self.split
start = 0
while start < l:
end = self.split if l > self.split else l
for start in range(0, total, split):
end = start + split
try:
names = \
astakos.get_displaynames(token=ASTAKOS_TOKEN,
......@@ -277,8 +277,6 @@ class UserCache(object):
except Exception as e:
log.error("Failed to fetch names: %s", e)
start = end
def get_uuid(self, name):
if not name in self.users:
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment