Properly compute the name of our tutorial stream server-side.

It's subtle, but the slice was in the wrong place and wasn't
actually truncating the stream name at all, so the client and
server disagreed about where the tutorial messages should go.

(It might be the case that we should accept the tutorial stream
name from the client directly, rather than computing it in two
places.)

(imported from commit 8273223f182e8ad36eaea1cbf75e1426fcfdfbab)
This commit is contained in:
Waseem Daher
2013-04-23 16:04:28 -04:00
parent c05c391c31
commit eab43f28f4
2 changed files with 9 additions and 2 deletions

View File

@@ -82,8 +82,11 @@ class UserProfile(AbstractBaseUser):
tutorial_status = models.CharField(default=TUTORIAL_WAITING, choices=TUTORIAL_STATES, max_length=1) tutorial_status = models.CharField(default=TUTORIAL_WAITING, choices=TUTORIAL_STATES, max_length=1)
def tutorial_stream_name(self): def tutorial_stream_name(self):
return "tutorial-%s" % \ # If you change this, you need to change the corresponding
(self.email.split('@')[0],)[:Stream.MAX_NAME_LENGTH] # client-computed version of it in tutorial.js
long_name = "tutorial-%s" % (self.email.split('@')[0],)
short_name = long_name[:Stream.MAX_NAME_LENGTH]
return short_name
objects = UserManager() objects = UserManager()
@@ -113,6 +116,8 @@ class MitUser(models.Model):
status = models.IntegerField(default=0) status = models.IntegerField(default=0)
class Stream(models.Model): class Stream(models.Model):
# If you change this, you also need to change the
# corresponding value in tutorial.js
MAX_NAME_LENGTH = 30 MAX_NAME_LENGTH = 30
name = models.CharField(max_length=MAX_NAME_LENGTH, db_index=True) name = models.CharField(max_length=MAX_NAME_LENGTH, db_index=True)
realm = models.ForeignKey(Realm, db_index=True) realm = models.ForeignKey(Realm, db_index=True)

View File

@@ -269,6 +269,8 @@ exports.is_running = function () {
function make_script() { function make_script() {
my_tutorial_stream = 'tutorial-' + page_params.email.split('@')[0]; my_tutorial_stream = 'tutorial-' + page_params.email.split('@')[0];
// If you change this, you need to change the corresponding
// client-computed version in models.py on the server.
my_tutorial_stream = my_tutorial_stream.substring(0, 30); my_tutorial_stream = my_tutorial_stream.substring(0, 30);
script = [ script = [