models: Update values of PreregistrationUser.invite_as dict.

This commit changes the PreregistrationUser.invite_as dict to have
same set of values as we have for UserProfile.role.

This also adds a data migration to update the already exisiting
PreregistrationUser and MultiuseInvite objects.
This commit is contained in:
sahil839 2020-06-22 01:25:48 +05:30 committed by Tim Abbott
parent b7b173d2ae
commit 1f8f227444
4 changed files with 16 additions and 13 deletions

View File

@ -14,7 +14,7 @@ from zerver.lib.actions import do_create_multiuse_invite_link, do_send_realm_rea
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import reset_emails_in_zulip_realm
from zerver.lib.timestamp import ceiling_to_day, ceiling_to_hour, datetime_to_timestamp
from zerver.models import Client, MultiuseInvite, get_realm
from zerver.models import Client, MultiuseInvite, PreregistrationUser, get_realm
class TestStatsEndpoint(ZulipTestCase):
@ -521,7 +521,8 @@ class TestSupportEndpoint(ZulipTestCase):
stream_ids = [self.get_stream_id("Denmark")]
invitee_emails = [self.nonreg_email("test1")]
self.client_post("/json/invites", {"invitee_emails": invitee_emails,
"stream_ids": ujson.dumps(stream_ids), "invite_as": 1})
"stream_ids": ujson.dumps(stream_ids),
"invite_as": PreregistrationUser.INVITE_AS['MEMBER']})
result = self.client_get("/activity/support", {"q": self.nonreg_email("test1")})
check_preregistration_user_query_result(result, self.nonreg_email("test1"), invite=True)
check_zulip_realm_query_result(result)

View File

@ -1,4 +1,5 @@
const util = require("./util");
const settings_config = require("./settings_config");
const render_admin_invites_list = require("../templates/admin_invites_list.hbs");
const render_settings_revoke_invite_modal = require("../templates/settings/revoke_invite_modal.hbs");
@ -16,10 +17,10 @@ function failed_listing_invites(xhr) {
}
exports.invited_as_values = new Map([
[1, i18n.t("Member")],
[2, i18n.t("Organization administrator")],
[3, i18n.t("Guest")],
[4, i18n.t("Organization owner")],
[100, i18n.t("Organization owner")],
[200, i18n.t("Organization administrator")],
[400, i18n.t("Member")],
[600, i18n.t("Guest")],
]);
function add_invited_as_text(invites) {
@ -52,7 +53,8 @@ function populate_invites(invites_data) {
modifier: function (item) {
item.invited_absolute_time = timerender.absolute_time(item.invited * 1000);
item.is_admin = page_params.is_admin;
item.disable_buttons = item.invited_as === 4 && !page_params.is_owner;
item.disable_buttons = item.invited_as === settings_config.user_role_values.owner.code
&& !page_params.is_owner;
return render_admin_invites_list({ invite: item });
},
filter: {

View File

@ -1370,10 +1370,10 @@ class PreregistrationUser(models.Model):
# settings_invites.invited_as_values in
# static/js/settings_invites.js
INVITE_AS = dict(
MEMBER = 1,
REALM_ADMIN = 2,
GUEST_USER = 3,
REALM_OWNER = 4,
REALM_OWNER = 100,
REALM_ADMIN = 200,
MEMBER = 400,
GUEST_USER = 600,
)
invited_as: int = models.PositiveSmallIntegerField(default=INVITE_AS['MEMBER'])

View File

@ -760,7 +760,7 @@ class InviteUserBase(ZulipTestCase):
self.assertRegex(outbox[0].from_email, fr" <{self.TOKENIZED_NOREPLY_REGEX}>\Z")
def invite(self, invitee_emails: str, stream_names: Sequence[str], body: str='',
invite_as: int=1) -> HttpResponse:
invite_as: int=PreregistrationUser.INVITE_AS['MEMBER']) -> HttpResponse:
"""
Invites the specified users to Zulip with the specified streams.
@ -989,7 +989,7 @@ class InviteUserTest(InviteUserBase):
"""
self.login('iago')
invitee = self.nonreg_email('alice')
response = self.invite(invitee, ["Denmark"], invite_as=100)
response = self.invite(invitee, ["Denmark"], invite_as=10)
self.assert_json_error(response, "Must be invited as an valid type of user")
def test_successful_invite_user_as_guest_from_normal_account(self) -> None: