Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include curated tags when querying for merge requests. #45

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions tests/merge_request/api/integration/get_merge_requests_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,63 @@ def test_get_merge_requests_with_hidden(
"hidden": False,
},
)


def test_includes_curated(
auth_server_commissioner,
merge_request_user,
merge_request_user1,
merge_request_curated,
):
server, cookies = auth_server_commissioner
rsp = req.get_merge_requests(server.url, cookies=cookies)
assert rsp.status_code == 200
json = rsp.json()
assert_versioned(
json["assigned"],
[
{
"id_persistent": c.id_persistent_merge_request_curated,
"created_by": {
"user_name": "test-user1",
"id_persistent": "2e858c5e-60cf-4ce5-946f-6b4559a21211",
"permission_group": "APPLICANT",
},
"assigned_to": None,
"created_at": format_datetime(c.time_merge_request_curated),
"state": "OPEN",
"destination": {
"id_persistent": "2ec43995-338b-4f4b-b1cc-4bfc71466fc5",
"id_parent_persistent": None,
"name": "name curated tag test",
"name_path": ["name curated tag test"],
"type": "STRING",
"owner": None,
"curated": True,
"hidden": False,
},
"origin": {
"id_persistent": "52d5de0a-2fdb-457f-80d0-6e10131ad1b9",
"id_parent_persistent": None,
"name": "name tag test1",
"name_path": ["name tag test1"],
"owner": "test-user1",
"type": "STRING",
"curated": False,
"hidden": False,
},
}
],
)
assert len(json["created"]) == 0


def test_does_not_include_curated_for_normal_user(
auth_server,
merge_request_curated,
):
server, cookies = auth_server
rsp = req.get_merge_requests(server.url, cookies=cookies)
assert rsp.status_code == 200
json = rsp.json()
assert json == {"assigned": [], "created": []}
2 changes: 2 additions & 0 deletions tests/merge_request/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
id_persistent_merge_request = "8a651ace-54d1-4c1d-850d-3e23d85fe990"
id_persistent_merge_request_fast_forward = "c2ed0d7c-a0f7-46b9-a28b-d3a5dc701640"
id_persistent_merge_request1 = "d530b3f2-2ae1-4ed6-ab8c-af2667bcde30"
id_persistent_merge_request_curated = "e0042964-781f-43da-8214-f0f82a1f569a"
time_merge_request = datetime(1970, 1, 5)
time_merge_request1 = datetime(1970, 1, 6)
time_merge_request_curated = datetime(1970, 2, 3)
name_contribution = "contribution test"
name_contribution1 = "contribution test 1"
description_contribution = "a contribution for tests"
Expand Down
13 changes: 13 additions & 0 deletions tests/merge_request/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ def merge_request_user1(
)


@pytest.fixture
def merge_request_curated(tag_def_curated, tag_def1, contribution_for_mr):
return TagMergeRequest.objects.create( # pylint: disable=no-member
id_destination_persistent=tag_def_curated.id_persistent,
id_origin_persistent=tag_def1.id_persistent,
created_by=tag_def1.owner,
assigned_to=None,
created_at=c.time_merge_request_curated,
id_persistent=c.id_persistent_merge_request_curated,
contribution_candidate=contribution_for_mr,
)


@pytest.fixture
def instances_merge_request_origin_user(merge_request_user, entity0, entity1):
id_tag_definition = merge_request_user.id_origin_persistent
Expand Down
32 changes: 26 additions & 6 deletions vran/merge_request/models_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,34 @@ class TagMergeRequest(AbstractMergeRequest):
@classmethod
def assigned_to_user(cls, user: VranUser):
"Get all merge requests assigned to a user"
return TagMergeRequest.objects.filter( # pylint: disable=no-member
states = [
TagMergeRequest.OPEN,
TagMergeRequest.CONFLICTS,
TagMergeRequest.ERROR,
]

assigned = TagMergeRequest.objects.filter( # pylint: disable=no-member
assigned_to=user,
state__in=[
TagMergeRequest.OPEN,
TagMergeRequest.CONFLICTS,
TagMergeRequest.ERROR,
],
state__in=states,
)
if user.permission_group in [VranUser.EDITOR, VranUser.COMMISSIONER]:
curated = (
TagMergeRequest.objects.filter( # pylint: disable=no-member
state__in=states
)
.annotate(
curated=models.Subquery(
TagDefinition.most_recent_query_set()
.filter(
id_persistent=models.OuterRef("id_destination_persistent")
)
.values("curated")
)
)
.filter(curated=True)
)
return assigned.annotate(curated=models.Value(False)).union(curated)
return assigned

def has_read_access(self, user: VranUser):
"Check wether a user can read the merge request."
Expand Down
Loading