예제 #1
0
    def validate_relation_by_type(cls, source_type, destination_type):
        """Checks if a mapping is allowed between given types."""
        if is_external_app_user():
            # external users can map and unmap scoping objects
            return

        from ggrc.models import all_models
        scoping_models_names = all_models.get_scope_model_names()

        # Check Regulation and Standard
        if cls._check_relation_types_group(source_type, destination_type,
                                           scoping_models_names,
                                           ("Regulation", "Standard")):
            raise ValidationError(
                u"You do not have the necessary permissions to map and unmap "
                u"scoping objects to directives in this application. Please "
                u"contact your administrator if you have any questions.")

        # Check Control
        control_external_only_mappings = set(scoping_models_names)
        control_external_only_mappings.update(("Regulation", "Standard"))
        if cls._check_relation_types_group(source_type, destination_type,
                                           control_external_only_mappings,
                                           ("Control", )):
            raise ValidationError(
                u"You do not have the necessary permissions to map and unmap "
                u"controls to scoping objects, standards and regulations in this "
                u"application. Please contact your administrator "
                u"if you have any questions.")
예제 #2
0
  def validate_relation_by_type(cls, source_type, destination_type):
    """Checks if a mapping is allowed between given types."""
    if is_external_app_user():
      # external users can map and unmap scoping objects
      return

    from ggrc.models import all_models
    scoping_models_names = all_models.get_scope_model_names()

    # Check Regulation and Standard
    if cls._check_relation_types_group(source_type, destination_type,
                                       scoping_models_names,
                                       ("Regulation", "Standard")):
      raise ValidationError(
          u"You do not have the necessary permissions to map and unmap "
          u"scoping objects to directives in this application. Please "
          u"contact your administrator if you have any questions.")

    # Check Control
    control_external_only_mappings = set(scoping_models_names)
    control_external_only_mappings.update(("Regulation", "Standard"))
    if cls._check_relation_types_group(source_type, destination_type,
                                       control_external_only_mappings,
                                       ("Control", )):
      raise ValidationError(
          u"You do not have the necessary permissions to map and unmap "
          u"controls to scoping objects, standards and regulations in this "
          u"application. Please contact your administrator "
          u"if you have any questions.")
예제 #3
0
    def test_asmnt_procedure_export(self, model):
        """Test export of Assessment Procedure. {}"""
        with factories.single_commit():
            program = factories.ProgramFactory()
            audit = factories.AuditFactory(program=program)
        import_queries = []
        for i in range(3):
            import_queries.append(
                collections.OrderedDict([
                    ("object_type", model),
                    ("Assessment Procedure", "Procedure-{}".format(i)),
                    ("Title", "Title {}".format(i)),
                    ("Code*", "{}-{}".format(model, i)),
                    ("Admin", "*****@*****.**"),
                    ("Assignees", "*****@*****.**"),
                    ("Creators", "*****@*****.**"),
                    ("Description", "{} description".format(model)),
                    ("Program", program.slug),
                    ("Audit", audit.slug),
                    ("Start Date", "01/02/2019"),
                    ("End Date", "03/03/2019"),
                ]))
            if model.replace(" ", "") in all_models.get_scope_model_names():
                import_queries[-1]["Assignee"] = "*****@*****.**"
                import_queries[-1]["Verifier"] = "*****@*****.**"

        self.check_import_errors(self.import_data(*import_queries))

        model_cls = inflector.get_model(model)
        objects = model_cls.query.order_by(model_cls.test_plan).all()
        self.assertEqual(len(objects), 3)
        for num, obj in enumerate(objects):
            self.assertEqual(obj.test_plan, "Procedure-{}".format(num))

        obj_dicts = [{
            "Code*": obj.slug,
            "Assessment Procedure": "Procedure-{}".format(i)
        } for i, obj in enumerate(objects)]
        search_request = [{
            "object_name": model_cls.__name__,
            "filters": {
                "expression": {},
                "order_by": {
                    "name": "id"
                }
            },
            "fields": ["slug", "test_plan"],
        }]
        exported_data = self.export_parsed_csv(search_request)[model]
        self.assertEqual(exported_data, obj_dicts)
예제 #4
0
  def test_asmnt_procedure_export(self, model):
    """Test export of Assessment Procedure. {}"""
    with factories.single_commit():
      program = factories.ProgramFactory()
      audit = factories.AuditFactory(program=program)
    import_queries = []
    for i in range(3):
      import_queries.append(collections.OrderedDict([
          ("object_type", model),
          ("Assessment Procedure", "Procedure-{}".format(i)),
          ("Title", "Title {}".format(i)),
          ("Code*", "{}-{}".format(model, i)),
          ("Admin", "*****@*****.**"),
          ("Assignees", "*****@*****.**"),
          ("Creators", "*****@*****.**"),
          ("Description", "{} description".format(model)),
          ("Program", program.slug),
          ("Audit", audit.slug),
          ("Start Date", "01/02/2019"),
          ("End Date", "03/03/2019"),
      ]))
      if model.replace(" ", "") in all_models.get_scope_model_names():
        import_queries[-1]["Assignee"] = "*****@*****.**"
        import_queries[-1]["Verifier"] = "*****@*****.**"

    self.check_import_errors(self.import_data(*import_queries))

    model_cls = inflector.get_model(model)
    objects = model_cls.query.order_by(model_cls.test_plan).all()
    self.assertEqual(len(objects), 3)
    for num, obj in enumerate(objects):
      self.assertEqual(obj.test_plan, "Procedure-{}".format(num))

    obj_dicts = [
        {
            "Code*": obj.slug,
            "Assessment Procedure": "Procedure-{}".format(i)
        } for i, obj in enumerate(objects)
    ]
    search_request = [{
        "object_name": model_cls.__name__,
        "filters": {
            "expression": {},
            "order_by": {"name": "id"}
        },
        "fields": ["slug", "test_plan"],
    }]
    exported_data = self.export_parsed_csv(search_request)[model]
    self.assertEqual(exported_data, obj_dicts)