Skip to content

Commit

Permalink
Fix: Check permission handles removed operator
Browse files Browse the repository at this point in the history
A removed operator is not available in the head repo and we need to get
it from base repo instead. This commit splits operators into 2
categories. Added,updated and removed. Each of them is parsed from a
different repository.

JIRA: ISV-5167

Signed-off-by: Ales Raszka <[email protected]>
  • Loading branch information
Allda committed Aug 26, 2024
1 parent d616d6d commit e828cf3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,20 @@ def check_permissions(
with open(args.changes_file, "r", encoding="utf8") as f:
changes = json.load(f)

affected_operators = changes.get("affected_operators", [])
operators = {head_repo.operator(operator) for operator in affected_operators}
# Get added and modified operators from head repo
added_or_updated_operators = changes.get("added_operators", [])
added_or_updated_operators.extend(changes.get("modified_operators", []))
operators = {
head_repo.operator(operator) for operator in added_or_updated_operators
}

# Get deleted operators from base repo
operators = operators.union(
{
base_repo.operator(operator)
for operator in changes.get("deleted_operators", [])
}
)

# In this step we need to map the affected catalog operators to the actual
# operators. This needs to be done because the permission and reviewers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,33 +326,39 @@ def test_check_permissions(
head_repo = MagicMock()

mock_json_load.return_value = {
"affected_operators": ["operator1", "operator2"],
"added_catalog_operators": ["c1/operator3"],
"modified_catalog_operators": ["c2/operator4"],
"removed_catalog_operators": ["c3/operator5"],
"added_operators": ["operator1"],
"modified_operators": ["operator2"],
"deleted_operators": ["operator3"],
"added_catalog_operators": ["c1/operator4"],
"modified_catalog_operators": ["c2/operator5"],
"removed_catalog_operators": ["c3/operator6"],
}
head_repo.operator.side_effect = [
MagicMock(name="operator1"),
MagicMock(name="operator2"),
]
base_repo.operator.side_effect = [MagicMock(name="operator5")]
base_repo.operator.side_effect = [
MagicMock(name="operator3"),
MagicMock(name="operator6"),
]
mock_review.return_value.check_permissions.side_effect = [
False,
check_permissions.MaintainersReviewNeeded("error"),
True,
True,
True,
True,
]
mock_catalog_operators.side_effect = [
set(
[
MagicMock(name="operator3"),
MagicMock(name="operator4"),
MagicMock(name="operator5"),
]
),
set(
[
MagicMock(name="operator5"),
MagicMock(name="operator6"),
]
),
]
Expand All @@ -361,10 +367,11 @@ def test_check_permissions(
assert not result

head_repo.operator.assert_has_calls([call("operator1"), call("operator2")])
base_repo.operator.assert_has_calls([call("operator3")])
mock_catalog_operators.assert_has_calls(
[
call(head_repo, ["c1/operator3", "c2/operator4"]),
call(base_repo, ["c3/operator5"]),
call(head_repo, ["c1/operator4", "c2/operator5"]),
call(base_repo, ["c3/operator6"]),
]
)

Expand Down

0 comments on commit e828cf3

Please sign in to comment.