Added get_object method to verify if the user is the owner of the ssh key

This commit is contained in:
PCoder 2017-08-04 20:54:28 +05:30
parent 824749545c
commit c6b23f6aa0

View file

@ -342,6 +342,13 @@ class SSHKeyDeleteView(LoginRequiredMixin, DeleteView):
success_url = reverse_lazy('hosting:ssh_keys') success_url = reverse_lazy('hosting:ssh_keys')
model = UserHostingKey model = UserHostingKey
def get_object(self, queryset=None):
""" Hook to ensure object is owned by request.user. """
obj = super(SSHKeyDeleteView, self).get_object()
if not obj.owner == self.request.user:
raise Http404
return obj
def delete(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs):
owner = self.request.user owner = self.request.user
manager = OpenNebulaManager() manager = OpenNebulaManager()