예제 #1
0
 def testDeleteRevisionsDaysNoMatch(self):
     date_created = timezone.now() - timedelta(days=20)
     with reversion.create_revision():
         obj = TestModel.objects.create()
         reversion.set_date_created(date_created)
     self.callCommand("deleterevisions", days=21)
     self.assertSingleRevision((obj,), date_created=date_created)
예제 #2
0
 def testDeleteRevisionsDaysNoMatch(self):
     date_created = timezone.now() - timedelta(days=20)
     with reversion.create_revision():
         obj = TestModel.objects.create()
         reversion.set_date_created(date_created)
     self.callCommand("deleterevisions", days=21)
     self.assertSingleRevision((obj,), date_created=date_created)
예제 #3
0
 def testDeleteRevisionsDays(self):
     date_created = timezone.now() - timedelta(days=20)
     with reversion.create_revision():
         TestModel.objects.create()
         reversion.set_date_created(date_created)
     self.callCommand("deleterevisions", days=19)
     self.assertNoRevision()
예제 #4
0
 def testDeleteRevisionsDays(self):
     date_created = timezone.now() - timedelta(days=20)
     with reversion.create_revision():
         TestModel.objects.create()
         reversion.set_date_created(date_created)
     self.callCommand("deleterevisions", days=19)
     self.assertNoRevision()
예제 #5
0
    def process_entity(self, entity, most_recent_version):
        # force revision date to be same as that of the most recent version
        # so status change is archived at the correct date

        reversion.set_date_created(most_recent_version.revision.date_created)

        # note in comment why this revision was created

        reversion.set_comment("Fixing status in object archives (script, #558)")

        # add entity to revision

        reversion.add_to_revision(entity)
예제 #6
0
    def put(self, request, pk):
        """Update diagram"""
        diagramModel = Diagram.objects.get(pk=pk)
        # Checks that the current user as the rights to update specified diagram
        serializer = serializers.DiagramSerializer(data=request.data)
        if serializer.is_valid():
            # print(diagramModel.owner.username)
            # print(request.user.username)
            diagram_xml = request.data['diagram']
            no_script_xml = noScriptTagsInXML(diagram_xml)
            try:
                # Checks that the diagram sent is properly built
                diagram = defusedxml.minidom.parseString(no_script_xml)
                root = diagram.documentElement.firstChild
                allMxCell = root.getElementsByTagName('mxCell')
            except (AttributeError, TypeError):
                return Response(status=status.HTTP_400_BAD_REQUEST)
            if diagramModel.owner.email != self.request.user.email:
                if diagramModel.is_public:
                    # If current user isn't the owner of the diagram,
                    # then he can only create a new private diagram from the public one
                    serializer.save(
                        owner=request.user,
                        is_public=False,
                        lastTimeSpent=request.data['lastTimeSpent'],
                        diagram=no_script_xml)
                    return Response(serializer.data,
                                    status=status.HTTP_201_CREATED)
                if self.request.user not in diagramModel.writer.all():
                    return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
            # In bellow case we either are the owner, or we have writer rights over the diagram
            # Hence we can modify it
            with reversion.create_revision():
                diagramModel.lastTimeSpent = float(
                    request.data['lastTimeSpent'])
                diagramModel.name = str(request.data['name'])
                diagramModel.diagram = no_script_xml
                diagramModel.is_public = request.data['is_public']
                if request.data['tags'] != "\"\"":
                    diagramModel.tags.set(request.data['tags'])
                diagramModel.preview = request.data['preview']
                diagramModel.save()
                reversion.set_date_created(timezone.now())

            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #7
0
    def test_audit_log_view(self):
        """Test retrieval of audit log."""
        initial_datetime = now()
        with reversion.create_revision():
            opportunity = LargeCapitalOpportunityFactory(
                name='This amazing opportunity', )

            reversion.set_comment('Initial')
            reversion.set_date_created(initial_datetime)
            reversion.set_user(self.user)

        changed_datetime = now()
        with reversion.create_revision():
            opportunity.name = 'That amazing opportunity'
            opportunity.save()

            reversion.set_comment('Changed')
            reversion.set_date_created(changed_datetime)
            reversion.set_user(self.user)

        versions = Version.objects.get_for_object(opportunity)
        version_id = versions[0].id
        url = reverse('api-v4:large-capital-opportunity:audit-item',
                      kwargs={'pk': opportunity.pk})

        response = self.api_client.get(url)
        response_data = response.json()['results']

        # No need to test the whole response
        assert len(response_data) == 1
        entry = response_data[0]

        assert entry['id'] == version_id
        assert entry['user']['name'] == self.user.name
        assert entry['comment'] == 'Changed'
        assert entry['timestamp'] == format_date_or_datetime(changed_datetime)
        assert entry['changes']['name'] == [
            'This amazing opportunity', 'That amazing opportunity'
        ]
        assert not set(EXCLUDED_BASE_MODEL_FIELDS) & entry['changes'].keys()
