Merge pull request #143 from Simple2B/svyat/fix/bugs

Svyat/fix/bugs
This commit is contained in:
Svyatoslav Artymovych 2023-06-16 10:09:54 +03:00 committed by GitHub
commit 18e66a8f01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 11 deletions

View File

@ -1,4 +1,4 @@
from app import models as m
from app import models as m, db
from app.logger import log
@ -31,3 +31,46 @@ def copy_access_groups(
m.SectionAccessGroups(
section_id=copy_to.id, access_group_id=access_group.id
).save()
def recursive_copy_access_groups(
copy_from: m.Book or m.Collection or m.Interpretation or m.Section, copy_to
):
current_access_groups = None
match type(copy_to):
case m.Book:
current_access_groups = m.BookAccessGroups.query.filter_by(
book_id=copy_to.id
).all()
case m.Collection:
current_access_groups = m.CollectionAccessGroups.query.filter_by(
collection_id=copy_to.id
).all()
case m.Interpretation:
current_access_groups = m.InterpretationAccessGroups.query.filter_by(
interpretation_id=copy_to.id
).all()
case m.Section:
current_access_groups = m.SectionAccessGroups.query.filter_by(
section_id=copy_to.id
).all()
if current_access_groups:
for access_group in current_access_groups:
db.session.delete(access_group)
db.session.commit()
copy_access_groups(copy_from, copy_to)
if hasattr(copy_to, "active_children"):
for collection in copy_to.active_children:
recursive_copy_access_groups(copy_to, collection)
if hasattr(copy_to, "active_sections"):
for section in copy_to.active_sections:
recursive_copy_access_groups(copy_to, section)
if hasattr(copy_to, "active_interpretations"):
for interpretations in copy_to.active_interpretations:
recursive_copy_access_groups(copy_to, interpretations)

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,7 @@ from app.controllers import (
create_breadcrumbs,
register_book_verify_route,
)
from app.controllers.copy_access_groups import recursive_copy_access_groups
from app.controllers.notification_producer import collection_notification
from app.controllers.delete_nested_book_entities import (
delete_nested_collection_entities,
@ -264,6 +265,8 @@ def change_collection_position(book_id: int, collection_id: int):
)
collection.parent_id = collection_id
recursive_copy_access_groups(new_parent, collection)
if new_parent.active_children:
collections_to_edit = (
m.Collection.query.filter(

View File

@ -2,6 +2,7 @@ from flask import flash, redirect, url_for, request
from flask_login import login_required, current_user
from app.controllers import register_book_verify_route
from app.controllers.copy_access_groups import recursive_copy_access_groups
from app.controllers.notification_producer import section_notification
from app.controllers.delete_nested_book_entities import delete_nested_section_entities
from app.controllers.error_flashes import create_error_flash
@ -160,6 +161,8 @@ def change_section_position(book_id: int, section_id: int):
)
section.collection_id = collection_id
recursive_copy_access_groups(collection, section)
if collection.active_sections:
sections_to_edit = (
m.Section.query.filter(

View File

@ -15,6 +15,8 @@ const refreshAccessLevelTree = async (userId: string, bookId: string) => {
const id = parseInt(element.getAttribute('data-access-to-id'));
if (ids.includes(id)) {
element.checked = true;
} else {
element.checked = false;
}
});
});

View File

@ -20,18 +20,19 @@ export const initUnsavedChangedAlerts = () => {
'.book-tags-input',
'.multiple-input-word',
'.contributor-role-select',
// '.edit-permissions-btn',
'.add-contributor-btn',
'input[type=checkbox]',
];
elementsSelectors.forEach(selector => {
const elements: NodeListOf<HTMLElement> =
document.querySelectorAll(selector);
elements.forEach(element => {
initAlertOnClick(element);
if (window.location.href.includes('/settings')) {
elementsSelectors.forEach(selector => {
const elements: NodeListOf<HTMLElement> =
document.querySelectorAll(selector);
elements.forEach(element => {
initAlertOnClick(element);
});
});
});
}
const elementsOnClickPrevent = document.querySelectorAll(
'.prevent-unsaved-changes-event',

View File

@ -74,7 +74,7 @@ def test_change_collection_ordering(client):
collection: m.Collection = db.session.get(m.Collection, 3)
assert collection.parent_id == collection_1.id
assert collection.position == 1
assert collection.position == 0
response: Response = client.post(
f"/book/{book.id}/{collection.id}/collection/change_position",
@ -156,7 +156,7 @@ def test_change_section_ordering(client):
collection: m.Collection = section.collection
assert len(collection.active_sections) == 1
assert section.position != new_position
assert section.position == 1
assert section.position == 0
response: Response = client.post(
f"/book/{book.id}/{section.id}/section/change_position",