mirror of
https://github.com/logos-co/open-law.git
synced 2025-02-13 07:16:25 +00:00
Merge branch 'develop' into kostia/feature/tab_content
This commit is contained in:
commit
be1181a9fc
@ -68,9 +68,13 @@ def create_app(environment="development"):
|
||||
login_manager.anonymous_user = AnonymousUser
|
||||
|
||||
# Jinja globals
|
||||
from app.controllers.jinja_globals import form_hidden_tag
|
||||
from app.controllers.jinja_globals import (
|
||||
form_hidden_tag,
|
||||
build_qa_url_using_interpretation,
|
||||
)
|
||||
|
||||
app.jinja_env.globals["form_hidden_tag"] = form_hidden_tag
|
||||
app.jinja_env.globals["build_qa_url"] = build_qa_url_using_interpretation
|
||||
|
||||
# Error handlers.
|
||||
@app.errorhandler(HTTPException)
|
||||
|
23
app/controllers/build_qa_url_using_interpretation.py
Normal file
23
app/controllers/build_qa_url_using_interpretation.py
Normal file
@ -0,0 +1,23 @@
|
||||
from flask import url_for
|
||||
|
||||
from app import models as m
|
||||
|
||||
|
||||
def build_qa_url_using_interpretation(interpretation: m.Interpretation):
|
||||
section: m.Section = interpretation.section
|
||||
collection: m.Collection = section.collection
|
||||
sub_collection = None
|
||||
if collection.is_leaf and collection.parent.is_root:
|
||||
collection: m.Collection = collection.parent
|
||||
sub_collection: m.Collection = collection
|
||||
book: m.Book = section.version.book
|
||||
|
||||
url = url_for(
|
||||
"book.qa_view",
|
||||
book_id=book.id,
|
||||
collection_id=collection.id,
|
||||
sub_collection_id=sub_collection.id if sub_collection else None,
|
||||
section_id=section.id,
|
||||
interpretation_id=interpretation.id,
|
||||
)
|
||||
return url
|
@ -1,7 +1,31 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from flask import url_for
|
||||
|
||||
from app import models as m
|
||||
|
||||
|
||||
# Using: {{ form_hidden_tag() }}
|
||||
def form_hidden_tag():
|
||||
form = FlaskForm()
|
||||
return form.hidden_tag()
|
||||
|
||||
|
||||
# Using: {{ build_qa_url(interpretation) }}
|
||||
def build_qa_url_using_interpretation(interpretation: m.Interpretation):
|
||||
section: m.Section = interpretation.section
|
||||
collection: m.Collection = section.collection
|
||||
sub_collection = None
|
||||
if collection.parent and not collection.parent.is_root:
|
||||
sub_collection: m.Collection = collection
|
||||
collection: m.Collection = collection.parent
|
||||
book: m.Book = section.version.book
|
||||
|
||||
url = url_for(
|
||||
"book.qa_view",
|
||||
book_id=book.id,
|
||||
collection_id=collection.id,
|
||||
sub_collection_id=sub_collection.id if sub_collection else None,
|
||||
section_id=section.id,
|
||||
interpretation_id=interpretation.id,
|
||||
)
|
||||
return url
|
||||
|
File diff suppressed because one or more lines are too long
143842
app/static/js/main.js
143842
app/static/js/main.js
File diff suppressed because one or more lines are too long
27
app/templates/book/approve_interpretation_modal.html
Normal file
27
app/templates/book/approve_interpretation_modal.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!-- prettier-ignore-->
|
||||
<div id="approve_interpretation_modal" tabindex="-1" aria-hidden="true" class="fixed top-0 left-0 right-0 z-[150] hidden w-full p-4 overflow-x-hidden overflow-y-auto md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
||||
<div class="relative w-full max-w-2xl max-h-full">
|
||||
<!-- Modal content -->
|
||||
<form
|
||||
id="approve-interpretation-form"
|
||||
class="relative bg-white rounded-lg shadow dark:bg-gray-700"
|
||||
>
|
||||
{{ form_hidden_tag() }}
|
||||
<!-- Modal header -->
|
||||
<div class="flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600">
|
||||
<h3 class="text-xl font-semibold text-gray-900 dark:text-white">Important Note</h3>
|
||||
<button id="modalAddCloseButton" data-modal-hide="approve_interpretation_modal" type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center dark:hover:bg-gray-600 dark:hover:text-white"> <svg aria-hidden="true" class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg> </button>
|
||||
</div>
|
||||
|
||||
<!-- Modal body -->
|
||||
<div class="flex dark:text-white items-center p-6 space-x-2 dark:border-gray-600">
|
||||
There's already an approved interpretation for this section. Do you want to proceed to replace it?
|
||||
</div>
|
||||
|
||||
<!-- Modal footer -->
|
||||
<div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600">
|
||||
<button name="submit" type="submit" class="text-white bg-red-700 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-green-600 dark:hover:bg-green-700 dark:focus:ring-green-800">Confirm</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
@ -2,15 +2,16 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% if current_user.is_authenticated %}
|
||||
{% include 'book/delete_section_modal.html' %}
|
||||
{% include 'book/edit_section_modal.html' %}
|
||||
{% include 'book/delete_section_modal.html' %}
|
||||
{% include 'book/edit_section_modal.html' %}
|
||||
{% include 'book/approve_interpretation_modal.html' %}
|
||||
<!-- prettier-ignore -->
|
||||
{% set show_delete_section = True %}
|
||||
<!-- prettier-ignore -->
|
||||
{% set show_edit_section = True %}
|
||||
{% block right_sidebar %}
|
||||
{% include 'book/right_sidebar.html' %}
|
||||
{% endblock %}
|
||||
{% block right_sidebar %}
|
||||
{% include 'book/right_sidebar.html' %}
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
@ -158,11 +159,7 @@
|
||||
<div class="space-x-0.5 flex items-center">
|
||||
<a
|
||||
class="!cursor-pointer text-no-underline flex items-center"
|
||||
{% if sub_collection %}
|
||||
href="{{ url_for('book.qa_view', book_id=book.id, collection_id=collection.id, sub_collection_id=sub_collection.id, section_id=section.id, interpretation_id=interpretation.id) }}"
|
||||
{% else %}
|
||||
href="{{ url_for('book.qa_view', book_id=book.id, collection_id=collection.id, section_id=section.id, interpretation_id=interpretation.id) }}"
|
||||
{% endif %}
|
||||
href="{{ build_qa_url(interpretation) }}"
|
||||
>
|
||||
<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="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
|
||||
<p class="select-none">{{interpretation.active_comments | length}}</p>
|
||||
@ -174,6 +171,12 @@
|
||||
</div>
|
||||
</dl>
|
||||
{% endfor %}
|
||||
|
||||
<span class="approved-interpretation-id hidden">
|
||||
{% if section.approved_interpretation.approved %}
|
||||
{{ section.approved_interpretation.id }}
|
||||
{% endif %}
|
||||
</span>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -86,8 +86,10 @@
|
||||
<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 8.25H7.5a2.25 2.25 0 00-2.25 2.25v9a2.25 2.25 0 002.25 2.25h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25H15m0-3l-3-3m0 0l-3 3m3-3V15" /> </svg>
|
||||
</span>
|
||||
<div class="space-x-0.5 flex items-center">
|
||||
<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="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
|
||||
<p>{{interpretation.active_comments | length}}</p>
|
||||
<a class="!cursor-pointer text-no-underline flex items-center" href="{{ build_qa_url(interpretation) }}" >
|
||||
<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="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
|
||||
<p>{{interpretation.active_comments | length}}</p>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -130,8 +130,10 @@
|
||||
<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 8.25H7.5a2.25 2.25 0 00-2.25 2.25v9a2.25 2.25 0 002.25 2.25h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25H15m0-3l-3-3m0 0l-3 3m3-3V15" /> </svg>
|
||||
</span>
|
||||
<div class="space-x-0.5 flex items-center">
|
||||
<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="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
|
||||
<p>{{interpretation.active_comments | length}}</p>
|
||||
<a class="!cursor-pointer text-no-underline flex items-center" href="{{ build_qa_url(interpretation) }}" >
|
||||
<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="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
|
||||
<p>{{interpretation.active_comments | length}}</p>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -33,6 +33,24 @@ def approve_interpretation(interpretation_id: int):
|
||||
)
|
||||
return jsonify({"message": "You dont have permission"}), 404
|
||||
|
||||
already_approved_interpretations = (
|
||||
m.Interpretation.query.filter_by(
|
||||
approved=True, section_id=interpretation.section_id
|
||||
)
|
||||
.filter(m.Interpretation.id != interpretation.id)
|
||||
.all()
|
||||
)
|
||||
for approved_interpretation in already_approved_interpretations:
|
||||
approved_interpretation: m.Interpretation
|
||||
approved_interpretation.approved = False
|
||||
log(
|
||||
log.INFO,
|
||||
"User [%s] revoked the approval of the interpretation: [%s]",
|
||||
current_user,
|
||||
interpretation,
|
||||
)
|
||||
approved_interpretation.save(False)
|
||||
|
||||
interpretation.approved = not interpretation.approved
|
||||
log(
|
||||
log.INFO,
|
||||
|
@ -1,8 +1,31 @@
|
||||
import {Modal} from 'flowbite';
|
||||
import type {ModalOptions, ModalInterface} from 'flowbite';
|
||||
|
||||
const REQUEST_URLS: {[key: string]: string} = {
|
||||
interpretation: '/approve/interpretation/',
|
||||
comment: '/approve/comment/',
|
||||
};
|
||||
|
||||
const setAllApproveIconsToInactive = () => {
|
||||
const approvedIconElements = document.querySelectorAll('.approved-icon');
|
||||
approvedIconElements.forEach(el => {
|
||||
el.classList.remove('hidden');
|
||||
el.classList.add('hidden');
|
||||
});
|
||||
|
||||
const notApprovedIconElements =
|
||||
document.querySelectorAll('.not-approved-icon');
|
||||
notApprovedIconElements.forEach(el => {
|
||||
el.classList.remove('hidden');
|
||||
});
|
||||
};
|
||||
|
||||
// prettier-ignore
|
||||
const $approveInterpretationModalElement: HTMLElement = document.querySelector( '#approve_interpretation_modal', );
|
||||
const modalOptions: ModalOptions = {onShow: () => {}};
|
||||
// prettier-ignore
|
||||
const approveModal: ModalInterface = new Modal( $approveInterpretationModalElement, modalOptions, );
|
||||
|
||||
const approveClickEventListener = async (btn: Element) => {
|
||||
const approve = btn.getAttribute('data-approve');
|
||||
|
||||
@ -13,6 +36,54 @@ const approveClickEventListener = async (btn: Element) => {
|
||||
|
||||
const entityId = btn.getAttribute('data-entity-id');
|
||||
|
||||
const approvedInterpretationIdBlock = document.querySelector(
|
||||
'.approved-interpretation-id',
|
||||
);
|
||||
if (approve == 'interpretation') {
|
||||
// prettier-ignore
|
||||
if (approvedInterpretationIdBlock) {
|
||||
const approvedInterpretationId = parseInt(
|
||||
approvedInterpretationIdBlock.innerHTML,
|
||||
);
|
||||
if (approvedInterpretationId && approvedInterpretationId != parseInt(entityId)) {
|
||||
approveModal.show();
|
||||
|
||||
const approvedInterpretationForm: HTMLFormElement =
|
||||
document.querySelector('#approve-interpretation-form');
|
||||
|
||||
const submitFormEventListener = async (e: any) => {
|
||||
e.preventDefault();
|
||||
approvedInterpretationForm.removeEventListener(
|
||||
'submit',
|
||||
submitFormEventListener,
|
||||
);
|
||||
sendApproveRequest(
|
||||
approve,
|
||||
entityId,
|
||||
btn,
|
||||
approvedInterpretationIdBlock,
|
||||
);
|
||||
setAllApproveIconsToInactive();
|
||||
approveModal.hide();
|
||||
};
|
||||
approvedInterpretationForm.addEventListener(
|
||||
'submit',
|
||||
submitFormEventListener,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sendApproveRequest(approve, entityId, btn, approvedInterpretationIdBlock);
|
||||
};
|
||||
|
||||
const sendApproveRequest = async (
|
||||
approve: string,
|
||||
entityId: string,
|
||||
btn: Element,
|
||||
approvedInterpretationIdBlock?: Element,
|
||||
) => {
|
||||
const requestUrl = REQUEST_URLS[approve] + entityId;
|
||||
const response = await fetch(requestUrl, {
|
||||
method: 'POST',
|
||||
@ -24,6 +95,13 @@ const approveClickEventListener = async (btn: Element) => {
|
||||
|
||||
const json = await response.json();
|
||||
const approved = json.approve;
|
||||
if (approve == 'interpretation') {
|
||||
if (approved) {
|
||||
approvedInterpretationIdBlock!.innerHTML = entityId;
|
||||
} else {
|
||||
approvedInterpretationIdBlock!.innerHTML = '';
|
||||
}
|
||||
}
|
||||
|
||||
const approvedIconSvg = btn.querySelector('.approved-icon');
|
||||
const notApprovedIconSvg = btn.querySelector('.not-approved-icon');
|
||||
|
27
tests/test_build_qa_url_using_interpretation.py
Normal file
27
tests/test_build_qa_url_using_interpretation.py
Normal file
@ -0,0 +1,27 @@
|
||||
from flask.testing import FlaskClient
|
||||
from flask import current_app as Response
|
||||
|
||||
from app.controllers.jinja_globals import (
|
||||
build_qa_url_using_interpretation,
|
||||
)
|
||||
from .utils import create_test_book, login
|
||||
from app import models as m
|
||||
|
||||
|
||||
def test_build_qa_url_using_interpretation(client: FlaskClient):
|
||||
_, user = login(client)
|
||||
user: m.User
|
||||
|
||||
create_test_book(user.id)
|
||||
|
||||
interpretation: m.Interpretation = m.Interpretation.query.first()
|
||||
|
||||
url = build_qa_url_using_interpretation(interpretation)
|
||||
assert url
|
||||
|
||||
response: Response = client.get(url, follow_redirects=True)
|
||||
assert response.status_code == 200
|
||||
|
||||
section: m.Section = m.Section.query.first()
|
||||
assert section
|
||||
assert str.encode(section.label) in response.data
|
Loading…
x
Reference in New Issue
Block a user