Skip to content

Commit

Permalink
fat links should be re-opened only once
Browse files Browse the repository at this point in the history
  • Loading branch information
ppfeufer committed Apr 20, 2021
1 parent 54875b3 commit 2c5e514
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 32 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Proper log messages to fatlink detail view and edit actions to differenciate if
someone is only viewing or actually editing some details
- Confirmation modal window when closing ESI fleets manually
- Ability to re-open FAT links for a certain time after they have expired
(`manage_afat` permissions are needed to re-open FAT links)
- Ability to re-open FAT links for a certain time after they have expired FAT links
can be re-opened only once though (`manage_afat` permissions are needed to re-open
FAT links)
- Logs view (`log_view` permissions are needed to view the logs)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion afat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

default_app_config: str = "afat.apps.AfatConfig"

__version__ = "2.0.0-alpha.12"
__version__ = "2.0.0-alpha.13"
__title__ = "Fleet Activity Tracking"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.1.8 on 2021-04-19 11:18
# Generated by Django 3.1.8 on 2021-04-20 20:16

import django.utils.timezone
from django.conf import settings
Expand Down Expand Up @@ -43,6 +43,13 @@ class Migration(migrations.Migration):
"verbose_name_plural": "Manual FATs",
},
),
migrations.AddField(
model_name="afatlink",
name="reopened",
field=models.BooleanField(
default=False, help_text="Has this FAT link being re-opened?"
),
),
migrations.AlterField(
model_name="afat",
name="afatlink",
Expand Down
5 changes: 5 additions & 0 deletions afat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ class AFatLink(models.Model):

esi_fleet_id = models.BigIntegerField(blank=True, null=True)

reopened = models.BooleanField(
default=False,
help_text="Has this FAT link being re-opened?",
)

class Meta: # pylint: disable=too-few-public-methods
"""
AFatLink :: Meta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
data-toggle="modal"
data-target="#reopenFatLinkModal"
data-url="{% url 'afat:fatlinks_reopen_fatlink' link.hash %}"
data-body-text="{% blocktranslate with reopen_duration=reopen_duration %}<p>Are you sure you want to re-open this FAT link for another {{ reopen_duration }} minutes?<br><em>(Be aware, this action will be logged)</em></p>{% endblocktranslate %}"
data-body-text="{% blocktranslate with reopen_duration=reopen_duration %}<p>Are you sure you want to re-open this FAT link for another {{ reopen_duration }} minutes?<br>FAT links can be re-opened only once!<br><em>(Be aware, this action will be logged)</em></p>{% endblocktranslate %}"
data-confirm-text="{% translate 'Re-Open' %}"
>
{% translate 'Re-Open FAT link' %}
Expand Down
12 changes: 12 additions & 0 deletions afat/templates/afat/partials/fatlinks/details/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ <h4>{% translate "Error" %}</h4>
</div>
{% endif %}

{% if msg_code == 7 %}
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="close">
<span aria-hidden="true">&times</span>
</button>

<h4>{% translate "Warning" %}</h4>

<p>{% translate "This FAT link has already been re-opened. FAT links can be re-opened only once!" %}</p>
</div>
{% endif %}

{% if msg_code == 999 %}
<div class="alert alert-{{ message.0 }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="close">
Expand Down
65 changes: 38 additions & 27 deletions afat/views/fatlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,8 @@ def details_fatlink(request: WSGIRequest, fatlink_hash: str = None) -> HttpRespo
link_ongoing = False

if (
get_time_delta(link_expires, now, "minutes")
link.reopened is False
and get_time_delta(link_expires, now, "minutes")
< AFAT_DEFAULT_FATLINK_REOPEN_GRACE_TIME
):
link_can_be_reopened = True
Expand Down Expand Up @@ -932,38 +933,48 @@ def reopen_fatlink(request: WSGIRequest, fatlink_hash: str):
try:
fatlink_duration = ClickAFatDuration.objects.get(fleet__hash=fatlink_hash)

created_at = fatlink_duration.fleet.afattime
now = datetime.now()
if fatlink_duration.fleet.reopened is False:
created_at = fatlink_duration.fleet.afattime
now = datetime.now()

time_difference_in_minutes = get_time_delta(created_at, now, "minutes")
new_duration = time_difference_in_minutes + AFAT_DEFAULT_FATLINK_REOPEN_DURATION
time_difference_in_minutes = get_time_delta(created_at, now, "minutes")
new_duration = (
time_difference_in_minutes + AFAT_DEFAULT_FATLINK_REOPEN_DURATION
)

fatlink_duration.duration = new_duration
fatlink_duration.save()
fatlink_duration.duration = new_duration
fatlink_duration.save()

# writing DB log
write_log(
request=request,
# log_event=AFatLogEvent.REOPEN_FATLINK,
log_event=AFatLogEvent.REOPEN_FATLINK,
log_text=(
f"FAT link re-opened for a "
f"duration of {AFAT_DEFAULT_FATLINK_REOPEN_DURATION} minutes"
),
fatlink_hash=fatlink_duration.fleet.hash,
)
fatlink_duration.fleet.reopened = True
fatlink_duration.fleet.save()

logger.info(
(
f'FAT link with hash "{fatlink_hash}" '
f"re-opened by {request.user} for a "
f"duration of {AFAT_DEFAULT_FATLINK_REOPEN_DURATION} minutes"
# writing DB log
write_log(
request=request,
# log_event=AFatLogEvent.REOPEN_FATLINK,
log_event=AFatLogEvent.REOPEN_FATLINK,
log_text=(
f"FAT link re-opened for a "
f"duration of {AFAT_DEFAULT_FATLINK_REOPEN_DURATION} minutes"
),
fatlink_hash=fatlink_duration.fleet.hash,
)
)

request.session[
"{fatlink_hash}-task-code".format(fatlink_hash=fatlink_hash)
] = 5
logger.info(
(
f'FAT link with hash "{fatlink_hash}" '
f"re-opened by {request.user} for a "
f"duration of {AFAT_DEFAULT_FATLINK_REOPEN_DURATION} minutes"
)
)

request.session[
"{fatlink_hash}-task-code".format(fatlink_hash=fatlink_hash)
] = 5
else:
request.session[
"{fatlink_hash}-task-code".format(fatlink_hash=fatlink_hash)
] = 7
except ClickAFatDuration.DoesNotExist:
request.session[
"{fatlink_hash}-task-code".format(fatlink_hash=fatlink_hash)
Expand Down

0 comments on commit 2c5e514

Please sign in to comment.