mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 20:40:17 +02:00
Forgot pre-commit for master > 2.9.x
This commit is contained in:
parent
392a0c4dcb
commit
dc97fb1cc5
@ -3,11 +3,11 @@ from .models import Notification
|
|||||||
|
|
||||||
|
|
||||||
@admin.register(Notification)
|
@admin.register(Notification)
|
||||||
class NotificationAdmin(admin.ModelAdmin):
|
class NotificationAdmin(admin.ModelAdmin):
|
||||||
list_display = ("timestamp", "_main", "_state", "title", "level", "viewed")
|
list_display = ("timestamp", "_main", "_state", "title", "level", "viewed")
|
||||||
list_select_related = ("user", "user__profile__main_character", "user__profile__state")
|
list_select_related = ("user", "user__profile__main_character", "user__profile__state")
|
||||||
list_filter = (
|
list_filter = (
|
||||||
"level",
|
"level",
|
||||||
"timestamp",
|
"timestamp",
|
||||||
"user__profile__state",
|
"user__profile__state",
|
||||||
('user__profile__main_character', admin.RelatedOnlyFieldListFilter),
|
('user__profile__main_character', admin.RelatedOnlyFieldListFilter),
|
||||||
@ -20,12 +20,12 @@ class NotificationAdmin(admin.ModelAdmin):
|
|||||||
return obj.user.profile.main_character
|
return obj.user.profile.main_character
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return obj.user
|
return obj.user
|
||||||
|
|
||||||
_main.admin_order_field = "user__profile__main_character__character_name"
|
_main.admin_order_field = "user__profile__main_character__character_name"
|
||||||
|
|
||||||
def _state(self, obj):
|
def _state(self, obj):
|
||||||
return obj.user.profile.state
|
return obj.user.profile.state
|
||||||
|
|
||||||
_state.admin_order_field = "user__profile__state__name"
|
_state.admin_order_field = "user__profile__state__name"
|
||||||
|
|
||||||
def has_change_permission(self, request, obj=None):
|
def has_change_permission(self, request, obj=None):
|
||||||
|
@ -10,18 +10,18 @@ from ..models import Notification
|
|||||||
MODULE_PATH = 'allianceauth.notifications.handlers'
|
MODULE_PATH = 'allianceauth.notifications.handlers'
|
||||||
|
|
||||||
|
|
||||||
class TestHandler(TestCase):
|
class TestHandler(TestCase):
|
||||||
def test_do_nothing_if_permission_does_not_exist(self):
|
def test_do_nothing_if_permission_does_not_exist(self):
|
||||||
# given
|
# given
|
||||||
Permission.objects.get(codename="logging_notifications").delete()
|
Permission.objects.get(codename="logging_notifications").delete()
|
||||||
handler = NotificationHandler()
|
handler = NotificationHandler()
|
||||||
record = LogRecord(
|
record = LogRecord(
|
||||||
name="name",
|
name="name",
|
||||||
level=DEBUG,
|
level=DEBUG,
|
||||||
pathname="pathname",
|
pathname="pathname",
|
||||||
lineno=42,
|
lineno=42,
|
||||||
msg="msg",
|
msg="msg",
|
||||||
args=[],
|
args=[],
|
||||||
exc_info=None,
|
exc_info=None,
|
||||||
func="func"
|
func="func"
|
||||||
)
|
)
|
||||||
@ -29,28 +29,28 @@ class TestHandler(TestCase):
|
|||||||
handler.emit(record)
|
handler.emit(record)
|
||||||
# then
|
# then
|
||||||
self.assertEqual(Notification.objects.count(), 0)
|
self.assertEqual(Notification.objects.count(), 0)
|
||||||
|
|
||||||
def test_should_emit_message_to_users_with_permission_only(self):
|
def test_should_emit_message_to_users_with_permission_only(self):
|
||||||
# given
|
# given
|
||||||
AuthUtils.create_user('Lex Luthor')
|
AuthUtils.create_user('Lex Luthor')
|
||||||
user_permission = AuthUtils.create_user('Bruce Wayne')
|
user_permission = AuthUtils.create_user('Bruce Wayne')
|
||||||
user_permission = AuthUtils.add_permission_to_user_by_name(
|
user_permission = AuthUtils.add_permission_to_user_by_name(
|
||||||
"auth.logging_notifications", user_permission
|
"auth.logging_notifications", user_permission
|
||||||
)
|
)
|
||||||
group = Group.objects.create(name="Dummy Group")
|
group = Group.objects.create(name="Dummy Group")
|
||||||
perm = Permission.objects.get(codename="logging_notifications")
|
perm = Permission.objects.get(codename="logging_notifications")
|
||||||
group.permissions.add(perm)
|
group.permissions.add(perm)
|
||||||
user_group = AuthUtils.create_user('Peter Parker')
|
user_group = AuthUtils.create_user('Peter Parker')
|
||||||
user_group.groups.add(group)
|
user_group.groups.add(group)
|
||||||
user_superuser = User.objects.create_superuser("Clark Kent")
|
user_superuser = User.objects.create_superuser("Clark Kent")
|
||||||
handler = NotificationHandler()
|
handler = NotificationHandler()
|
||||||
record = LogRecord(
|
record = LogRecord(
|
||||||
name="name",
|
name="name",
|
||||||
level=DEBUG,
|
level=DEBUG,
|
||||||
pathname="pathname",
|
pathname="pathname",
|
||||||
lineno=42,
|
lineno=42,
|
||||||
msg="msg",
|
msg="msg",
|
||||||
args=[],
|
args=[],
|
||||||
exc_info=None,
|
exc_info=None,
|
||||||
func="func"
|
func="func"
|
||||||
)
|
)
|
||||||
|
@ -7,13 +7,13 @@ The notifications package has an API for sending notifications.
|
|||||||
Location: ``allianceauth.notifications``
|
Location: ``allianceauth.notifications``
|
||||||
|
|
||||||
.. automodule:: allianceauth.notifications.__init__
|
.. automodule:: allianceauth.notifications.__init__
|
||||||
:members: notify
|
:members: notify
|
||||||
|
|
||||||
models
|
models
|
||||||
===========
|
===========
|
||||||
|
|
||||||
.. autoclass:: allianceauth.notifications.models.Notification
|
.. autoclass:: allianceauth.notifications.models.Notification
|
||||||
:members: Level, mark_viewed, set_level
|
:members: Level, mark_viewed, set_level
|
||||||
|
|
||||||
managers
|
managers
|
||||||
===========
|
===========
|
||||||
|
Loading…
x
Reference in New Issue
Block a user