Skip to content
Open

Tests #136

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
cdcfc0c
Send verification emails from the settings page.
tehdragonfly Aug 9, 2016
c66a95f
Email verification.
tehdragonfly Aug 11, 2016
5876729
Send a verification email on registration.
tehdragonfly Aug 11, 2016
276b855
Get mail server settings from the environ.
tehdragonfly Aug 11, 2016
9adc796
Email templates.
tehdragonfly Aug 11, 2016
485921e
Don't bother sending an email when people change their email to itself.
tehdragonfly Aug 12, 2016
9183f1c
Use different templates for the welcome message.
tehdragonfly Aug 12, 2016
92fb1cd
Merge pull request #101 from MSPARP/development
thecount92 Aug 15, 2016
27de71e
Merge remote-tracking branch 'origin/development'
nepeat Aug 16, 2016
765b8d3
Merge pull request #104 from MSPARP/development
nepeat Aug 16, 2016
c20f997
Update welcome.html
GamzeeMabara Aug 19, 2016
182f016
Update welcome_plain.html
GamzeeMabara Aug 19, 2016
83ffd91
Update verify.html
GamzeeMabara Aug 19, 2016
7298add
Update base.html
tehdragonfly Aug 19, 2016
65caaea
Update verify_plain.html
GamzeeMabara Aug 19, 2016
bd48fb3
Update verify.html
GamzeeMabara Aug 19, 2016
219edde
Add test tasks to the celery includes.
tehdragonfly Aug 20, 2016
8468a87
Merge branch 'production' into master
tehdragonfly Aug 22, 2016
cedf46b
Merge pull request #105 from MSPARP/master
tehdragonfly Aug 22, 2016
8d02633
Fix the redis key for welcome emails.
tehdragonfly Aug 24, 2016
b8a4354
Merge branch 'production'
tehdragonfly Aug 24, 2016
715c6cf
Merge pull request #106 from MSPARP/master
tehdragonfly Aug 24, 2016
ec9e5bc
Remove link colour in emails.
tehdragonfly Aug 25, 2016
b26a8d8
Move search initialisation to a pipeline.
tehdragonfly Aug 27, 2016
bc1c180
New handler class for searching.
tehdragonfly Aug 28, 2016
701fea8
New tasks for searching.
tehdragonfly Aug 28, 2016
b244254
Unset roulette character if necessary.
tehdragonfly Aug 28, 2016
5feebc2
Set up ping loop.
tehdragonfly Aug 29, 2016
0efbb6b
Use Lua scripts to get searcher information.
tehdragonfly Sep 3, 2016
9c41731
Search character comparison.
tehdragonfly Sep 3, 2016
41ede35
Send people to chats when they're matched.
tehdragonfly Sep 4, 2016
0a08ac1
Copy the rest of the comparisons.
tehdragonfly Sep 6, 2016
935a611
Remove the old matchmaker tasks.
tehdragonfly Sep 6, 2016
8b1323c
Lock the matchmaker.
tehdragonfly Sep 6, 2016
2274775
Remove old search views.
tehdragonfly Sep 6, 2016
3db24ef
Merge pull request #107 from MSPARP/matchmaker2
tehdragonfly Sep 8, 2016
5132939
Remove tasks, views and templates for roulette.
tehdragonfly Sep 8, 2016
635998e
Remove roulette from the navigation.
tehdragonfly Sep 9, 2016
254e1c6
Remove unused code from helpers/matchmaker.py.
tehdragonfly Sep 11, 2016
77b684b
Update searching_users.
tehdragonfly Sep 14, 2016
c88a9a5
Remove roulette/old search JS.
tehdragonfly Sep 16, 2016
4393461
Remove search_type reference.
tehdragonfly Sep 17, 2016
ca0ef17
Merge pull request #108 from MSPARP/master
tehdragonfly Sep 17, 2016
5238e96
Remove long poll transport from the JS.
tehdragonfly Sep 17, 2016
8ff44ab
Remove long poll API views.
tehdragonfly Sep 17, 2016
ea2abf4
Fix setting groups from the full user list.
tehdragonfly Sep 17, 2016
d7e3a75
Set Websocket protocol based on the current URL.
tehdragonfly Sep 20, 2016
c4ef9d7
Remove #messages_method and #connection_method.
tehdragonfly Sep 21, 2016
4a8b563
Merge pull request #109 from MSPARP/nolongpoll
tehdragonfly Sep 21, 2016
5b16a9e
Add a re-send button for verification emails.
tehdragonfly Sep 25, 2016
5662215
Fix reconnect call.
tehdragonfly Oct 8, 2016
4c966bf
Merge pull request #110 from MSPARP/master
tehdragonfly Oct 18, 2016
adada4f
Move user dropdown stuff to the main navigation bar.
tehdragonfly Oct 20, 2016
f502a0d
Fix titles on log pages.
tehdragonfly Oct 31, 2016
93916a3
Don't use a prompt to set the topic.
tehdragonfly Nov 13, 2016
5000e9f
Remove prompt from blocking.
tehdragonfly Dec 11, 2016
7cabadd
Table for email host bans.
tehdragonfly Dec 12, 2016
bd7fd82
Add user group for new sign ups.
tehdragonfly Dec 13, 2016
f91ff46
Admin page for email bans.
tehdragonfly Dec 14, 2016
909a01d
Form for banning e-mail addresses.
tehdragonfly Dec 15, 2016
0c69727
View for deleting email bans.
tehdragonfly Dec 16, 2016
4e18731
Delete button for email bans.
tehdragonfly Dec 17, 2016
40f7f0b
Check email bans when activating.
tehdragonfly Dec 17, 2016
33178d3
Template for activation with a banned email.
tehdragonfly Dec 18, 2016
c1e0199
Update user_deactivated.html
GamzeeMabara Dec 19, 2016
76ed13b
Update user_new.html
GamzeeMabara Dec 19, 2016
4d54c93
Allow admins to reset people's regexes.
tehdragonfly Dec 29, 2016
6d69ed5
Indicate banned email addresses on user pages.
tehdragonfly Jan 1, 2017
c0b1441
List email addresses for the above.
tehdragonfly Jan 2, 2017
fcc1d7a
Update user_deactivated.html
GamzeeMabara Jan 2, 2017
57f0830
Banned email text.
tehdragonfly Jan 4, 2017
c36590e
Update banned_email.html
GamzeeMabara Jan 4, 2017
6cb2c65
Merge pull request #111 from MSPARP/master
tehdragonfly Jan 4, 2017
e1266d2
Don't allow new/deactivated users to enter chats.
tehdragonfly Jan 4, 2017
cce49aa
Fix the database population wrapper to return the exit code.
nepeat Jan 5, 2017
96251c7
Fix errors when logged out users visit a chat page.
nepeat Jan 5, 2017
e7b4b12
Fix log out button padding.
tehdragonfly Jan 5, 2017
fc565d6
Use Chat.computed_url and Chat.computed_title with PM user.
tehdragonfly Jan 6, 2017
dd811d8
Merge pull request #113 from MSPARP/master
thecount92 Jan 8, 2017
009fe41
Disable mail sending for testing or environment.
nepeat Jan 8, 2017
6d40409
Temporary disabling of groups testing until a socket mock is made.
nepeat Jan 8, 2017
a0b77fb
Merge pull request #114 from MSPARP/fix-tests
nepeat Jan 8, 2017
6636be8
Allow new and deactivated users to visit the settings page.
tehdragonfly Jan 8, 2017
6ad402a
Merge remote-tracking branch 'origin/production'
tehdragonfly Jan 8, 2017
d7bed89
Merge pull request #115 from MSPARP/master
nepeat Jan 9, 2017
3189416
Pytest for tests instead of using unittests.
nepeat Jan 9, 2017
f8e4a85
Fixtures that create admin and user clients.
nepeat Jan 30, 2017
ff38b3b
Move redirect test to a separate file.
nepeat Jan 30, 2017
c61344d
Settings theme/timezone testing.
nepeat Jan 30, 2017
de31bd8
Provide the user object inside the test client.
nepeat Jan 30, 2017
99e4d0f
Make the group tests work without a websocket.
nepeat Jan 30, 2017
5dc9f7b
Update requirements for the project.
nepeat Jan 30, 2017
fe5f2e9
Tests for admin only chats, private chats, and group creation
nepeat Feb 10, 2017
2a4994e
Working ban unit test.
nepeat Feb 11, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions alembic/versions/cac1f275a725_add_emailhostban_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Add EmailBan table.

