Exemple #1
0
def createOrganizationTxn(data, profile_keys, form, key_name):
    """Creates a new organization in a transaction.

  Args:
    data: request_data.RequestData for the current request.
    profile_keys: List of profile keys of an admins for the new organization.
    form: Form with organization data.
    key_name: Key name of the organization to create.

  Returns:
    Newly created organization entity.
  """
    organization = form.create(key_name=key_name)

    for profile_key in profile_keys:
        connection_view.createConnectionTxn(
            data,
            profile_key,
            data.program,
            organization,
            conversation_updater.CONVERSATION_UPDATER,
            org_role=connection_model.ORG_ADMIN_ROLE,
            user_role=connection_model.ROLE)

    return organization
Exemple #2
0
def createOrganizationTxn(data, org_id, program_key, org_properties, admin_keys, models):
    """Creates a new organization profile based on the specified properties.

  This function simply calls organization logic's function to do actual job
  but ensures that the entire operation is executed within a transaction.

  Args:
    data: request_data.RequestData for the current request.
    org_id: Identifier of the new organization. Must be unique on
      'per program' basis.
    program_key: Program key.
    org_properties: A dict mapping organization properties to their values.
    admin_keys: List of profile keys of organization administrators for
      this organization.
    models: instance of types.Models that represent appropriate models.

  Returns:
    RichBool whose value is set to True if organization has been successfully
    created. In that case, extra part points to the newly created organization
    entity. Otherwise, RichBool whose value is set to False and extra part is
    a string that represents the reason why the action could not be completed.
  """
    result = org_logic.createOrganization(org_id, program_key, org_properties, models)
    if not result:
        raise exception.BadRequest(message=result.extra)

    for admin_key in admin_keys:
        connection_view.createConnectionTxn(
            data,
            admin_key,
            data.program,
            result.extra,
            conversation_updater.CONVERSATION_UPDATER,
            org_role=connection_model.ORG_ADMIN_ROLE,
            user_role=connection_model.ROLE,
            seen_by_org=True,
            seen_by_user=True,
        )

    return result
Exemple #3
0
def createOrganizationTxn(data, profile_keys, form, key_name):
  """Creates a new organization in a transaction.

  Args:
    data: request_data.RequestData for the current request.
    profile_keys: List of profile keys of an admins for the new organization.
    form: Form with organization data.
    key_name: Key name of the organization to create.

  Returns:
    Newly created organization entity.
  """
  organization = form.create(key_name=key_name)

  for profile_key in profile_keys:
    connection_view.createConnectionTxn(
        data, profile_key, data.program, organization,
        conversation_updater.CONVERSATION_UPDATER,
        org_role=connection_model.ORG_ADMIN_ROLE,
        user_role=connection_model.ROLE)

  return organization
Exemple #4
0
def createOrganizationTxn(
    data, org_id, program_key, org_properties, admin_keys, models):
  """Creates a new organization profile based on the specified properties.

  This function simply calls organization logic's function to do actual job
  but ensures that the entire operation is executed within a transaction.

  Args:
    data: request_data.RequestData for the current request.
    org_id: Identifier of the new organization. Must be unique on
      'per program' basis.
    program_key: Program key.
    org_properties: A dict mapping organization properties to their values.
    admin_keys: List of profile keys of organization administrators for
      this organization.
    models: instance of types.Models that represent appropriate models.

  Returns:
    RichBool whose value is set to True if organization has been successfully
    created. In that case, extra part points to the newly created organization
    entity. Otherwise, RichBool whose value is set to False and extra part is
    a string that represents the reason why the action could not be completed.
  """
  result = org_logic.createOrganization(
      org_id, program_key, org_properties, models)
  if not result:
    raise exception.BadRequest(message=result.extra)

  for admin_key in admin_keys:
    connection_view.createConnectionTxn(
        data, admin_key, data.program, result.extra,
        conversation_updater.CONVERSATION_UPDATER,
        org_role=connection_model.ORG_ADMIN_ROLE,
        user_role=connection_model.ROLE, seen_by_org=True, seen_by_user=True)

  return result