udata 9.2.2.dev31569__py2.py3-none-any.whl → 9.2.2.dev31595__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of udata might be problematic. Click here for more details.

@@ -6,6 +6,10 @@ from flask_security import current_user
6
6
 
7
7
  from udata.api import API, api, fields
8
8
  from udata.auth import admin_permission
9
+ from udata.core.dataservices.models import Dataservice
10
+ from udata.core.dataset.models import Dataset
11
+ from udata.core.organization.models import Organization
12
+ from udata.core.reuse.models import Reuse
9
13
  from udata.core.spam.api import SpamAPIMixin
10
14
  from udata.core.spam.fields import spam_fields
11
15
  from udata.core.user.api_fields import user_ref_fields
@@ -73,8 +77,15 @@ comment_discussion_fields = api.model(
73
77
  discussion_page_fields = api.model("DiscussionPage", fields.pager(discussion_fields))
74
78
 
75
79
  parser = api.parser()
80
+ sorting_keys: list[str] = ["created", "title", "closed"]
81
+ sorting_choices: list[str] = sorting_keys + ["-" + k for k in sorting_keys]
76
82
  parser.add_argument(
77
- "sort", type=str, default="-created", location="args", help="The sorting attribute"
83
+ "sort",
84
+ type=str,
85
+ default="-created",
86
+ choices=sorting_choices,
87
+ location="args",
88
+ help="The field (and direction) on which sorting apply",
78
89
  )
79
90
  parser.add_argument(
80
91
  "closed",
@@ -85,6 +96,9 @@ parser.add_argument(
85
96
  parser.add_argument(
86
97
  "for", type=str, location="args", action="append", help="Filter discussions for a given subject"
87
98
  )
99
+ parser.add_argument(
100
+ "org", type=str, location="args", help="Filter discussions for a given organization"
101
+ )
88
102
  parser.add_argument("user", type=str, location="args", help="Filter discussions created by a user")
89
103
  parser.add_argument("page", type=int, default=1, location="args", help="The page to fetch")
90
104
  parser.add_argument(
@@ -198,6 +212,15 @@ class DiscussionsAPI(API):
198
212
  discussions = Discussion.objects
199
213
  if args["for"]:
200
214
  discussions = discussions.generic_in(subject=args["for"])
215
+ if args["org"]:
216
+ org = Organization.objects.get_or_404(id=id_or_404(args["org"]))
217
+ if not org:
218
+ api.abort(404, "Organization does not exist")
219
+ reuses = Reuse.objects(organization=org).only("id")
220
+ datasets = Dataset.objects(organization=org).only("id")
221
+ dataservices = Dataservice.objects(organization=org).only("id")
222
+ subjects = list(reuses) + list(datasets) + list(dataservices)
223
+ discussions = discussions(subject__in=subjects)
201
224
  if args["user"]:
202
225
  discussions = discussions(discussion__posted_by=ObjectId(args["user"]))
203
226
  if args["closed"] is False: