Gitlab CSE Unil

Commit d5b641f8 authored by M. Chardon's avatar M. Chardon
Browse files

moodle acces image par simple user

parent 28ed518d
......@@ -194,57 +194,57 @@ class ATTP(PermissionClass):
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:
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):
pass
def check_registration(self, request, anobj):
pass
def check_revocation(self, request, anobj):
pass
def check_revocation(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_permission(self, request, anobj):
perm_status = self.get_attp_status(request, anobj)
if perm_status is None:
raise PermissionDenied()
elif perm_status == 'denied':
if not anobj.locked:
# Revoke only if anobj is not locked
self._revoke_user(request.user, anobj)
elif perm_status == 'denied':
if not anobj.locked:
# Revoke only if anobj is not locked
self._revoke_user(request.user, anobj)
self.clear_attp_status(request, anobj)
raise PermissionDenied()
self.clear_attp_status(request, anobj)
raise PermissionDenied()
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)
else:
if request.user not in anobj.members.all():
if not self._register_user(request.user, anobj):
raise PermissionDenied()
return True
# 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)
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:
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()
self.clear_attp_status(request, anobj)
raise PermissionDenied()
PERMISSION_CLASSES = {
......
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