forked from Github-Mirrors/canaille
Enable group deletion
This commit is contained in:
parent
aed6b18aa8
commit
9780fc9eed
8 changed files with 68 additions and 8 deletions
|
@ -44,6 +44,16 @@ def create_group(user):
|
|||
@moderator_needed()
|
||||
def group(user, groupname):
|
||||
group = Group.get(groupname) or abort(404)
|
||||
|
||||
if request.method == "GET" or request.form.get("action") == "edit":
|
||||
return edit_group(group)
|
||||
|
||||
if request.form.get("action") == "delete":
|
||||
return delete_group(group)
|
||||
|
||||
abort(400)
|
||||
|
||||
def edit_group(group):
|
||||
form = GroupForm(request.form or None, data={"name": group.name})
|
||||
form["name"].render_kw["disabled"] = "true"
|
||||
|
||||
|
@ -60,3 +70,7 @@ def group(user, groupname):
|
|||
members=group.get_members()
|
||||
)
|
||||
|
||||
def delete_group(group):
|
||||
flash(_("The group %(group)s has been sucessfully deleted", group=group.name), "success")
|
||||
group.delete()
|
||||
return redirect(url_for("groups.groups"))
|
||||
|
|
|
@ -48,9 +48,9 @@
|
|||
{% trans %}Users{% endtrans %}
|
||||
</a>
|
||||
<a class="item {% if menuitem == "groups" %}active{% endif %}"
|
||||
href="{{ url_for('groups.groups') }}">
|
||||
<i class="users icon"></i>
|
||||
{% trans %}Groups{% endtrans %}
|
||||
href="{{ url_for('groups.groups') }}">
|
||||
<i class="users cog icon"></i>
|
||||
{% trans %}Groups{% endtrans %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if user.admin %}
|
||||
|
|
|
@ -2,7 +2,29 @@
|
|||
{% import 'fomanticui.j2' as sui %}
|
||||
{% import 'flask.j2' as flask %}
|
||||
|
||||
{% block script %}
|
||||
<script src="/static/js/confirm.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if edited_group %}
|
||||
<div class="ui basic modal">
|
||||
<div class="ui icon header">
|
||||
<i class="trash alternate icon"></i>
|
||||
{% trans %}Group deletion{% endtrans %}
|
||||
</div>
|
||||
<div class="content">
|
||||
<p>
|
||||
{% trans %}Are you sure you want to delete this group? This action is unrevokable and all the data about this group will be removed.{% endtrans %}
|
||||
</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui inverted cancel button">{% trans %}Cancel{% endtrans %}</div>
|
||||
<div class="ui inverted red approve button">{% trans %}Delete{% endtrans %}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if edited_group %}
|
||||
<div class="ui segment">
|
||||
<h2 class="ui header">{% trans %}Members{% endtrans %}</h2>
|
||||
|
@ -46,13 +68,23 @@
|
|||
>
|
||||
{{ form.hidden_tag() if form.hidden_tag }}
|
||||
{{ sui.render_field(form.name) }}
|
||||
<button type="submit" class="ui right floated primary button">
|
||||
{% if not edited_group %}
|
||||
<p>
|
||||
{% trans %}Because group cannot be empty, you will be added to the group. You can remove you later by editing your profile when you will have added other members to the group.{% endtrans %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<button type="submit" class="ui right floated primary button" name="action" value="edit">
|
||||
{% if not edited_group %}
|
||||
{% trans %}Create group{% endtrans %}
|
||||
{% else %}
|
||||
{% trans %}Submit{% endtrans %}
|
||||
{% endif %}
|
||||
</button>
|
||||
{% if edited_group %}
|
||||
<button type="submit" class="ui right floated basic negative button confirm" name="action" value="delete" id="delete">
|
||||
{% trans %}Delete group{% endtrans %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
{% extends 'base.html' %}
|
||||
{% import 'flask.j2' as flask %}
|
||||
|
||||
{% block content %}
|
||||
{{ flask.messages() }}
|
||||
|
||||
<div class="ui segment">
|
||||
<a class="ui primary button" href="{{ url_for('groups.create_group') }}">{% trans %}Add a group{% endtrans %}</a>
|
||||
</div>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
{% import 'flask.j2' as flask %}
|
||||
|
||||
{% block script %}
|
||||
<script src="/static/js/profile.js"></script>
|
||||
<script src="/static/js/confirm.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% extends 'base.html' %}
|
||||
{% import 'flask.j2' as flask %}
|
||||
|
||||
{% block style %}
|
||||
<link href="/static/datatables/jquery.dataTables.min.css" rel="stylesheet">
|
||||
|
@ -12,6 +13,7 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ flask.messages() }}
|
||||
|
||||
<div class="ui segment">
|
||||
<a class="ui primary button" href="{{ url_for('account.profile_creation') }}">{% trans %}Add a user{% endtrans %}</a>
|
||||
|
|
|
@ -33,7 +33,7 @@ def test_set_groups(app, slapd_connection, user, foo_group, bar_group):
|
|||
assert user.dn in foo_dns
|
||||
assert user.dn not in bar_dns
|
||||
|
||||
def test_group_creation(testclient, slapd_connection, logged_moderator, foo_group):
|
||||
def test_moderator_can_create_edit_and_delete_group(testclient, slapd_connection, logged_moderator, foo_group):
|
||||
# The group does not exist
|
||||
res = testclient.get("/groups", status=200)
|
||||
with testclient.app.app_context():
|
||||
|
@ -59,7 +59,7 @@ def test_group_creation(testclient, slapd_connection, logged_moderator, foo_grou
|
|||
res = testclient.get("/groups/bar", status=200)
|
||||
res.form["name"] = "bar2"
|
||||
|
||||
res = res.form.submit(status=200)
|
||||
res = res.form.submit(name="action", value="edit", status=200)
|
||||
|
||||
with testclient.app.app_context():
|
||||
bar_group = Group.get("bar", conn=slapd_connection)
|
||||
|
@ -69,4 +69,13 @@ def test_group_creation(testclient, slapd_connection, logged_moderator, foo_grou
|
|||
for member in members:
|
||||
assert member.name in res.text
|
||||
|
||||
# TODO: Group is deleted
|
||||
# Group is deleted
|
||||
res = res.form.submit(name="action", value="delete", status=302).follow(status=200)
|
||||
with testclient.app.app_context():
|
||||
assert Group.get("bar", conn=slapd_connection) is None
|
||||
assert "The group bar has been sucessfully deleted" in res.text
|
||||
|
||||
def test_simple_user_cannot_view_or_edit_groups(testclient, slapd_connection, logged_user, foo_group):
|
||||
testclient.get("/groups", status=403)
|
||||
testclient.get("/groups/add", status=403)
|
||||
testclient.get("/groups/foo", status=403)
|
||||
|
|
Loading…
Reference in a new issue