Skip to content

Commit c38e628

Browse files
committed
allow admins/curators to publish draft works; fix polygon editing
1 parent c3a25f3 commit c38e628

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

works/templates/work_landing_page.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,16 @@ <h5 class="mb-0">
632632
drawnItems = featureGroup;
633633

634634
if (publicationFeature) {
635-
L.geoJSON(publicationFeature).eachLayer(function(l) {
635+
// GeometryCollection must be split into individual features; L.geoJSON
636+
// wraps the whole collection in a nested FeatureGroup that Leaflet.Draw
637+
// cannot edit directly.
638+
const geom = publicationFeature.geometry;
639+
const editFeatures = (geom && geom.type === 'GeometryCollection')
640+
? geom.geometries.map(function(g) {
641+
return { type: 'Feature', geometry: g, properties: publicationFeature.properties };
642+
})
643+
: [publicationFeature];
644+
L.geoJSON({ type: 'FeatureCollection', features: editFeatures }).eachLayer(function(l) {
636645
drawnItems.addLayer(l);
637646
});
638647
}

works/views/work_views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,13 @@ def work_landing(request, identifier):
452452
not request.user.is_authenticated
453453
and work.status in ('h', 'c')
454454
)
455-
can_publish = is_admin and (
456-
work.status == 'c'
455+
is_curator = (
456+
request.user.is_authenticated
457+
and not is_admin
458+
and work.collections.filter(curators=request.user).exists()
459+
)
460+
can_publish = (is_admin or is_curator) and (
461+
work.status in ('c', 'd')
457462
or (work.status == 'h' and (cacheable["has_geometry"] or cacheable["has_temporal"]))
458463
)
459464
can_unpublish = is_admin and work.status == 'p'

works/views_geometry.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,41 +157,46 @@ def contribute_geometry_by_id(request, work_id):
157157
return JsonResponse({'error': str(e)}, status=500)
158158

159159

160-
@staff_member_required
161160
@require_POST
162161
def publish_work_by_id(request, work_id):
163162
"""
164-
API endpoint for admins to publish a work by ID.
165-
Used for publications without a DOI.
166-
Changes status from 'Contributed' or 'Harvested' to 'Published'.
167-
For harvested publications, requires that at least one extent (spatial or temporal) exists.
163+
API endpoint for admins and collection curators to publish a work by ID.
164+
Changes status from Contributed, Harvested, or Draft to Published.
165+
Harvested works require at least one spatial or temporal extent.
168166
"""
167+
if not request.user.is_authenticated:
168+
return JsonResponse({'error': 'Authentication required'}, status=401)
169+
169170
try:
170171
work = Work.objects.get(id=work_id)
171172
except Work.DoesNotExist:
172173
return JsonResponse({'error': 'Work not found'}, status=404)
173174

175+
is_staff = request.user.is_staff
176+
is_curator = not is_staff and work.collections.filter(curators=request.user).exists()
177+
if not (is_staff or is_curator):
178+
return JsonResponse({'error': 'Permission denied'}, status=403)
179+
174180
# Check if work has any extent information
175181
has_geometry = work.geometry and not work.geometry.empty
176182
has_temporal = (
177183
any(d is not None for d in (work.timeperiod_startdate or [])) or
178184
any(d is not None for d in (work.timeperiod_enddate or []))
179185
)
180186

181-
# Allow publishing of contributed publications or harvested publications with at least one extent
182187
if work.status == 'c':
183-
# Contributed - can always publish
184188
old_status = 'Contributed'
189+
elif work.status == 'd':
190+
old_status = 'Draft'
185191
elif work.status == 'h':
186-
# Harvested - only if it has at least one extent type
187192
if not (has_geometry or has_temporal):
188193
return JsonResponse({
189194
'error': 'Cannot publish harvested work without spatial or temporal extent'
190195
}, status=400)
191196
old_status = 'Harvested'
192197
else:
193198
return JsonResponse({
194-
'error': 'Can only publish contributed or harvested publications'
199+
'error': 'Can only publish contributed, draft, or harvested publications'
195200
}, status=400)
196201

197202
try:

0 commit comments

Comments
 (0)