aa-structures 2.11.0__py3-none-any.whl → 2.12.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aa-structures
3
- Version: 2.11.0
3
+ Version: 2.12.0
4
4
  Summary: App for managing Eve Online structures with Alliance Auth.
5
5
  Author-email: Erik Kalkoken <kalkoken87@gmail.com>
6
6
  Requires-Python: >=3.8
@@ -1,4 +1,4 @@
1
- structures/__init__.py,sha256=73A8QmbMlzuQCd4B1PJ0x0-1eGmBUMeyKhZGFG2Oafk,204
1
+ structures/__init__.py,sha256=CxjO-itYCGXfwByFQ-cKfhmKWBvz2Lygf1fchGS8_nU,204
2
2
  structures/admin.py,sha256=TYWGPou4s-mgspoGaZSiZu2nxBeNzidL_DcJTv7JGJI,40068
3
3
  structures/app_settings.py,sha256=7I_6VC7YecCxnSgtyNQa9h1Zdwb11qJhrNaBLgyA5m0,6527
4
4
  structures/apps.py,sha256=MNZH9l3qWCwuS7OGiKGkBVrDzKoOFlqwDdEgyEFzxVA,195
@@ -20,7 +20,7 @@ structures/core/notification_embeds/__init__.py,sha256=30cpjKLZ5_OFtXDACDcjvWQAY
20
20
  structures/core/notification_embeds/billing_embeds.py,sha256=d9XkTyYH7U3UDZaqXu0WoN0wvlrT2S68Rfn2jEpVtM4,5164
21
21
  structures/core/notification_embeds/corporate_embeds.py,sha256=mfm6dDrgzupyRZ9TZGXML-UGoY_PymNj9LuR8EthdDA,6098
22
22
  structures/core/notification_embeds/helpers.py,sha256=0SlrLLFyV0IrdOYfIOLQs0xZgzK8bO7Iroqh7dZnm98,2974
23
- structures/core/notification_embeds/main.py,sha256=N-l9PJYxgsBvcPOG1WQ2OgxC6hCAQnxgx2V1gWUsSMc,15233
23
+ structures/core/notification_embeds/main.py,sha256=P8Ajvd9j4SUBpZde2IOejFUV5bEXMUWU4lolNjkrxWQ,16048
24
24
  structures/core/notification_embeds/moonmining_embeds.py,sha256=5OJtfwoLE18mB62iwyHTcMo9eOPBC2vQFSjQlDnTcTY,7130
25
25
  structures/core/notification_embeds/orbital_embeds.py,sha256=ovAnTqrc2X0s-HhQS-UleI8J5-gJEO361HYJzcoAdeQ,2864
26
26
  structures/core/notification_embeds/sov_embeds.py,sha256=_r4U5zN3MfEag9FCeN0my2d4qfMBUwYUGWW-oGftjn8,8901
@@ -61,7 +61,7 @@ structures/migrations/0006_add_ownercharacter_disabled.py,sha256=yfcuwWHdSoF7HTE
61
61
  structures/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
62
62
  structures/models/__init__.py,sha256=Da0-Z4BtsZ_mlnI6XtyvoE0UtTuOA0psGCuVhVPVKrM,916
63
63
  structures/models/eveuniverse.py,sha256=vTIfzZL9guEDuZHQvRdG6pI4zSEdMqfVE-2SkHdqbRo,2213
64
- structures/models/notifications.py,sha256=tznJo2prNjhk9C7S4cDrQxftIvuLcidB6vSkvFfb4mw,35146
64
+ structures/models/notifications.py,sha256=HwQc-ChdP0ULuJgxUym9_CBsCWCmcHT7whlk9tB2vzw,35364
65
65
  structures/models/owners.py,sha256=8VDRL1fPep0TN6Nv5MJg1NC6_2V6bMJd6f-eda4-PJg,55697
66
66
  structures/models/structures_1.py,sha256=e1sI-2zMSKcPi2PyYA--fcc8rn-yQwODzlUHKjeWgLI,29778
67
67
  structures/models/structures_2.py,sha256=g5Pct5jNmZC-n7fnpLs5UyiP9JLrGdI1vjYucHTV_wQ,10371
@@ -171,7 +171,7 @@ structures/tests/core/test_sovereignty.py,sha256=SGgNw6NxmaU3jV-EDhKJRLfHnRnqDCw
171
171
  structures/tests/core/test_starbases.py,sha256=Q3EZVIKZGzxUUvvn0TvZYOL9YQ-baiTRTT83xWqTAhQ,3186
172
172
  structures/tests/core/notification_embeds/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
173
173
  structures/tests/core/notification_embeds/test_helpers.py,sha256=HG20TC8Bz7NqpaQWo6uvrsxfNIwTL2Zi_NRkh3UyN2Y,1776
