Skip to content

Commit 796d7a6

Browse files
Merge pull request #2012 from betagouv/feat/files-tab-upload#1967
feat: Restauration de l'upload de document depuis l'onglet Fichiers
2 parents dd2add4 + f37e289 commit 796d7a6

5 files changed

Lines changed: 37 additions & 27 deletions

File tree

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
<div class="observed-element"
2-
:data-notifications="JSON.stringify({id: element.id, unread: element.unread, type: element.type})"
3-
x-data="TaskStatus()">
1+
<div x-data="TaskStatus()">
42
<div class="fr-mb-0 d-flex align-items-center justify-content-center">
53
<div class="d-flex align-items-center"
64
x-data="{user: null}"
75
x-init="user = getUserById(element.actor.id);">{% include "user/user_card_js.html" %}</div>
8-
<span class="followup-item__action fr-ml-1v" x-text="element.verb + ' : ' + element.action_object.feed_label"></span>
6+
<span class="followup-item__action fr-ml-1v"
7+
x-text="element.verb + ' : ' + element.action_object.feed_label"></span>
98
</div>
109
</div>

recoco/apps/projects/templates/projects/project/documents.html

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,14 @@
2626
<div class="col-8">
2727
<div class="d-flex align-items-center justify-content-between fr-mb-3w">
2828
<h6 class="text-uppercase small fr-mb-0">
29-
{% with public_files.count as files_count %}
29+
{% with all_files.count as files_count %}
3030
{% if files_count > 0 %}{{ files_count }}{% endif %}
3131
fichier{{ files_count|pluralize }} partagé{{ files_count|pluralize }}
3232
{% endwith %}
3333
</h6>
3434
{% if "manage_documents" in user_project_perms %}
35-
<button class="fr-btn fr-btn--sm fr-btn--secondary"
36-
aria-describedby="tooltip-add-file">Ajouter un fichier</button>
37-
<span class="fr-tooltip fr-placement fr-placement-bottom fr-text--xs z-1001"
38-
role="tooltip"
39-
id="tooltip-add-file">
40-
L'ajout de nouveaux fichiers se fait <a class="fr-link fr-text--xs fr-text--bold"
41-
href="{% url 'projects-project-detail-conversations' project.pk %}">dans la conversation</a>.
42-
</span>
43-
{% comment %} {% url 'projects-documents-upload-document' project.pk as upload_action %}
44-
{% include "projects/project/fragments/files_links/file_upload_button.html" with type="project" action=upload_action small=True %} {% endcomment %}
35+
{% url 'projects-documents-upload-document' project.pk as upload_action %}
36+
{% include "projects/project/fragments/files_links/file_upload_button.html" with type="project" action=upload_action small=True %}
4537
{% endif %}
4638
</div>
4739
<!-- Fichiers partagés -->

recoco/apps/projects/tests/test_documents.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from recoco.apps.projects.utils import assign_advisor, assign_collaborator
2222
from recoco.utils import login
2323

24+
from ...conversations import models as conversation_models
2425
from .. import models
2526

2627

@@ -193,13 +194,17 @@ def test_upload_file_available_for_project_collaborators(
193194

194195
assert response.status_code == 302
195196

196-
document = models.Document.objects.all()[0]
197+
document = models.Document.objects.first()
197198
assert document.project == project
198199
assert document.description == data["description"]
199200
assert document.uploaded_by == user
200201
assert not document.private
201202
assert document.the_file is not None
202203

204+
msg = conversation_models.Message.objects.first()
205+
assert msg.posted_by == user
206+
assert msg.nodes.first().document == document
207+
203208

204209
@pytest.mark.django_db
205210
def test_upload_file_rejects_executables(client, request, project, malicious_file):
@@ -229,9 +234,7 @@ def test_upload_document_is_either_link_or_file(client, request, project):
229234

230235

231236
@pytest.mark.django_db
232-
def test_upload_file_does_not_trigger_notifications(
233-
client, request, project, good_file
234-
):
237+
def test_upload_file_trigger_msg_trace_notif(client, request, project, good_file):
235238
data = {"description": "this is some content", "the_file": good_file}
236239

237240
other_user = baker.make(auth_models.User)
@@ -247,10 +250,12 @@ def test_upload_file_does_not_trigger_notifications(
247250
assert response.status_code == 302
248251

249252
document = models.Document.objects.all()[0]
253+
msg = document.documentnode_set.first().message
250254

251-
assert action_object_stream(document).count() == 1
255+
assert action_object_stream(msg).count() == 1
256+
assert action_object_stream(document).count() == 0
252257
assert user.notifications.count() == 0
253-
assert other_user.notifications.count() == 0
258+
assert other_user.notifications.count() == 1
254259

255260

256261
@pytest.mark.django_db

recoco/apps/projects/views/documents.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from django.contrib.auth.decorators import login_required
1212
from django.contrib.contenttypes.models import ContentType
1313
from django.core.exceptions import PermissionDenied
14+
from django.db import transaction
1415
from django.db.utils import IntegrityError
1516
from django.shortcuts import get_object_or_404, redirect, render
1617
from django.urls import reverse
@@ -19,7 +20,9 @@
1920
from recoco.apps.survey.models import Answer
2021
from recoco.utils import has_perm, has_perm_or_403
2122

22-
from .. import models, signals
23+
from ...conversations import models as conversation_models
24+
from ...conversations import signals as conversation_signals
25+
from .. import models
2326
from ..forms import DocumentUploadForm
2427
from ..utils import get_advising_context_for_project, is_regional_actor_for_project
2528

@@ -110,19 +113,29 @@ def document_upload(request, project_id):
110113
instance.uploaded_by = request.user
111114
instance.private = False
112115

116+
msg = conversation_models.Message(
117+
posted_by=instance.uploaded_by, project=project
118+
)
119+
node = conversation_models.DocumentNode(
120+
document=instance, position=1, message=msg
121+
)
122+
113123
try:
114-
instance.save()
124+
with transaction.atomic():
125+
instance.save()
126+
msg.save()
127+
node.save()
115128

116-
signals.document_uploaded.send(
117-
sender=document_upload, instance=instance
129+
conversation_signals.message_posted.send(
130+
sender=document_upload, message=msg
118131
)
119132

120133
messages.success(
121134
request,
122135
"Le document a bien été enregistré",
123136
)
124137

125-
except IntegrityError:
138+
except IntegrityError as _e:
126139
messages.error(request, "Impossible de sauver le document")
127140

128141
return redirect(reverse("projects-project-detail-documents", args=[project.id]))

recoco/frontend/src/css/projects/conversations_new.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
color: #3a3a3a;
322322
font-size: 14px;
323323
font-weight: 700;
324+
margin-right: 0.25rem;
324325
}
325326
&__filename,
326327
&__size {
@@ -331,7 +332,7 @@
331332
&__info-container,
332333
&__actions-container {
333334
display: flex;
334-
align-items: center;
335+
align-items: baseline;
335336
}
336337
}
337338
}

0 commit comments

Comments
 (0)