Esempio n. 1
0
def main(command, **kwargs):
    qs = User.objects.filter(actor__isnull=True).order_by("username")
    total = len(qs)
    command.stdout.write("{} users found without actors".format(total))
    for i, user in enumerate(qs):
        command.stdout.write("{}/{} creating actor for {}".format(
            i + 1, total, user.username))
        try:
            user.actor = create_actor(user)
        except IntegrityError as e:
            # somehow, an actor with the the url exists in the database
            command.stderr.write("Error while creating actor: {}".format(
                str(e)))
            continue
        user.save(update_fields=["actor"])
Esempio n. 2
0
def handler_create_user(
    username,
    password,
    email,
    is_superuser=False,
    is_staff=False,
    permissions=[],
    upload_quota=None,
):
    serializer = serializers.RS(
        data={
            "username": username,
            "email": email,
            "password1": password,
            "password2": password,
        })
    utils.logger.debug("Validating user data…")
    serializer.is_valid(raise_exception=True)

    # Override email validation, we assume accounts created from CLI have a valid email
    request = FakeRequest(session={"account_verified_email": email})
    utils.logger.debug("Creating user…")
    user = serializer.save(request=request)
    utils.logger.debug("Setting permissions and other attributes…")
    user.is_staff = is_staff
    user.upload_quota = upload_quota
    user.is_superuser = is_superuser
    for permission in permissions:
        if permission in models.PERMISSIONS:
            utils.logger.debug("Setting %s permission to True", permission)
            setattr(user, "permission_{}".format(permission), True)
        else:
            utils.logger.warn("Unknown permission %s", permission)
    utils.logger.debug("Creating actor…")
    user.actor = models.create_actor(user)
    user.save()
    return user
Esempio n. 3
0
def test_creating_actor_from_user(factories, settings):
    user = factories["users.User"](username="******")
    actor = models.create_actor(user)

    assert actor.preferred_username == "Hello_M_world"  # slugified
    assert actor.domain.pk == settings.FEDERATION_HOSTNAME
    assert actor.type == "Person"
    assert actor.name == user.username
    assert actor.manually_approves_followers is False
    assert actor.fid == federation_utils.full_url(
        reverse(
            "federation:actors-detail",
            kwargs={"preferred_username": actor.preferred_username},
        ))
    assert actor.shared_inbox_url == federation_utils.full_url(
        reverse("federation:shared-inbox"))
    assert actor.inbox_url == federation_utils.full_url(
        reverse(
            "federation:actors-inbox",
            kwargs={"preferred_username": actor.preferred_username},
        ))
    assert actor.outbox_url == federation_utils.full_url(
        reverse(
            "federation:actors-outbox",
            kwargs={"preferred_username": actor.preferred_username},
        ))
    assert actor.followers_url == federation_utils.full_url(
        reverse(
            "federation:actors-followers",
            kwargs={"preferred_username": actor.preferred_username},
        ))
    assert actor.following_url == federation_utils.full_url(
        reverse(
            "federation:actors-following",
            kwargs={"preferred_username": actor.preferred_username},
        ))