Пример #1
0
  def get_permissions_query(model_names, permission_type='read',
                            permission_model=None):
    """Prepare the query based on the allowed contexts and resources for
     each of the required objects(models).
    """
    type_queries = []
    for model_name in model_names:
      contexts, resources = query_helpers.get_context_resource(
          model_name=model_name,
          permission_type=permission_type,
          permission_model=permission_model
      )
      if contexts is not None:
        if resources:
          resource_sql = and_(
              MysqlRecordProperty.type == model_name,
              MysqlRecordProperty.key.in_(resources))
        else:
          resource_sql = false()

        type_query = or_(
            and_(
                MysqlRecordProperty.type == model_name,
                context_query_filter(MysqlRecordProperty.context_id, contexts)
            ),
            resource_sql)
        type_queries.append(type_query)

    return and_(
        MysqlRecordProperty.type.in_(model_names),
        or_(*type_queries))
Пример #2
0
    def get_permissions_query(self,
                              model_names,
                              permission_type='read',
                              permission_model=None):
        """Prepare the query based on the allowed contexts and resources for
     each of the required objects(models).
    """
        type_queries = []
        for model_name in model_names:
            contexts, resources = query_helpers.get_context_resource(
                model_name=model_name,
                permission_type=permission_type,
                permission_model=permission_model)
            if contexts is not None:
                if resources:
                    resource_sql = and_(MysqlRecordProperty.type == model_name,
                                        MysqlRecordProperty.key.in_(resources))
                else:
                    resource_sql = false()

                type_query = or_(
                    and_(
                        MysqlRecordProperty.type == model_name,
                        context_query_filter(MysqlRecordProperty.context_id,
                                             contexts)), resource_sql)
                type_queries.append(type_query)

        return and_(MysqlRecordProperty.type.in_(model_names),
                    or_(*type_queries))
Пример #3
0
    def _get_type_query(model, permission_type):
        """Filter by contexts and resources

    Prepare query to filter models based on the available contexts and
    resources for the given type of object.
    """
        contexts, resources = query_helpers.get_context_resource(
            model_name=model.__name__, permission_type=permission_type)

        if contexts is not None:
            if resources:
                resource_sql = model.id.in_(resources)
            else:
                resource_sql = sa.sql.false()

            return sa.or_(context_query_filter(model.context_id, contexts),
                          resource_sql)
Пример #4
0
  def _get_type_query(model, permission_type):
    """Filter by contexts and resources

    Prepare query to filter models based on the available contexts and
    resources for the given type of object.
    """
    contexts, resources = query_helpers.get_context_resource(
        model_name=model.__name__, permission_type=permission_type
    )

    if contexts is not None:
      if resources:
        resource_sql = model.id.in_(resources)
      else:
        resource_sql = sa.sql.false()

      return sa.or_(
          context_query_filter(model.context_id, contexts),
          resource_sql)