You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2016/01/08 11:43:13 UTC
[3/9] allura git commit: [#8024] ticket:871 Added SiteNotifications
in admin
[#8024] ticket:871 Added SiteNotifications in admin
* Add new controller for showing SiteNotifications, add link in admin menu,
* add tests
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/5c25043f
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/5c25043f
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/5c25043f
Branch: refs/heads/ib/8024a
Commit: 5c25043f8b093cfca5b3ba67a83d3f30ba25dd2d
Parents: dfa249a
Author: Denis Kotov <de...@gmail.com>
Authored: Wed Dec 9 02:13:05 2015 +0200
Committer: Denis Kotov <de...@gmail.com>
Committed: Thu Jan 7 21:41:20 2016 +0200
----------------------------------------------------------------------
Allura/allura/controllers/site_admin.py | 37 +++++++
.../site_admin_site_notifications_list.html | 108 +++++++++++++++++++
.../allura/tests/functional/test_site_admin.py | 18 ++++
3 files changed, 163 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/5c25043f/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index b6c0223..550f5af 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -47,6 +47,7 @@ from allura.scripts.delete_projects import DeleteProjects
import allura
from urlparse import urlparse
+from webhelpers import paginate
log = logging.getLogger(__name__)
@@ -66,6 +67,7 @@ class SiteAdminController(object):
c.site_admin_sidebar_menu = self.sidebar_menu()
self.user = AdminUserDetailsController()
self.delete_projects = DeleteProjectsController()
+ self.site_notifications = SiteNotificationController()
def _check_security(self):
with h.push_context(config.get('site_admin_project', 'allura'),
@@ -92,6 +94,7 @@ class SiteAdminController(object):
SitemapEntry('Search Projects', base_url + 'search_projects', ui_icon=g.icons['search']),
SitemapEntry('Delete Projects', base_url + 'delete_projects', ui_icon=g.icons['delete']),
SitemapEntry('Search Users', base_url + 'search_users', ui_icon=g.icons['search']),
+ SitemapEntry('Site Notifications', base_url + 'site_notifications', ui_icon=g.icons['admin']),
]
for ep_name in sorted(g.entry_points['site_admin']):
g.entry_points['site_admin'][ep_name]().update_sidebar_menu(links)
@@ -417,6 +420,40 @@ class DeleteProjectsController(object):
redirect('.')
+class SiteNotificationController(object):
+
+ def _check_security(self):
+ with h.push_context(config.get('site_admin_project', 'allura'),
+ neighborhood=config.get('site_admin_project_nbhd', 'Projects')):
+ require_access(c.project, 'admin')
+
+ @expose('jinja:allura:templates/site_admin_site_notifications_list.html')
+ @with_trailing_slash
+ def index(self, page=0, limit=25):
+ c.page_list = W.page_list
+ c.page_size = W.page_size
+
+ try:
+ page_url = int(page)
+ except ValueError:
+ page_url = 0
+ try:
+ limit = int(limit)
+ except ValueError:
+ limit = 25
+
+ query = M.notification.SiteNotification.query.find().sort('_id', -1)
+ count = query.count()
+ notifications = paginate.Page(query.all(), page_url+1, limit)
+
+ return {
+ 'notifications': notifications,
+ 'count': count,
+ 'page_url': page_url,
+ 'limit': limit
+ }
+
+
class TaskManagerController(object):
def _check_security(self):
http://git-wip-us.apache.org/repos/asf/allura/blob/5c25043f/Allura/allura/templates/site_admin_site_notifications_list.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_site_notifications_list.html b/Allura/allura/templates/site_admin_site_notifications_list.html
new file mode 100644
index 0000000..7ab0ad7
--- /dev/null
+++ b/Allura/allura/templates/site_admin_site_notifications_list.html
@@ -0,0 +1,108 @@
+{#-
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-#}
+{% set page = "site_notifications" %}
+{% set hide_left_bar = True %}
+
+{% extends 'allura:templates/site_admin.html' %}
+{% block content %}
+ {{c.page_size.display(limit=limit, page=page_url, count=count)}}
+ <div class="grid-24"><a href="">Create a new notification</a></div>
+ <table id="site_notifications">
+ <thead>
+ <tr>
+ <th>Active</th>
+ <th>Impressions</th>
+ <th>Content</th>
+ <th>User Role</th>
+ <th>Page Regex</th>
+ <th>Page Type</th>
+ <th></th>
+ </tr>
+ </thead>
+ {% for note in notifications %}
+ <tr>
+ <td><small>{{ note.active }}</small></td>
+ <td><small>{{ note.impressions}}</small></td>
+ <td><small class="tooltip" title="{{ note.content }}">{{ note.content|truncate(50) }}</small></td>
+ <td><small>{{ note.user_role if note.user_role}}</small></td>
+ <td><small class="tooltip" title="{{ note.page_regex }}">{{ note.page_regex|truncate(20) if note.page_regex}}</small></td>
+ <td><small class="tooltip" title="{{ note.page_tool_type }}">{{ note.page_tool_type|truncate(20) if note.page_tool_type}}</small></td>
+ <td>
+ <a href="">Edit</a><br>
+ <a href="">Delete</a>
+ </td>
+ </tr>
+ {% endfor %}
+ </table>
+ <div class="grid-23">
+ {{c.page_list.display(limit=limit, page=page_url, count=count)}}
+ </div>
+{% endblock %}
+
+{% block extra_css %}
+<style type="text/css">
+ .paging {
+ float: right;
+ margin: 1em;
+ }
+ .pad table {
+ width: 915px;
+ }
+ td {
+ max-width: 200px;
+ }
+ th.header {
+ background-image: url("{{g.forge_static('images/bg.gif')}}");
+ cursor: pointer;
+ font-weight: bold;
+ background-repeat: no-repeat;
+ background-position: center left;
+ padding-left: 20px;
+ }
+ th.headerSortUp {
+ background-image: url("{{g.forge_static('images/asc.gif')}}");
+ background-color: #6bb3fd;
+ }
+ th.headerSortDown {
+ background-image: url("{{g.forge_static('images/desc.gif')}}");
+ background-color: #6bb3fd;
+ }
+</style>
+{% endblock %}
+
+{% block extra_js %}
+ <script>
+ $(document).ready(function() {
+ $(".tooltip").tooltipster({
+ animation: 'fade',
+ delay: 200,
+ theme: 'tooltipster-light',
+ trigger: 'hover',
+ iconCloning: false
+ }).focus(function () {
+ $(this).tooltipster('show');
+ }).blur(function () {
+ $(this).tooltipster('hide');
+ });
+ });
+ </script>
+{% endblock %}
+
+
+
http://git-wip-us.apache.org/repos/asf/allura/blob/5c25043f/Allura/allura/tests/functional/test_site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_site_admin.py b/Allura/allura/tests/functional/test_site_admin.py
index fd81965..a0c5371 100644
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -169,6 +169,24 @@ class TestSiteAdmin(TestController):
task_name='allura.tests.functional.test_site_admin.test_task'))
assert json.loads(r.body)['doc'] == 'test_task doc string'
+ def test_site_notifications_access(self):
+ self.app.get('/nf/admin/site_notifications', extra_environ=dict(
+ username='test_user'), status=403)
+ r = self.app.get('/nf/admin/site_notifications', extra_environ=dict(
+ username='*anonymous'), status=302).follow()
+ assert 'Login' in r
+
+ def test_site_notifications(self):
+ r = self.app.get('/nf/admin/site_notifications/', extra_environ=dict(
+ username='root'))
+ headers = r.html.find('table').findAll('th')
+ assert headers[0].contents[0] == 'Active'
+ assert headers[1].contents[0] == 'Impressions'
+ assert headers[2].contents[0] == 'Content'
+ assert headers[3].contents[0] == 'User Role'
+ assert headers[4].contents[0] == 'Page Regex'
+ assert headers[5].contents[0] == 'Page Type'
+
class TestProjectsSearch(TestController):