Skip to content

Commit

Permalink
Merge pull request #334 from aiarena/staging
Browse files Browse the repository at this point in the history
Release v1.6.2
  • Loading branch information
lladdy authored Nov 30, 2021
2 parents 7b3f881 + ca19a16 commit 99397bf
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
4 changes: 4 additions & 0 deletions aiarena/frontend/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1464,4 +1464,8 @@ input[type=text], input[type=password], input[type=email], input[type=number], i
width: 84.5%;
overflow: hidden;
transition: max-height 0.2s ease-out
}

.private-download-warning {
background-color: rgba(255, 0, 0, 0.6);
}
2 changes: 1 addition & 1 deletion aiarena/frontend/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h3>user</h3>
</ul>
</li>

{% if user.is_staff %}
{% if user.is_superuser %}
<li>
<div id="sidebar-header">
<em class="material-icons">bug_report</em>
Expand Down
16 changes: 14 additions & 2 deletions aiarena/frontend/templates/bot.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@
</tr>
<tr>
<td><strong>Bot Zip</strong></td>
{# Highlight red to warn super users if it's not a public download #}
{% if request.user.is_superuser and not request.user == bot.user and not bot.bot_zip_publicly_downloadable %}
<td class="private-download-warning">
Warning: Private download!
{% else %}
<td>
{% if request.user == bot.user or bot.bot_zip_publicly_downloadable or request.user.is_staff %}
{% endif %}
{% if request.user == bot.user or bot.bot_zip_publicly_downloadable or request.user.is_superuser %}
<a href="{{ bot.bot_zip.url }}">Download</a>
{% else %}
--
Expand All @@ -51,9 +57,15 @@
</tr>
<tr>
<td><strong>Bot data</strong></td>
{# Highlight red to warn super users if it's not a public download #}
{% if request.user.is_superuser and not request.user == bot.user and not bot.bot_data_publicly_downloadable %}
<td class="private-download-warning">
Warning: Private download!
{% else %}
<td>
{% endif %}
{% if bot.bot_data %} {# Done with two if statements because templates don't allow parentheses #}
{% if request.user == bot.user or bot.bot_data_publicly_downloadable or request.user.is_staff %}
{% if request.user == bot.user or bot.bot_data_publicly_downloadable or request.user.is_superuser %}
<a href="{{ bot.bot_data.url }}">Download</a>
{% else %}
--
Expand Down
33 changes: 33 additions & 0 deletions aiarena/patreon/migrations/0003_auto_20211112_1942.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.0.8 on 2021-11-12 09:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('patreon', '0002_patreonaccountbind'),
]

operations = [
migrations.AddField(
model_name='patreonaccountbind',
name='last_token_refresh_attempt',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='patreonaccountbind',
name='last_token_refresh_failure',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='patreonaccountbind',
name='last_token_refresh_failure_message',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='patreonaccountbind',
name='last_token_refresh_success',
field=models.DateTimeField(blank=True, null=True),
),
]
17 changes: 16 additions & 1 deletion aiarena/patreon/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.utils import timezone
import json
import logging

Expand All @@ -15,16 +16,30 @@ class PatreonAccountBind(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)
access_token = models.CharField(max_length=64)
refresh_token = models.CharField(max_length=64)
last_token_refresh_attempt = models.DateTimeField(blank=True, null=True)
"""The datetime when the patreon token refresh was last attempted"""
last_token_refresh_success = models.DateTimeField(blank=True, null=True)
"""The datetime when the patreon token refresh last succeeded"""
last_token_refresh_failure = models.DateTimeField(blank=True, null=True)
"""The datetime when the patreon token refresh last failed"""
last_token_refresh_failure_message = models.TextField(blank=True, null=True)
"""The exception text provided with the latest refresh failure"""

def update_refresh_token(self):
oauth_client = PatreonOAuth(config.PATREON_CLIENT_ID, config.PATREON_CLIENT_SECRET)
tokens = oauth_client.refresh_token(self.refresh_token)
self.last_token_refresh_attempt = timezone.now()
if 'access_token' in tokens and 'refresh_token' in tokens:
self.access_token = tokens['access_token']
self.refresh_token = tokens['refresh_token']
self.last_token_refresh_success = timezone.now()
self.save()
else:
raise Exception(f"Failed to refresh patreon token for user {self.user.id}. Tokens dump:\n" + json.dumps(tokens))
exception_message = f"Failed to refresh patreon token for user {self.user.id}. Tokens dump:\n" + json.dumps(tokens)
self.last_token_refresh_failure = timezone.now()
self.last_token_refresh_failure_message = exception_message
self.save()
raise Exception(exception_message)

def update_user_patreon_tier(self):
api_client = PatreonApi(self.access_token)
Expand Down

0 comments on commit 99397bf

Please sign in to comment.