@@ -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
162161def 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