diff --git a/api/zephyr_mirror.py b/api/zephyr_mirror.py index 715dcf1381..dd0b4cc7fe 100644 --- a/api/zephyr_mirror.py +++ b/api/zephyr_mirror.py @@ -153,7 +153,7 @@ def process_loop(log): 'zsig' : zsig, # logged here but not used by app 'content' : body } else: - zeph = { 'type' : 'class', + zeph = { 'type' : 'stream', 'time' : str(notice.time), 'sender' : sender, 'class' : notice.cls.lower(), @@ -221,7 +221,7 @@ def forward_to_zephyr(message): for line in cleaned_content.split("\n")) print "Sending message from %s humbug=>zephyr at %s" % (message["sender_email"], datetime.datetime.now()) - if message['type'] == "class": + if message['type'] == "stream": zeph = zephyr.ZNotice(sender=message["sender_email"].replace("mit.edu", "ATHENA.MIT.EDU"), auth=True, cls=message["display_recipient"], instance=message["instance"]) diff --git a/tools/post-receive b/tools/post-receive index 66efdc8b46..668fbe75dc 100755 --- a/tools/post-receive +++ b/tools/post-receive @@ -43,7 +43,7 @@ def process_push(oldrev, newrev, refname): oldrev, newrev, refname]) commits = subprocess.check_output(["git", "log", "--reverse", "--pretty=- **%aN**: %s", "%s..%s" % (oldrev, newrev)]) message_data = { - "type": "class", + "type": "stream", "class": "test" if refname == "refs/heads/test-post-receive" else "devel", "instance": "commits", "content": "The following commits were just pushed to `%s`:\n\n" diff --git a/zephyr/management/commands/populate_db.py b/zephyr/management/commands/populate_db.py index e37ff4a873..b9b43674c0 100644 --- a/zephyr/management/commands/populate_db.py +++ b/zephyr/management/commands/populate_db.py @@ -118,7 +118,7 @@ class Command(BaseCommand): # Create public classes. create_streams(class_list, humbug_realm) recipient_classes = [klass.type_id for klass in - Recipient.objects.filter(type=Recipient.CLASS)] + Recipient.objects.filter(type=Recipient.STREAM)] # Create subscriptions to classes profiles = UserProfile.objects.all() @@ -126,14 +126,14 @@ class Command(BaseCommand): # Subscribe to some classes. for recipient in recipient_classes[:int(len(recipient_classes) * float(i)/len(profiles)) + 1]: - r = Recipient.objects.get(type=Recipient.CLASS, type_id=recipient) + r = Recipient.objects.get(type=Recipient.STREAM, type_id=recipient) new_subscription = Subscription(userprofile=profile, recipient=r) new_subscription.save() else: humbug_realm = Realm.objects.get(domain="humbughq.com") recipient_classes = [klass.type_id for klass in - Recipient.objects.filter(type=Recipient.CLASS)] + Recipient.objects.filter(type=Recipient.STREAM)] # Extract a list of all users users = [user.id for user in User.objects.all()] @@ -170,7 +170,7 @@ class Command(BaseCommand): profiles = UserProfile.objects.filter(realm=mit_realm) for cls in mit_subs_list.all_subs: stream = Stream.objects.get(name=cls, realm=mit_realm) - recipient = Recipient.objects.get(type=Recipient.CLASS, type_id=stream.id) + recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id) for i, profile in enumerate(profiles): if profile.user.email in mit_subs_list.subs_lists: key = profile.user.email @@ -189,7 +189,7 @@ class Command(BaseCommand): profiles = UserProfile.objects.filter(realm=humbug_realm) for cls in humbug_class_list: stream = Stream.objects.get(name=cls, realm=humbug_realm) - recipient = Recipient.objects.get(type=Recipient.CLASS, type_id=stream.id) + recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id) for i, profile in enumerate(profiles): # Subscribe to some classes. new_subscription = Subscription(userprofile=profile, recipient=recipient) @@ -235,7 +235,7 @@ def restore_saved_messages(): old_message["sender_full_name"], old_message["sender_short_name"]) message.sender = UserProfile.objects.get(user__email=old_message["sender_email"]) - type_hash = {"class": Recipient.CLASS, "huddle": Recipient.HUDDLE, "personal": Recipient.PERSONAL} + type_hash = {"stream": Recipient.STREAM, "huddle": Recipient.HUDDLE, "personal": Recipient.PERSONAL} message.type = type_hash[old_message["type"]] message.content = old_message["content"] message.instance = old_message["instance"] @@ -248,9 +248,9 @@ def restore_saved_messages(): user_profile = UserProfile.objects.get(user__email=u["email"]) message.recipient = Recipient.objects.get(type=Recipient.PERSONAL, type_id=user_profile.id) - elif message.type == Recipient.CLASS: + elif message.type == Recipient.STREAM: stream = create_stream_if_needed(realm, old_message["recipient"]) - message.recipient = Recipient.objects.get(type=Recipient.CLASS, + message.recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id) elif message.type == Recipient.HUDDLE: for u in old_message["recipient"]: @@ -280,7 +280,7 @@ def send_messages(data): offset = random.randint(0, len(texts)) recipient_classes = [klass.id for klass in - Recipient.objects.filter(type=Recipient.CLASS)] + Recipient.objects.filter(type=Recipient.STREAM)] recipient_huddles = [h.id for h in Recipient.objects.filter(type=Recipient.HUDDLE)] huddle_members = {} @@ -309,7 +309,7 @@ def send_messages(data): if message_type == Recipient.PERSONAL: personals_pair = saved_data random.shuffle(personals_pair) - elif message_type == Recipient.CLASS: + elif message_type == Recipient.STREAM: message.instance = saved_data message.recipient = get_recipient_by_id(recipient_id) elif message_type == Recipient.HUDDLE: @@ -322,7 +322,7 @@ def send_messages(data): personals_pair = random.choice(personals_pairs) random.shuffle(personals_pair) elif (randkey <= random_max * 1.0): - message_type = Recipient.CLASS + message_type = Recipient.STREAM message.recipient = get_recipient_by_id(random.choice(recipient_classes)) if message_type == Recipient.HUDDLE: @@ -333,7 +333,7 @@ def send_messages(data): type_id=personals_pair[0]) message.sender = get_user_profile_by_id(personals_pair[1]) saved_data = personals_pair - elif message_type == Recipient.CLASS: + elif message_type == Recipient.STREAM: stream = Stream.objects.get(id=message.recipient.type_id) # Pick a random subscriber to the class message.sender = random.choice(Subscription.objects.filter( diff --git a/zephyr/models.py b/zephyr/models.py index f2a45fbca0..7d6ae7f722 100644 --- a/zephyr/models.py +++ b/zephyr/models.py @@ -22,7 +22,7 @@ def get_display_recipient(recipient): returns: an appropriate string describing the recipient (the class name, for a class, or the email, for a user). """ - if recipient.type == Recipient.CLASS: + if recipient.type == Recipient.STREAM: stream = Stream.objects.get(id=recipient.type_id) return stream.name elif recipient.type == Recipient.HUDDLE: @@ -41,7 +41,7 @@ def get_log_recipient(recipient): returns: an appropriate string describing the recipient (the class name, for a class, or the email, for a user). """ - if recipient.type == Recipient.CLASS: + if recipient.type == Recipient.STREAM: stream = Stream.objects.get(id=recipient.type_id) return stream.name @@ -149,7 +149,7 @@ def create_stream_if_needed(realm, class_name): new_class.name = class_name new_class.realm = realm new_class.save() - recipient = Recipient(type_id=new_class.id, type=Recipient.CLASS) + recipient = Recipient(type_id=new_class.id, type=Recipient.STREAM) recipient.save() return new_class @@ -168,7 +168,7 @@ class Stream(models.Model): stream = cls(name=name, realm=realm) stream.save() - recipient = Recipient(type_id=stream.id, type=Recipient.CLASS) + recipient = Recipient(type_id=stream.id, type=Recipient.STREAM) recipient.save() return (stream, recipient) @@ -177,14 +177,14 @@ class Recipient(models.Model): type = models.PositiveSmallIntegerField(db_index=True) # Valid types are {personal, class, huddle} PERSONAL = 1 - CLASS = 2 + STREAM = 2 HUDDLE = 3 def type_name(self): if self.type == self.PERSONAL: return "personal" - elif self.type == self.CLASS: - return "class" + elif self.type == self.STREAM: + return "stream" elif self.type == self.HUDDLE: return "huddle" else: @@ -297,7 +297,7 @@ def do_send_message(message, synced_from_mit=False, no_log=False): # For personals, you send out either 1 or 2 copies of the message, for # personals to yourself or to someone else, respectively. assert((len(recipients) == 1) or (len(recipients) == 2)) - elif (message.recipient.type == Recipient.CLASS or + elif (message.recipient.type == Recipient.STREAM or message.recipient.type == Recipient.HUDDLE): recipients = [get_user_profile_by_id(s.userprofile_id) for s in Subscription.objects.filter(recipient=message.recipient, active=True)] diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 4bf4d06759..e7c96077ca 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -207,7 +207,7 @@ function same_recipient(a, b) { return a.recipient_id === b.recipient_id; case 'personal': return a.reply_to === b.reply_to; - case 'class': + case 'stream': return (a.recipient_id === b.recipient_id) && (a.instance === b.instance); } @@ -364,7 +364,7 @@ function add_message_metadata(dummy, message) { received.last = Math.max(received.last, message.id); switch (message.type) { - case 'class': + case 'stream': message.is_class = true; if ($.inArray(message.instance, instance_list) === -1) { instance_list.push(message.instance); diff --git a/zephyr/tests.py b/zephyr/tests.py index 23615aa010..3ec05e7371 100644 --- a/zephyr/tests.py +++ b/zephyr/tests.py @@ -62,7 +62,7 @@ class AuthedTestCase(TestCase): def users_subscribed_to_class(self, class_name, realm_domain): realm = Realm.objects.get(domain=realm_domain) stream = Stream.objects.get(name=class_name, realm=realm) - recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.CLASS) + recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM) subscriptions = Subscription.objects.filter(recipient=recipient) return [subscription.userprofile.user for subscription in subscriptions] @@ -247,7 +247,7 @@ class ClassMessagesTest(AuthedTestCase): a_subscriber = subscribers[0].username a_subscriber_email = subscribers[0].email self.login(a_subscriber_email, a_subscriber) - self.send_message(a_subscriber_email, "Scotland", Recipient.CLASS) + self.send_message(a_subscriber_email, "Scotland", Recipient.STREAM) new_subscriber_messages = [] for subscriber in subscribers: @@ -316,7 +316,7 @@ class MessagePOSTTest(AuthedTestCase): successful. """ self.login("hamlet@humbughq.com", "hamlet") - result = self.client.post("/send_message/", {"type": "class", + result = self.client.post("/send_message/", {"type": "stream", "class": "Verona", "content": "Test message", "instance": "Test instance"}) @@ -329,7 +329,7 @@ class MessagePOSTTest(AuthedTestCase): """ self.login("hamlet@humbughq.com", "hamlet") self.assertFalse(Stream.objects.filter(name="nonexistent_class")) - result = self.client.post("/send_message/", {"type": "class", + result = self.client.post("/send_message/", {"type": "stream", "class": "nonexistent_class", "content": "Test message", "instance": "Test instance"}) diff --git a/zephyr/views.py b/zephyr/views.py index 8a788ec52c..2fab061c1a 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -167,7 +167,7 @@ def home(request): subscriptions = Subscription.objects.filter(userprofile_id=user_profile, active=True) classes = [get_display_recipient(sub.recipient) for sub in subscriptions - if sub.recipient.type == Recipient.CLASS] + if sub.recipient.type == Recipient.STREAM] return render_to_response('zephyr/index.html', {'user_profile': user_profile, @@ -354,7 +354,7 @@ def send_message_backend(request, user_profile, sender): sender = create_forged_message_users(request, user_profile) message_type_name = request.POST["type"] - if message_type_name == 'class': + if message_type_name == 'stream': if "class" not in request.POST: return json_error("Missing class") if "instance" not in request.POST: @@ -369,7 +369,7 @@ def send_message_backend(request, user_profile, sender): # return json_error("Invalid instance name") stream = create_stream_if_needed(user_profile.realm, stream_name) - recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.CLASS) + recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM) elif message_type_name == 'personal': if "recipient" not in request.POST: return json_error("Missing recipient") @@ -408,7 +408,7 @@ def send_message_backend(request, user_profile, sender): message.sender = UserProfile.objects.get(user=sender) message.content = strip_html(request.POST['content']) message.recipient = recipient - if message_type_name == 'class': + if message_type_name == 'stream': message.instance = instance_name if 'time' in request.POST: # Forged messages come with a timestamp @@ -426,7 +426,7 @@ def gather_subscriptions(user_profile): subscriptions = Subscription.objects.filter(userprofile=user_profile, active=True) # For now, don't display the subscription for your ability to receive personals. return sorted([get_display_recipient(sub.recipient) for sub in subscriptions - if sub.recipient.type == Recipient.CLASS]) + if sub.recipient.type == Recipient.STREAM]) @login_required def subscriptions(request): @@ -456,7 +456,7 @@ def json_remove_subscription(request): return json_error("Not subscribed, so you can't unsubscribe") recipient = Recipient.objects.get(type_id=stream.id, - type=Recipient.CLASS) + type=Recipient.STREAM) subscription = Subscription.objects.get( userprofile=user_profile, recipient=recipient) subscription.active = False @@ -482,7 +482,7 @@ def json_add_subscription(request): stream = create_stream_if_needed(user_profile.realm, sub_name) recipient = Recipient.objects.get(type_id=stream.id, - type=Recipient.CLASS) + type=Recipient.STREAM) subscription = Subscription.objects.filter(userprofile=user_profile, recipient=recipient)