コード例 #1
0
    def get(self, request, server_id=None):

        HasUser.load(self, request)

        try:
            if server_id is None:
                servers = MaBoSSServer.objects.all()
                servers = [
                    server for server in servers
                    if server.user == request.user or server.user.is_staff
                ]
                serializer = MaBoSSServerSerializer(servers, many=True)

                return Response(serializer.data)
            else:
                server = MaBoSSServer.objects.get(id=server_id)

                if server.user != self.user:
                    raise PermissionDenied

                serializer = MaBoSSServerSerializer(server)
                return Response(serializer.data)

        except MaBoSSServer.DoesNotExist:
            raise Http404
コード例 #2
0
    def put(self, request):

        HasUser.load(self, request)

        self.user.email = request.data['email']
        self.user.save()

        return Response(status=status.HTTP_200_OK)
コード例 #3
0
ファイル: Projects.py プロジェクト: vincent-noel/WebMaBoSS
    def post(self, request):

        HasUser.load(self, request)

        Project(user=self.user,
                name=request.data['name'],
                description=request.data['description']).save()

        return Response(status=status.HTTP_200_OK)
コード例 #4
0
    def post(self, request):

        HasUser.load(self, request)

        MaBoSSServer(user=self.user,
                     desc=request.POST['desc'],
                     host=request.POST['host'],
                     port=request.POST['port']).save()

        return Response(status=status.HTTP_200_OK)
コード例 #5
0
ファイル: HasProject.py プロジェクト: sysbio-curie/WebMaBoSS
    def load(self, request, project_id):

        HasUser.load(self, request)

        try:
            project = Project.objects.get(id=project_id)

            if project.user != self.user:
                raise PermissionDenied

            self.project = project

        except Project.DoesNotExist:
            raise NotFound
コード例 #6
0
	def delete(self, request, server_id):

		HasUser.load(self, request)

		try:
			server = MaBoSSServer.objects.get(id=server_id)

			if server.user != self.user:
				raise PermissionDenied

			server.delete()
			return Response(status=status.HTTP_200_OK)

		except MaBoSSServer.DoesNotExist:
			raise Http404
コード例 #7
0
ファイル: Projects.py プロジェクト: vincent-noel/WebMaBoSS
    def delete(self, request, project_id):

        HasUser.load(self, request)

        try:
            project = Project.objects.get(id=project_id)

            if project.user != self.user:
                raise PermissionDenied

            project.delete()
            return Response(status=status.HTTP_200_OK)

        except Project.DoesNotExist:
            raise NotFound
コード例 #8
0
ファイル: Projects.py プロジェクト: vincent-noel/WebMaBoSS
    def put(self, request, project_id):

        HasUser.load(self, request)

        try:
            project = Project.objects.get(id=project_id)

            if project.user != self.user:
                raise PermissionDenied

            project.name = request.data['name']
            project.description = request.data['description']
            project.save()

            return Response(status=status.HTTP_200_OK)

        except Project.DoesNotExist:
            raise NotFound
コード例 #9
0
ファイル: HasProject.py プロジェクト: vincent-noel/WebMaBoSS
    def load(self, request, project_id):

        HasUser.load(self, request)

        try:
            if self.user.is_anonymous:
                guest_user = User.objects.get(username="******")
                project = Project.objects.get(user=guest_user)

            else:
                project = Project.objects.get(id=project_id)
                if project.user != self.user:
                    raise PermissionDenied

            self.project = project

        except Project.DoesNotExist:
            raise NotFound
コード例 #10
0
	def get(self, request, server_id):

		HasUser.load(self, request)

		try:
			server = MaBoSSServer.objects.get(id=server_id)

			if server.user != self.user and not server.user.is_staff:
				raise PermissionDenied

			mbcli = MaBoSSClient(server.host, int(server.port), timeout=1)
			mbcli.close()
			return Response(status=status.HTTP_200_OK, data=True)

		except MaBoSSServer.DoesNotExist:
			raise Http404

		except (timeout, TimeoutError, ConnectionRefusedError):
			return Response(status=status.HTTP_200_OK, data=False)
コード例 #11
0
	def put(self, request, server_id):

		HasUser.load(self, request)

		try:
			server = MaBoSSServer.objects.get(id=server_id)

			if server.user != self.user:
				raise PermissionDenied

			server.desc = request.data['desc']
			server.host = request.data['host']
			server.port = int(request.data['port'])
			server.save()

			return Response(status=status.HTTP_200_OK)

		except MaBoSSServer.DoesNotExist:
			raise Http404
コード例 #12
0
ファイル: Projects.py プロジェクト: vincent-noel/WebMaBoSS
    def get(self, request, project_id=None):

        HasUser.load(self, request)

        try:
            if project_id is None:
                projects = Project.objects.filter(user=request.user)
                serializer = ProjectSerializer(projects, many=True)

                return Response(serializer.data)
            else:
                project = Project.objects.get(id=project_id)

                if project.user != self.user:
                    raise PermissionDenied

                serializer = ProjectSerializer(project)

                return Response(serializer.data)

        except Project.DoesNotExist:
            raise NotFound
コード例 #13
0
    def get(self, request):

        HasUser.load(self, request)

        return Response({'email': self.user.email})