Ejemplo n.º 1
0
def create_federated_user(
        username,
        email,
        service_id,
        service_ident,
        set_password_notification,
        metadata={},
        email_required=True,
        confirm_username=True,
        prompts=tuple(),
):
    prompts = set(prompts)

    if confirm_username:
        prompts.add(UserPromptTypes.CONFIRM_USERNAME)

    new_user = create_user_noverify(username,
                                    email,
                                    email_required=email_required,
                                    prompts=prompts)
    new_user.verified = True
    new_user.save()

    FederatedLogin.create(
        user=new_user,
        service=_get_login_service(service_id),
        service_ident=service_ident,
        metadata_json=json.dumps(metadata),
    )

    if set_password_notification:
        notification.create_notification("password_required", new_user)

    return new_user
Ejemplo n.º 2
0
def _notify_superusers(key):
    notification_metadata = {
        "name": key.name,
        "kid": key.kid,
        "service": key.service,
        "jwk": key.jwk,
        "metadata": key.metadata,
        "created_date": timegm(key.created_date.utctimetuple()),
    }

    if key.expiration_date is not None:
        notification_metadata["expiration_date"] = timegm(
            key.expiration_date.utctimetuple())

    if len(config.app_config["SUPER_USERS"]) > 0:
        superusers = User.select().where(
            User.username << config.app_config["SUPER_USERS"])
        for superuser in superusers:
            create_notification(
                "service_key_submitted",
                superuser,
                metadata=notification_metadata,
                lookup_path="/service_key_approval/{0}/{1}".format(
                    key.kid, superuser.id),
            )
Ejemplo n.º 3
0
def _notify_superusers(key):
  notification_metadata = {
    'name': key.name,
    'kid': key.kid,
    'service': key.service,
    'jwk': key.jwk,
    'metadata': key.metadata,
    'created_date': timegm(key.created_date.utctimetuple()),
  }

  if key.expiration_date is not None:
    notification_metadata['expiration_date'] = timegm(key.expiration_date.utctimetuple())

  if len(config.app_config['SUPER_USERS']) > 0:
    superusers = User.select().where(User.username << config.app_config['SUPER_USERS'])
    for superuser in superusers:
      create_notification('service_key_submitted', superuser, metadata=notification_metadata,
                          lookup_path='/service_key_approval/{0}/{1}'.format(key.kid, superuser.id))
Ejemplo n.º 4
0
def test_delete_robot(initialized_db):
  # Create a robot account.
  user = create_user_noverify('foobar', '*****@*****.**', email_required=False)
  robot, _ = create_robot('foo', user)

  # Add some notifications and other rows pointing to the robot.
  create_notification('repo_push', robot)

  team = create_team('someteam', get_organization('buynlarge'), 'member')
  add_user_to_team(robot, team)

  # Ensure the robot exists.
  assert lookup_robot(robot.username).id == robot.id

  # Delete the robot.
  delete_robot(robot.username)

  # Ensure it is gone.
  with pytest.raises(InvalidRobotException):
    lookup_robot(robot.username)
Ejemplo n.º 5
0
def notify_organization_admins(repository_ref, notification_kind, metadata={}):
    namespace_user = model.user.get_namespace_user(
        repository_ref.namespace_name)
    if namespace_user is None:
        raise InvalidUsernameException("Namespace '%s' does not exist" %
                                       repository_ref.namespace_name)

    metadata.update({"namespace": repository_ref.namespace_name})

    if namespace_user.organization:
        admins = organization.get_admin_users(namespace_user)

        for admin in admins:
            notification.create_notification(
                notification_kind,
                admin,
                metadata,
            )
    else:
        notification.create_notification(
            notification_kind,
            namespace_user,
            metadata,
        )