Aller au contenu

# Views

## `MergeUsersView`

Bases: `FormView`

## `DeleteAllForumUserMessagesView`

Bases: `FormView`

Delete all forum messages from an user.

Messages are soft deleted and are still visible from admins GUI frontend to the dedicated command.

## `OperationLogListView`

Bases: `ListView`, `CanEditPropMixin`

List all logs.

## `BanView`

Bases: `PermissionRequiredMixin`, `ListView`

UserBan management view.

Displays :

- the list of active bans with their main information, with a link to BanDeleteView for each one
- a link which redirects to BanCreateView

## `BanCreateView`

Bases: `PermissionRequiredMixin`, `CreateView`

UserBan creation view.

## `BanDeleteView`

Bases: `PermissionRequiredMixin`, `DeleteView`

UserBan deletion view.

## `merge_users(u1, u2)`

Merge u2 into u1.

This means that u1 shall receive everything that belonged to u2 :

    - pictures
    - refills of the sith account
    - purchases of any item bought on the eboutic or the counters
    - subscriptions
    - godfathers
    - godchildren

If u1 had no account id, he shall receive the one of u2. If u1 and u2 were both in the middle of a subscription, the remaining durations stack If u1 had no profile picture, he shall receive the one of u2

Source code in `rootplace/views.py`

     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    def merge_users(u1: User, u2: User) -> User:
        """Merge u2 into u1.

        This means that u1 shall receive everything that belonged to u2 :

            - pictures
            - refills of the sith account
            - purchases of any item bought on the eboutic or the counters
            - subscriptions
            - godfathers
            - godchildren

        If u1 had no account id, he shall receive the one of u2.
        If u1 and u2 were both in the middle of a subscription, the remaining
        durations stack
        If u1 had no profile picture, he shall receive the one of u2
        """
        for field in u1._meta.fields:
            if not field.is_relation and not u1.__dict__[field.name]:
                u1.__dict__[field.name] = u2.__dict__[field.name]
        for group in u2.groups.all():
            u1.groups.add(group.id)
        for godfather in u2.godfathers.exclude(id=u1.id):
            u1.godfathers.add(godfather)
        for godchild in u2.godchildren.exclude(id=u1.id):
            u1.godchildren.add(godchild)
        __merge_subscriptions(u1, u2)
        __merge_pictures(u1, u2)
        u2.invoices.all().update(user=u1)
        c_src = Customer.objects.filter(user=u2).first()
        if c_src is not None:
            c_dest, created = Customer.get_or_create(u1)
            c_src.refillings.update(customer=c_dest)
            c_src.buyings.update(customer=c_dest)
            Customer.objects.filter(pk=c_dest.pk).update_amount()
            if created:
                # swap the account numbers, so that the user keep
                # the id he is accustomed to
                tmp_id = c_src.account_id
                # delete beforehand in order not to have a unique constraint violation
                c_src.delete()
                c_dest.account_id = tmp_id
        u1.save()
        u2.delete()  # everything remaining in u2 gets deleted thanks to on_delete=CASCADE
        return u1

## `delete_all_forum_user_messages(user, moderator, *, verbose=False)`

Soft delete all messages of a user.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`user` | `User` | core.models.User the user to delete messages from | required
`moderator` | `User` | core.models.User the one marked as the moderator. | required
`verbose` | `bool` | bool if True, print the deleted messages | `False`

Source code in `rootplace/views.py`

    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    def delete_all_forum_user_messages(
        user: User, moderator: User, *, verbose: bool = False
    ):
        """Soft delete all messages of a user.

        Args:
            user: core.models.User the user to delete messages from
            moderator: core.models.User the one marked as the moderator.
            verbose: bool if True, print the deleted messages
        """
        for message in user.forum_messages.all():
            if message.is_deleted():
                continue

            if verbose:
                logging.getLogger("django").info(message)
            ForumMessageMeta(message=message, user=moderator, action="DELETE").save()