Example #1
0
 def get_context_for_object(self, obj):
   return {
     'instance': obj,
     'controller': self,
     'instance_json':
       lambda: as_json({ self.model_name: ggrc.builder.json.publish(obj) })
     }
Example #2
0
def get_all_attributes_json(load_custom_attributes=False):
    """Get a list of all attribute definitions

  This exports all attributes related to a given model, including custom
  attributes and mapping attributes, that are used in csv import and export.
  """
    with benchmark('Loading all attributes JSON'):
        published = {}
        ca_cache = collections.defaultdict(list)
        if load_custom_attributes:
            # get only GCA and exclude external CADs
            # external GCA should be deleted from internal GCA table
            definitions = models.CustomAttributeDefinition.eager_query(
            ).filter(~models.CustomAttributeDefinition.definition_type.in_(
                constants.GGRCQ_OBJ_TYPES_FOR_SYNC)).group_by(
                    models.CustomAttributeDefinition.title,
                    models.CustomAttributeDefinition.definition_type)
            for attr in definitions:
                ca_cache[attr.definition_type].append(attr)
            ecad = models.ExternalCustomAttributeDefinition
            definitions = ecad.eager_query().group_by(
                models.ExternalCustomAttributeDefinition.title,
                models.ExternalCustomAttributeDefinition.definition_type)
            for attr in definitions:
                ca_cache[attr.definition_type].append(attr)
        for model in models.all_models.all_models:
            published[model.__name__] = \
                reflection.AttributeInfo.get_attr_definitions_array(
                    model, ca_cache=ca_cache)
        return services_common.as_json(published)
Example #3
0
def get_full_user_json():
  """Get the full current user"""
  with benchmark("Get full user JSON"):
    from ggrc.models.person import Person
    current_user = get_current_user()
    person = Person.eager_query().filter_by(id=current_user.id).one()
    result = publish_representation(publish(person, (), inclusion_filter))
    return as_json(result)
Example #4
0
def get_full_user_json():
    """Get the full current user"""
    with benchmark("Get full user JSON"):
        from ggrc.models.person import Person
        current_user = get_current_user()
        person = Person.eager_query().filter_by(id=current_user.id).one()
        result = publish_representation(publish(person, (), inclusion_filter))
        return as_json(result)
Example #5
0
 def get_context_for_object(self, obj):
   return {
     'instance': obj,
     'controller': self,
     'instance_json':
       lambda: as_json({
           self.model._inflector.table_singular: ggrc.builder.json.publish(obj)
         })
     }
Example #6
0
def get_roles_json():
  """Get a list of all roles"""
  with benchmark("Get roles JSON"):
    attrs = all_models.Role.query.all()
    published = []
    for attr in attrs:
      published.append(publish(attr, attribute_whitelist=('id', 'name')))
    published = publish_representation(published)
    return as_json(published)
Example #7
0
def get_access_control_roles_json():
    """Get a list of all access control roles"""
    with benchmark("Get access roles JSON"):
        attrs = all_models.AccessControlRole.query.all()
        published = []
        for attr in attrs:
            published.append(publish(attr))
        published = publish_representation(published)
        return as_json(published)
Example #8
0
 def get_object_json(self, obj):
     """Returns object json"""
     with benchmark("Get object JSON"):
         return as_json({
             self.model._inflector.table_singular:
             filter_resource(
                 ggrc.builder.json.publish_representation(
                     ggrc.builder.json.publish(obj, (), inclusion_filter)))
         })
Example #9
0
 def get_context_for_object(self, obj):
   return {
     'instance': obj,
     'controller': self,
     'instance_json':
       lambda: as_json({
           self.model._inflector.table_singular: ggrc.builder.json.publish(obj)
         })
     }
Example #10
0
def get_access_control_roles_json():
  """Get a list of all access control roles"""
  with benchmark("Get access roles JSON"):
    attrs = all_models.AccessControlRole.query.all()
    published = []
    for attr in attrs:
      published.append(publish(attr))
    published = publish_representation(published)
    return as_json(published)
