stripe: Create make_user_billing_admin helper function.

This commit is contained in:
Vishnu KS 2021-05-28 16:06:41 +05:30 committed by Tim Abbott
parent d5ba94082a
commit 3d5ee69b21
3 changed files with 10 additions and 4 deletions

View File

@ -299,8 +299,9 @@ def do_create_stripe_customer(user: UserProfile, stripe_token: Optional[str] = N
customer, created = Customer.objects.update_or_create(
realm=realm, defaults={"stripe_customer_id": stripe_customer.id}
)
user.is_billing_admin = True
user.save(update_fields=["is_billing_admin"])
from zerver.lib.actions import do_make_user_billing_admin
do_make_user_billing_admin(user)
return customer

View File

@ -44,6 +44,7 @@ from zerver.decorator import (
require_organization_member,
zulip_login_required,
)
from zerver.lib.actions import do_make_user_billing_admin
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_error, json_success
from zerver.lib.send_email import FromAddress, send_email
@ -260,8 +261,7 @@ def sponsorship(
)
update_sponsorship_status(realm, True, acting_user=user)
user.is_billing_admin = True
user.save(update_fields=["is_billing_admin"])
do_make_user_billing_admin(user)
return json_success()

View File

@ -4559,6 +4559,11 @@ def do_change_user_role(
send_event(user_profile.realm, event, active_user_ids(user_profile.realm_id))
def do_make_user_billing_admin(user_profile: UserProfile) -> None:
user_profile.is_billing_admin = True
user_profile.save(update_fields=["is_billing_admin"])
def do_change_can_forge_sender(user_profile: UserProfile, value: bool) -> None:
user_profile.can_forge_sender = value
user_profile.save(update_fields=["can_forge_sender"])