예제 #8
0
 def post(self, request):
     """Create new Diagram"""
     # request_img = request.data['preview']
     serializer = serializers.DiagramSerializer(data=request.data)
     if serializer.is_valid():
         diagram_xml = request.data['diagram']
         no_script_xml = noScriptTagsInXML(diagram_xml)
         try:
             # Checks that the diagram sent is properly built
             diagram = defusedxml.minidom.parseString(no_script_xml)
             root = diagram.documentElement.firstChild
             allMxCell = root.getElementsByTagName('mxCell')
         except (AttributeError, TypeError):
             return Response(status=status.HTTP_400_BAD_REQUEST)
         # Checks against XSS
         with reversion.create_revision():
             serializer.save(owner=request.user,
                             lastTimeSpent=request.data['lastTimeSpent'],
                             diagram=no_script_xml)
             reversion.set_date_created(timezone.now())
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #9
0
    def test_audit_log_view(self):
        """Test retrieval of audit log."""
        initial_datetime = now()
        with reversion.create_revision():
            company = CompanyFactory(
                description='Initial desc',
            )

            reversion.set_comment('Initial')
            reversion.set_date_created(initial_datetime)
            reversion.set_user(self.user)

        changed_datetime = now()
        with reversion.create_revision():
            company.description = 'New desc'
            company.save()

            reversion.set_comment('Changed')
            reversion.set_date_created(changed_datetime)
            reversion.set_user(self.user)

        versions = Version.objects.get_for_object(company)
        version_id = versions[0].id
        url = reverse('api-v4:company:audit-item', kwargs={'pk': company.pk})

        response = self.api_client.get(url)
        response_data = response.json()['results']

        # No need to test the whole response
        assert len(response_data) == 1
        entry = response_data[0]

        assert entry['id'] == version_id
        assert entry['user']['name'] == self.user.name
        assert entry['comment'] == 'Changed'
        assert entry['timestamp'] == format_date_or_datetime(changed_datetime)
        assert entry['changes']['description'] == ['Initial desc', 'New desc']
        assert not set(EXCLUDED_BASE_MODEL_FIELDS) & entry['changes'].keys()
예제 #10
0
 def testGetDateCreated(self):
     date_created = timezone.now() - timedelta(days=20)
     with reversion.create_revision():
         reversion.set_date_created(date_created)
         self.assertEqual(reversion.get_date_created(), date_created)
예제 #11
0
 def testDateCreatedNoBlock(self):
     with self.assertRaises(reversion.RevisionManagementError):
         reversion.set_date_created(timezone.now())
예제 #12
0
 def testSetDateCreated(self):
     date_created = timezone.now() - timedelta(days=20)
     with reversion.create_revision():
         reversion.set_date_created(date_created)
         obj = TestModel.objects.create()
     self.assertSingleRevision((obj, ), date_created=date_created)
예제 #13
0
 def testGetDateCreated(self):
     date_created = timezone.now() - timedelta(days=20)
     with reversion.create_revision():
         reversion.set_date_created(date_created)
         self.assertEqual(reversion.get_date_created(), date_created)
예제 #14
0
 def testDateCreatedNoBlock(self):
     with self.assertRaises(reversion.RevisionManagementError):
         reversion.set_date_created(timezone.now())
예제 #15
0
 def testSetDateCreated(self):
     date_created = timezone.now() - timedelta(days=20)
     with reversion.create_revision():
         reversion.set_date_created(date_created)
         obj = TestModel.objects.create()
     self.assertSingleRevision((obj,), date_created=date_created)
예제 #16
0
def submit_reversion(request):
    reversion.set_comment(request.method)
    reversion.set_date_created(date_created=timezone.now())