Example #11
0
 def get_object_json(self, obj):
   """Returns object json"""
   with benchmark("Get object JSON"):
     return as_json({
         self.model._inflector.table_singular:
         filter_resource(
             ggrc.builder.json.publish_representation(
                 ggrc.builder.json.publish(obj, (), inclusion_filter)))
     })
Example #12
0
def get_roles_json():
    """Get a list of all roles"""
    with benchmark("Get roles JSON"):
        attrs = all_models.Role.query.all()
        published = []
        for attr in attrs:
            published.append(publish(attr, attribute_whitelist=('id', 'name')))
        published = publish_representation(published)
        return as_json(published)
Example #13
0
def get_attributes_json():
    """Get a list of all custom attribute definitions"""
    with benchmark("Get attributes JSON"):
        attrs = models.CustomAttributeDefinition.eager_query().filter(
            models.CustomAttributeDefinition.definition_id.is_(None))
        published = []
        for attr in attrs:
            published.append(publish(attr))
        published = publish_representation(published)
        return as_json(published)
Example #14
0
def get_access_control_roles_json():
    """Get a list of all access control roles"""
    with benchmark("Get access roles JSON"):
        attrs = all_models.AccessControlRole.query.options(
            sqlalchemy.orm.undefer_group("AccessControlRole_complete")).all()
        published = []
        for attr in attrs:
            published.append(publish(attr))
        published = publish_representation(published)
        return as_json(published)
Example #15
0
def related_objects():
  obj_id = request.args['oid']
  obj_type = request.args['otype']
  far_type = request.args['related_model']

  related_object_results = RelatedObjectResults(obj_id, obj_type, far_type)
  results = related_object_results.get_results()

  current_app.make_response((
      'application/json', 200, [('Content-Type', 'application/json')]))
  return as_json(results)
Example #16
0
def get_internal_roles_json():
  """Get a list of all access control roles"""
  with benchmark("Get access roles JSON"):
    attrs = all_models.AccessControlRole.query.options(
        sqlalchemy.orm.undefer_group("AccessControlRole_complete")
    ).filter(all_models.AccessControlRole.internal == true()).all()
    published = []
    for attr in attrs:
      published.append(publish(attr))
    published = publish_representation(published)
    return as_json(published)
Example #17
0
def related_objects():
    obj_id = request.args['oid']
    obj_type = request.args['otype']
    far_type = request.args['related_model']

    related_object_results = RelatedObjectResults(obj_id, obj_type, far_type)
    results = related_object_results.get_results()

    current_app.make_response(
        ('application/json', 200, [('Content-Type', 'application/json')]))
    return as_json(results)
Example #18
0
def get_attributes_json():
  """Get a list of all custom attribute definitions"""
  with benchmark("Get attributes JSON"):
    attrs = models.CustomAttributeDefinition.eager_query().filter(
        models.CustomAttributeDefinition.definition_id.is_(None)
    )
    published = []
    for attr in attrs:
      published.append(publish(attr))
    published = publish_representation(published)
    return as_json(published)
Example #19
0
def get_current_user_json():
    """Get current user"""
    with benchmark("Get current user JSON"):
        person = get_current_user()
        return as_json({
            "id": person.id,
            "company": person.company,
            "email": person.email,
            "language": person.language,
            "name": person.name,
            "system_wide_role": person.system_wide_role,
        })
Example #20
0
def get_current_user_json():
  """Get current user"""
  with benchmark("Get current user JSON"):
    person = get_current_user()
    return as_json({
        "id": person.id,
        "company": person.company,
        "email": person.email,
        "language": person.language,
        "name": person.name,
        "system_wide_role": person.system_wide_role,
    })
Example #21
0
def get_internal_roles_json():
    """Get a list of all access control roles"""
    with benchmark("Get access roles JSON"):
        attrs = models.all_models.AccessControlRole.query.options(
            sqlalchemy.orm.undefer_group("AccessControlRole_complete")).filter(
                models.all_models.AccessControlRole.internal ==
                sqlalchemy.true()).all()
        published = []
        for attr in attrs:
            published.append(builder_json.publish(attr))
        published = builder_json.publish_representation(published)
        return services_common.as_json(published)
