Mercurial > wikked
changeset 419:f4629148e72e
web: Add the list of users in the special pages section.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 22 Mar 2017 18:35:31 -0700 |
parents | f8410cd802ad |
children | 596e9ca2da86 |
files | wikked/auth.py wikked/templates/special-users.html wikked/views/admin.py wikked/views/special.py |
diffstat | 4 files changed, 74 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/wikked/auth.py Wed Mar 22 18:35:04 2017 -0700 +++ b/wikked/auth.py Wed Mar 22 18:35:31 2017 -0700 @@ -98,9 +98,15 @@ 'writers': None } if config.has_option('permissions', 'readers'): - self._permissions['readers'] = [p.strip() for p in re.split(r'[ ,;]', config.get('permissions', 'readers'))] + self._permissions['readers'] = [ + p.strip() + for p in re.split(r'[ ,;]', + config.get('permissions', 'readers'))] if config.has_option('permissions', 'writers'): - self._permissions['writers'] = [p.strip() for p in re.split(r'[ ,;]', config.get('permissions', 'writers'))] + self._permissions['writers'] = [ + p.strip() + for p in re.split( + r'[ ,;]', config.get('permissions', 'writers'))] def _updateUserInfos(self, config): self._users = [] @@ -110,9 +116,14 @@ groups = config.items('groups') for user in config.items('users'): - user_info = {'username': user[0], 'password': user[1], 'groups': []} + user_info = { + 'username': user[0], + 'password': user[1], + 'groups': []} for group in groups: - users_in_group = [u.strip() for u in re.split(r'[ ,;]', group[1])] + users_in_group = [ + u.strip() + for u in re.split(r'[ ,;]', group[1])] if user[0] in users_in_group: user_info['groups'].append(group[0]) self._users.append(user_info)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wikked/templates/special-users.html Wed Mar 22 18:35:31 2017 -0700 @@ -0,0 +1,23 @@ +{% extends 'index.html' %} +{% block nav %}{% include 'special-nav.html' %}{% endblock %} +{% block content %} +<article> + <header> + <h1>{{title}}</h1> + </header> + <section> + <p>Here are the users on this wiki:</p> + {%if users%} + <ul> + {%for u in users%} + <li><a href="{{u.url}}">{{u.username}}</a></li> + {%endfor%} + </ul> + {%else%} + <p>This wiki has no users! You can edit its configuration file + to add some.</p> + {%endif%} + </section> +</article> +{% endblock %} +
--- a/wikked/views/admin.py Wed Mar 22 18:35:04 2017 -0700 +++ b/wikked/views/admin.py Wed Mar 22 18:35:31 2017 -0700 @@ -1,6 +1,8 @@ -from flask import request, redirect, render_template +import urllib.parse +from flask import url_for, request, redirect, render_template from flask.ext.login import login_user, logout_user, current_user -from wikked.views import add_auth_data, add_navigation_data +from wikked.views import ( + add_auth_data, add_navigation_data, requires_reader_auth) from wikked.web import app, get_wiki @@ -51,3 +53,25 @@ logout_user() return redirect('/') + +@app.route('/special/users') +@requires_reader_auth +def special_users(): + wiki = get_wiki() + + users = [] + for user in wiki.auth.getUsers(): + user_url = 'user:/%s' % urllib.parse.quote(user.username.title()) + users.append({ + 'username': user.username, + 'url': url_for('read', url=user_url), + 'groups': list(user.groups) + }) + + data = { + 'title': "Users", + 'users': users} + add_auth_data(data) + add_navigation_data(None, data) + + return render_template('special-users.html', **data)
--- a/wikked/views/special.py Wed Mar 22 18:35:04 2017 -0700 +++ b/wikked/views/special.py Wed Mar 22 18:35:31 2017 -0700 @@ -1,4 +1,4 @@ -from flask import render_template +from flask import url_for, render_template from flask.ext.login import current_user from wikked.views import ( requires_reader_auth, @@ -27,13 +27,13 @@ special_pages = { 'changes': { "title": "Recent Changes", - "url": "/special/history", + "view": 'site_history', "description": "See all changes in the wiki.", "section": "wiki", }, 'orphans': { "title": "Orphaned Pages", - "url": "/special/list/orphans", + "view": 'special_list_orphans', "description": ("Lists pages in the wiki that have no " "links to them."), "section": "lists", @@ -41,7 +41,7 @@ }, 'broken-redirects': { "title": "Broken Redirects", - "url": "/special/list/broken-redirects", + "view": 'special_list_broken_redirects', "description": ("Lists pages that redirect to a missing " "page."), "section": "lists", @@ -49,14 +49,14 @@ }, 'double-redirects': { "title": "Double Redirects", - "url": "/special/list/double-redirects", + "view": 'special_list_broken_redirects', "description": "Lists pages that redirect twice or more.", "section": "lists", "template": "special-double-redirects.html" }, 'dead-ends': { "title": "Dead-End Pages", - "url": "/special/list/dead-ends", + "view": 'special_list_dead_ends', "description": ("Lists pages that don't have any " "outgoing links."), "section": "lists", @@ -64,7 +64,7 @@ }, 'users': { "title": "All Users", - "url": "/special/users", + "view": 'special_users', "description": "A list of all registered users.", "section": "users", } @@ -81,7 +81,9 @@ sec = {'title': info['title'], 'pages': []} for k, p in special_pages.items(): if p['section'] == info['name']: - sec['pages'].append(p) + pdata = p.copy() + pdata['url'] = url_for(pdata['view']) + sec['pages'].append(pdata) sec['pages'] = sorted(sec['pages'], key=lambda i: i['title']) data['sections'].append(sec) @@ -134,4 +136,3 @@ def special_list_dead_ends(): return call_api('dead-ends', get_dead_ends, raw_url='/api/dead-ends') -