Revision ID: cac1f275a725
Revises: 231e2c1e26da
Create Date: 2016-12-12 23:41:56.438144

"""

# revision identifiers, used by Alembic.
revision = 'cac1f275a725'
down_revision = '231e2c1e26da'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('email_bans',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pattern', sa.Unicode(length=255), nullable=False),
sa.Column('date', sa.DateTime(), nullable=False),
sa.Column('creator_id', sa.Integer(), nullable=False),
sa.Column('reason', sa.Unicode(length=255), nullable=False),
sa.ForeignKeyConstraint(['creator_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('pattern')
)
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('email_host_bans')
### end Alembic commands ###
31 changes: 31 additions & 0 deletions alembic/versions/ea30a8851312_add_new_user_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Add new user group.

Revision ID: ea30a8851312
Revises: cac1f275a725
Create Date: 2016-12-13 23:10:06.709741

"""

# revision identifiers, used by Alembic.
revision = 'ea30a8851312'
down_revision = 'cac1f275a725'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.execute("COMMIT;")
op.execute("ALTER TYPE users_group ADD VALUE 'new';")
op.execute("ALTER TYPE users_group ADD VALUE 'deactivated';")
op.execute("""UPDATE users SET "group"='deactivated' WHERE "group"='guest';""")
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
pass
### end Alembic commands ###
3 changes: 2 additions & 1 deletion extras/ensure_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ def init_db(redis: StrictRedis):
del db
del redis

