[schema] models: add an email_token field to Streams.

The e-mail forwarder will use this. Set it to nullable temporarily to
accomodate existing streams; later commits will a) provide a script to
give all streams a token, and b) make the field non-null.

Realm administrators will eventually have a UI to regenerate stream
tokens.

(imported from commit a084d0a7012eb9665e4da095cbc46aa9ef354eaa)
This commit is contained in:
Jessica McKellar
2013-08-08 10:51:18 -04:00
parent 3f8dfc7b9b
commit c020545e02
2 changed files with 197 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ from django.contrib.auth.models import AbstractBaseUser, UserManager, \
from zerver.lib.cache import cache_with_key, update_user_profile_cache, \
user_profile_by_id_cache_key, user_profile_by_email_cache_key, \
update_user_presence_cache, generic_bulk_cached_fetch
from zerver.lib.utils import make_safe_digest
from zerver.lib.utils import make_safe_digest, generate_random_token
from django.db import transaction, IntegrityError
from zerver.lib import bugdown
from zerver.lib.avatar import gravatar_hash, avatar_url
@@ -182,6 +182,11 @@ class Stream(models.Model):
name = models.CharField(max_length=MAX_NAME_LENGTH, db_index=True)
realm = models.ForeignKey(Realm, db_index=True)
invite_only = models.NullBooleanField(default=False)
# Used by the e-mail forwarder. The e-mail RFC specifies a maximum
# e-mail length of 254, and our max stream length is 30, so we
# have plenty of room for the token.
email_token = models.CharField(
max_length=32, default=lambda: generate_random_token(32), null=True)
def __repr__(self):
return (u"<Stream: %s>" % (self.name,)).encode("utf-8")