Skip to content

Commit

Permalink
Merge pull request #25 from ppfeufer/development
Browse files Browse the repository at this point in the history
v2.3.0
  • Loading branch information
ppfeufer authored Oct 23, 2020
2 parents 37f61d1 + 125c7c9 commit e6d4849
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
__pycache__

fleetpings/static/fleetpings/js/fleetpings.dev.js
fleetpings/static/fleetpings/js/fleetpings.dev.min.js
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [2.3.0] - xxxx-xx-xx
## [2.3.0] - 2020-10-14

### Important!

Expand All @@ -17,17 +17,20 @@ so have your Auth updated before installing this version.
### Fixed

- mySQL text fields can't have default values
- Parameters differ from overridden method warning

### Added

- Filter to the admin backend
- More checks for Discord. Now checking if the Discord Service s actually activated and setup properly
- Compatibility to AA Timezones (v1.2.1) new link style
- Backwards compatibility to versions of AA Timezones before 1.2.1, so the old link style is still generated when using an older version

### Changed

- Use clipboard.js bundled with Alliance Auth
- Minimum required Alliance Auth version set to 2.8.0 due to us using clipboard.js bundled with Alliance Auth
- Unused lib removed from templates
- Unused lib removed


## [2.2.2] - 2020-09-23
Expand Down
2 changes: 1 addition & 1 deletion fleetpings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

default_app_config: str = "fleetpings.apps.AaFleetpingsConfig"

__version__ = "2.3.0a1"
__version__ = "2.3.0"
__title__ = "Fleet Pings"
42 changes: 40 additions & 2 deletions fleetpings/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

from django.conf import settings

from .utils import clean_setting
from fleetpings.utils import clean_setting

from packaging import version

# set default panels if none are set in local.py
AA_FLEETPINGS_USE_SLACK = clean_setting("AA_FLEETPINGS_USE_SLACK", False)
Expand All @@ -25,6 +27,7 @@ def get_site_url(): # regex sso url
get the site url
:return: string
"""

regex = r"^(.+)\/s.+"
matches = re.finditer(regex, settings.ESI_SSO_CALLBACK_URL, re.MULTILINE)
url = "http://"
Expand All @@ -40,14 +43,47 @@ def timezones_installed() -> bool:
check if aa-timezones is installed
:return: bool
"""

return "timezones" in settings.INSTALLED_APPS


def get_timzones_version():
"""
get the version of aa-timezones, when installed
:return: string or None
"""

if timezones_installed():
from timezones import __version__ as timezones_version

return timezones_version

return None


def use_new_timezone_links() -> bool:
"""
determins whether to use then new link format from aa-timezones or not
the new link format has been introduced with aa-timezones v1.2.1
:return: bool
"""

return_value = True

if get_timzones_version() and version.parse(get_timzones_version()) < version.parse(
"1.2.1"
):
return_value = False

return return_value


def fittings_installed() -> bool:
"""
check if fittings is installed
:return: bool
"""

return "fittings" in settings.INSTALLED_APPS