174
- structures/tests/core/notification_embeds/test_main.py,sha256=vTDByjxxVCA6KMcr5XH4f4QsMgcDI_YDd-fjZfHztng,13808
174
+ structures/tests/core/notification_embeds/test_main.py,sha256=rSUm8dGsddjnX_OUwtCh-wd5UhJ6ttTsfxc1soAoDv8,14667
175
175
  structures/tests/integration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
176
176
  structures/tests/integration/test_tasks.py,sha256=s6hL5UBotDmhLq7NUiOad72W-S_18u_yAHiLWVryVi8,23617
177
177
  structures/tests/integration/test_views.py,sha256=SkbIposTUjo0nujHL4WEaZO7nY1Bfuvm805H39XUv-g,4361
@@ -180,7 +180,7 @@ structures/tests/models/test_eveuniverse.py,sha256=bQ1upOLfoivfaa9KCrzjWvSH_EvL2
180
180
  structures/tests/models/test_notifications_1.py,sha256=xVX4an54sZM8WLUdsAGUG2Nb4Rl7W5FBzhI0hBhJo5g,30300
181
181
  structures/tests/models/test_notifications_2.py,sha256=wBoB6lHMK4yrd63DSkZ570yXW6coevDtI0pl1ttgB1o,31989
182
182
  structures/tests/models/test_notifications_3.py,sha256=u11s0k9EmtFgL3kyb4zDyLVliQLOps701ZgEA2T2i0Y,7257
183
- structures/tests/models/test_notifications_discord.py,sha256=9_42lcrb2lUUMRqgdRJAub9cJ4QZI71OyoORwK0LEvg,5551
183
+ structures/tests/models/test_notifications_discord.py,sha256=6maDXjl2C5yH2XRgsvMtb3P-tfOdZLQDaksffiqS8OM,6312
184
184
  structures/tests/models/test_owners_1.py,sha256=o8AJasQ0-Pdb0FRFZcmNcMGjaIk8fH3OZIZw4paJiDw,24433
185
185
  structures/tests/models/test_owners_2.py,sha256=gkTXpSibPWs1XfZtPvyeEvVebyYZcKERD9GQSYSClYk,21911
186
186
  structures/tests/models/test_owners_3.py,sha256=cpDkfFkVvC1v4uuXha1vGUmWZ163huYTUDuZyed9Rdc,16947
@@ -220,7 +220,7 @@ structures/webhooks/models.py,sha256=kUkt9rnRQIJIrU9Bjcs34rvkb-TMbUubHdn-kny08kI
220
220
  structures/webhooks/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
221
221
  structures/webhooks/tests/test_core.py,sha256=4NcEAQgK2KhQkFOxYh2ad0S-qUWh1DNGDmLo5Mo5opI,6762
222
222
  structures/webhooks/tests/test_utils.py,sha256=ekADFv0JOEtXeqdiejbeqrABO__Q1flJHzVieQ7L9e0,459
223
- aa_structures-2.11.0.dist-info/LICENSE,sha256=XZiwB_S_40_HhnvLg5xvtBb3g1oGjPrk0rpFwk8iInE,1070
224
- aa_structures-2.11.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
225
- aa_structures-2.11.0.dist-info/METADATA,sha256=yuYKAElX7wpn9YDI8qwLn20gb_Vksa5A7mnjsnN5dBg,5972
226
- aa_structures-2.11.0.dist-info/RECORD,,
223
+ aa_structures-2.12.0.dist-info/LICENSE,sha256=XZiwB_S_40_HhnvLg5xvtBb3g1oGjPrk0rpFwk8iInE,1070
224
+ aa_structures-2.12.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
225
+ aa_structures-2.12.0.dist-info/METADATA,sha256=E2IAO0tGX_bRqM9r1ryldZsIGyv22TLHn8tMs8zQ2zs,5972
226
+ aa_structures-2.12.0.dist-info/RECORD,,
structures/__init__.py CHANGED
@@ -3,5 +3,5 @@
3
3
  # pylint: disable = invalid-name
4
4
  default_app_config = "structures.apps.StructuresConfig"
5
5
 
6
- __version__ = "2.11.0"
6
+ __version__ = "2.12.0"
7
7
  __title__ = "Structures"
@@ -10,6 +10,8 @@ import dhooks_lite
10
10
  from django.conf import settings
11
11
  from django.utils.translation import gettext as _
12
12
 
13
+ from allianceauth.services.hooks import get_extension_logger
14
+ from app_utils.logging import LoggerAddTag
13
15
  from app_utils.urls import reverse_absolute, static_file_absolute_url
14
16
 
15
17
  from structures import __title__
@@ -19,6 +21,8 @@ from structures.models.notifications import Notification, NotificationBase, Webh
19
21
 
20
22
  from .helpers import target_datetime_formatted
21
23
 