subprocess.call(sys.argv[1:])
status = subprocess.call(sys.argv[1:])
sys.exit(status)
46 changes: 28 additions & 18 deletions newparp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from flask import Flask, abort, redirect, request, send_from_directory
from flask_mail import Mail
from werkzeug.routing import BaseConverter

from newparp.helpers import check_csrf_token
Expand All @@ -12,17 +13,12 @@
redis_disconnect,
set_cookie,
)
from newparp import views
from newparp.views import (
account, admin, characters, chat, chat_api, chat_list, errors, guides,
roulette, search, search_characters, settings,
)
from newparp.views.admin import spamless, spamless2


app = Flask(__name__)
app.url_map.strict_slashes = False


# Config

app.config["SERVER_NAME"] = os.environ["BASE_DOMAIN"]
Expand Down Expand Up @@ -52,6 +48,25 @@
app.teardown_request(redis_disconnect)


app.config["MAIL_SERVER"] = os.environ.get("MAIL_SERVER", "localhost")
app.config["MAIL_PORT"] = int(os.environ.get("MAIL_PORT", 25))
app.config["MAIL_USE_TLS"] = "MAIL_USE_TLS" in os.environ
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["MAIL_SUPPRESS_SEND"] = app.testing or bool(os.environ.get("NOMAIL"))
mail = Mail(app)


# Views/routes

from newparp import views
from newparp.views import (
account, admin, characters, chat, chat_api, chat_list, errors, guides,
search, search_characters, settings,
)
from newparp.views.admin import spamless, spamless2


