Skip to content

Commit

Permalink
Use a simpler single if statement for group scope
Browse files Browse the repository at this point in the history
This matches the formulation in the tests and keeps this a unitary
piece of logic, rather than split over two separate tests. This form
has less chance of getting split up in a weird way in a refactor.
  • Loading branch information
Jon Betts committed Jun 15, 2023
1 parent 49c3960 commit 7043db3
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions h/services/annotation_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,13 @@ def _validate_group(self, annotation: Annotation):
"group: " + _("You may not create annotations in the specified group!")
)

# If no scopes are present, or if the group is configured to allow
# annotations outside its scope, there's nothing to do here
if not group.scopes or not group.enforce_scope:
return

# The target URI must match at least one
# of a group's defined scopes, if the group has any
if not url_in_scope(
annotation.target_uri, [scope.scope for scope in group.scopes]
if (
group.scopes # If we have scopes
and group.enforce_scope # ... and we are enforcing them
# the target URI must match one of a group's defined scopes
and not url_in_scope(
annotation.target_uri, [scope.scope for scope in group.scopes]
)
):
raise ValidationError(
"group scope: "
Expand Down

0 comments on commit 7043db3

Please sign in to comment.