24
+ logger = LoggerAddTag(get_extension_logger(__name__), __title__)
25
+
22
26
 
23
27
  class NotificationBaseEmbed:
24
28
  """Base class for all notification embeds.
@@ -141,6 +145,20 @@ class NotificationBaseEmbed:
141
145
  footer_text += f" #{my_text}"
142
146
  footer_icon_url = footer_icon_url if is_absolute_url(footer_icon_url) else None
143
147
  footer = dhooks_lite.Footer(text=footer_text, icon_url=footer_icon_url)
148
+ max_description = dhooks_lite.Embed.MAX_DESCRIPTION
149
+ if self._description and len(self._description) > max_description:
150
+ logger.warning(
151
+ "%s: Description of notification is too long: %s",
152
+ self,
153
+ self._description,
154
+ )
155
+ self._description = self._description[:max_description]
156
+ max_title = dhooks_lite.Embed.MAX_TITLE
157
+ if self._title and len(self._title) > max_title:
158
+ logger.warning(
159
+ "%s: Title of notification is too long: %s", self, self._title
160
+ )
161
+ self._title = self._title[:max_title]
144
162
  return dhooks_lite.Embed(
145
163
  author=author,
146
164
  color=self._color,
@@ -410,11 +410,15 @@ class NotificationBase(models.Model):
410
410
  try:
411
411
  embed, ping_type = self._generate_embed(webhook.language_code)
412
412
  except OSError as ex:
413
- logger.warning("%s: Failed to generate embed: %s", self, ex, exc_info=True)
413
+ logger.error("%s: Failed to generate embed: %s", self, ex, exc_info=True)
414
414
  return False
415
415
 
416
416
  content = self._create_content_with_pings(webhook, ping_type)
417
417
  content += self._add_discord_group_pings(webhook)
418
+ max_content = dhooks_lite.Webhook.MAX_CHARACTERS
419
+ if content and len(content) > max_content:
420
+ logger.error("%s: Content of notification is too long: %s", self, content)
421
+ return False
418
422
 
419
423
  username, avatar_url = self._gen_avatar()
420
424
  new_queue_size = webhook.send_message(
@@ -240,6 +240,26 @@ class TestNotificationEmbedsGenerate(TestCase):
240
240
  self.assertEqual(discord_embed.footer.text, "Structures")
241
241
  self.assertIn("structures_logo.png", discord_embed.footer.icon_url)
242
242
 
243
+ def test_should_not_break_with_too_large_description(self):
244
+ # given
245
+ notification = Notification.objects.get(notification_id=1000000403)
246
+ notification_embed = NotificationBaseEmbed.create(notification)
247
+ notification_embed._description = "x" * 2049
248
+ # when
249
+ discord_embed = notification_embed.generate_embed()
250
+ # then
251
+ self.assertIsInstance(discord_embed, dhooks_lite.Embed)
252
+
253
+ def test_should_not_break_with_too_large_title(self):
254
+ # given
255
+ notification = Notification.objects.get(notification_id=1000000403)
256
+ notification_embed = NotificationBaseEmbed.create(notification)
257
+ notification_embed._title = "x" * 257
258
+ # when
259
+ discord_embed = notification_embed.generate_embed()
260
+ # then
261
+ self.assertIsInstance(discord_embed, dhooks_lite.Embed)
262
+
243
263
 
244
264
  class TestNotificationEmbedsClasses(NoSocketsTestCase):
245
265
  @classmethod
@@ -33,6 +33,7 @@ if "discord" in app_labels():
33
33
  super().setUpClass()
34
34
  load_eveuniverse()
35
35
  load_eve_entities()
36
+
36
37
  cls.group_1 = Group.objects.create(name="Dummy Group 1")
37
38
  cls.group_2 = Group.objects.create(name="Dummy Group 2")
38
39
  cls.owner = OwnerFactory()
@@ -140,3 +141,23 @@ if "discord" in app_labels():
140
141
  self.assertTrue(mock_import_discord.called)
141
142
  _, kwargs = mock_send_message.call_args
142
143
  self.assertFalse(re.search(r"(<@&\d+>)", kwargs["content"]))
144
+
145
+ def test_should_abort_when_content_is_too_large(
146
+ self, mock_send_message, mock_import_discord
147
+ ):
148
+ # given
149
+ mock_send_message.return_value = 1
150
+ mock_import_discord.return_value.objects.group_to_role.side_effect = (
151
+ self._my_group_to_role
152
+ )
153
+ webhook = WebhookFactory()
154
+ for i in range(286):
155
+ group = Group.objects.create(name=f"Group {i+1}")
156
+ webhook.ping_groups.add(group)
157
+ obj = clone_notification(
158
+ Notification.objects.get(notification_id=1000000509)
159
+ )
160
+ # when
161
+ result = obj.send_to_webhook(webhook)
162
+ # then
163
+ self.assertFalse(result)