mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 01:14:21 +01:00
adding notification after an action is performed
This commit is contained in:
parent
bb8aa3f43c
commit
2451b2efdd
@ -396,6 +396,8 @@ class LdapCherry(object):
|
|||||||
severity=logging.DEBUG
|
severity=logging.DEBUG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.notifications = {}
|
||||||
|
|
||||||
self.attributes = Attributes(self.attributes_file)
|
self.attributes = Attributes(self.attributes_file)
|
||||||
|
|
||||||
cherrypy.log.error(
|
cherrypy.log.error(
|
||||||
@ -424,6 +426,27 @@ class LdapCherry(object):
|
|||||||
)
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
def _add_notification(self, message):
|
||||||
|
""" add a notification in the notification queue of a user
|
||||||
|
"""
|
||||||
|
sess = cherrypy.session
|
||||||
|
username = sess.get(SESSION_KEY, None)
|
||||||
|
if username is not self.notifications:
|
||||||
|
self.notifications[username] = []
|
||||||
|
self.notifications[username].append(message)
|
||||||
|
|
||||||
|
def _empty_notification(self):
|
||||||
|
""" empty and return list of message notification
|
||||||
|
"""
|
||||||
|
sess = cherrypy.session
|
||||||
|
username = sess.get(SESSION_KEY, None)
|
||||||
|
if username in self.notifications:
|
||||||
|
ret = self.notifications[username]
|
||||||
|
else:
|
||||||
|
ret = []
|
||||||
|
self.notifications[username] = []
|
||||||
|
return ret
|
||||||
|
|
||||||
def _merge_user_attrs(self, attrs_backend, attrs_out, backend_name):
|
def _merge_user_attrs(self, attrs_backend, attrs_out, backend_name):
|
||||||
""" merge attributes from one backend search to the attributes dict
|
""" merge attributes from one backend search to the attributes dict
|
||||||
output
|
output
|
||||||
@ -853,7 +876,10 @@ class LdapCherry(object):
|
|||||||
"""
|
"""
|
||||||
self._check_auth(must_admin=False)
|
self._check_auth(must_admin=False)
|
||||||
is_admin = self._check_admin()
|
is_admin = self._check_admin()
|
||||||
return self.temp['index.tmpl'].render(is_admin=is_admin)
|
return self.temp['index.tmpl'].render(
|
||||||
|
is_admin=is_admin,
|
||||||
|
notifications=self._empty_notification(),
|
||||||
|
)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@exception_decorator
|
@exception_decorator
|
||||||
@ -871,6 +897,7 @@ class LdapCherry(object):
|
|||||||
attrs_list=attrs_list,
|
attrs_list=attrs_list,
|
||||||
is_admin=is_admin,
|
is_admin=is_admin,
|
||||||
custom_js=self.custom_js,
|
custom_js=self.custom_js,
|
||||||
|
notifications=self._empty_notification(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@ -907,6 +934,7 @@ class LdapCherry(object):
|
|||||||
attrs_list=attrs_list,
|
attrs_list=attrs_list,
|
||||||
is_admin=is_admin,
|
is_admin=is_admin,
|
||||||
custom_js=self.custom_js,
|
custom_js=self.custom_js,
|
||||||
|
notifications=self._empty_notification(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@ -917,13 +945,11 @@ class LdapCherry(object):
|
|||||||
is_admin = self._check_admin()
|
is_admin = self._check_admin()
|
||||||
|
|
||||||
if cherrypy.request.method.upper() == 'POST':
|
if cherrypy.request.method.upper() == 'POST':
|
||||||
notification = "<script type=\"text/javascript\">" \
|
|
||||||
"$.notify('User Added')" \
|
|
||||||
"</script>"
|
|
||||||
params = self._parse_params(params)
|
params = self._parse_params(params)
|
||||||
self._adduser(params)
|
self._adduser(params)
|
||||||
else:
|
self._add_notification(
|
||||||
notification = ''
|
"User added"
|
||||||
|
)
|
||||||
|
|
||||||
graph = {}
|
graph = {}
|
||||||
for r in self.roles.graph:
|
for r in self.roles.graph:
|
||||||
@ -952,8 +978,8 @@ class LdapCherry(object):
|
|||||||
form=form,
|
form=form,
|
||||||
roles=roles,
|
roles=roles,
|
||||||
is_admin=is_admin,
|
is_admin=is_admin,
|
||||||
notification=notification,
|
|
||||||
custom_js=self.custom_js,
|
custom_js=self.custom_js,
|
||||||
|
notifications=self._empty_notification(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@ -977,18 +1003,16 @@ class LdapCherry(object):
|
|||||||
is_admin = self._check_admin()
|
is_admin = self._check_admin()
|
||||||
|
|
||||||
if cherrypy.request.method.upper() == 'POST':
|
if cherrypy.request.method.upper() == 'POST':
|
||||||
notification = "<script type=\"text/javascript\">" \
|
|
||||||
"$.notify('User Modify')" \
|
|
||||||
"</script>"
|
|
||||||
params = self._parse_params(params)
|
params = self._parse_params(params)
|
||||||
self._modify(params)
|
self._modify(params)
|
||||||
|
self._add_notification(
|
||||||
|
"User modified"
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
referer = cherrypy.request.headers['Referer']
|
referer = cherrypy.request.headers['Referer']
|
||||||
except:
|
except:
|
||||||
referer = '/'
|
referer = '/'
|
||||||
raise cherrypy.HTTPRedirect(referer)
|
raise cherrypy.HTTPRedirect(referer)
|
||||||
else:
|
|
||||||
notification = ''
|
|
||||||
|
|
||||||
graph = {}
|
graph = {}
|
||||||
for r in self.roles.graph:
|
for r in self.roles.graph:
|
||||||
@ -1030,10 +1054,10 @@ class LdapCherry(object):
|
|||||||
form=form,
|
form=form,
|
||||||
roles=roles,
|
roles=roles,
|
||||||
is_admin=is_admin,
|
is_admin=is_admin,
|
||||||
notification=notification,
|
|
||||||
standalone_groups=user_lonely_groups,
|
standalone_groups=user_lonely_groups,
|
||||||
backends_display_names=self.backends_display_names,
|
backends_display_names=self.backends_display_names,
|
||||||
custom_js=self.custom_js,
|
custom_js=self.custom_js,
|
||||||
|
notifications=self._empty_notification(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@ -1053,6 +1077,9 @@ class LdapCherry(object):
|
|||||||
if cherrypy.request.method.upper() == 'POST':
|
if cherrypy.request.method.upper() == 'POST':
|
||||||
params = self._parse_params(params)
|
params = self._parse_params(params)
|
||||||
self._selfmodify(params)
|
self._selfmodify(params)
|
||||||
|
self._add_notification(
|
||||||
|
"Self modification done"
|
||||||
|
)
|
||||||
user_attrs = self._get_user(user)
|
user_attrs = self._get_user(user)
|
||||||
if user_attrs == {}:
|
if user_attrs == {}:
|
||||||
return self.temp['error.tmpl'].render(
|
return self.temp['error.tmpl'].render(
|
||||||
@ -1068,5 +1095,6 @@ class LdapCherry(object):
|
|||||||
)
|
)
|
||||||
return self.temp['selfmodify.tmpl'].render(
|
return self.temp['selfmodify.tmpl'].render(
|
||||||
form=form,
|
form=form,
|
||||||
is_admin=is_admin
|
is_admin=is_admin,
|
||||||
|
notifications=self._empty_notification(),
|
||||||
)
|
)
|
||||||
|
@ -56,6 +56,11 @@
|
|||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
% if notifications:
|
||||||
|
% for notif in notifications:
|
||||||
|
<script type="text/javascript">$.notify('${notif}')</script>
|
||||||
|
% endfor
|
||||||
|
% endif
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<%block name="navbar"/>
|
<%block name="navbar"/>
|
||||||
<%block name="core" />
|
<%block name="core" />
|
||||||
|
Loading…
Reference in New Issue
Block a user