diff --git a/atlas/decorators.py b/atlas/decorators.py index 55091d1a..62efd247 100755 --- a/atlas/decorators.py +++ b/atlas/decorators.py @@ -3,8 +3,17 @@ from .models import Case, CaseCollection, Series def user_is_author_or_atlas_series_checker_or_atlas_marker_or_open_access(function): + """Decorator to check if user is author of the series, + an atlas editor, an atlas marker, or if the series is open access. + Used for series-level permissions. + + Requires the decorated view to have a "pk" or "series_id" kwarg to identify the series. + """ def wrap(request, *args, **kwargs): - series = Series.objects.get(pk=kwargs["pk"]) + if "pk" in kwargs: + series = Series.objects.get(pk=kwargs["pk"]) + elif "series_id" in kwargs: + series = Series.objects.get(pk=kwargs["series_id"]) if ( request.user in series.get_author_objects() or series.open_access @@ -23,7 +32,10 @@ def user_is_author_or_atlas_series_checker_or_atlas_marker_or_open_access(functi def user_is_author_or_atlas_series_checker(function): def wrap(request, *args, **kwargs): - series = Series.objects.get(pk=kwargs["pk"]) + if "pk" in kwargs: + series = Series.objects.get(pk=kwargs["pk"]) + elif "series_id" in kwargs: + series = Series.objects.get(pk=kwargs["series_id"]) if ( request.user in series.get_author_objects() or request.user.groups.filter(name="atlas_editor").exists() @@ -40,7 +52,10 @@ def user_is_author_or_atlas_series_checker(function): def user_has_case_view_access(function): def wrap(request, *args, **kwargs): - atlas = Case.objects.get(pk=kwargs["pk"]) + if "pk" in kwargs: + atlas = Case.objects.get(pk=kwargs["pk"]) + elif "case_id" in kwargs: + atlas = Case.objects.get(pk=kwargs["case_id"]) # If open access everyone can view if atlas.open_access: @@ -62,7 +77,10 @@ def user_has_case_view_access(function): def user_is_author_or_atlas_editor(function): def wrap(request, *args, **kwargs): - atlas = Case.objects.get(pk=kwargs["pk"]) + if "pk" in kwargs: + atlas = Case.objects.get(pk=kwargs["pk"]) + elif "case_id" in kwargs: + atlas = Case.objects.get(pk=kwargs["case_id"]) if ( request.user in atlas.author.all() or request.user.groups.filter(name="atlas_editor").exists() diff --git a/atlas/tasks.py b/atlas/tasks.py index fe4c9769..266792ec 100644 --- a/atlas/tasks.py +++ b/atlas/tasks.py @@ -405,23 +405,22 @@ def series_reconstruct_task( axis_positions_mm = np.arange(axis_length, dtype=float) * float(axis_spacing) end_pos = axis_positions_mm[-1] if axis_positions_mm.size else 0.0 - start_positions_mm = np.arange(0.0, end_pos + 1e-6, output_spacing, dtype=float) - if start_positions_mm.size == 0: - start_positions_mm = np.array([0.0], dtype=float) + center_positions_mm = np.arange(0.0, end_pos + 1e-6, output_spacing, dtype=float) + if center_positions_mm.size == 0: + center_positions_mm = np.array([0.0], dtype=float) slabs = [] centers_idx = [] - for start_mm in start_positions_mm: - end_mm = start_mm + slab_thickness - mask = (axis_positions_mm >= (start_mm - 1e-6)) & (axis_positions_mm < (end_mm - 1e-6)) + half_thickness = slab_thickness / 2.0 + for center_mm in center_positions_mm: + mask = np.abs(axis_positions_mm - center_mm) <= (half_thickness + 1e-6) if not mask.any(): - nearest = int(np.argmin(np.abs(axis_positions_mm - start_mm))) + nearest = int(np.argmin(np.abs(axis_positions_mm - center_mm))) idxs = np.array([nearest], dtype=int) else: idxs = np.where(mask)[0].astype(int) slabs.append(idxs) - center_mm = start_mm + (slab_thickness / 2.0) centers_idx.append(float(center_mm / axis_spacing) if axis_spacing > 0 else float(idxs[0])) return slabs, centers_idx diff --git a/atlas/templates/atlas/partials/case_search_widget.html b/atlas/templates/atlas/partials/case_search_widget.html index 69313ad0..3f616dba 100644 --- a/atlas/templates/atlas/partials/case_search_widget.html +++ b/atlas/templates/atlas/partials/case_search_widget.html @@ -1,5 +1,13 @@