Esempio n. 1
0
def profile_delete(e: TextMessageEventObject, name: str):
    # --- Check profile name
    prof = ProfileManager.get_profile_name(name)
    if not prof:
        return [
            HandledMessageEventText(content=_(
                "Profile with the name `{}` not found.").format(name))
        ]

    # --- Check permission

    profiles = ProfileManager.get_user_profiles(e.channel_model.id,
                                                e.user_model.id)
    user_permissions = ProfileManager.get_permissions(profiles)

    if ProfilePermission.PRF_CED not in user_permissions:
        return [
            HandledMessageEventText(
                content=_("Insufficient permission to delete profile."))
        ]

    deleted = ProfileManager.delete_profile(e.channel_oid, prof.id,
                                            e.user_model.id)
    if deleted:
        return [HandledMessageEventText(content=_("Profile deleted."))]
    else:
        return [
            HandledMessageEventText(content=_("Failed to delete the profile."))
        ]
Esempio n. 2
0
    def action_delete(request, channel_model, profile_oid):
        # Terminate if the profile to be deleted is the default profile
        if channel_model.config.default_profile_oid == profile_oid:
            messages.warning(
                request,
                _("Attempted to delete the default profile which is not allowed."
                  ))
            return redirect(
                reverse("info.profile", kwargs={"profile_oid": profile_oid}))

        # Detach profile from all users and delete the profile from the database
        deleted = ProfileManager.delete_profile(channel_model.id, profile_oid,
                                                get_root_oid(request))

        # Alert messages
        if deleted:
            messages.info(request, _("Profile deleted."))
            return redirect(reverse("account.channel.list"))
        else:
            messages.warning(request, _("Failed to delete the profile."))
            return redirect(
                reverse("info.profile", kwargs={"profile_oid": profile_oid}))