Commit 76285354 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

AstakosUser signed_terms property instead of function

parent fc839045
...@@ -98,7 +98,7 @@ def authenticate_old(request, user=None): ...@@ -98,7 +98,7 @@ def authenticate_old(request, user=None):
if (time() - mktime(user.auth_token_expires.timetuple())) > 0: if (time() - mktime(user.auth_token_expires.timetuple())) > 0:
raise Unauthorized('Authentication expired') raise Unauthorized('Authentication expired')
if not user.signed_terms(): if not user.signed_terms:
raise Unauthorized('Pending approval terms') raise Unauthorized('Pending approval terms')
response = HttpResponse() response = HttpResponse()
...@@ -109,7 +109,7 @@ def authenticate_old(request, user=None): ...@@ -109,7 +109,7 @@ def authenticate_old(request, user=None):
'auth_token_created':user.auth_token_created.isoformat(), 'auth_token_created':user.auth_token_created.isoformat(),
'auth_token_expires':user.auth_token_expires.isoformat(), 'auth_token_expires':user.auth_token_expires.isoformat(),
'has_credits':user.has_credits, 'has_credits':user.has_credits,
'has_signed_terms':user.signed_terms(), 'has_signed_terms':user.signed_terms,
'groups':[g.name for g in user.groups.all()]} 'groups':[g.name for g in user.groups.all()]}
response.content = json.dumps(user_info) response.content = json.dumps(user_info)
response['Content-Type'] = 'application/json; charset=UTF-8' response['Content-Type'] = 'application/json; charset=UTF-8'
...@@ -133,7 +133,7 @@ def authenticate(request, user=None): ...@@ -133,7 +133,7 @@ def authenticate(request, user=None):
if (time() - mktime(user.auth_token_expires.timetuple())) > 0: if (time() - mktime(user.auth_token_expires.timetuple())) > 0:
raise Unauthorized('Authentication expired') raise Unauthorized('Authentication expired')
if not user.signed_terms(): if not user.signed_terms:
raise Unauthorized('Pending approval terms') raise Unauthorized('Pending approval terms')
response = HttpResponse() response = HttpResponse()
......
...@@ -84,7 +84,7 @@ class Command(BaseCommand): ...@@ -84,7 +84,7 @@ class Command(BaseCommand):
'resources' : user.quota 'resources' : user.quota
} }
if get_latest_terms(): if get_latest_terms():
has_signed_terms = user.signed_terms() has_signed_terms = user.signed_terms
kv['has_signed_terms'] = format_bool(has_signed_terms) kv['has_signed_terms'] = format_bool(has_signed_terms)
if has_signed_terms: if has_signed_terms:
kv['date_signed_terms'] = format_date(user.date_signed_terms) kv['date_signed_terms'] = format_date(user.date_signed_terms)
......
...@@ -149,10 +149,6 @@ class AstakosGroup(Group): ...@@ -149,10 +149,6 @@ class AstakosGroup(Group):
return False return False
return True return True
# @property
# def participants(self):
# return len(self.approved_members)
def enable(self): def enable(self):
if self.is_enabled: if self.is_enabled:
return return
...@@ -351,6 +347,7 @@ class AstakosUser(User): ...@@ -351,6 +347,7 @@ class AstakosUser(User):
if q.count() != 0: if q.count() != 0:
raise ValidationError({'__all__':[_('Another account with the same email & is_active combination found.')]}) raise ValidationError({'__all__':[_('Another account with the same email & is_active combination found.')]})
@property
def signed_terms(self): def signed_terms(self):
term = get_latest_terms() term = get_latest_terms()
if not term: if not term:
......
...@@ -68,7 +68,7 @@ def login(request): ...@@ -68,7 +68,7 @@ def login(request):
if request.user.is_authenticated(): if request.user.is_authenticated():
# if user has not signed the approval terms # if user has not signed the approval terms
# redirect to approval terms with next the request path # redirect to approval terms with next the request path
if not request.user.signed_terms(): if not request.user.signed_terms:
# first build next parameter # first build next parameter
parts = list(urlsplit(request.build_absolute_uri())) parts = list(urlsplit(request.build_absolute_uri()))
params = dict(parse_qsl(parts[3], keep_blank_values=True)) params = dict(parse_qsl(parts[3], keep_blank_values=True))
......
...@@ -113,7 +113,7 @@ def signed_terms_required(func): ...@@ -113,7 +113,7 @@ def signed_terms_required(func):
""" """
@wraps(func) @wraps(func)
def wrapper(request, *args, **kwargs): def wrapper(request, *args, **kwargs):
if request.user.is_authenticated() and not request.user.signed_terms(): if request.user.is_authenticated() and not request.user.signed_terms:
params = urlencode({'next': request.build_absolute_uri(), params = urlencode({'next': request.build_absolute_uri(),
'show_form':''}) 'show_form':''})
terms_uri = reverse('latest_terms') + '?' + params terms_uri = reverse('latest_terms') + '?' + params
...@@ -545,7 +545,7 @@ def approval_terms(request, term_id=None, template_name='im/approval_terms.html' ...@@ -545,7 +545,7 @@ def approval_terms(request, term_id=None, template_name='im/approval_terms.html'
return HttpResponseRedirect(next) return HttpResponseRedirect(next)
else: else:
form = None form = None
if request.user.is_authenticated() and not request.user.signed_terms(): if request.user.is_authenticated() and not request.user.signed_terms:
form = SignApprovalTermsForm(instance=request.user) form = SignApprovalTermsForm(instance=request.user)
return render_response(template_name, return render_response(template_name,
terms = terms, terms = terms,
......
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