class RegexConverter(BaseConverter):
def __init__(self, url_map, *items):
super(RegexConverter, self).__init__(url_map)
Expand Down Expand Up @@ -94,6 +109,7 @@ def make_rules(subdomain, path, func, formats=False, paging=False):
app.add_url_rule("/settings/theme", "settings_theme", settings.theme, methods=("POST",))
app.add_url_rule("/settings/log_in_details", "settings_log_in_details", settings.log_in_details, methods=("GET",))
app.add_url_rule("/settings/change_email", "settings_change_email", settings.change_email, methods=("POST",))
app.add_url_rule("/settings/verify_email", "settings_verify_email", settings.verify_email, methods=("GET",))
app.add_url_rule("/settings/change_password", "settings_change_password", settings.change_password, methods=("POST",))
make_rules("settings", "/settings/blocks", settings.blocks, formats=True)
app.add_url_rule("/settings/unblock", "settings_unblock", settings.unblock, methods=("POST",))
Expand Down Expand Up @@ -136,14 +152,6 @@ def make_rules(subdomain, path, func, formats=False, paging=False):
app.add_url_rule("/search/save", "rp_search_save", search.search_save, methods=("POST",))
app.add_url_rule("/search", "rp_search", search.search_get, methods=("GET",))
app.add_url_rule("/search", "rp_search_post", search.search_post, methods=("POST",))
app.add_url_rule("/search/continue", "rp_search_continue", search.search_continue, methods=("POST",))
app.add_url_rule("/search/stop", "rp_search_stop", search.search_stop, methods=("POST",))

app.add_url_rule("/roulette/save", "rp_roulette_save", roulette.roulette_save, methods=("POST",))
app.add_url_rule("/roulette", "rp_roulette", roulette.roulette_get, methods=("GET",))
app.add_url_rule("/roulette", "rp_roulette_post", roulette.roulette_post, methods=("POST",))
app.add_url_rule("/roulette/continue", "rp_roulette_continue", roulette.roulette_continue, methods=("POST",))
app.add_url_rule("/roulette/stop", "rp_roulette_stop", roulette.roulette_stop, methods=("POST",))

# 6. Groups

Expand All @@ -162,6 +170,7 @@ def make_rules(subdomain, path, func, formats=False, paging=False):
make_rules("rp", "/<path:url>/log/<regex(\"20[0-9]{2}\"):year>-<regex(\"0[1-9]|1[0-2]\"):month>-<regex(\"0[1-9]|[1-2][0-9]|3[0-1]\"):day>", chat.log_day, formats=True)

make_rules("rp", "/<path:url>/users", chat.users, formats=True, paging=True)
app.add_url_rule("/<path:url>/users/reset_regexes", "rp_chat_reset_regexes", chat.reset_regexes, methods=("POST",))
make_rules("rp", "/<path:url>/invites", chat.invites, formats=True, paging=True)

app.add_url_rule("/<path:url>/uninvite", "rp_chat_uninvite", chat.uninvite, methods=("POST",))
Expand All @@ -170,11 +179,10 @@ def make_rules(subdomain, path, func, formats=False, paging=False):
app.add_url_rule("/<path:url>/subscribe", "rp_chat_subscribe", chat.subscribe, methods=("POST",))
app.add_url_rule("/<path:url>/unsubscribe", "rp_chat_unsubscribe", chat.unsubscribe, methods=("POST",))

app.add_url_rule("/redirect", "redirect", views.redirect, methods=("GET",))
app.add_url_rule("/redirect", "redirect", views.redirect_view, methods=("GET",))

# 8. Chat API

app.add_url_rule("/chat_api/messages", "messages", chat_api.messages, methods=("POST",))
app.add_url_rule("/chat_api/send", "send", chat_api.send, methods=("POST",))
app.add_url_rule("/chat_api/draft", "draft", chat_api.draft, methods=("POST",))
app.add_url_rule("/chat_api/block", "block", chat_api.block, methods=("POST",))
Expand All @@ -190,8 +198,6 @@ def make_rules(subdomain, path, func, formats=False, paging=False):
app.add_url_rule("/chat_api/request_username", "request_username", chat_api.request_username, methods=("POST",))
app.add_url_rule("/chat_api/exchange_usernames", "exchange_usernames", chat_api.exchange_usernames, methods=("POST",))
app.add_url_rule("/chat_api/look_up_user", "look_up_user", chat_api.look_up_user, methods=("POST",))
app.add_url_rule("/chat_api/ping", "ping", chat_api.ping, methods=("POST",))
app.add_url_rule("/chat_api/quit", "quit", chat_api.quit, methods=("POST",))

# 9. Admin

