mirror of https://github.com/logos-co/open-law.git
issue When a new contributor is added, stay in user permissions tab instead of jumping back to book settings #122
This commit is contained in:
parent
ebaf525068
commit
66ba559216
|
@ -24,7 +24,7 @@
|
|||
<ul class="flex flex-wrap -mb-px text-sm font-medium text-center" id="myTab" data-tabs-toggle="#myTabContent" role="tablist">
|
||||
<li class="mr-2" role="presentation">
|
||||
<!-- prettier-ignore -->
|
||||
<button class="flex items-center space-x-2 p-4 rounded-t-lg" id="settings-tab" data-tabs-target="#settings" type="button" role="tab" aria-controls="settings" aria-selected="false">
|
||||
<button class="flex items-center space-x-2 p-4 rounded-t-lg" id="settings-tab" data-tabs-target="#settings" type="button" role="tab" aria-controls="settings" {% if selected_tab == 'book_settings' %} aria-selected="true" {% endif %}>
|
||||
<!-- prettier-ignore -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z" /> <path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /> </svg>
|
||||
<span>Book settings</span>
|
||||
|
@ -33,7 +33,7 @@
|
|||
{% if book.user_id == current_user.id %}
|
||||
<li class="mr-2" role="presentation">
|
||||
<!-- prettier-ignore -->
|
||||
<button class="flex items-center space-x-2 p-4 rounded-t-lg hover:text-gray-600 dark:hover:text-gray-300" id="permissions-tab" data-tabs-target="#permissions" type="button" role="tab" aria-controls="permissions" aria-selected="false">
|
||||
<button class="flex items-center space-x-2 p-4 rounded-t-lg hover:text-gray-600 dark:hover:text-gray-300" id="permissions-tab" data-tabs-target="#permissions" type="button" role="tab" aria-controls="permissions" {% if selected_tab == 'user_permissions' %} aria-selected="true" {% endif %}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M6 13.5V3.75m0 9.75a1.5 1.5 0 010 3m0-3a1.5 1.5 0 000 3m0 3.75V16.5m12-3V3.75m0 9.75a1.5 1.5 0 010 3m0-3a1.5 1.5 0 000 3m0 3.75V16.5m-6-9V3.75m0 3.75a1.5 1.5 0 010 3m0-3a1.5 1.5 0 000 3m0 9.75V10.5" /> </svg>
|
||||
<span>User permissions</span>
|
||||
</button>
|
||||
|
|
|
@ -3,6 +3,7 @@ from flask import (
|
|||
flash,
|
||||
redirect,
|
||||
url_for,
|
||||
request,
|
||||
)
|
||||
from flask_login import login_required
|
||||
|
||||
|
@ -25,9 +26,13 @@ from .bp import bp
|
|||
@login_required
|
||||
def settings(book_id: int):
|
||||
book: m.Book = db.session.get(m.Book, book_id)
|
||||
selected_tab = request.args.get("selected_tab", "book_settings")
|
||||
|
||||
return render_template(
|
||||
"book/settings.html", book=book, roles=m.BookContributor.Roles
|
||||
"book/settings.html",
|
||||
book=book,
|
||||
selected_tab=selected_tab,
|
||||
roles=m.BookContributor.Roles,
|
||||
)
|
||||
|
||||
|
||||
|
@ -41,7 +46,7 @@ def settings(book_id: int):
|
|||
@login_required
|
||||
def add_contributor(book_id: int):
|
||||
form = f.AddContributorForm()
|
||||
|
||||
selected_tab = "user_permissions"
|
||||
if form.validate_on_submit():
|
||||
user_id = form.user_id.data
|
||||
book_contributor = m.BookContributor.query.filter_by(
|
||||
|
@ -50,7 +55,9 @@ def add_contributor(book_id: int):
|
|||
if book_contributor:
|
||||
log(log.INFO, "Contributor: [%s] already exists", book_contributor)
|
||||
flash("Already exists!", "danger")
|
||||
return redirect(url_for("book.settings", book_id=book_id))
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
|
||||
role = m.BookContributor.Roles(int(form.role.data))
|
||||
contributor = m.BookContributor(user_id=user_id, book_id=book_id, role=role)
|
||||
|
@ -70,14 +77,18 @@ def add_contributor(book_id: int):
|
|||
m.UserAccessGroups(user_id=user_id, access_group_id=group.id).save()
|
||||
|
||||
flash("Contributor was added!", "success")
|
||||
return redirect(url_for("book.settings", book_id=book_id))
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
else:
|
||||
log(log.ERROR, "Book create errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
return redirect(url_for("book.settings", book_id=book_id))
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/<int:book_id>/delete_contributor", methods=["POST"])
|
||||
|
@ -90,6 +101,7 @@ def add_contributor(book_id: int):
|
|||
@login_required
|
||||
def delete_contributor(book_id: int):
|
||||
form = f.DeleteContributorForm()
|
||||
selected_tab = "user_permissions"
|
||||
|
||||
if form.validate_on_submit():
|
||||
user_id = int(form.user_id.data)
|
||||
|
@ -104,7 +116,9 @@ def delete_contributor(book_id: int):
|
|||
book_id,
|
||||
)
|
||||
flash("Does not exists!", "success")
|
||||
return redirect(url_for("book.settings", book_id=book_id))
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
|
||||
book: m.Book = db.session.get(m.Book, book_id)
|
||||
user: m.User = db.session.get(m.User, user_id)
|
||||
|
@ -128,14 +142,18 @@ def delete_contributor(book_id: int):
|
|||
db.session.commit()
|
||||
|
||||
flash("Success!", "success")
|
||||
return redirect(url_for("book.settings", book_id=book_id))
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
else:
|
||||
log(log.ERROR, "Delete contributor errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
return redirect(url_for("book.settings", book_id=book_id))
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/<int:book_id>/edit_contributor_role", methods=["POST"])
|
||||
|
@ -148,6 +166,7 @@ def delete_contributor(book_id: int):
|
|||
@login_required
|
||||
def edit_contributor_role(book_id: int):
|
||||
form = f.EditContributorRoleForm()
|
||||
selected_tab = "user_permissions"
|
||||
|
||||
if form.validate_on_submit():
|
||||
book_contributor: m.BookContributor = m.BookContributor.query.filter_by(
|
||||
|
@ -161,7 +180,9 @@ def edit_contributor_role(book_id: int):
|
|||
book_id,
|
||||
)
|
||||
flash("Does not exists!", "success")
|
||||
return redirect(url_for("book.settings", book_id=book_id))
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
|
||||
role = m.BookContributor.Roles(int(form.role.data))
|
||||
|
||||
|
@ -193,11 +214,15 @@ def edit_contributor_role(book_id: int):
|
|||
book_contributor.save()
|
||||
|
||||
flash("Success!", "success")
|
||||
return redirect(url_for("book.settings", book_id=book_id))
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
else:
|
||||
log(log.ERROR, "Edit contributor errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
return redirect(url_for("book.settings", book_id=book_id))
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue