Beispiel #1
0
 def lazy_loader():
     """Lazy load diff for revisions."""
     referenced_objects.rewarm_cache()
     instance = referenced_objects.get(self.resource_type,
                                       self.resource_id)
     meta_dict = {}
     if instance:
         instance_meta_info = meta_info.MetaInfo(instance)
         meta_dict["mandatory"] = instance_meta_info.mandatory
     return meta_dict
Beispiel #2
0
def changes_present(obj,
                    new_rev_content,
                    prev_rev_content=None,
                    obj_meta=None):
    """Check if `new_rev_content` contains obj changes.

  Checks whether `new_rev_content` contains changes in `obj` state or not. If
  `prev_rev_content` is not passed to this function, the latest revision of
  `obj` will be taken. Note that in this case revision whose content is passed
  as `new_rev_content` should not been saved in DB or no changes would be
  detected since two equal contents will be compared.

  Args:
      obj: db.Model instance which last revision would be compared with
        `new_revision` to detect presence of changes.
      new_rev_content: Content of newer revision to ckeck for changes.
      prev_rev_content: Content of older revision. Optional. If is not passed,
        latest `obj` revision will be taken.
      obj_meta: MetaInfo instance of `obj`. Optionla. If is not passed, will
        be constructed manually.

  Returns:
      Boolean flag indicating whether `new_rev_content` contains any changes
        in `obj` state comparing to `prev_rev_content`.
  """
    new_rev_content = _normalize_content(new_rev_content)
    if obj_meta is None:
        obj_meta = meta_info.MetaInfo(obj)
    if prev_rev_content is None:
        prev_rev_content = get_latest_revision_content(obj)
        if prev_rev_content is None:
            return True
    diff = prepare_content_full_diff(
        instance_meta_info=obj_meta,
        l_content=prev_rev_content,
        r_content=new_rev_content,
    )
    return any(diff.values())
Beispiel #3
0
def is_identical_acr(instance, value_1, value_2):
    """Checks acls for identity"""
    meta = meta_info.MetaInfo(instance)
    result = generate_acl_diff(meta.acrs, value_1, value_2)
    return len(result) == 0