Commit 56a9959c authored by Lukas Burgey's avatar Lukas Burgey

Clean up some code

parent 5685d34c
......@@ -322,13 +322,13 @@ class User(AbstractUser):
# is the idp key still present?
if idp_key_name not in userinfo:
self._remove_key(key)
self.remove_key(key)
return
# is the idp key changed?
if key.key != unity_key_value:
self._remove_key(key)
self.remove_key(key)
# causes creation of a new key
raise SSHPublicKey.DoesNotExist
......@@ -344,7 +344,7 @@ class User(AbstractUser):
)
key.save()
self._add_key(key)
self.add_key(key)
def update_userinfo(self, userinfo):
......@@ -365,15 +365,15 @@ class User(AbstractUser):
self.update_userinfo_ssh_key(userinfo)
def _add_key(self, key):
LOGGER.debug(self.msg('Key added: {}'.format(key)))
def add_key(self, key):
LOGGER.debug(self.msg('Adding key: {}'.format(key)))
from . import deployments
for dep in deployments.get_deployment(self):
dep.user_credential_added(key)
def _remove_key(self, key):
LOGGER.debug(self.msg('Key remove: {}'.format(key)))
def remove_key(self, key):
LOGGER.debug(self.msg('Removing key: {}'.format(key)))
if key.delete_key():
return
......@@ -384,7 +384,7 @@ class User(AbstractUser):
def _add_vo(self, vo):
self.vos.add(vo)
LOGGER.debug(self.msg('VO added: {}'.format(vo)))
LOGGER.debug(self.msg('Adding VO: {}'.format(vo)))
# check if the user has deactivated deployments for this exact vo
# if yes: reactivate the deployments
......@@ -395,7 +395,7 @@ class User(AbstractUser):
def _remove_vo(self, vo):
self.vos.remove(vo)
LOGGER.debug(self.msg('VO removed: {}'.format(vo)))
LOGGER.debug(self.msg('Removing VO: {}'.format(vo)))
# TODO this does nothing for ServiceDeployments
......
......@@ -44,8 +44,8 @@ class SSHPublicKeyView(generics.RetrieveDestroyAPIView):
id=self.request.query_params.get('id'),
)
def perform_destroy(self, instance):
self.request.user.user_remove_key(instance)
def perform_destroy(self, key):
self.request.user.remove_key(key)
class SSHPublicKeyListView(generics.ListCreateAPIView):
......@@ -56,7 +56,7 @@ class SSHPublicKeyListView(generics.ListCreateAPIView):
def perform_create(self, serializer):
key = serializer.save(user=self.request.user)
self.request.user.user_changed_key_added(key)
self.request.user.add_key(key)
class ServiceListView(generics.ListAPIView):
......
......@@ -42,65 +42,6 @@ class StateView(generics.RetrieveAPIView):
return state_view_data(self.request)
class SSHPublicKeyView(views.APIView):
def post(self, request):
if 'type' not in request.data:
LOGGER.debug('request has no "type"')
return _api_error_response("malformed request")
if request.data['type'] == 'remove' and 'id' in request.data:
key = get_object_or_404(
models.SSHPublicKey,
id=request.data['id'],
)
request.user.user_remove_key(key)
return Response({
'deleted': True,
})
elif request.data['type'] == 'add':
if 'file' in request.FILES and 'name' in request.data:
key_name = request.data['name']
key_file = request.FILES['file'].read().decode()
key = models.SSHPublicKey(
user=request.user,
name=key_name,
key=key_file,
)
key.save()
request.user.user_changed_key_added(key)
return Response(
serializers.SSHPublicKeySerializer(
key,
).data
)
elif 'key' in request.data and 'name' in request.data:
key_name = request.data['key']
key_data = request.data['key']
key = models.SSHPublicKey(
user=request.user,
name=key_name,
key=key_data,
)
key.save()
request.user.user_changed_key_added(key)
return Response(
serializers.SSHPublicKeySerializer(
key,
).data
)
LOGGER.error('SSHPublicKeyView: malformed request %s', request.data)
return _api_error_response("malformed request")
class DeploymentView(views.APIView):
def post(self, request):
if (
......@@ -147,7 +88,7 @@ class QuestionnaireView(views.APIView):
def post(self, request):
state_item_id = request.query_params.get('id', '')
if state_item_id != '':
item = models.DeploymentState.objects.filter(
item = deployments.DeploymentState.objects.filter(
id=int(state_item_id),
)
if item.exists():
......
......@@ -3,7 +3,6 @@ from . import webpage as views
URLPATTERNS = [
url(r'^state', views.StateView.as_view()),
url(r'^sshkey', views.SSHPublicKeyView.as_view()),
url(r'^deployments', views.DeploymentView.as_view()),
url(r'^delete_user', views.UserDeletionView.as_view()),
url(r'^questionnaire', views.QuestionnaireView.as_view()),
......
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