users: Remove redundant get_role_for_new_user in lib/create_user.py.

The function get_role_for_new_user was added to get role from the
invited_as value, as invited_as values were one of (1,2,3,4)
previously, but it was then changed to be the actual role value,
i.e. one of (100, 200, 400, 600), in 1f8f227444.

So, we can safely remove this function now and use invited_as value
directly and handle realm_creation case by using an if condition.
This commit is contained in:
sahil839
2021-04-30 18:07:48 +05:30
committed by Tim Abbott
parent bf447a726f
commit a4c3224328
3 changed files with 9 additions and 23 deletions

View File

@@ -7,15 +7,7 @@ from django.utils.timezone import now as timezone_now
from zerver.lib.hotspots import copy_hotspots
from zerver.lib.upload import copy_avatar
from zerver.lib.utils import generate_api_key
from zerver.models import (
PreregistrationUser,
Realm,
Recipient,
Stream,
Subscription,
UserProfile,
get_fake_email_domain,
)
from zerver.models import Realm, Recipient, Stream, Subscription, UserProfile, get_fake_email_domain
def copy_user_settings(source_profile: UserProfile, target_profile: UserProfile) -> None:
@@ -57,16 +49,6 @@ def get_display_email_address(user_profile: UserProfile) -> str:
return user_profile.delivery_email
def get_role_for_new_user(invited_as: int, realm_creation: bool = False) -> int:
if realm_creation or invited_as == PreregistrationUser.INVITE_AS["REALM_OWNER"]:
return UserProfile.ROLE_REALM_OWNER
elif invited_as == PreregistrationUser.INVITE_AS["REALM_ADMIN"]:
return UserProfile.ROLE_REALM_ADMINISTRATOR
elif invited_as == PreregistrationUser.INVITE_AS["GUEST_USER"]:
return UserProfile.ROLE_GUEST
return UserProfile.ROLE_MEMBER
# create_user_profile is based on Django's User.objects.create_user,
# except that we don't save to the database so it can used in
# bulk_creates