Changeset 1232 in main


Ignore:
Timestamp:
06/19/12 15:16:06 (7 years ago)
Author:
zali
Message:

Lifecycle cancel : prevent user from cancelling objects with at least one link (DocumentPartLink? , ParentChildrenLink?) created and documents that contains at least one file

Location:
trunk/openPLM/plmapp
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/controllers/document.py

    r1137 r1232  
    3333 
    3434import openPLM.plmapp.models as models 
    35 from openPLM.plmapp.exceptions import LockError, UnlockError, DeleteFileError 
     35from openPLM.plmapp.exceptions import LockError, UnlockError, DeleteFileError, PermissionError 
    3636from openPLM.plmapp.controllers.plmobject import PLMObjectController 
    3737from openPLM.plmapp.controllers.base import get_controller 
     
    495495        self.get_attached_parts().delete() 
    496496 
     497    def check_cancel(self, raise_=True): 
     498        res = super(DocumentController, self).check_cancel(raise_=raise_) 
     499        if res : 
     500            res = res and not self.get_attached_parts() 
     501            if (not res) and raise_ : 
     502                raise PermissionError("This document has is related to a part.") 
     503            res = res and not models.DocumentFile.objects.filter(document=self.object).exists() 
     504            if (not res) and raise_ : 
     505                raise PermissionError("This document contains one or more files. ") 
     506        return res 
  • trunk/openPLM/plmapp/controllers/part.py

    r1107 r1232  
    3535from openPLM.plmapp.controllers.plmobject import PLMObjectController 
    3636from openPLM.plmapp.controllers.base import get_controller 
     37 
     38from openPLM.plmapp.exceptions import PermissionError 
    3739 
    3840Child = namedtuple("Child", "level link") 
     
    742744        now = datetime.datetime.today() 
    743745        models.ParentChildLink.objects.filter(q, end_time=None).update(end_time=now) 
    744  
     746         
     747    def check_cancel(self,raise_=True): 
     748        res = super(PartController, self).check_cancel(raise_=raise_) 
     749        if res : 
     750            q = Q(parent=self.object) | Q(child=self.object) 
     751            res = res and not models.ParentChildLink.objects.filter(q).exists() 
     752            if (not res) and raise_ : 
     753                raise PermissionError("This part is related to an other part.") 
     754            res = res and not self.get_attached_documents() 
     755            if (not res) and raise_ : 
     756                raise PermissionError("This part has a document related to it.") 
     757        return res 
     758 
  • trunk/openPLM/plmapp/controllers/plmobject.py

    r1210 r1232  
    741741        self.check_cancel() 
    742742        self.cancel() 
     743         
     744    def can_clone(self): 
     745        """ 
     746        .. versionadded:: 1.1 
     747         
     748        Returns True if the user can clone this object 
     749        """ 
     750        return True 
     751         
     752    def clone(self): 
     753        """  
     754        Returns the form to clone this object 
     755        """ 
     756        pass 
  • trunk/openPLM/plmapp/tests/controllers/document.py

    r864 r1232  
    340340        # tests the links 
    341341        self.assertEqual(0, self.controller.get_attached_parts().count()) 
    342  
     342         
     343    def assertCancelError(self, ctrl): 
     344        res = super(DocumentControllerTest, self).assertCancelError(ctrl) 
     345        res = res or bool(ctrl.get_attached_parts()) 
     346        res = res or models.DocumentFile.objects.filter(document=self.object).exists() 
     347        self.assertTrue(res) 
     348         
     349    def test_cancel_linked_document(self): 
     350        part = self.get_part() 
     351        self.controller.attach_to_part(part) 
     352        self.assertEqual(1, self.controller.get_attached_parts().count()) 
     353        self.assertCancelError(self.controller) 
  • trunk/openPLM/plmapp/tests/controllers/part.py

    r911 r1232  
    867867        self.assertEqual(1, len(children)) 
    868868        self.assertEqual(children_o[0].child_id, self.controller3.id) 
    869  
     869         
     870 
     871    def assertCancelError(self, ctrl): 
     872        res = super(PartControllerTest, self).assertCancelError(ctrl) 
     873        from django.db.models.query import Q 
     874        q = Q(parent=ctrl.object) | Q(child=ctrl.object) 
     875        res = res or models.ParentChildLink.objects.filter(q).exists() 
     876        res = res or bool(ctrl.get_attached_documents()) 
     877        self.assertTrue(res) 
     878         
     879    def test_cancel_child(self) : 
     880        """ Test that a child (part) can *not* be cancelled. """ 
     881        self.add_child() 
     882        children = self.controller.get_children() 
     883        self.assertEqual(len(children), 1) 
     884        self.assertCancelError(self.controller2) 
     885     
     886    def test_cancel_parent(self) : 
     887        """ Tests that a parent (part) can *not* be cancelled. """ 
     888        self.add_child() 
     889        children = self.controller.get_children() 
     890        self.assertEqual(len(children), 1) 
     891        self.assertCancelError(self.controller) 
  • trunk/openPLM/plmapp/tests/controllers/plmobject.py

    r1211 r1232  
    615615        self.assertRaises(exc.PermissionError, ctrl.check_cancel) 
    616616        self.assertRaises(exc.PermissionError, ctrl.check_cancel) 
     617        self.assertRaises(exc.PermissionError, ctrl.check_cancel) 
     618        self.assertRaises(exc.PermissionError, ctrl.check_cancel) 
    617619        res = not ctrl.is_draft 
    618620        res = res or len(ctrl.get_all_revisions()) > 1 
    619621        res = res or not ctrl.check_permission("owner",raise_=False) 
    620         self.assertTrue(res) 
     622        return res 
    621623     
    622624    def test_cancel_draft(self): 
Note: See TracChangeset for help on using the changeset viewer.