This repository was archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauth_hooks.py
54 lines (38 loc) · 1.57 KB
/
auth_hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from __future__ import unicode_literals
from services.hooks import ServicesHook, MenuItemHook
from alliance_auth import hooks
from .urls import urlpatterns
from .models import StandingsRequest
import logging
logger = logging.getLogger(__name__)
class StandingsRequestService(ServicesHook):
def __init__(self):
ServicesHook.__init__(self)
self.name = 'standingsrequests'
self.urlpatterns = urlpatterns
self.access_perm = 'standingsrequests.request_standings'
def delete_user(self, user, notify_user=False):
logger.debug('Deleting user {} standings'.format(user))
StandingsRequest.objects.delete_for_user(user)
def validate_user(self, user):
logger.debug('Validating user {} standings'.format(user))
if not self.service_active_for_user(user):
self.delete_user(user)
def service_active_for_user(self, user):
return user.has_perm(self.access_perm)
@hooks.register('services_hook')
def register_service():
return StandingsRequestService()
class StandingsRequestMenuItem(MenuItemHook):
def __init__(self):
MenuItemHook.__init__(self,
'Standings Requests',
'fa fa-plus-square fa-fw grayiconecolor',
'standings-requests:index')
def render(self, request):
if request.user.has_perm('standingsrequests.request_standings'):
return MenuItemHook.render(self, request)
return ''
@hooks.register('menu_util_hook')
def register_menu():
return StandingsRequestMenuItem()