Skip to content

Followers API reference

Follow requests, acceptance and removal between users. The follow graph is visible only to its owner and their accepted followers. See Sharing, privacy and followers.

Service

Application logic for follower relationships.

The privacy-aware read surface (whether a requester may view a target's follower / following graph) and the follow / accept / unfollow writes. Access decisions live here, not in the router, so the same rule applies however this module is reached.

A user's follow graph is visible only to the user and their accepted followers. Endurain has no public-profile concept: profiles are never public, and only individual activities can be shared (via server-level public links), so no "public" tier applies to the follow graph.

This is the module's own application layer. What other modules may consume lives in :mod:modules.followers.integration_service.

accept_follow_request

accept_follow_request(requester_user_id, follower_id, db)

Accept a pending follow request and publish follower.accepted.

Parameters:

Name Type Description Default
requester_user_id UUID

The authenticated user accepting the request.

required
follower_id UUID

The user whose pending request is being accepted.

required
db Session

Database session.

required

Returns:

Type Description
FollowRelationshipRead

The accepted relationship, read back after the flush.

Raises:

Type Description
ConflictError

When the requester already follows the maximum number of users.

NotFoundError

When no pending request from that user exists.

Source code in backend/app/modules/followers/service.py
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
def accept_follow_request(
    requester_user_id: uuid.UUID,
    follower_id: uuid.UUID,
    db: Session,
) -> followers_schema.FollowRelationshipRead:
    """Accept a pending follow request and publish ``follower.accepted``.

    Args:
        requester_user_id: The authenticated user accepting the request.
        follower_id: The user whose pending request is being accepted.
        db: Database session.

    Returns:
        The accepted relationship, read back after the flush.

    Raises:
        ConflictError: When the requester already follows the maximum number of users.
        NotFoundError: When no pending request from that user exists.
    """
    followers_crud.lock_accepted_followees(follower_id, db)
    if (
        followers_crud.count_following_by_user_id(follower_id, db, accepted_only=True)
        >= followers_constants.MAX_ACCEPTED_FOLLOWEES
    ):
        logger.debug(
            "Refused a follow acceptance: the follower follows too many users",
            extra=core_logger.context(requester_user_id=requester_user_id, follower_id=follower_id),
        )
        raise core_exceptions.ConflictError("This user already follows the maximum number of users")
    relationship = followers_crud.accept_follower(requester_user_id, follower_id, db)
    jasil_audit.stage(
        db,
        followers_audit_actions.FOLLOW_ACCEPT,
        target_type="user",
        target_id=str(follower_id),
        target_owner_id=str(requester_user_id),
    )
    followers_event_publishers.publish_follower_accepted(requester_user_id, follower_id, db, commit=db.commit)
    logger.info(
        "Follow request accepted",
        extra=core_logger.context(requester_user_id=requester_user_id, follower_id=follower_id),
    )
    return relationship

block_user

block_user(blocker_id, blocked_id, db)

Block a user: end every follow between the two and refuse the blocked user's future requests.

The answer is the same for a user that does not exist, so the route cannot be used to look users up. Nothing tells the blocked user: only a pending request is taken back, as when it is withdrawn. Blocking again changes nothing and writes no audit row.

Parameters:

Name Type Description Default
blocker_id UUID

The user who blocks.

required
blocked_id UUID

The user to block; must differ from the blocker (the route checks it).

required
db Session

Database session.

required
Source code in backend/app/modules/followers/service.py
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
def block_user(blocker_id: uuid.UUID, blocked_id: uuid.UUID, db: Session) -> None:
    """Block a user: end every follow between the two and refuse the blocked user's future requests.

    The answer is the same for a user that does not exist, so the route cannot be used to look users up.
    Nothing tells the blocked user: only a pending request is taken back, as when it is withdrawn.
    Blocking again changes nothing and writes no audit row.

    Args:
        blocker_id: The user who blocks.
        blocked_id: The user to block; must differ from the blocker (the route checks it).
        db: Database session.
    """
    if users_integration.get_user(blocked_id, db) is None:
        return
    # A follow in either direction takes the addressee's lock; holding both, in a fixed order so two blocks
    # cannot deadlock, makes a follow either commit before the block (and be removed by it) or see the block.
    for user_id in sorted((blocker_id, blocked_id), key=str):
        followers_crud.lock_pending_requests(user_id, db)
    created = followers_crud.create_block(blocker_id, blocked_id, db)
    removed = followers_crud.delete_follows_between(blocker_id, blocked_id, db)
    if created:
        jasil_audit.stage(
            db,
            followers_audit_actions.BLOCK_ADD,
            target_type="user",
            target_id=str(blocked_id),
            target_owner_id=str(blocker_id),
        )
    pending = [row for row in removed if row.status == followers_constants.FollowStatus.PENDING]
    if not pending:
        db.commit()
    for row in pending:
        followers_event_publishers.publish_follower_request_removed(
            row.follower_id, row.followee_id, db, commit=db.commit, source="api:block_user"
        )
    logger.info(
        "Blocked a user",
        extra=core_logger.context(blocker_id=blocker_id, blocked_id=blocked_id, created=created),
    )

delete_relationship

delete_relationship(followee_id, follower_id, requester_user_id, db)

Delete a follow relationship on behalf of either party.

One operation serves unfollow and remove-follower: the row is the same and the direction is explicit in the arguments, so the only difference is which of the two parties asked.

Parameters:

Name Type Description Default
followee_id UUID

The user being followed.

required
follower_id UUID

The user doing the following.

required
requester_user_id UUID

The authenticated caller, who must be one of the two.

required
db Session

Database session.

required

Publishes follower.request_removed when the deleted row was still a pending request, records a decline when the followee removed it, and stages a followers.follow.remove audit row when it was an accepted relationship.

Raises:

Type Description
AccessConcealedError

When the caller is not part of the relationship; answered as a missing relationship so it does not confirm one exists.

Source code in backend/app/modules/followers/service.py
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
def delete_relationship(
    followee_id: uuid.UUID, follower_id: uuid.UUID, requester_user_id: uuid.UUID, db: Session
) -> None:
    """Delete a follow relationship on behalf of either party.

    One operation serves unfollow and remove-follower: the row is the same and
    the direction is explicit in the arguments, so the only difference is which
    of the two parties asked.

    Args:
        followee_id: The user being followed.
        follower_id: The user doing the following.
        requester_user_id: The authenticated caller, who must be one of the two.
        db: Database session.

    Publishes ``follower.request_removed`` when the deleted row was still a pending request, records a
    decline when the followee removed it, and stages a ``followers.follow.remove`` audit row when it was
    an accepted relationship.

    Raises:
        AccessConcealedError: When the caller is not part of the relationship; answered as a
            missing relationship so it does not confirm one exists.
    """
    if requester_user_id not in (followee_id, follower_id):
        logger.warning(
            "Blocked an attempt to delete a follow relationship the caller is not part of",
            extra=core_logger.context(
                requester_user_id=requester_user_id, followee_id=followee_id, follower_id=follower_id
            ),
        )
        raise core_exceptions.AccessConcealedError("Follow relationship not found")
    deleted_status = followers_crud.delete_follower(follower_id, followee_id, db)
    # Only an accepted relationship granted access; a pending request taken back never did.
    if deleted_status == followers_constants.FollowStatus.ACCEPTED:
        jasil_audit.stage(
            db,
            followers_audit_actions.FOLLOW_REMOVE,
            target_type="user",
            target_id=str(follower_id),
            target_owner_id=str(followee_id),
        )
    # Only a request that was still pending has a notification to take back.
    if deleted_status == followers_constants.FollowStatus.PENDING:
        # The followee removing a pending request is a decline, whichever route did it.
        if requester_user_id == followee_id:
            followers_crud.record_decline(follower_id, followee_id, datetime.now(UTC), db)
        followers_event_publishers.publish_follower_request_removed(
            follower_id, followee_id, db, commit=db.commit, source="api:delete_follow_relationship"
        )
    else:
        db.commit()
    logger.info(
        "Deleted a follow relationship",
        extra=core_logger.context(
            requester_user_id=requester_user_id, followee_id=followee_id, follower_id=follower_id
        ),
    )

follow_user

follow_user(requester_user_id, target_user_id, db)

Create a follow request and publish follower.requested.

The CRUD row write is the source of truth; the notification is produced by the follower.requested subscriber reacting to the published event, so the request succeeds even if notification delivery later fails.

Parameters:

Name Type Description Default
requester_user_id UUID

The authenticated user requesting to follow.

required
target_user_id UUID

The user to follow.

required
db Session

Database session.

required

Returns:

Type Description
FollowRelationshipRead

The newly created follow relationship as a DTO.

Raises:

Type Description
InvalidInputError

If the requester targets themselves.

NotFoundError

If the target user does not exist, is inactive or awaits approval, or has blocked the requester. The answer is the same for all four, so a follow reveals nothing about hidden accounts or blocks.

TooManyRequestsError

If the target declined a request from the requester less than :data:~modules.followers.constants.FOLLOW_REQUEST_COOLDOWN ago; retry_at is when it ends.

ConflictError

If the requester blocked the target, the relationship already exists or the target already has the maximum pending requests.

Source code in backend/app/modules/followers/service.py
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
def follow_user(
    requester_user_id: uuid.UUID, target_user_id: uuid.UUID, db: Session
) -> followers_schema.FollowRelationshipRead:
    """Create a follow request and publish ``follower.requested``.

    The CRUD row write is the source of truth; the notification is produced by the
    ``follower.requested`` subscriber reacting to the published event, so the
    request succeeds even if notification delivery later fails.

    Args:
        requester_user_id: The authenticated user requesting to follow.
        target_user_id: The user to follow.
        db: Database session.

    Returns:
        The newly created follow relationship as a DTO.

    Raises:
        InvalidInputError: If the requester targets themselves.
        NotFoundError: If the target user does not exist, is inactive or awaits approval, or has blocked
            the requester. The answer is the same for all four, so a follow reveals nothing about hidden
            accounts or blocks.
        TooManyRequestsError: If the target declined a request from the requester less than
            :data:`~modules.followers.constants.FOLLOW_REQUEST_COOLDOWN` ago; ``retry_at`` is when it ends.
        ConflictError: If the requester blocked the target, the relationship already exists or the target
            already has the maximum pending requests.
    """
    if requester_user_id == target_user_id:
        # Prevent self-follow, which would otherwise pollute counts and
        # notifications.
        raise core_exceptions.InvalidInputError("Cannot follow yourself")

    # Checked before the pending cap, so a hidden account answers not found, never "too many pending".
    users_integration.get_public_profile(target_user_id, db)
    # A block between the two users takes this same lock, so the block checks below hold until the insert commits.
    followers_crud.lock_pending_requests(target_user_id, db)
    if followers_crud.is_blocked(target_user_id, requester_user_id, db):
        raise core_exceptions.NotFoundError("User not found")
    if followers_crud.is_blocked(requester_user_id, target_user_id, db):
        # The requester blocked the target themselves, so saying so discloses nothing.
        raise core_exceptions.ConflictError("Unblock this user first")
    _ensure_cooldown_over(requester_user_id, target_user_id, db)
    if (
        followers_crud.count_pending_requests_for_user_id(target_user_id, db)
        >= followers_constants.MAX_PENDING_REQUESTS
    ):
        logger.debug(
            "Refused a follow request: the target has too many pending",
            extra=core_logger.context(requester_user_id=requester_user_id, target_user_id=target_user_id),
        )
        raise core_exceptions.ConflictError("This user has too many pending follow requests")
    follower = followers_crud.create_follower(requester_user_id, target_user_id, db)
    followers_event_publishers.publish_follower_requested(requester_user_id, target_user_id, db, commit=db.commit)
    logger.info(
        "Follow requested",
        extra=core_logger.context(requester_user_id=requester_user_id, target_user_id=target_user_id),
    )
    return follower

get_profile_follow_counts

get_profile_follow_counts(target_user_id, requester_user_id, db)

Return accepted network counts, or None when the viewer cannot see the network.

Parameters:

Name Type Description Default
target_user_id UUID

The profile owner whose network to count.

required
requester_user_id UUID

The authenticated viewer.

required
db Session

Database session.

required

Returns:

Type Description
ProfileFollowCounts | None

Both accepted relationship counts, or None when the network is private to this viewer.

Source code in backend/app/modules/followers/service.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
def get_profile_follow_counts(
    target_user_id: uuid.UUID,
    requester_user_id: uuid.UUID,
    db: Session,
) -> followers_contracts.ProfileFollowCounts | None:
    """Return accepted network counts, or None when the viewer cannot see the network.

    Args:
        target_user_id: The profile owner whose network to count.
        requester_user_id: The authenticated viewer.
        db: Database session.

    Returns:
        Both accepted relationship counts, or None when the network is private to this viewer.
    """
    if not _requester_may_view_network(target_user_id, requester_user_id, db):
        return None
    return followers_contracts.ProfileFollowCounts(
        followers=followers_crud.count_followers_by_user_id(target_user_id, db, accepted_only=True),
        following=followers_crud.count_following_by_user_id(target_user_id, db, accepted_only=True),
    )

get_user_relationship

get_user_relationship(other_user_id, requester_user_id, db)

Return the authenticated user's relationship with another user (both directions).

Only ever reports relationships the requester is part of — their outgoing follow of other_user_id and other_user_id's incoming follow of them — so there is no way to probe arbitrary pairs.

Parameters:

Name Type Description Default
other_user_id UUID

The other user in the relationship.

required
requester_user_id UUID

The authenticated requester.

required
db Session

Database session.

required

Returns:

Type Description
RelationshipRead

The requester's outgoing and incoming follow relationships with the other

RelationshipRead

user (either may be None), and whether the requester blocked the other user.

Source code in backend/app/modules/followers/service.py
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
def get_user_relationship(
    other_user_id: uuid.UUID, requester_user_id: uuid.UUID, db: Session
) -> followers_schema.RelationshipRead:
    """Return the authenticated user's relationship with another user (both directions).

    Only ever reports relationships the requester is part of — their outgoing
    follow of ``other_user_id`` and ``other_user_id``'s incoming follow of them —
    so there is no way to probe arbitrary pairs.

    Args:
        other_user_id: The other user in the relationship.
        requester_user_id: The authenticated requester.
        db: Database session.

    Returns:
        The requester's outgoing and incoming follow relationships with the other
        user (either may be None), and whether the requester blocked the other user.
    """
    outgoing = followers_crud.get_follower_for_user_id_and_target_user_id(requester_user_id, other_user_id, db)
    incoming = followers_crud.get_follower_for_user_id_and_target_user_id(other_user_id, requester_user_id, db)
    return followers_schema.RelationshipRead(
        outgoing=outgoing,
        incoming=incoming,
        is_blocked=followers_crud.is_blocked(requester_user_id, other_user_id, db),
    )

list_blocked_users

list_blocked_users(blocker_id, db, *, page_number=1, num_records=core_pagination.DEFAULT_NUM_RECORDS)

Return one page of the users the caller blocked, newest block first.

A blocked user who is inactive or awaiting approval has no public profile, so the list leaves them out and total does not count them.

Parameters:

Name Type Description Default
blocker_id UUID

The user who blocked.

required
db Session

Database session.

required
page_number int

1-based page number.

1
num_records int

Page size.

DEFAULT_NUM_RECORDS

Returns:

Type Description
UserPublicPage

The page of public profiles.

Source code in backend/app/modules/followers/service.py
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
def list_blocked_users(
    blocker_id: uuid.UUID,
    db: Session,
    *,
    page_number: int = 1,
    num_records: int = core_pagination.DEFAULT_NUM_RECORDS,
) -> users_schema.UserPublicPage:
    """Return one page of the users the caller blocked, newest block first.

    A blocked user who is inactive or awaiting approval has no public profile, so the list leaves them out
    and ``total`` does not count them.

    Args:
        blocker_id: The user who blocked.
        db: Database session.
        page_number: 1-based page number.
        num_records: Page size.

    Returns:
        The page of public profiles.
    """
    blocked_ids = followers_crud.list_blocked_user_ids(blocker_id, db)
    profiles = users_integration.list_public_profiles(blocked_ids, db)
    visible = [profiles[user_id] for user_id in blocked_ids if user_id in profiles]
    start = (page_number - 1) * num_records
    return users_schema.UserPublicPage.build(
        visible[start : start + num_records], len(visible), page_number, num_records
    )

list_followers

list_followers(target_user_id, requester_user_id, db, *, page_number=1, num_records=core_pagination.DEFAULT_NUM_RECORDS, accepted_only=False)

Return one page of the target's followers with the matching total.

Parameters:

Name Type Description Default
target_user_id UUID

The user whose followers to list.

required
requester_user_id UUID

The authenticated requester.

required
db Session

Database session.

required
page_number int

1-based page number.

1
num_records int

Page size.

DEFAULT_NUM_RECORDS
accepted_only bool

Exclude pending follow requests when True.

False

Returns:

Type Description
FollowRelationshipPage

The page envelope. total counts every follower matching the same

FollowRelationshipPage

filter, not just this page.

Raises:

Type Description
AccessConcealedError

When the requester may not view this network; answered like a missing user.

Source code in backend/app/modules/followers/service.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def list_followers(
    target_user_id: uuid.UUID,
    requester_user_id: uuid.UUID,
    db: Session,
    *,
    page_number: int = 1,
    num_records: int = core_pagination.DEFAULT_NUM_RECORDS,
    accepted_only: bool = False,
) -> followers_schema.FollowRelationshipPage:
    """Return one page of the target's followers with the matching total.

    Args:
        target_user_id: The user whose followers to list.
        requester_user_id: The authenticated requester.
        db: Database session.
        page_number: 1-based page number.
        num_records: Page size.
        accepted_only: Exclude pending follow requests when True.

    Returns:
        The page envelope. ``total`` counts every follower matching the same
        filter, not just this page.

    Raises:
        AccessConcealedError: When the requester may not view this network;
            answered like a missing user.
    """
    return _list_network(
        target_user_id,
        requester_user_id,
        followers_crud.get_all_followers_by_user_id,
        followers_crud.count_followers_by_user_id,
        operator.attrgetter("follower_id"),
        db,
        page_number=page_number,
        num_records=num_records,
        accepted_only=accepted_only,
    )

list_following

list_following(target_user_id, requester_user_id, db, *, page_number=1, num_records=core_pagination.DEFAULT_NUM_RECORDS, accepted_only=False)

Return one page of who the target follows with the matching total.

Parameters:

Name Type Description Default
target_user_id UUID

The user whose following list to return.

required
requester_user_id UUID

The authenticated requester.

required
db Session

Database session.

required
page_number int

1-based page number.

1
num_records int

Page size.

DEFAULT_NUM_RECORDS
accepted_only bool

Exclude pending follow requests when True.

False

Returns:

Type Description
FollowRelationshipPage

The page envelope. total counts every followee matching the same

FollowRelationshipPage

filter, not just this page.

Raises:

Type Description
AccessConcealedError

When the requester may not view this network; answered like a missing user.

Source code in backend/app/modules/followers/service.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
def list_following(
    target_user_id: uuid.UUID,
    requester_user_id: uuid.UUID,
    db: Session,
    *,
    page_number: int = 1,
    num_records: int = core_pagination.DEFAULT_NUM_RECORDS,
    accepted_only: bool = False,
) -> followers_schema.FollowRelationshipPage:
    """Return one page of who the target follows with the matching total.

    Args:
        target_user_id: The user whose following list to return.
        requester_user_id: The authenticated requester.
        db: Database session.
        page_number: 1-based page number.
        num_records: Page size.
        accepted_only: Exclude pending follow requests when True.

    Returns:
        The page envelope. ``total`` counts every followee matching the same
        filter, not just this page.

    Raises:
        AccessConcealedError: When the requester may not view this network;
            answered like a missing user.
    """
    return _list_network(
        target_user_id,
        requester_user_id,
        followers_crud.get_all_following_by_user_id,
        followers_crud.count_following_by_user_id,
        operator.attrgetter("followee_id"),
        db,
        page_number=page_number,
        num_records=num_records,
        accepted_only=accepted_only,
    )

list_pending_requests

list_pending_requests(requester_user_id, db, *, page_number=1, num_records=core_pagination.DEFAULT_NUM_RECORDS)

Return one page of follow requests awaiting the caller's decision.

Always scoped to the caller: a pending request is private to the two parties, so there is no target_user_id to pass and therefore nothing to probe.

Parameters:

Name Type Description Default
requester_user_id UUID

The authenticated caller.

required
db Session

Database session.

required
page_number int

1-based page number.

1
num_records int

Page size.

DEFAULT_NUM_RECORDS

Returns:

Type Description
FollowRelationshipPage

The page envelope, with the profile of each requester.

Source code in backend/app/modules/followers/service.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def list_pending_requests(
    requester_user_id: uuid.UUID,
    db: Session,
    *,
    page_number: int = 1,
    num_records: int = core_pagination.DEFAULT_NUM_RECORDS,
) -> followers_schema.FollowRelationshipPage:
    """Return one page of follow requests awaiting the caller's decision.

    Always scoped to the caller: a pending request is private to the two parties,
    so there is no ``target_user_id`` to pass and therefore nothing to probe.

    Args:
        requester_user_id: The authenticated caller.
        db: Database session.
        page_number: 1-based page number.
        num_records: Page size.

    Returns:
        The page envelope, with the profile of each requester.
    """
    items = followers_crud.get_pending_requests_for_user_id(
        requester_user_id, db, page_number=page_number, num_records=num_records
    )
    total = followers_crud.count_pending_requests_for_user_id(requester_user_id, db)
    page = followers_schema.FollowRelationshipPage.build(items, total, page_number, num_records)
    return _with_profiles(page, operator.attrgetter("follower_id"), db)

reject_follow_request

reject_follow_request(requester_user_id, follower_id, db)

Decline a pending follow request addressed to the caller and publish follower.request_removed.

Records the decline, so the requester cannot ask the caller again for :data:~modules.followers.constants.FOLLOW_REQUEST_COOLDOWN.

Distinct from :func:delete_relationship, which severs an already-accepted relationship. Both delete the same row, but only one of them is a decision the requester never had granted — so this one is scoped to PENDING, and an accepted follower is removed through the relationship route instead of silently through here.

Parameters:

Name Type Description Default
requester_user_id UUID

The authenticated user declining the request.

required
follower_id UUID

The user whose pending request is declined.

required
db Session

Database session.

required

Raises:

Type Description
NotFoundError

When no pending request from that user exists.

Source code in backend/app/modules/followers/service.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
def reject_follow_request(requester_user_id: uuid.UUID, follower_id: uuid.UUID, db: Session) -> None:
    """Decline a pending follow request addressed to the caller and publish ``follower.request_removed``.

    Records the decline, so the requester cannot ask the caller again for
    :data:`~modules.followers.constants.FOLLOW_REQUEST_COOLDOWN`.

    Distinct from :func:`delete_relationship`, which severs an already-accepted
    relationship. Both delete the same row, but only one of them is a decision
    the requester never had granted — so this one is scoped to ``PENDING``, and
    an accepted follower is removed through the relationship route instead of
    silently through here.

    Args:
        requester_user_id: The authenticated user declining the request.
        follower_id: The user whose pending request is declined.
        db: Database session.

    Raises:
        NotFoundError: When no pending request from that user exists.
    """
    followers_crud.delete_follower(follower_id, requester_user_id, db, status=followers_constants.FollowStatus.PENDING)
    followers_crud.record_decline(follower_id, requester_user_id, datetime.now(UTC), db)
    followers_event_publishers.publish_follower_request_removed(
        follower_id, requester_user_id, db, commit=db.commit, source="api:reject_follow_request"
    )
    logger.info(
        "Follow request rejected",
        extra=core_logger.context(requester_user_id=requester_user_id, follower_id=follower_id),
    )

unblock_user

unblock_user(blocker_id, blocked_id, db)

Remove a block.

Parameters:

Name Type Description Default
blocker_id UUID

The user who blocked.

required
blocked_id UUID

The user to unblock.

required
db Session

Database session.

required

Raises:

Type Description
NotFoundError

When the user has not blocked that user.

Source code in backend/app/modules/followers/service.py
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
def unblock_user(blocker_id: uuid.UUID, blocked_id: uuid.UUID, db: Session) -> None:
    """Remove a block.

    Args:
        blocker_id: The user who blocked.
        blocked_id: The user to unblock.
        db: Database session.

    Raises:
        NotFoundError: When the user has not blocked that user.
    """
    followers_crud.delete_block(blocker_id, blocked_id, db)
    jasil_audit.stage(
        db,
        followers_audit_actions.BLOCK_REMOVE,
        target_type="user",
        target_id=str(blocked_id),
        target_owner_id=str(blocker_id),
    )
    db.commit()
    logger.info("Unblocked a user", extra=core_logger.context(blocker_id=blocker_id, blocked_id=blocked_id))

Schemas

Pydantic schemas for follower relationships.

FollowRelationshipPage

Bases: Page[FollowRelationshipRead]

One page of follow relationships, in the envelope the activities lists use.

Attributes:

Name Type Description
users dict[UUID, UserPublicRead]

The public profile of the user on the other side of each row (the follower in a followers list, the followee in a following list, the requester among pending requests), keyed by user ID. It is the projection GET /users/{user_id} returns, so a list needs no lookup per row. A user who is inactive or awaiting approval has no entry.

Source code in backend/app/modules/followers/schema.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class FollowRelationshipPage(core_pagination.Page[FollowRelationshipRead]):
    """One page of follow relationships, in the envelope the activities lists use.

    Attributes:
        users: The public profile of the user on the other side of each row (the follower in a
            followers list, the followee in a following list, the requester among pending requests),
            keyed by user ID. It is the projection ``GET /users/{user_id}`` returns, so a list needs
            no lookup per row. A user who is inactive or awaiting approval has no entry.
    """

    users: dict[uuid.UUID, users_schema.UserPublicRead] = Field(
        default_factory=dict,
        description="Public profile of the user on the other side of each row, keyed by user ID",
    )

FollowRelationshipRead

Bases: BaseModel

Serialized representation of a follow relationship.

Attributes:

Name Type Description
follower_id UUID

The user who follows (the requester).

followee_id UUID

The user being followed.

status FollowStatus

Whether the request is pending or accepted.

Source code in backend/app/modules/followers/schema.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class FollowRelationshipRead(BaseModel):
    """Serialized representation of a follow relationship.

    Attributes:
        follower_id: The user who follows (the requester).
        followee_id: The user being followed.
        status: Whether the request is pending or accepted.
    """

    model_config = ConfigDict(from_attributes=True, extra="forbid")

    follower_id: uuid.UUID
    followee_id: uuid.UUID
    status: followers_constants.FollowStatus

RelationshipRead

Bases: BaseModel

The authenticated user's relationship with another user, both directions.

Attributes:

Name Type Description
outgoing FollowRelationshipRead | None

The authenticated user's follow of the other user, if any.

incoming FollowRelationshipRead | None

The other user's follow of the authenticated user, if any.

is_blocked bool

Whether the authenticated user has blocked the other user.

Source code in backend/app/modules/followers/schema.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class RelationshipRead(BaseModel):
    """The authenticated user's relationship with another user, both directions.

    Attributes:
        outgoing: The authenticated user's follow of the other user, if any.
        incoming: The other user's follow of the authenticated user, if any.
        is_blocked: Whether the authenticated user has blocked the other user.
    """

    model_config = ConfigDict(from_attributes=True, extra="forbid")

    outgoing: FollowRelationshipRead | None = None
    incoming: FollowRelationshipRead | None = None
    is_blocked: bool = False

Events

Domain event channels owned by the followers module.

Channel names (event_type values) are owned by the publishing domain, not the platform substrate. The follow service publishes the facts below; the follower notification subscriber reacts by subscribing to the same constants, so producer and subscriber cannot drift on the string. Convention: <domain>.<fact>, past tense.

FollowerAcceptedPayload

Bases: VersionedPayload

Validated payload for the follower.accepted event.

Attributes:

Name Type Description
accepter_user_id UUID

The user who accepted the request.

requester_user_id UUID

The original requester (who is notified).

Source code in backend/app/modules/followers/events.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class FollowerAcceptedPayload(VersionedPayload):
    """Validated payload for the ``follower.accepted`` event.

    Attributes:
        accepter_user_id: The user who accepted the request.
        requester_user_id: The original requester (who is notified).
    """

    model_config = ConfigDict(extra="ignore")

    SCHEMA_VERSION: ClassVar[int] = 1

    accepter_user_id: uuid.UUID
    requester_user_id: uuid.UUID

FollowerRequestRemovedPayload

Bases: VersionedPayload

Validated payload for the follower.request_removed event.

Attributes:

Name Type Description
requester_user_id UUID

The user whose follow request was removed.

target_user_id UUID

The user the request was addressed to (who owns the notification).

Source code in backend/app/modules/followers/events.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class FollowerRequestRemovedPayload(VersionedPayload):
    """Validated payload for the ``follower.request_removed`` event.

    Attributes:
        requester_user_id: The user whose follow request was removed.
        target_user_id: The user the request was addressed to (who owns the notification).
    """

    model_config = ConfigDict(extra="ignore")

    SCHEMA_VERSION: ClassVar[int] = 1

    requester_user_id: uuid.UUID
    target_user_id: uuid.UUID

FollowerRequestedPayload

Bases: VersionedPayload

Validated payload for the follower.requested event.

Subscribers validate against this schema so a malformed payload raises at the boundary — with the offending fields named — instead of being silently dropped by ad-hoc type checks.

Attributes:

Name Type Description
requester_user_id UUID

The user who requested to follow.

target_user_id UUID

The user being followed (who is notified).

Source code in backend/app/modules/followers/events.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class FollowerRequestedPayload(VersionedPayload):
    """Validated payload for the ``follower.requested`` event.

    Subscribers validate against this schema so a malformed payload raises at the
    boundary — with the offending fields named — instead of being silently
    dropped by ad-hoc type checks.

    Attributes:
        requester_user_id: The user who requested to follow.
        target_user_id: The user being followed (who is notified).
    """

    model_config = ConfigDict(extra="ignore")

    SCHEMA_VERSION: ClassVar[int] = 1

    requester_user_id: uuid.UUID
    target_user_id: uuid.UUID