summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-07-04 15:29:49 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-07-04 15:34:03 +0200
commit9e386e5454ca6108e5c45664ca24aab79f41af48 (patch)
treedaa2637021c13f434ab62d7bbb1ec612480d5a5f
parentc068bd21448c2e202720a9daf2923a375c96370d (diff)
Add "Delete Repository"
In "Repositories" view, users select a repository from the list on the left and press "Delete repository".
-rw-r--r--ogcp/forms/action_forms.py5
-rw-r--r--ogcp/templates/actions/delete_repository.html23
-rw-r--r--ogcp/templates/repositories.html2
-rw-r--r--ogcp/views.py35
4 files changed, 64 insertions, 1 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index b1da58b..951ea06 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -192,3 +192,8 @@ class RepositoryForm(FlaskForm):
ip = StringField(label=_l('IP'),
validators=[InputRequired()])
submit = SubmitField(label=_l('Submit'))
+
+class DeleteRepositoryForm(FlaskForm):
+ repository = SelectField(label=_l('Repository'),
+ validators=[InputRequired()])
+ submit = SubmitField(label=_l('Submit'))
diff --git a/ogcp/templates/actions/delete_repository.html b/ogcp/templates/actions/delete_repository.html
new file mode 100644
index 0000000..82177a3
--- /dev/null
+++ b/ogcp/templates/actions/delete_repository.html
@@ -0,0 +1,23 @@
+{% extends 'repositories.html' %}
+{% import "bootstrap/wtf.html" as wtf %}
+
+{% set sidebar_state = 'disabled' %}
+{% set btn_back = true %}
+
+{% block content %}
+
+{{ args }}
+
+<h1 class="m-5">
+ {{ _('Delete repository %(repo_name)s', repo_name=repo_name) }}
+</h1>
+
+{{ wtf.quick_form(form,
+ action=url_for('repository_delete_post'),
+ method='post',
+ button_map={'submit': 'primary'},
+ extra_classes="mx-5") }}
+
+{% endblock %}
+
+
diff --git a/ogcp/templates/repositories.html b/ogcp/templates/repositories.html
index 2333a88..7aa2d06 100644
--- a/ogcp/templates/repositories.html
+++ b/ogcp/templates/repositories.html
@@ -26,6 +26,8 @@
{% block commands %}
<input class="btn btn-light {% block nav_repository_add %}{% endblock %}" type="submit" value="{{ _('Add repository') }}"
form="repositoriesForm" formaction="{{ url_for('repository_add_get') }}" formmethod="get">
+ <input class="btn btn-light {% block nav_repository_delete %}{% endblock %}" type="submit" value="{{ _('Delete repository') }}"
+ form="repositoriesForm" formaction="{{ url_for('repository_delete_get') }}" formmethod="get">
{% if btn_back %}
<button class="btn btn-danger ml-3" type="button" id="backButton" onclick="history.back()">
{{ _("Back") }}
diff --git a/ogcp/views.py b/ogcp/views.py
index c391302..84bcc56 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -13,7 +13,7 @@ from ogcp.forms.action_forms import (
SessionForm, ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm,
RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm, OgliveForm,
GenericForm, SelectClientForm, ImageUpdateForm, ImportClientsForm,
- RepositoryForm
+ RepositoryForm, DeleteRepositoryForm
)
from flask_login import (
current_user, LoginManager,
@@ -1274,6 +1274,39 @@ def repository_add_post():
return redirect(url_for("repositories"))
+@app.route('/repositories/delete', methods=['GET'])
+@login_required
+def repository_delete_get():
+ form = GenericForm()
+ repositories = get_repositories()
+ selected_repo = [(name, repo_id) for name, repo_id in
+ request.args.to_dict().items() if name != "csrf_token"]
+ if not validate_elements(selected_repo, max_len=1):
+ flash(_('Please select one repository to delete'), category='error')
+ return redirect(url_for('repositories'))
+ repo_name, repo_id = selected_repo[0]
+ form.ids.data = repo_id
+ return render_template('actions/delete_repository.html', form=form,
+ repo_name=repo_name, repositories=repositories)
+
+
+@app.route('/repositories/delete', methods=['POST'])
+@login_required
+def repository_delete_post():
+ form = GenericForm(request.form)
+ ids = form.ids.data.split(' ')
+ if not validate_elements(ids, max_len=1):
+ return redirect(url_for('repositories'))
+ repo_id = ids.pop()
+ payload = {'id': repo_id}
+ r = g.server.post('/repository/delete', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('OgServer: error deleting repository'), category='error')
+ else:
+ flash(_('Repository deleted successfully'), category='info')
+ return redirect(url_for('repositories'))
+
+
@app.route('/users/', methods=['GET'])
@login_required
def users():