Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
web: Add the list of users in the special pages section.
  • Loading branch information
ludovicchabant committed Mar 23, 2017
1 parent a9ad15b commit d509fd8
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
19 changes: 15 additions & 4 deletions wikked/auth.py
Expand Up @@ -98,9 +98,15 @@ def _updatePermissions(self, config):
'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 = []
Expand All @@ -110,9 +116,14 @@ def _updateUserInfos(self, config):
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)
Expand Down
23 changes: 23 additions & 0 deletions wikked/templates/special-users.html
@@ -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 %}

28 changes: 26 additions & 2 deletions wikked/views/admin.py
@@ -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


Expand Down Expand Up @@ -51,3 +53,25 @@ def logout():
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)
19 changes: 10 additions & 9 deletions wikked/views/special.py
@@ -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,
Expand Down Expand Up @@ -27,44 +27,44 @@
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",
"template": "special-orphans.html"
},
'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",
"template": "special-broken-redirects.html"
},
'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",
"template": "special-dead-ends.html"
},
'users': {
"title": "All Users",
"url": "/special/users",
"view": 'special_users',
"description": "A list of all registered users.",
"section": "users",
}
Expand All @@ -81,7 +81,9 @@ def special_pages_dashboard():
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)

Expand Down Expand Up @@ -134,4 +136,3 @@ def special_list_double_redirects():
def special_list_dead_ends():
return call_api('dead-ends', get_dead_ends,
raw_url='/api/dead-ends')

0 comments on commit d509fd8

Please sign in to comment.