Example #22
0
def get_attributes_json():
  """Get a list of all custom attribute definitions"""
  with benchmark("Get attributes JSON"):
    with benchmark("Get attributes JSON: query"):
      attrs = models.CustomAttributeDefinition.eager_query().filter(
          models.CustomAttributeDefinition.definition_id.is_(None)
      ).all()
    with benchmark("Get attributes JSON: publish"):
      published = []
      for attr in attrs:
        published.append(builder_json.publish(attr))
      published = builder_json.publish_representation(published)
    with benchmark("Get attributes JSON: json"):
      publish_json = services_common.as_json(published)
      return publish_json
Example #23
0
def get_attributes_json():
    """Get a list of all custom attribute definitions"""
    with benchmark("Get attributes JSON"):
        with benchmark("Get attributes JSON: query"):
            attrs = models.CustomAttributeDefinition.eager_query().filter(
                models.CustomAttributeDefinition.definition_id.is_(
                    None)).all()
        with benchmark("Get attributes JSON: publish"):
            published = []
            for attr in attrs:
                published.append(builder_json.publish(attr))
            published = builder_json.publish_representation(published)
        with benchmark("Get attributes JSON: json"):
            publish_json = services_common.as_json(published)
            return publish_json
Example #24
0
def get_all_attributes_json(load_custom_attributes=False):
  """Get a list of all attribute definitions

  This exports all attributes related to a given model, including custom
  attributes and mapping attributes, that are used in csv import and export.
  """
  with benchmark('Loading all attributes JSON'):
    published = {}
    ca_cache = collections.defaultdict(list)
    if load_custom_attributes:
      definitions = models.CustomAttributeDefinition.eager_query().group_by(
          models.CustomAttributeDefinition.title,
          models.CustomAttributeDefinition.definition_type)
      for attr in definitions:
        ca_cache[attr.definition_type].append(attr)
    for model in all_models.all_models:
      published[model.__name__] = \
          AttributeInfo.get_attr_definitions_array(model, ca_cache=ca_cache)
    return as_json(published)
Example #25
0
def get_all_attributes_json(load_custom_attributes=False):
    """Get a list of all attribute definitions

  This exports all attributes related to a given model, including custom
  attributes and mapping attributes, that are used in csv import and export.
  """
    with benchmark('Loading all attributes JSON'):
        published = {}
        ca_cache = collections.defaultdict(list)
        if load_custom_attributes:
            definitions = models.CustomAttributeDefinition.eager_query(
            ).group_by(models.CustomAttributeDefinition.title,
                       models.CustomAttributeDefinition.definition_type)
            for attr in definitions:
                ca_cache[attr.definition_type].append(attr)
        for model in all_models.all_models:
            published[model.__name__] = \
                AttributeInfo.get_attr_definitions_array(model, ca_cache=ca_cache)
        return as_json(published)
Example #26
0
def get_attributes_json():
    """Get a list of all custom attribute definitions"""
    with benchmark("Get attributes JSON"):
        with benchmark("Get attributes JSON: query"):
            # get only GCA and exclude external CADs
            # external GCA should be deleted from internal GCA table
            attrs = models.CustomAttributeDefinition.eager_query().filter(
                models.CustomAttributeDefinition.definition_id.is_(None),
                ~models.CustomAttributeDefinition.definition_type.in_(
                    constants.GGRCQ_OBJ_TYPES_FOR_SYNC)).all()
            ext_attrs = models.ExternalCustomAttributeDefinition.eager_query(
            ).all()
        with benchmark("Get attributes JSON: publish"):
            published = []
            for attr in attrs:
                published.append(builder_json.publish(attr))
            for attr in ext_attrs:
                published.append(builder_json.publish(attr))
            published = builder_json.publish_representation(published)
        with benchmark("Get attributes JSON: json"):
            publish_json = services_common.as_json(published)
            return publish_json