def approve_user_profile(update: Update, context: CallbackContext) -> None: _, user_id = update.callback_query.data.split(":", 1) user = User.objects.get(id=user_id) if user.moderation_status == User.MODERATION_STATUS_APPROVED: update.effective_chat.send_message(f"Пользователь «{user.full_name}» уже одобрен") return None if user.moderation_status == User.MODERATION_STATUS_REJECTED: update.effective_chat.send_message(f"Пользователь «{user.full_name}» уже был отклонен") return None user.moderation_status = User.MODERATION_STATUS_APPROVED user.save() # make intro visible Post.objects\ .filter(author=user, type=Post.TYPE_INTRO)\ .update(is_visible=True, published_at=datetime.utcnow(), is_approved_by_moderator=True) SearchIndex.update_user_index(user) notify_user_profile_approved(user) send_welcome_drink(user) update.effective_chat.send_message( f"✅ Пользователь «{user.full_name}» одобрен ({update.effective_user.full_name})" ) # hide buttons update.callback_query.edit_message_reply_markup(reply_markup=None) return None
def approve_user_profile(user_id: str, update: Update) -> (str, bool): user = User.objects.get(id=user_id) if user.is_profile_reviewed and user.is_profile_complete: return f"Пользователь «{user.full_name}» уже одобрен", True user.is_profile_complete = True user.is_profile_reviewed = True user.is_profile_rejected = False user.save() # make intro visible Post.objects\ .filter(author=user, type=Post.TYPE_INTRO)\ .update(is_visible=True, is_approved_by_moderator=True) notify_user_profile_approved(user) send_welcome_drink(user) return f"✅ Пользователь «{user.full_name}» одобрен ({update.effective_user.full_name})", True
def approve_user_profile(user_id: str, update: Update) -> (str, bool): user = User.objects.get(id=user_id) if user.moderation_status == User.MODERATION_STATUS_APPROVED: return f"Пользователь «{user.full_name}» уже одобрен", True if user.moderation_status == User.MODERATION_STATUS_REJECTED: return f"Пользователь «{user.full_name}» уже отклонен", True user.moderation_status = User.MODERATION_STATUS_APPROVED user.save() # make intro visible Post.objects\ .filter(author=user, type=Post.TYPE_INTRO)\ .update(is_visible=True, published_at=datetime.utcnow(), is_approved_by_moderator=True) SearchIndex.update_user_index(user) notify_user_profile_approved(user) send_welcome_drink(user) return f"✅ Пользователь «{user.full_name}» одобрен ({update.effective_user.full_name})", True