Skip to content
This repository was archived by the owner on Jun 15, 2021. It is now read-only.

Commit cb3fbde

Browse files
authored
Merge pull request #347 from KryptedGaming/development
Release: 4.2.0
2 parents db9bf75 + a1e728b commit cb3fbde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+531
-88
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ ENV/
103103
# settings
104104
settings.py
105105
db.sqlite3
106+
*.sqlite
106107
*.db
107108
.DS_Store
108109

@@ -123,3 +124,8 @@ old/
123124

124125
# vscode
125126
.vscode/
127+
128+
# ignore packages
129+
app/packages/*
130+
!app/packages/.gitkeep
131+

.gitmodules

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
[submodule "app/packages/django-eveonline-connector"]
2-
path = app/packages/django-eveonline-connector
3-
url = https://github.com/KryptedGaming/django-eveonline-connector
4-
[submodule "app/packages/django-discord-connector"]
5-
path = app/packages/django-discord-connector
6-
url = https://github.com/KryptedGaming/django-discord-connector.git
7-
[submodule "app/packages/django-discourse-connector"]
8-
path = app/packages/django-discourse-connector
9-
url = https://github.com/KryptedGaming/django-discourse-connector

app/accounts/models.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ def display_name(self):
2525

2626
def display_avatar(self):
2727
if "django_eveonline_connector" in settings.INSTALLED_APPS:
28-
if self.get_eveonline_character():
29-
return "https://imageserver.eveonline.com/Character/%s_128.jpg" % self.get_eveonline_character().external_id
28+
from django_eveonline_connector.models import EveCharacter
29+
character = EveCharacter.get_primary_character(self.user)
30+
if character:
31+
return "https://imageserver.eveonline.com/Character/%s_128.jpg" % character.external_id
3032
return "https://api.adorable.io/avatars/160/%s.png" % self.user.username
3133

32-
def get_eveonline_character(self):
33-
if "django_eveonline_connector" not in settings.INSTALLED_APPS:
34-
return None
35-
if self.user.eve_tokens.all().count() > 0:
36-
return self.user.eve_tokens.all()[0].get_primary_character()
34+
def get_primary_character(self):
35+
if "django_eveonline_connector" in settings.INSTALLED_APPS:
36+
from django_eveonline_connector.models import EveCharacter
37+
character = EveCharacter.get_primary_character(self.user)
38+
return character
3739
else:
38-
return None
40+
return None

app/accounts/templates/accounts/user_view.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ <h3 class="profile-username text-center">{{user.info.display_name}}</h3>
8282
{% if "django_eveonline_connector" in INSTALLED_APPS %}
8383
<li class="list-group-item">
8484
<b>EVE Character</b>
85-
{% if user.info.get_eveonline_character %}
85+
{% if user.info.get_primary_character %}
8686
<p class="pull-right">
87-
{{user.info.get_eveonline_character.name}}
88-
<a class="text-danger"
89-
href="{% url 'django-eveonline-connector-sso-token-remove' user.info.get_eveonline_character.token.pk %}"><i
90-
class="fa fa-times pull-right"></i></a>
87+
{{user.info.get_primary_character.name}}
88+
<a class="text-success"
89+
href="{% url 'django-eveonline-connector-character-select-primary' %}"><i
90+
class="fa fa-refresh pull-right"></i></a>
9191
</p>
9292
{% else %}
93-
<p class="pull-right"><b><a href="{% url 'django-eveonline-connector-sso-token-add' %}">Add
93+
<p class="pull-right"><b><a href="{% url 'django-eveonline-connector-character-select-primary' %}">Select
9494
Main Character</a></b></p>
9595
{% endif %}
9696
</li>

app/app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# \/ \/ \/ \/ \/ #
99

1010
__title__ = 'Krypted'
11-
__version__ = '4.1.0'
11+
__version__ = '4.2.0'
1212
__author__ = 'Krypted Gaming'
1313
__license__ = 'MIT License'
1414
__copyright__ = 'Copyright © 2017-2020 Krypted Gaming. All rights reserved.'

app/app/templates/403.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends "base.html" %}
2+
{% block title %}
3+
Permission Denied
4+
{% endblock %}
5+
6+
{% block header %}
7+
Permission Denied
8+
{% endblock %}
9+
10+
{% block description %}
11+
12+
{% endblock %}
13+
14+
{% block content %}
15+
<p>You were denied access for that action. If you think this was a mistake, contact your administrator.</p>
16+
{% endblock %}

app/app/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
from django.contrib.auth.decorators import permission_required, login_required
88
from django.urls import reverse_lazy
99
from django.views.generic.edit import FormView
10+
from django.conf import settings
1011

1112

1213
@login_required
1314
def dashboard(request):
15+
if 'django_eveonline_connector' in settings.INSTALLED_APPS:
16+
from django_eveonline_connector.models import PrimaryEveCharacterAssociation
17+
if request.user.eve_tokens.all().count() > 1 and not PrimaryEveCharacterAssociation.objects.filter(user=request.user).exists():
18+
messages.warning(request, "You need to select a primary EVE Online character.")
19+
return redirect('django-eveonline-connector-character-select-primary')
1420
return redirect('accounts-user', username=request.user.username)
15-
16-
21+
1722
def handler500(request):
1823
return render(request, '500.html', status=505)

app/applications/apps.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
from django.apps import AppConfig
2+
import os
3+
import logging
24

35

6+
logger = logging.getLogger(__name__)
7+
48
class ApplicationsConfig(AppConfig):
59
name = 'applications'
610
verbose_name = "Applications"
711
url_slug = 'applications'
12+
13+
APPLICATIONS_NOTIFICATION_CHANNEL = os.environ.get(
14+
'APPLICATIONS_NOTIFICATION_CHANNEL', None)
15+
16+
def ready(self):
17+
from django.db.models.signals import post_save
18+
from .models import Application
19+
from .signals import notify_discord_channel
20+
from django.conf import settings
21+
if 'django_discord_connector' in settings.INSTALLED_APPS and self.APPLICATIONS_NOTIFICATION_CHANNEL:
22+
logger.info("Application notifications are enabled")
23+
post_save.connect(notify_discord_channel, sender=Application)

app/applications/decorators.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55

66
def user_can_manage_application(function):
77
def wrap(request, *args, **kwargs):
8+
if 'application_id' in kwargs:
9+
application_id = kwargs.get('application_id')
10+
elif 'pk' in kwargs:
11+
application_id = kwargs.get('pk')
812
try:
9-
application = Application.objects.get(pk=kwargs['application_id'])
10-
except Exception as e:
11-
application = Application.objects.get(pk=kwargs['pk'])
13+
application = Application.objects.get(pk=application_id)
14+
except Application.DoesNotExist:
15+
messages.warning(request, "That application no longer exists.")
16+
return redirect('application-list')
17+
1218
if application.template not in get_manageable_application_templates(request.user):
1319
messages.warning(request, "You cannot manage that application, it requires a particular group.")
1420
return redirect('application-list')
1521
return function(request, *args, **kwargs)
16-
return wrap
22+
return wrap

app/applications/signals.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from django.dispatch import receiver
2+
from django.urls import reverse
3+
from django.db.models.signals import post_save
4+
from django.apps import apps
5+
from django.conf import settings
6+
from .models import Application
7+
import logging
8+
logger = logging.getLogger(__name__)
9+
10+
@receiver(post_save, sender=Application)
11+
def notify_discord_channel(sender, **kwargs):
12+
if 'created' not in kwargs or not kwargs.get('created'):
13+
return
14+
try:
15+
from django_discord_connector.request import DiscordRequest
16+
channel = apps.get_app_config(
17+
'applications').APPLICATIONS_NOTIFICATION_CHANNEL
18+
application = kwargs.get('instance')
19+
20+
application_url = reverse('application-detail', kwargs={'pk': application.pk})
21+
url = f"{settings.SITE_PROTOCOL}{settings.SITE_DOMAIN}{application_url}"
22+
23+
message = {
24+
'title': f"New Application - {application.template.name}",
25+
'fields': [
26+
{
27+
'name' : "Description",
28+
'value': f"There is a new application by {application.request_user}"
29+
},
30+
{
31+
'name' : "View Application",
32+
'value': f"[Click here to view the application]({url})"
33+
},
34+
],
35+
}
36+
37+
response = DiscordRequest.get_instance().send_channel_message(
38+
channel,
39+
embed=message
40+
)
41+
42+
except Exception as e:
43+
logger.error(f"Failed to notify Discord channel of new application. {e}")

0 commit comments

Comments
 (0)