Expand All @@ -56,12 +92,14 @@ def avoid_cdn() -> bool:
check if we should aviod CDN usage
:return: bool
"""

return AVOID_CDN


def discord_service_installed() -> bool:
"""
check if the Discord service is installed
:return:
:return: bool
"""

return "allianceauth.services.modules.discord" in settings.INSTALLED_APPS
2 changes: 1 addition & 1 deletion fleetpings/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from django.apps import AppConfig

from . import __version__
from fleetpings import __version__


class AaFleetpingsConfig(AppConfig):
Expand Down
4 changes: 2 additions & 2 deletions fleetpings/auth_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from django.utils.translation import ugettext_lazy as _

from fleetpings import urls, __title__

from allianceauth.services.hooks import MenuItemHook, UrlHook
from allianceauth import hooks

from . import urls, __title__


class AaFleetpingsMenuItem(MenuItemHook): # pylint: disable=too-few-public-methods
""" This class ensures only authorized users will see the menu entry """
Expand Down
1 change: 1 addition & 0 deletions fleetpings/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from django.forms import ModelForm, TextInput

from fleetpings.models import FleetType


Expand Down
18 changes: 6 additions & 12 deletions fleetpings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ class FleetDoctrine(models.Model):
help_text=_("Whether this doctrine is enabled or not"),
)

def clean(self, *args, **kwargs):
def clean(self):
"""
check if the doctrine link is an actual link to a website
:param args:
:param kwargs:
"""

doctrine_link = self.link
Expand All @@ -129,7 +127,7 @@ def clean(self, *args, **kwargs):
_("Your doctrine URL is not valid.")
) from exception

super().clean(*args, **kwargs)
super().clean()

def __str__(self) -> str:
return str(self.name)
Expand Down Expand Up @@ -239,12 +237,10 @@ class DiscordPingTargets(models.Model):
help_text=_("Whether this formup location is enabled or not"),
)

def clean(self, *args, **kwargs):
def clean(self):
"""
check if the group has already been synched to Discord,
if not, raise an error
:param args:
:param kwargs:
"""

# check if the Discord service is active
Expand All @@ -266,18 +262,16 @@ def clean(self, *args, **kwargs):
_("This group has not been synched to Discord yet.")
)

super().clean(*args, **kwargs)
super().clean()

def save(self, *args, **kwargs):
def save(self):
"""
Add the Discord group ID and save the whole thing
:param args:
:param kwargs:
"""

discord_group_info = DiscordUser.objects.group_to_role(self.name)
self.discord_id = discord_group_info["id"]
super().save(*args, **kwargs) # Call the "real" save() method.
super().save() # Call the "real" save() method.

def __str__(self) -> str:
return str(self.name)
Expand Down
63 changes: 35 additions & 28 deletions fleetpings/static/fleetpings/js/fleetpings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global fleetpingsSettings, fleetpingsTranslations */
/* global fleetpingsSettings, fleetpingsTranslations, ClipboardJS */

jQuery(document).ready(function($) {
/* Functions
Expand Down Expand Up @@ -153,10 +153,15 @@ jQuery(document).ready(function($) {
* @param {string} formupTime
*/
var getTimezonesUrl = function(formupTime) {
var formupDateTime = new Date(formupTime)
var formupDateTime = new Date(formupTime);
var formupTimestamp = (formupDateTime.getTime() - formupDateTime.getTimezoneOffset() *60 * 1000) / 1000;
var timezonesUrl = '';

var timezonesUrl = fleetpingsSettings.siteUrl + 'timezones/?#' + formupTimestamp;
if(fleetpingsSettings.useNewTimezoneLinks === true) {
timezonesUrl = fleetpingsSettings.siteUrl + 'timezones/' + formupTimestamp + '/';
} else {
timezonesUrl = fleetpingsSettings.siteUrl + 'timezones/?#' + formupTimestamp;
}

return timezonesUrl;
};
Expand Down Expand Up @@ -186,7 +191,7 @@ jQuery(document).ready(function($) {
// let's see if we can find a doctrine link
var fleetDoctrineLink = null;
if(fleetDoctrine !== '') {
selectedLink = $('#fleetDoctrineList [value="' + fleetDoctrine + '"]').data('doctrine-url');
var selectedLink = $('#fleetDoctrineList [value="' + fleetDoctrine + '"]').data('doctrine-url');

if(undefined !== selectedLink && selectedLink !== '') {
// Houston, we have a link!
Expand All @@ -209,13 +214,15 @@ jQuery(document).ready(function($) {
var pingText = '';

// determine pingTargetText
var discordPingTarget = '';
if(pingTargetText.indexOf('@') > -1) {
discordPingTarget = pingTargetText;
} else {
discordPingTarget = '@' + pingTargetText;
}

// determine pingTarget
var webhookPingTarget = '';
if(pingTarget.indexOf('@') > -1) {
webhookPingTarget = pingTarget;
} else {
Expand Down Expand Up @@ -250,34 +257,34 @@ jQuery(document).ready(function($) {
webhookPingTextHeader += 'Fleet is up';
}

pingText += '**' + "\n";
pingText += '**' + '\n';

// check if FC name is available
if(fcName !== '') {
pingText += "\n" + '**FC:** ' + fcName;
webhookPingTextContent += "\n" + '**FC:** ' + fcName;
pingText += '\n' + '**FC:** ' + fcName;
webhookPingTextContent += '\n' + '**FC:** ' + fcName;
}

// check if fleet name is available
if(fleetName !== '') {
pingText += "\n" + '**Fleet Name:** ' + fleetName;
webhookPingTextContent += "\n" + '**Fleet Name:** ' + fleetName;
pingText += '\n' + '**Fleet Name:** ' + fleetName;
webhookPingTextContent += '\n' + '**Fleet Name:** ' + fleetName;
}

// check if form-up location is available
if(formupLocation !== '') {
pingText += "\n" + '**Formup Location:** ' + formupLocation;
webhookPingTextContent += "\n" + '**Formup Location:** ' + formupLocation;
pingText += '\n' + '**Formup Location:** ' + formupLocation;
webhookPingTextContent += '\n' + '**Formup Location:** ' + formupLocation;
}

// check if form-up time is available
if($('input#formupTimeNow').is(':checked')) {
pingText += "\n" + '**Formup Time:** NOW';
webhookPingTextContent += "\n" + '**Formup Time:** NOW';
pingText += '\n' + '**Formup Time:** NOW';
webhookPingTextContent += '\n' + '**Formup Time:** NOW';
} else {
if(formupTime !== '') {
pingText += "\n" + '**Formup Time:** ' + formupTime;
webhookPingTextContent += "\n" + '**Formup Time:** ' + formupTime;
pingText += '\n' + '**Formup Time:** ' + formupTime;
webhookPingTextContent += '\n' + '**Formup Time:** ' + formupTime;

// get the timestamp and build the link to the timezones module if it's installed
if(fleetpingsSettings.timezonesInstalled === true) {
Expand All @@ -298,14 +305,14 @@ jQuery(document).ready(function($) {

// check if fleet comms is available
if(fleetComms !== '') {
pingText += "\n" + '**Comms:** ' + fleetComms;
webhookPingTextContent += "\n" + '**Comms:** ' + fleetComms;
pingText += '\n' + '**Comms:** ' + fleetComms;
webhookPingTextContent += '\n' + '**Comms:** ' + fleetComms;
}

// check if doctrine is available
if(fleetDoctrine !== '') {
pingText += "\n" + '**Ships / Doctrine:** ' + fleetDoctrine;
webhookPingTextContent += "\n" + '**Ships / Doctrine:** ' + fleetDoctrine;
pingText += '\n' + '**Ships / Doctrine:** ' + fleetDoctrine;
webhookPingTextContent += '\n' + '**Ships / Doctrine:** ' + fleetDoctrine;

// grab the doctrine link if there is one
if(fleetDoctrineLink !== null) {
Expand All @@ -323,14 +330,14 @@ jQuery(document).ready(function($) {

// check if srp is available
if(fleetSrp !== '') {
pingText += "\n" + '**SRP:** ' + fleetSrp;
webhookPingTextContent += "\n" + '**SRP:** ' + fleetSrp;
pingText += '\n' + '**SRP:** ' + fleetSrp;
webhookPingTextContent += '\n' + '**SRP:** ' + fleetSrp;
}

// check if additional information is available
if(additionalInformation !== '') {
pingText += "\n\n" + '**Additional Information**:' + "\n" + additionalInformation;
webhookPingTextContent += "\n\n" + '**Additional Information**:' + "\n" + additionalInformation;
pingText += '\n\n' + '**Additional Information**:' + '\n' + additionalInformation;
webhookPingTextContent += '\n\n' + '**Additional Information**:' + '\n' + additionalInformation;
}

if(fleetpingsSettings.platformUsed === 'Discord') {
Expand All @@ -345,7 +352,7 @@ jQuery(document).ready(function($) {
if(webhookUrl !== false && webhookUrl !== '') {
// add ping creator at the end
if(fleetpingsSettings.pingCreator !== '') {
pingText += "\n\n" + '*(Ping sent by: ' + fleetpingsSettings.pingCreator + ')*';
pingText += '\n\n' + '*(Ping sent by: ' + fleetpingsSettings.pingCreator + ')*';
webhookPingTextFooter = '(Ping sent by: ' + fleetpingsSettings.pingCreator + ')';
}

Expand All @@ -368,7 +375,7 @@ jQuery(document).ready(function($) {
if(undefined !== webhookEmbedPing && webhookEmbedPing === 'True') {
sendEmbeddedDiscordPing(
webhookUrl,
webhookPingTarget + ' :: **' + webhookPingTextHeader + '**' + "\n" + '** **',
webhookPingTarget + ' :: **' + webhookPingTextHeader + '**' + '\n' + '** **',
// embedded content » https://discohook.org/ - https://leovoel.github.io/embed-visualizer/
{
'title': '**.: Fleet Details :.**',
Expand Down Expand Up @@ -399,7 +406,7 @@ jQuery(document).ready(function($) {
'fallback': pingText,
'color': embedColor,
'pretext': '<' + slackEmbedPingTarget + '>' + ' :: *' + webhookPingTextHeader + '*',
'text': '*.: Fleet Details :.*' + "\n" + webhookPingTextContent.split('**').join('*'),
'text': '*.: Fleet Details :.*' + '\n' + webhookPingTextContent.split('**').join('*'),
'footer': webhookPingTextFooter,
// 'footer_icon': 'https://platform.slack-edge.com/img/default_application_icon.png'
}
Expand All @@ -420,7 +427,7 @@ jQuery(document).ready(function($) {
/**
* copy the fleet ping to clipboard
*/
var CopyFleetPing = function() {
var copyFleetPing = function() {
/**
* copy text to clipboard
*
Expand Down Expand Up @@ -498,6 +505,6 @@ jQuery(document).ready(function($) {
* copy ping text
*/
$('button#copyFleetPing').on('click', function() {
CopyFleetPing();
copyFleetPing();
});
});
Loading

0 comments on commit e6d4849

Please sign in to comment.