mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
Access the UserProfile's new email field rather than using User.
This is preparatory for stopping using the User model. (imported from commit a1b0808c8cc2ddd19a25163f91c4f18620c9ce90)
This commit is contained in:
@@ -28,7 +28,7 @@ def report(state, short_msg, too_old=None):
|
||||
too_old_data = ""
|
||||
if too_old:
|
||||
too_old_data = "\nLast call to get_message for recently out of date mirrors:\n" + "\n".join(
|
||||
["%16s: %s" % (user.user_profile.user.email,
|
||||
["%16s: %s" % (user.user_profile.email,
|
||||
user.last_visit.strftime("%Y-%m-%d %H:%M %Z")
|
||||
) for user in too_old]
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Hi there,
|
||||
|
||||
{{ referrer.full_name }} ({{ referrer.user.email }}) wants you to join them on Humbug -- the group communication tool you've always wished you had at work.
|
||||
{{ referrer.full_name }} ({{ referrer.email }}) wants you to join them on Humbug -- the group communication tool you've always wished you had at work.
|
||||
|
||||
To get started, visit the link below:
|
||||
<{{ activate_url }}>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
src="https://secure.gravatar.com/avatar/{{ email_hash }}?d=identicon&s=60" />
|
||||
<span id="my_information">
|
||||
<span class="my_fullname">{{ user_profile.full_name }}</span><br />
|
||||
<span class="my_email">{{ user_profile.user.email }}</span>
|
||||
<span class="my_email">{{ user_profile.email }}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</div>
|
||||
<div class="span7" id="navbar-middle">
|
||||
<a class="brand skinny-user-gravatar visible-phone" href="#"
|
||||
title="{{user_profile.full_name}} - {{user_profile.user.email}}">
|
||||
title="{{user_profile.full_name}} - {{user_profile.email}}">
|
||||
<img class="img-rounded gravatar-profile"
|
||||
src="https://secure.gravatar.com/avatar/{{ email_hash }}?d=identicon&s=30" />
|
||||
</a>
|
||||
|
||||
@@ -145,7 +145,7 @@ def authenticate_log_and_execute_json(request, client, view_func, *args, **kwarg
|
||||
return json_error("Not logged in", status=401)
|
||||
request.client = client
|
||||
user_profile = get_user_profile_by_user_id(request.user.id)
|
||||
request._email = user_profile.user.email
|
||||
request._email = user_profile.email
|
||||
update_user_activity(request, user_profile)
|
||||
return view_func(request, user_profile, *args, **kwargs)
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ def do_create_user(email, password, realm, full_name, short_name,
|
||||
user_profile = create_user(email, password, realm, full_name, short_name, active)
|
||||
|
||||
notice = dict(event=dict(type="realm_user", op="add",
|
||||
person=dict(email=user_profile.user.email,
|
||||
person=dict(email=user_profile.email,
|
||||
full_name=user_profile.full_name)),
|
||||
users=[up.id for up in
|
||||
UserProfile.objects.select_related().filter(realm=user_profile.realm,
|
||||
@@ -107,11 +107,11 @@ def do_deactivate(user_profile):
|
||||
|
||||
log_event({'type': 'user_deactivated',
|
||||
'timestamp': time.time(),
|
||||
'user': user_profile.user.email,
|
||||
'user': user_profile.email,
|
||||
'domain': user_profile.realm.domain})
|
||||
|
||||
notice = dict(event=dict(type="realm_user", op="remove",
|
||||
person=dict(email=user_profile.user.email,
|
||||
person=dict(email=user_profile.email,
|
||||
full_name=user_profile.full_name)),
|
||||
users=[up.id for up in
|
||||
UserProfile.objects.select_related().filter(realm=user_profile.realm,
|
||||
@@ -120,7 +120,7 @@ def do_deactivate(user_profile):
|
||||
|
||||
|
||||
def do_change_user_email(user_profile, new_email):
|
||||
old_email = user_profile.user.email
|
||||
old_email = user_profile.email
|
||||
|
||||
user_profile.email = new_email
|
||||
user_profile.save(update_fields=["email"])
|
||||
@@ -449,7 +449,7 @@ def do_add_subscription(user_profile, stream, no_log=False):
|
||||
if did_subscribe:
|
||||
if not no_log:
|
||||
log_event({'type': 'subscription_added',
|
||||
'user': user_profile.user.email,
|
||||
'user': user_profile.email,
|
||||
'name': stream.name,
|
||||
'domain': stream.realm.domain})
|
||||
|
||||
@@ -476,7 +476,7 @@ def do_remove_subscription(user_profile, stream, no_log=False):
|
||||
if did_remove:
|
||||
if not no_log:
|
||||
log_event({'type': 'subscription_removed',
|
||||
'user': user_profile.user.email,
|
||||
'user': user_profile.email,
|
||||
'name': stream.name,
|
||||
'domain': stream.realm.domain})
|
||||
|
||||
@@ -510,7 +510,7 @@ def do_activate_user(user_profile, log=True, join_date=timezone.now()):
|
||||
if log:
|
||||
domain = user_profile.realm.domain
|
||||
log_event({'type': 'user_activated',
|
||||
'user': user.email,
|
||||
'user': user_profile.email,
|
||||
'domain': domain})
|
||||
|
||||
def do_change_password(user_profile, password, log=True, commit=True,
|
||||
@@ -528,15 +528,15 @@ def do_change_password(user_profile, password, log=True, commit=True,
|
||||
user_profile.save(update_fields=["password"])
|
||||
if log:
|
||||
log_event({'type': 'user_change_password',
|
||||
'user': user.email,
|
||||
'pwhash': user.password})
|
||||
'user': user_profile.email,
|
||||
'pwhash': user_profile.password})
|
||||
|
||||
def do_change_full_name(user_profile, full_name, log=True):
|
||||
user_profile.full_name = full_name
|
||||
user_profile.save(update_fields=["full_name"])
|
||||
if log:
|
||||
log_event({'type': 'user_change_full_name',
|
||||
'user': user_profile.user.email,
|
||||
'user': user_profile.email,
|
||||
'full_name': full_name})
|
||||
|
||||
def do_create_realm(domain, replay=False):
|
||||
@@ -555,7 +555,7 @@ def do_change_enable_desktop_notifications(user_profile, enable_desktop_notifica
|
||||
user_profile.save(update_fields=["enable_desktop_notifications"])
|
||||
if log:
|
||||
log_event({'type': 'enable_desktop_notifications_changed',
|
||||
'user': user_profile.user.email,
|
||||
'user': user_profile.email,
|
||||
'enable_desktop_notifications': enable_desktop_notifications})
|
||||
|
||||
def do_change_enter_sends(user_profile, enter_sends):
|
||||
@@ -702,7 +702,7 @@ def process_update_message_flags(event):
|
||||
|
||||
def update_flags_externally(op, flag, user_profile, until_id):
|
||||
args = ['python', os.path.join(os.path.dirname(__file__), '../..', 'manage.py'),
|
||||
'set_message_flags', '--for-real', '-o', op, '-f', flag, '-m', user_profile.user.email,
|
||||
'set_message_flags', '--for-real', '-o', op, '-f', flag, '-m', user_profile.email,
|
||||
'-u', str(until_id)]
|
||||
|
||||
subprocess.Popen(args, stdin=subprocess.PIPE, stdout=None, stderr=None)
|
||||
@@ -780,7 +780,7 @@ def do_events_register(user_profile, apply_markdown=True, event_types=None):
|
||||
if event_types is None or "pointer" in event_types:
|
||||
ret['pointer'] = user_profile.pointer
|
||||
if event_types is None or "realm_user" in event_types:
|
||||
ret['realm_users'] = [{'email' : profile.user.email,
|
||||
ret['realm_users'] = [{'email' : profile.email,
|
||||
'full_name' : profile.full_name}
|
||||
for profile in
|
||||
UserProfile.objects.select_related().filter(realm=user_profile.realm,
|
||||
|
||||
@@ -59,7 +59,7 @@ def bulk_create_users(realms, users_raw):
|
||||
profiles_by_email = {}
|
||||
profiles_by_id = {}
|
||||
for profile in UserProfile.objects.select_related().all():
|
||||
profiles_by_email[profile.user.email] = profile
|
||||
profiles_by_email[profile.email] = profile
|
||||
profiles_by_id[profile.id] = profile
|
||||
|
||||
recipients_to_create = []
|
||||
@@ -70,7 +70,7 @@ def bulk_create_users(realms, users_raw):
|
||||
|
||||
recipients_by_email = {}
|
||||
for recipient in Recipient.objects.filter(type=Recipient.PERSONAL):
|
||||
recipients_by_email[profiles_by_id[recipient.type_id].user.email] = recipient
|
||||
recipients_by_email[profiles_by_id[recipient.type_id].email] = recipient
|
||||
|
||||
subscriptions_to_create = []
|
||||
for (email, _, _, _) in users:
|
||||
|
||||
@@ -76,7 +76,7 @@ def user_by_id_cache_key(user_id):
|
||||
def update_user_profile_cache(sender, **kwargs):
|
||||
user_profile = kwargs['instance']
|
||||
items_for_memcached = {}
|
||||
items_for_memcached[user_profile_by_email_cache_key(user_profile.user.email)] = (user_profile,)
|
||||
items_for_memcached[user_profile_by_email_cache_key(user_profile.email)] = (user_profile,)
|
||||
items_for_memcached[user_profile_by_user_cache_key(user_profile.user.id)] = (user_profile,)
|
||||
items_for_memcached[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,)
|
||||
djcache.set_many(items_for_memcached)
|
||||
|
||||
@@ -23,7 +23,7 @@ def message_cache_items(items_for_memcached, message):
|
||||
items_for_memcached[message_cache_key(message.id)] = (message,)
|
||||
|
||||
def user_cache_items(items_for_memcached, user_profile):
|
||||
items_for_memcached[user_profile_by_email_cache_key(user_profile.user.email)] = (user_profile,)
|
||||
items_for_memcached[user_profile_by_email_cache_key(user_profile.email)] = (user_profile,)
|
||||
items_for_memcached[user_profile_by_user_cache_key(user_profile.user.id)] = (user_profile,)
|
||||
items_for_memcached[user_by_id_cache_key(user_profile.user.id)] = (user_profile.user,)
|
||||
items_for_memcached[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,)
|
||||
|
||||
@@ -225,7 +225,7 @@ def request_event_queue(user_profile, apply_markdown, event_types=None):
|
||||
if event_types is not None:
|
||||
req['event_types'] = simplejson.dumps(event_types)
|
||||
resp = requests.get(settings.TORNADO_SERVER + '/api/v1/events',
|
||||
auth=requests.auth.HTTPBasicAuth(user_profile.user.email,
|
||||
auth=requests.auth.HTTPBasicAuth(user_profile.email,
|
||||
user_profile.api_key),
|
||||
params=req)
|
||||
|
||||
@@ -238,7 +238,7 @@ def request_event_queue(user_profile, apply_markdown, event_types=None):
|
||||
def get_user_events(user_profile, queue_id, last_event_id):
|
||||
if settings.TORNADO_SERVER:
|
||||
resp = requests.get(settings.TORNADO_SERVER + '/api/v1/events',
|
||||
auth=requests.auth.HTTPBasicAuth(user_profile.user.email,
|
||||
auth=requests.auth.HTTPBasicAuth(user_profile.email,
|
||||
user_profile.api_key),
|
||||
params={'queue_id' : queue_id,
|
||||
'last_event_id': last_event_id,
|
||||
|
||||
@@ -51,4 +51,4 @@ class Command(BaseCommand):
|
||||
did_subscribe = do_add_subscription(user_profile, stream)
|
||||
print "%s %s to %s" % (
|
||||
"Subscribed" if did_subscribe else "Already subscribed",
|
||||
user_profile.user.email, stream_name)
|
||||
user_profile.email, stream_name)
|
||||
|
||||
@@ -16,18 +16,18 @@ def compute_stats(log_level):
|
||||
recipient__type=Recipient.STREAM,
|
||||
pub_date__gt=one_week_ago)
|
||||
for bot_sender_start in ["imap.", "rcmd.", "sys."]:
|
||||
mit_query = mit_query.exclude(sender__user__email__startswith=(bot_sender_start))
|
||||
mit_query = mit_query.exclude(sender__email__startswith=(bot_sender_start))
|
||||
# Filtering for "/" covers tabbott/extra@ and all the daemon/foo bots.
|
||||
mit_query = mit_query.exclude(sender__user__email__contains=("/"))
|
||||
mit_query = mit_query.exclude(sender__user__email__contains=("aim.com"))
|
||||
mit_query = mit_query.exclude(sender__email__contains=("/"))
|
||||
mit_query = mit_query.exclude(sender__email__contains=("aim.com"))
|
||||
mit_query = mit_query.exclude(
|
||||
sender__user__email__in=["rss@mit.edu", "bash@mit.edu", "apache@mit.edu",
|
||||
"bitcoin@mit.edu", "lp@mit.edu", "clocks@mit.edu",
|
||||
"root@mit.edu", "nagios@mit.edu",
|
||||
"www-data|local-realm@mit.edu"])
|
||||
sender__email__in=["rss@mit.edu", "bash@mit.edu", "apache@mit.edu",
|
||||
"bitcoin@mit.edu", "lp@mit.edu", "clocks@mit.edu",
|
||||
"root@mit.edu", "nagios@mit.edu",
|
||||
"www-data|local-realm@mit.edu"])
|
||||
user_counts = {}
|
||||
for m in mit_query.select_related("sending_client", "sender", "sender__user"):
|
||||
email = m.sender.user.email
|
||||
for m in mit_query.select_related("sending_client", "sender"):
|
||||
email = m.sender.email
|
||||
user_counts.setdefault(email, {})
|
||||
user_counts[email].setdefault(m.sending_client.name, 0)
|
||||
user_counts[email][m.sending_client.name] += 1
|
||||
|
||||
@@ -9,11 +9,11 @@ def banish_busted_users(change=False):
|
||||
if (u.user.is_active or u.realm.domain != "mit.edu"):
|
||||
continue
|
||||
(banished_realm, _) = Realm.objects.get_or_create(domain="mit.deleted")
|
||||
if "|mit.edu@mit.edu" in u.user.email.lower():
|
||||
print u.user.email
|
||||
if "|mit.edu@mit.edu" in u.email.lower():
|
||||
print u.email
|
||||
if change:
|
||||
u.realm = banished_realm
|
||||
u.user.email = u.user.email.split("@")[0] + "@" + banished_realm.domain
|
||||
u.email = u.email.split("@")[0] + "@" + banished_realm.domain
|
||||
u.user.save()
|
||||
u.save()
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ class Command(BaseCommand):
|
||||
user_profile = get_user_profile_by_email(args[0])
|
||||
|
||||
print "Deactivating %s (%s) - %s" % (user_profile.full_name,
|
||||
user_profile.user.email,
|
||||
user_profile.email,
|
||||
user_profile.realm.domain)
|
||||
print "%s has the following active sessions:" % (user_profile.user.email,)
|
||||
print "%s has the following active sessions:" % (user_profile.email,)
|
||||
for session in user_sessions(user_profile.user):
|
||||
print session.expire_date, session.get_decoded()
|
||||
print ""
|
||||
|
||||
@@ -7,7 +7,7 @@ import simplejson
|
||||
def dump():
|
||||
passwords = []
|
||||
for user_profile in UserProfile.objects.all():
|
||||
passwords.append((user_profile.user.email, user_profile.password))
|
||||
passwords.append((user_profile.email, user_profile.password))
|
||||
file("dumped-passwords", "w").write(simplejson.dumps(passwords) + "\n")
|
||||
|
||||
def restore(change):
|
||||
|
||||
@@ -7,13 +7,13 @@ import simplejson
|
||||
|
||||
def dump():
|
||||
pointers = []
|
||||
for u in UserProfile.objects.select_related("user__email").all():
|
||||
for u in UserProfile.objects.all():
|
||||
pointer = u.pointer
|
||||
if pointer != -1:
|
||||
pub_date = Message.objects.get(id=pointer).pub_date
|
||||
pointers.append((u.user.email, datetime_to_timestamp(pub_date)))
|
||||
pointers.append((u.email, datetime_to_timestamp(pub_date)))
|
||||
else:
|
||||
pointers.append((u.user.email, -1))
|
||||
pointers.append((u.email, -1))
|
||||
file("dumped-pointers", "w").write(simplejson.dumps(pointers) + "\n")
|
||||
|
||||
def restore(change):
|
||||
|
||||
@@ -7,9 +7,9 @@ from zephyr.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime
|
||||
|
||||
def dump():
|
||||
pointers = []
|
||||
for activity in UserActivity.objects.select_related("user_profile__user__email",
|
||||
for activity in UserActivity.objects.select_related("user_profile__email",
|
||||
"client__name").all():
|
||||
pointers.append((activity.user_profile.user.email, activity.client.name,
|
||||
pointers.append((activity.user_profile.email, activity.client.name,
|
||||
activity.query, activity.count,
|
||||
datetime_to_timestamp(activity.last_visit)))
|
||||
file("dumped-activity", "w").write(simplejson.dumps(pointers) + "\n")
|
||||
|
||||
@@ -252,7 +252,7 @@ def restore_saved_messages():
|
||||
|
||||
stream_dict = {}
|
||||
user_set = set()
|
||||
email_set = set([u.email for u in User.objects.all()])
|
||||
email_set = set([u.email for u in UserProfile.objects.all()])
|
||||
realm_set = set()
|
||||
# Initial client_set is nonempty temporarily because we don't have
|
||||
# clients in logs at all right now -- later we can start with nothing.
|
||||
@@ -401,10 +401,10 @@ def restore_saved_messages():
|
||||
users = {}
|
||||
users_by_id = {}
|
||||
for user_profile in UserProfile.objects.select_related().all():
|
||||
users[user_profile.user.email] = user_profile
|
||||
users[user_profile.email] = user_profile
|
||||
users_by_id[user_profile.id] = user_profile
|
||||
for recipient in Recipient.objects.filter(type=Recipient.PERSONAL):
|
||||
user_recipients[users_by_id[recipient.type_id].user.email] = recipient
|
||||
user_recipients[users_by_id[recipient.type_id].email] = recipient
|
||||
|
||||
print datetime.datetime.now(), "Creating huddles..."
|
||||
bulk_create_huddles(users, huddle_user_set)
|
||||
|
||||
@@ -51,4 +51,4 @@ class Command(BaseCommand):
|
||||
did_remove = do_remove_subscription(user_profile, stream)
|
||||
print "%s %s from %s" % (
|
||||
"Removed" if did_remove else "Couldn't remove",
|
||||
user_profile.user.email, stream_name)
|
||||
user_profile.email, stream_name)
|
||||
|
||||
@@ -55,10 +55,10 @@ class Command(BaseCommand):
|
||||
if not options["for_real"]:
|
||||
for msg in msgs:
|
||||
print "Adding read flag to msg: %s - %s/%s (own msg: %s)" \
|
||||
% (user_profile.user.email,
|
||||
% (user_profile.email,
|
||||
msg.message.id,
|
||||
msg.id,
|
||||
msg.message.sender.user.email == user_profile.user.email)
|
||||
msg.message.sender.email == user_profile.email)
|
||||
else:
|
||||
def do_update(batch):
|
||||
with transaction.commit_on_success():
|
||||
|
||||
@@ -12,9 +12,9 @@ def update_mit_fullnames(change=False):
|
||||
# actually have an account (is_active) and thus have
|
||||
# presumably set their fullname how they like it.
|
||||
continue
|
||||
computed_name = compute_mit_user_fullname(u.user.email)
|
||||
computed_name = compute_mit_user_fullname(u.email)
|
||||
if u.full_name != computed_name:
|
||||
print "%s: %s => %s" % (u.user.email, u.full_name, computed_name)
|
||||
print "%s: %s => %s" % (u.email, u.full_name, computed_name)
|
||||
if change:
|
||||
u.full_name = computed_name
|
||||
u.save()
|
||||
|
||||
@@ -29,7 +29,7 @@ class Command(BaseCommand):
|
||||
print "%d streams" % (len(Stream.objects.filter(realm=realm)),)
|
||||
|
||||
for user_profile in user_profiles:
|
||||
print "%35s" % (user_profile.user.email,),
|
||||
print "%35s" % (user_profile.email,),
|
||||
for week in range(10):
|
||||
print "%5d" % (self.messages_sent_by(user_profile, week)),
|
||||
print ""
|
||||
|
||||
@@ -38,8 +38,8 @@ def get_display_recipient(recipient):
|
||||
# We don't really care what the ordering is, just that it's deterministic.
|
||||
user_profile_list = (UserProfile.objects.filter(subscription__recipient=recipient)
|
||||
.select_related()
|
||||
.order_by('user__email'))
|
||||
return [{'email': user_profile.user.email,
|
||||
.order_by('email'))
|
||||
return [{'email': user_profile.email,
|
||||
'full_name': user_profile.full_name,
|
||||
'short_name': user_profile.short_name} for user_profile in user_profile_list]
|
||||
|
||||
@@ -99,7 +99,7 @@ class UserProfile(AbstractBaseUser):
|
||||
return profile
|
||||
|
||||
def __repr__(self):
|
||||
return (u"<UserProfile: %s %s>" % (self.user.email, self.realm)).encode("utf-8")
|
||||
return (u"<UserProfile: %s %s>" % (self.email, self.realm)).encode("utf-8")
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
@@ -266,7 +266,7 @@ class Message(models.Model):
|
||||
if len(display_recipient) == 1:
|
||||
# add the sender in if this isn't a message between
|
||||
# someone and his self, preserving ordering
|
||||
recip = {'email': self.sender.user.email,
|
||||
recip = {'email': self.sender.email,
|
||||
'full_name': self.sender.full_name,
|
||||
'short_name': self.sender.short_name};
|
||||
if recip['email'] < display_recipient[0]['email']:
|
||||
@@ -278,7 +278,7 @@ class Message(models.Model):
|
||||
|
||||
obj = dict(
|
||||
id = self.id,
|
||||
sender_email = self.sender.user.email,
|
||||
sender_email = self.sender.email,
|
||||
sender_full_name = self.sender.full_name,
|
||||
sender_short_name = self.sender.short_name,
|
||||
type = display_type,
|
||||
@@ -286,7 +286,7 @@ class Message(models.Model):
|
||||
recipient_id = self.recipient.id,
|
||||
subject = self.subject,
|
||||
timestamp = datetime_to_timestamp(self.pub_date),
|
||||
gravatar_hash = gravatar_hash(self.sender.user.email),
|
||||
gravatar_hash = gravatar_hash(self.sender.email),
|
||||
client = self.sending_client.name)
|
||||
|
||||
if apply_markdown and self.rendered_content_version is not None:
|
||||
@@ -313,7 +313,7 @@ class Message(models.Model):
|
||||
def to_log_dict(self):
|
||||
return dict(
|
||||
id = self.id,
|
||||
sender_email = self.sender.user.email,
|
||||
sender_email = self.sender.email,
|
||||
sender_full_name = self.sender.full_name,
|
||||
sender_short_name = self.sender.short_name,
|
||||
sending_client = self.sending_client.name,
|
||||
@@ -342,7 +342,7 @@ class UserMessage(models.Model):
|
||||
|
||||
def __repr__(self):
|
||||
display_recipient = get_display_recipient(self.message.recipient)
|
||||
return (u"<UserMessage: %s / %s (%s)>" % (display_recipient, self.user_profile.user.email, self.flags_dict())).encode("utf-8")
|
||||
return (u"<UserMessage: %s / %s (%s)>" % (display_recipient, self.user_profile.email, self.flags_dict())).encode("utf-8")
|
||||
|
||||
def flags_dict(self):
|
||||
return dict(flags = [flag for flag in self.flags.keys() if getattr(self.flags, flag).is_set])
|
||||
@@ -368,7 +368,7 @@ def get_user_profile_by_id(uid):
|
||||
|
||||
@cache_with_key(user_profile_by_email_cache_key, timeout=3600*24*7)
|
||||
def get_user_profile_by_email(email):
|
||||
return UserProfile.objects.select_related().get(user__email__iexact=email)
|
||||
return UserProfile.objects.select_related().get(email__iexact=email)
|
||||
|
||||
class Huddle(models.Model):
|
||||
# TODO: We should consider whether using
|
||||
|
||||
@@ -85,7 +85,7 @@ class AuthedTestCase(TestCase):
|
||||
"""
|
||||
# Usernames are unique, even across Realms.
|
||||
# We use this rather than get_user_profile_by_email to circumvent memcached (I think?)
|
||||
return UserProfile.objects.get(user__email__iexact=email)
|
||||
return UserProfile.objects.get(email__iexact=email)
|
||||
|
||||
def get_streams(self, email):
|
||||
"""
|
||||
@@ -317,8 +317,8 @@ class PersonalMessagesTest(AuthedTestCase):
|
||||
sender_messages = len(self.message_stream(sender))
|
||||
receiver_messages = len(self.message_stream(receiver))
|
||||
|
||||
other_user_profiles = UserProfile.objects.filter(~Q(user__email=sender_email) &
|
||||
~Q(user__email=receiver_email))
|
||||
other_user_profiles = UserProfile.objects.filter(~Q(email=sender_email) &
|
||||
~Q(email=receiver_email))
|
||||
old_other_messages = []
|
||||
for user_profile in other_user_profiles:
|
||||
old_other_messages.append(len(self.message_stream(user_profile)))
|
||||
@@ -375,7 +375,7 @@ class StreamMessagesTest(AuthedTestCase):
|
||||
for non_subscriber in non_subscribers:
|
||||
old_non_subscriber_messages.append(len(self.message_stream(non_subscriber)))
|
||||
|
||||
a_subscriber_email = subscribers[0].user.email
|
||||
a_subscriber_email = subscribers[0].email
|
||||
self.login(a_subscriber_email)
|
||||
self.send_message(a_subscriber_email, stream_name, Recipient.STREAM,
|
||||
subject, content)
|
||||
@@ -1676,7 +1676,7 @@ class GetSubscribersTest(AuthedTestCase):
|
||||
"""
|
||||
self.assertIn("subscribers", result)
|
||||
self.assertIsInstance(result["subscribers"], list)
|
||||
true_subscribers = [user_profile.user.email for user_profile in self.users_subscribed_to_stream(
|
||||
true_subscribers = [user_profile.email for user_profile in self.users_subscribed_to_stream(
|
||||
stream_name, domain)]
|
||||
self.assertItemsEqual(result["subscribers"], true_subscribers)
|
||||
|
||||
@@ -2297,7 +2297,7 @@ class UnreadCountTests(AuthedTestCase):
|
||||
self.assertEqual(last.content, "Test message for unset read bit")
|
||||
for um in UserMessage.objects.filter(message=last):
|
||||
self.assertEqual(um.message.content, content)
|
||||
if um.user_profile.user.email != "hamlet@humbughq.com":
|
||||
if um.user_profile.email != "hamlet@humbughq.com":
|
||||
self.assertFalse(um.flags.read)
|
||||
|
||||
def test_update_flags(self):
|
||||
@@ -2407,7 +2407,7 @@ class JiraHookTests(AuthedTestCase):
|
||||
api_key = self.get_api_key(email)
|
||||
|
||||
stream, _ = create_stream_if_needed(Realm.objects.get(domain="humbughq.com"), 'jira')
|
||||
user_profile = UserProfile.objects.get(user__email=email)
|
||||
user_profile = self.get_user_profile(email)
|
||||
do_add_subscription(user_profile, stream, no_log=True)
|
||||
|
||||
result = self.client.post("/api/v1/external/jira/%s/" % api_key, self.fixture_data(action),
|
||||
@@ -2416,7 +2416,7 @@ class JiraHookTests(AuthedTestCase):
|
||||
|
||||
# Check the correct message was sent
|
||||
msg = Message.objects.filter().order_by('-id')[0]
|
||||
self.assertEqual(msg.sender.user.email, email)
|
||||
self.assertEqual(msg.sender.email, email)
|
||||
self.assertEqual(get_display_recipient(msg.recipient), 'jira')
|
||||
|
||||
return msg
|
||||
|
||||
@@ -117,7 +117,7 @@ def send_signup_message(sender, signups_stream, user_profile, internal=False):
|
||||
"stream", signups_stream, user_profile.realm.domain,
|
||||
"%s <`%s`> just signed up for Humbug!%s(total: **%i**)" % (
|
||||
user_profile.full_name,
|
||||
user_profile.user.email,
|
||||
user_profile.email,
|
||||
internal_blurb,
|
||||
UserProfile.objects.filter(realm=user_profile.realm,
|
||||
user__is_active=True).count(),
|
||||
@@ -224,10 +224,10 @@ def accounts_register(request):
|
||||
if prereg_user.referred_by is not None:
|
||||
# This is a cross-realm private message.
|
||||
internal_send_message("humbug+signups@humbughq.com",
|
||||
"private", prereg_user.referred_by.user.email, user_profile.realm.domain,
|
||||
"private", prereg_user.referred_by.email, user_profile.realm.domain,
|
||||
"%s <`%s`> accepted your invitation to join Humbug!" % (
|
||||
user_profile.full_name,
|
||||
user_profile.user.email,
|
||||
user_profile.email,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -242,7 +242,7 @@ def accounts_register(request):
|
||||
|
||||
@login_required(login_url = settings.HOME_NOT_LOGGED_IN)
|
||||
def accounts_accept_terms(request):
|
||||
email = request.user.email
|
||||
email = request.email
|
||||
company_name = email.split('@')[-1]
|
||||
if request.method == "POST":
|
||||
form = ToSForm(request.POST)
|
||||
@@ -271,7 +271,7 @@ def json_invite_users(request, user_profile, invitee_emails=POST):
|
||||
# Validation
|
||||
if settings.ALLOW_REGISTER == False:
|
||||
try:
|
||||
isnt_mit(user_profile.user.email)
|
||||
isnt_mit(user_profile.email)
|
||||
except ValidationError:
|
||||
return json_error("Invitations are not enabled for MIT at this time.")
|
||||
|
||||
@@ -427,7 +427,7 @@ def home(request):
|
||||
people_list = register_ret['realm_users'],
|
||||
initial_pointer = register_ret['pointer'],
|
||||
fullname = user_profile.full_name,
|
||||
email = user_profile.user.email,
|
||||
email = user_profile.email,
|
||||
domain = user_profile.realm.domain,
|
||||
enter_sends = user_profile.enter_sends,
|
||||
needs_tutorial = needs_tutorial,
|
||||
@@ -439,7 +439,7 @@ def home(request):
|
||||
))
|
||||
|
||||
try:
|
||||
isnt_mit(user_profile.user.email)
|
||||
isnt_mit(user_profile.email)
|
||||
show_invites = True
|
||||
except ValidationError:
|
||||
show_invites = settings.ALLOW_REGISTER
|
||||
@@ -447,7 +447,7 @@ def home(request):
|
||||
return render_to_response('zephyr/index.html',
|
||||
{'user_profile': user_profile,
|
||||
'page_params' : page_params,
|
||||
'email_hash' : gravatar_hash(user_profile.user.email),
|
||||
'email_hash' : gravatar_hash(user_profile.email),
|
||||
'show_debug':
|
||||
settings.DEBUG and ('show_debug' in request.GET),
|
||||
'show_invites': show_invites
|
||||
@@ -547,7 +547,7 @@ class NarrowBuilder(object):
|
||||
return Q(message__subject__iexact=operand)
|
||||
|
||||
def by_sender(self, operand):
|
||||
return Q(message__sender__user__email__iexact=operand)
|
||||
return Q(message__sender__email__iexact=operand)
|
||||
|
||||
def by_pm_with(self, operand):
|
||||
if ',' in operand:
|
||||
@@ -562,7 +562,7 @@ class NarrowBuilder(object):
|
||||
else:
|
||||
# Personal message
|
||||
self_recipient = get_recipient(Recipient.PERSONAL, type_id=self.user_profile.id)
|
||||
if operand == self.user_profile.user.email:
|
||||
if operand == self.user_profile.email:
|
||||
# Personals with self
|
||||
return Q(message__recipient__type=Recipient.PERSONAL,
|
||||
message__sender=self.user_profile, message__recipient=self_recipient)
|
||||
@@ -762,13 +762,13 @@ def json_tutorial_send_message(request, user_profile,
|
||||
# can only send to you.
|
||||
internal_send_message(sender_name,
|
||||
"private",
|
||||
user_profile.user.email,
|
||||
user_profile.email,
|
||||
"",
|
||||
message_content,
|
||||
realm=user_profile.realm)
|
||||
return json_success()
|
||||
elif message_type_name == 'stream':
|
||||
tutorial_stream_name = 'tutorial-%s' % user_profile.user.email.split('@')[0]
|
||||
tutorial_stream_name = 'tutorial-%s' % user_profile.email.split('@')[0]
|
||||
tutorial_stream_name = tutorial_stream_name[:Stream.MAX_NAME_LENGTH]
|
||||
## TODO: For open realms, we need to use the full name here,
|
||||
## so that me@gmail.com and me@hotmail.com don't get the same stream.
|
||||
@@ -942,15 +942,15 @@ def add_subscriptions_backend(request, user_profile,
|
||||
for subscriber in subscribers:
|
||||
did_subscribe = do_add_subscription(subscriber, stream)
|
||||
if did_subscribe:
|
||||
result["subscribed"][subscriber.user.email].append(stream.name)
|
||||
result["subscribed"][subscriber.email].append(stream.name)
|
||||
else:
|
||||
result["already_subscribed"][subscriber.user.email].append(stream.name)
|
||||
result["already_subscribed"][subscriber.email].append(stream.name)
|
||||
private_streams[stream.name] = stream.invite_only
|
||||
|
||||
# Inform the user if someone else subscribed them to stuff
|
||||
if principals and result["subscribed"]:
|
||||
for email, subscriptions in result["subscribed"].iteritems():
|
||||
if email == user_profile.user.email:
|
||||
if email == user_profile.email:
|
||||
# Don't send a Humbug if you invited yourself.
|
||||
continue
|
||||
|
||||
@@ -984,7 +984,7 @@ def json_get_members(request, user_profile):
|
||||
return get_members_backend(request, user_profile)
|
||||
|
||||
def get_members_backend(request, user_profile):
|
||||
members = [(profile.full_name, profile.user.email) for profile in \
|
||||
members = [(profile.full_name, profile.email) for profile in \
|
||||
UserProfile.objects.select_related().filter(realm=user_profile.realm)]
|
||||
return json_success({'members': members})
|
||||
|
||||
@@ -1012,7 +1012,7 @@ def get_subscribers_backend(request, user_profile, stream_name=POST('stream')):
|
||||
recipient__type_id=stream.id,
|
||||
active=True).select_related()
|
||||
|
||||
return json_success({'subscribers': [subscription.user_profile.user.email
|
||||
return json_success({'subscribers': [subscription.user_profile.email
|
||||
for subscription in subscriptions]})
|
||||
|
||||
@authenticated_json_post_view
|
||||
@@ -1027,7 +1027,7 @@ def json_change_settings(request, user_profile, full_name=POST,
|
||||
if new_password != "" or confirm_password != "":
|
||||
if new_password != confirm_password:
|
||||
return json_error("New password must match confirmation password!")
|
||||
if not authenticate(username=user_profile.user.email, password=old_password):
|
||||
if not authenticate(username=user_profile.email, password=old_password):
|
||||
return json_error("Wrong password!")
|
||||
do_change_password(user_profile, new_password)
|
||||
|
||||
@@ -1111,7 +1111,7 @@ class SubscriptionProperties(object):
|
||||
color = self.request_property(request.POST, "color")
|
||||
|
||||
set_stream_color(user_profile, stream_name, color)
|
||||
log_subscription_property_change(user_profile.user.email, "stream_color",
|
||||
log_subscription_property_change(user_profile.email, "stream_color",
|
||||
{"stream_name": stream_name, "color": color})
|
||||
return json_success()
|
||||
|
||||
@@ -1190,10 +1190,10 @@ class ActivityTable(object):
|
||||
for record in UserActivity.objects.filter(
|
||||
query=url,
|
||||
client__name__startswith=client_name).select_related():
|
||||
row = self.rows.setdefault(record.user_profile.user.email, {})
|
||||
row = self.rows.setdefault(record.user_profile.email, {})
|
||||
row['realm'] = record.user_profile.realm.domain
|
||||
row['full_name'] = record.user_profile.full_name
|
||||
row['email'] = record.user_profile.user.email
|
||||
row['email'] = record.user_profile.email
|
||||
row[query_name + '_count'] = record.count
|
||||
row[query_name + '_last' ] = record.last_visit
|
||||
|
||||
@@ -1399,7 +1399,7 @@ def get_status_list(requesting_user_profile):
|
||||
user_profile__realm=requesting_user_profile.realm).select_related(
|
||||
'user_profile', 'user_profile__user', 'client'):
|
||||
|
||||
user_statuses[presence.user_profile.user.email][presence.client.name] = \
|
||||
user_statuses[presence.user_profile.email][presence.client.name] = \
|
||||
presence_to_dict(presence)
|
||||
|
||||
return {'presences': user_statuses}
|
||||
@@ -1445,7 +1445,7 @@ if not (settings.DEBUG or settings.TEST_SUITE):
|
||||
@has_request_variables
|
||||
def json_report_error(request, user_profile, message=POST, stacktrace=POST,
|
||||
ui_message=POST(converter=json_to_bool), user_agent=POST):
|
||||
subject = "error for %s" % (user_profile.user.email,)
|
||||
subject = "error for %s" % (user_profile.email,)
|
||||
if ui_message:
|
||||
subject = "User-visible browser " + subject
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user