diff --git a/progit/templates/login/admin_groups.html b/progit/templates/login/admin_groups.html new file mode 100644 index 0000000..cd6a31d --- /dev/null +++ b/progit/templates/login/admin_groups.html @@ -0,0 +1,33 @@ +{% extends "master.html" %} +{% from "_formhelper.html" import render_field_in_row %} + +{% block title %}Groups{% endblock %} +{%block tag %}admin{% endblock %} + +{% block content %} +

Progit Groups

+ +
+

Create a new group

+
+ + {{ form.csrf_token }} + +
+
+ +{% if groups %} + +{% else %} +

No group found

+{% endif %} + +{% endblock %} diff --git a/progit/ui/login.py b/progit/ui/login.py index b09451d..ccd6522 100644 --- a/progit/ui/login.py +++ b/progit/ui/login.py @@ -20,6 +20,7 @@ import progit.login_forms as forms import progit.lib import progit.notify from progit import APP, SESSION, is_admin +from progit.ui.admin import admin_required import progit.model as model @@ -248,6 +249,42 @@ def reset_password(token): # +# Admin endpoint specific to local login +# + +@APP.route('/admin/groups', methods=['GET', 'POST']) +@admin_required +def admin_groups(): + """ List of the groups present in the system + """ + # Add new group if asked + form = forms.NewGroupForm() + if form.validate_on_submit(): + + grp = model.ProgitGroup() + form.populate_obj(obj=grp) + SESSION.add(grp) + try: + SESSION.flush() + except SQLAlchemyError as err: + SESSION.rollback() + flask.flash('Could not create group.') + APP.logger.debug('Could not create group.') + APP.logger.exception(err) + + flask.flash('Group `%s` created.' % grp.group_name) + SESSION.commit() + + groups = progit.lib.get_groups(SESSION) + + return flask.render_template( + 'login/admin_groups.html', + groups=groups, + form=form, + ) + + +# # Methods specific to local login. #