Add view to check if the vm belongs to a user
This commit is contained in:
		
					parent
					
						
							
								fa66d48323
							
						
					
				
			
			
				commit
				
					
						b8ca7286f2
					
				
			
		
					 2 changed files with 22 additions and 1 deletions
				
			
		| 
						 | 
					@ -9,13 +9,14 @@ from .views import (
 | 
				
			||||||
    HostingPricingView, CreateVirtualMachinesView, HostingBillListView,
 | 
					    HostingPricingView, CreateVirtualMachinesView, HostingBillListView,
 | 
				
			||||||
    HostingBillDetailView, SSHKeyDeleteView, SSHKeyCreateView, SSHKeyListView,
 | 
					    HostingBillDetailView, SSHKeyDeleteView, SSHKeyCreateView, SSHKeyListView,
 | 
				
			||||||
    SSHKeyChoiceView, DashboardView, SettingsView, ResendActivationEmailView,
 | 
					    SSHKeyChoiceView, DashboardView, SettingsView, ResendActivationEmailView,
 | 
				
			||||||
    InvoiceListView, InvoiceDetailView
 | 
					    InvoiceListView, InvoiceDetailView, CheckUserVM
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
urlpatterns = [
 | 
					urlpatterns = [
 | 
				
			||||||
    url(r'index/?$', IndexView.as_view(), name='index'),
 | 
					    url(r'index/?$', IndexView.as_view(), name='index'),
 | 
				
			||||||
    url(r'django/?$', DjangoHostingView.as_view(), name='djangohosting'),
 | 
					    url(r'django/?$', DjangoHostingView.as_view(), name='djangohosting'),
 | 
				
			||||||
 | 
					    url(r'checkvm/?$', CheckUserVM.as_view(), name='chech_vm'),
 | 
				
			||||||
    url(r'dashboard/?$', DashboardView.as_view(), name='dashboard'),
 | 
					    url(r'dashboard/?$', DashboardView.as_view(), name='dashboard'),
 | 
				
			||||||
    url(r'nodejs/?$', NodeJSHostingView.as_view(), name='nodejshosting'),
 | 
					    url(r'nodejs/?$', NodeJSHostingView.as_view(), name='nodejshosting'),
 | 
				
			||||||
    url(r'rails/?$', RailsHostingView.as_view(), name='railshosting'),
 | 
					    url(r'rails/?$', RailsHostingView.as_view(), name='railshosting'),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,8 @@ from django.views.generic import (
 | 
				
			||||||
    View, CreateView, FormView, ListView, DetailView, DeleteView,
 | 
					    View, CreateView, FormView, ListView, DetailView, DeleteView,
 | 
				
			||||||
    TemplateView, UpdateView
 | 
					    TemplateView, UpdateView
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					from rest_framework.views import APIView
 | 
				
			||||||
 | 
					from rest_framework.response import Response
 | 
				
			||||||
from guardian.mixins import PermissionRequiredMixin
 | 
					from guardian.mixins import PermissionRequiredMixin
 | 
				
			||||||
from oca.pool import WrongIdError
 | 
					from oca.pool import WrongIdError
 | 
				
			||||||
from stored_messages.api import mark_read
 | 
					from stored_messages.api import mark_read
 | 
				
			||||||
| 
						 | 
					@ -1755,3 +1757,21 @@ def forbidden_view(request, exception=None, reason=''):
 | 
				
			||||||
                'again.')
 | 
					                'again.')
 | 
				
			||||||
    messages.add_message(request, messages.ERROR, err_msg)
 | 
					    messages.add_message(request, messages.ERROR, err_msg)
 | 
				
			||||||
    return HttpResponseRedirect(request.get_full_path())
 | 
					    return HttpResponseRedirect(request.get_full_path())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CheckUserVM(APIView):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get(self, request):
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            email = request.data['email']
 | 
				
			||||||
 | 
					            ip = request.data['ip']
 | 
				
			||||||
 | 
					            uservms = VMDetail.objects.filter(user__email=email)
 | 
				
			||||||
 | 
					            if len(uservms) > 0:
 | 
				
			||||||
 | 
					                for i in range(len(uservms)):
 | 
				
			||||||
 | 
					                    if uservms[i].ipv4 == ip or uservms[i].ipv6 == ip:
 | 
				
			||||||
 | 
					                        return Response('success', 200)
 | 
				
			||||||
 | 
					                return Response('No VM found matching the ip address provided', 403)
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                return Response('No VM found with the given email address', 403)
 | 
				
			||||||
 | 
					        except KeyError:
 | 
				
			||||||
 | 
					            return Response('Not enough data provided', 400)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue