Gitlab CSE Unil

Commit 28ed518d authored by M. Chardon's avatar M. Chardon
Browse files

mise en forme

parent ad10d99f
......@@ -183,60 +183,68 @@ class ATTP(PermissionClass):
uuid=anobj.uuid[:12]
)
status = cache.get(key)
#if status is None:
# session_key = "anobj_{}".format(anobj.uuid[:12])
# try:
# status = request.session[session_key]
# except KeyError:
# pass
logger.debug("ATTP status from cache: {}".format(status is not None))
return status
def clear_attp_status(self, request, anobj):
session_key = "anobj_{}".format(anobj.uuid[:12])
try:
del(request.session[session_key])
except KeyError:
pass
def check_registration(self, request, anobj):
def clear_attp_status(self, request, anobj):
session_key = "anobj_{}".format(anobj.uuid[:12])
try:
del (request.session[session_key])
except KeyError:
pass
def check_revocation(self, request, anobj):
pass
def check_registration(self, request, anobj):
pass
def check_permission(self, request, anobj):
perm_status = self.get_attp_status(request, anobj)
if perm_status is None:
raise PermissionDenied()
def check_revocation(self, request, anobj):
pass
elif perm_status == 'denied':
if not anobj.locked:
# Revoke only if anobj is not locked
self._revoke_user(request.user, anobj)
def check_permission(self, request, anobj):
perm_status = self.get_attp_status(request, anobj)
if perm_status is None:
raise PermissionDenied()
self.clear_attp_status(request, anobj)
raise PermissionDenied()
elif perm_status == 'denied':
if not anobj.locked:
# Revoke only if anobj is not locked
self._revoke_user(request.user, anobj)
else:
if request.user not in anobj.members.all():
if not self._register_user(request.user, anobj):
raise PermissionDenied()
# Check ownership
owners = anobj.owners.all()
if request.user in owners:
if perm_status != 'owner' and len(owners) > 1:
# is owner, but shouldn't -> remove only if not last one
anobj.owners.remove(request.user)
else:
if perm_status == 'owner':
# is not owner, but should -> add
anobj.owners.add(request.user)
self.clear_attp_status(request, anobj)
raise PermissionDenied()
return True
else:
if request.user not in anobj.members.all():
if not self._register_user(request.user, anobj):
raise PermissionDenied()
def get_interactive_registration_response(self, request, anobj):
if self.get_attp_status(request, anobj) is None:
check_url = settings.ATTP.get(self.ttp_id, {}).get('CHECK_URL')
return HttpResponseRedirect(check_url.format(uuid=anobj.uuid))
# Check ownership
owners = anobj.owners.all()
if request.user in owners:
if perm_status != 'owner' and len(owners) > 1:
# is owner, but shouldn't -> remove only if not last one
anobj.owners.remove(request.user)
else:
self.clear_attp_status(request, anobj)
raise PermissionDenied()
if perm_status == 'owner':
# is not owner, but should -> add
anobj.owners.add(request.user)
return True
def get_interactive_registration_response(self, request, anobj):
if self.get_attp_status(request, anobj) is None:
check_url = settings.ATTP.get(self.ttp_id, {}).get('CHECK_URL')
return HttpResponseRedirect(check_url.format(uuid=anobj.uuid))
else:
self.clear_attp_status(request, anobj)
raise PermissionDenied()
PERMISSION_CLASSES = {
......@@ -294,4 +302,4 @@ def has_anobj_access(request, anobj):
"""
# return request.user == anobj.owner or request.user in anobj.members.all()
# return request.user in anobj.owners.all() or request.user in anobj.members.all()
return anobj.is_owned(request.user.id) or request.user in anobj.members.all()
\ No newline at end of file
return anobj.is_owned(request.user.id) or request.user in anobj.members.all()
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