Skip to content

Commit

Permalink
Allow invalid classifications to be ignored during accessibility test
Browse files Browse the repository at this point in the history
  • Loading branch information
cccs-sgaron committed Sep 24, 2021
1 parent 08d5ac3 commit 31f50e0
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions assemblyline/common/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def intersect_user_classification(self, user_c12n_1: str, user_c12n_2: str, long
long_format=long_format,
skip_auto_select=True)

def is_accessible(self, user_c12n: str, c12n: str) -> bool:
def is_accessible(self, user_c12n: str, c12n: str, ignore_invalid: bool = False) -> bool:
"""
Given a user classification, check if a user is allow to see a certain classification
Expand All @@ -656,24 +656,30 @@ def is_accessible(self, user_c12n: str, c12n: str) -> bool:
if c12n is None:
return True

# Normalize classifications before comparing them
user_c12n = self.normalize_classification(user_c12n, skip_auto_select=True)
c12n = self.normalize_classification(c12n, skip_auto_select=True)

user_req = self._get_c12n_required(user_c12n)
user_groups, user_subgroups = self._get_c12n_groups(user_c12n)
req = self._get_c12n_required(c12n)
groups, subgroups = self._get_c12n_groups(c12n)

if self._get_c12n_level_index(user_c12n) >= self._get_c12n_level_index(c12n):
if not self._can_see_required(user_req, req):
return False
if not self._can_see_groups(user_groups, groups):
return False
if not self._can_see_groups(user_subgroups, subgroups):
try:
# Normalize classifications before comparing them
user_c12n = self.normalize_classification(user_c12n, skip_auto_select=True)
c12n = self.normalize_classification(c12n, skip_auto_select=True)

user_req = self._get_c12n_required(user_c12n)
user_groups, user_subgroups = self._get_c12n_groups(user_c12n)
req = self._get_c12n_required(c12n)
groups, subgroups = self._get_c12n_groups(c12n)

if self._get_c12n_level_index(user_c12n) >= self._get_c12n_level_index(c12n):
if not self._can_see_required(user_req, req):
return False
if not self._can_see_groups(user_groups, groups):
return False
if not self._can_see_groups(user_subgroups, subgroups):
return False
return True
return False
except InvalidClassification:
if ignore_invalid:
return False
return True
return False
else:
raise

def is_valid(self, c12n: str, skip_auto_select: bool = False) -> bool:
"""
Expand Down

0 comments on commit 31f50e0

Please sign in to comment.