Expand Down Expand Up @@ -237,6 +243,10 @@ def make_rules(subdomain, path, func, formats=False, paging=False):
app.add_url_rule("/admin/ip_bans/new", "admin_new_ip_ban", admin.new_ip_ban, methods=("POST",))
app.add_url_rule("/admin/ip_bans/delete", "admin_delete_ip_ban", admin.delete_ip_ban, methods=("POST",))

make_rules("admin", "/admin/email_bans", admin.email_bans, formats=True)
app.add_url_rule("/admin/email_bans/new", "admin_new_email_ban", admin.new_email_ban, methods=("POST",))
app.add_url_rule("/admin/email_bans/delete", "admin_delete_email_ban", admin.delete_email_ban, methods=("POST",))

app.add_url_rule("/admin/worker_status", "admin_worker_status", admin.worker_status, methods=("GET",))

# 10. Guides
Expand Down
15 changes: 13 additions & 2 deletions newparp/helpers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@ def decorated_function(*args, **kwargs):
return decorated_function


def activation_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if g.user is None:
return render_template("account/log_in_required.html")
elif g.user.group == "new":
return render_template("account/user_new.html")
elif g.user.group == "deactivated":
return render_template("account/user_deactivated.html")
return f(*args, **kwargs)
return decorated_function


def log_in_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if g.user is None:
return render_template("account/log_in_required.html")
elif g.user.group == "guest":
return render_template("account/activation_required.html")
return f(*args, **kwargs)
return decorated_function

Expand Down
40 changes: 8 additions & 32 deletions newparp/helpers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,22 @@ class KickedException(Exception):
pass


def group_chat_only(f):
def require_socket(f):
"""Only allow this request if the user has a socket open."""
@wraps(f)
def decorated_function(*args, **kwargs):
if g.chat.type != "group":
abort(404)
g.chat_id = int(request.form["chat_id"])
if g.redis.scard("chat:%s:sockets:%s" % (g.chat_id, g.session_id)) == 0:
abort(403)
return f(*args, **kwargs)
return decorated_function


def mark_alive(f):
def group_chat_only(f):
@wraps(f)
def decorated_function(*args, **kwargs):
g.joining = False
g.chat_id = int(request.form["chat_id"])
# Don't bother with any of this if we have a socket open, because the
# request is probably from that window.
if g.redis.scard("chat:%s:sockets:%s" % (g.chat_id, g.session_id)) != 0:
return f(*args, **kwargs)
session_online = g.redis.hexists("chat:%s:online" % g.chat_id, g.session_id)
if not session_online:
g.joining = True
# Make sure we're connected to the database.
db_connect()
# Get ChatUser if we haven't got it already.
if not hasattr(g, "chat_user"):
get_chat_user()
try:
authorize_joining(g.redis, g.db, g)
except (UnauthorizedException, BannedException, TooManyPeopleException):
abort(403)
try:
kick_check(g.redis, g)
except KickedException:
return jsonify({"exit": "kick"})
join(g.redis, g.db, g)
g.redis.zadd(
"chats_alive",
time.time() + 60,
"%s/%s" % (g.chat_id, g.session_id),
)
if g.chat.type != "group":
abort(404)
return f(*args, **kwargs)
return decorated_function

Expand Down
42 changes: 42 additions & 0 deletions newparp/helpers/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from flask import g, render_template, url_for
from flask_mail import Message as EmailMessage
from uuid import uuid4

from newparp import mail


expiry_times = {
"welcome": 86400,
"verify": 86400,
"reset": 600,
}

subjects = {
"welcome": "Welcome to MSPARP",
"verify": "Verify your e-mail address",
"reset": "Reset your password",
}

keys = {
"welcome": "verify",
"verify": "verify",
"reset": "reset",
}


def send_email(action, email_address):
email_token = str(uuid4())
g.redis.setex(
":".join([keys[action], str(g.user.id), email_address]),
expiry_times[action],
email_token,
)
message = EmailMessage(
subject=subjects[action],
sender="admin@msparp.com",
recipients=[email_address],
body=render_template("email/%s_plain.html" % action, user=g.user, email_address=email_address, email_token=email_token),
html=render_template("email/%s.html" % action, user=g.user, email_address=email_address, email_token=email_token),
)
mail.send(message)

Loading