Skip to content

fix(objects): make lists work for filters in all objects #1420

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

Merged
merged 2 commits into from
May 6, 2021
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
3 changes: 3 additions & 0 deletions gitlab/v4/objects/deploy_tokens.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from gitlab import types
from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import CreateMixin, DeleteMixin, ListMixin, ObjectDeleteMixin

Expand Down Expand Up @@ -39,6 +40,7 @@ class GroupDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
"username",
),
)
_types = {"scopes": types.ListAttribute}


class ProjectDeployToken(ObjectDeleteMixin, RESTObject):
Expand All @@ -59,3 +61,4 @@ class ProjectDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager
"username",
),
)
_types = {"scopes": types.ListAttribute}
3 changes: 2 additions & 1 deletion gitlab/v4/objects/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class GroupManager(CRUDMixin, RESTManager):
"default_branch_protection",
),
)
_types = {"avatar": types.ImageAttribute}
_types = {"avatar": types.ImageAttribute, "skip_groups": types.ListAttribute}

@exc.on_http_error(exc.GitlabImportError)
def import_group(self, file, path, name, parent_id=None, **kwargs):
Expand Down Expand Up @@ -293,3 +293,4 @@ class GroupSubgroupManager(ListMixin, RESTManager):
"owned",
"with_custom_attributes",
)
_types = {"skip_groups": types.ListAttribute}
4 changes: 2 additions & 2 deletions gitlab/v4/objects/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class IssueManager(RetrieveMixin, RESTManager):
"updated_after",
"updated_before",
)
_types = {"labels": types.ListAttribute}
_types = {"iids": types.ListAttribute, "labels": types.ListAttribute}


class GroupIssue(RESTObject):
Expand All @@ -89,7 +89,7 @@ class GroupIssueManager(ListMixin, RESTManager):
"updated_after",
"updated_before",
)
_types = {"labels": types.ListAttribute}
_types = {"iids": types.ListAttribute, "labels": types.ListAttribute}


class ProjectIssue(
Expand Down
4 changes: 3 additions & 1 deletion gitlab/v4/objects/members.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gitlab import cli
from gitlab import cli, types
from gitlab import exceptions as exc
from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
Expand Down Expand Up @@ -26,6 +26,7 @@ class GroupMemberManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
required=("access_level",), optional=("expires_at",)
)
_types = {"user_ids": types.ListAttribute}

@cli.register_custom_action("GroupMemberManager")
@exc.on_http_error(exc.GitlabListError)
Expand Down Expand Up @@ -67,6 +68,7 @@ class ProjectMemberManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
required=("access_level",), optional=("expires_at",)
)
_types = {"user_ids": types.ListAttribute}

@cli.register_custom_action("ProjectMemberManager")
@exc.on_http_error(exc.GitlabListError)
Expand Down
26 changes: 23 additions & 3 deletions gitlab/v4/objects/merge_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ class MergeRequestManager(ListMixin, RESTManager):
"scope",
"author_id",
"assignee_id",
"approver_ids",
"approved_by_ids",
"my_reaction_emoji",
"source_branch",
"target_branch",
"search",
"wip",
)
_types = {"labels": types.ListAttribute}
_types = {
"approver_ids": types.ListAttribute,
"approved_by_ids": types.ListAttribute,
"labels": types.ListAttribute,
}


class GroupMergeRequest(RESTObject):
Expand All @@ -93,13 +99,19 @@ class GroupMergeRequestManager(ListMixin, RESTManager):
"scope",
"author_id",
"assignee_id",
"approver_ids",
"approved_by_ids",
"my_reaction_emoji",
"source_branch",
"target_branch",
"search",
"wip",
)
_types = {"labels": types.ListAttribute}
_types = {
"approver_ids": types.ListAttribute,
"approved_by_ids": types.ListAttribute,
"labels": types.ListAttribute,
}


class ProjectMergeRequest(
Expand Down Expand Up @@ -377,15 +389,23 @@ class ProjectMergeRequestManager(CRUDMixin, RESTManager):
"updated_after",
"updated_before",
"scope",
"iids",
"author_id",
"assignee_id",
"approver_ids",
"approved_by_ids",
"my_reaction_emoji",
"source_branch",
"target_branch",
"search",
"wip",
)
_types = {"labels": types.ListAttribute}
_types = {
"approver_ids": types.ListAttribute,
"approved_by_ids": types.ListAttribute,
"iids": types.ListAttribute,
"labels": types.ListAttribute,
}


class ProjectMergeRequestDiff(RESTObject):
Expand Down
4 changes: 3 additions & 1 deletion gitlab/v4/objects/milestones.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gitlab import cli
from gitlab import cli, types
from gitlab import exceptions as exc
from gitlab.base import RequiredOptional, RESTManager, RESTObject, RESTObjectList
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
Expand Down Expand Up @@ -86,6 +86,7 @@ class GroupMilestoneManager(CRUDMixin, RESTManager):
optional=("title", "description", "due_date", "start_date", "state_event"),
)
_list_filters = ("iids", "state", "search")
_types = {"iids": types.ListAttribute}


class ProjectMilestone(SaveMixin, ObjectDeleteMixin, RESTObject):
Expand Down Expand Up @@ -159,3 +160,4 @@ class ProjectMilestoneManager(CRUDMixin, RESTManager):
optional=("title", "description", "due_date", "start_date", "state_event"),
)
_list_filters = ("iids", "state", "search")
_types = {"iids": types.ListAttribute}
3 changes: 2 additions & 1 deletion gitlab/v4/objects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ class ProjectManager(CRUDMixin, RESTManager):
"service_desk_enabled",
),
)
_types = {"avatar": types.ImageAttribute}
_list_filters = (
"archived",
"id_after",
Expand All @@ -695,13 +694,15 @@ class ProjectManager(CRUDMixin, RESTManager):
"sort",
"starred",
"statistics",
"topic",
"visibility",
"wiki_checksum_failed",
"with_custom_attributes",
"with_issues_enabled",
"with_merge_requests_enabled",
"with_programming_language",
)
_types = {"avatar": types.ImageAttribute, "topic": types.ListAttribute}

def import_project(
self,
Expand Down
9 changes: 7 additions & 2 deletions gitlab/v4/objects/runners.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gitlab import cli
from gitlab import cli, types
from gitlab import exceptions as exc
from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import (
Expand Down Expand Up @@ -40,7 +40,6 @@ class Runner(SaveMixin, ObjectDeleteMixin, RESTObject):
class RunnerManager(CRUDMixin, RESTManager):
_path = "/runners"
_obj_cls = Runner
_list_filters = ("scope",)
_create_attrs = RequiredOptional(
required=("token",),
optional=(
Expand All @@ -65,6 +64,8 @@ class RunnerManager(CRUDMixin, RESTManager):
"maximum_timeout",
),
)
_list_filters = ("scope", "tag_list")
_types = {"tag_list": types.ListAttribute}

@cli.register_custom_action("RunnerManager", tuple(), ("scope",))
@exc.on_http_error(exc.GitlabListError)
Expand Down Expand Up @@ -122,6 +123,8 @@ class GroupRunnerManager(NoUpdateMixin, RESTManager):
_obj_cls = GroupRunner
_from_parent_attrs = {"group_id": "id"}
_create_attrs = RequiredOptional(required=("runner_id",))
_list_filters = ("scope", "tag_list")
_types = {"tag_list": types.ListAttribute}


class ProjectRunner(ObjectDeleteMixin, RESTObject):
Expand All @@ -133,3 +136,5 @@ class ProjectRunnerManager(NoUpdateMixin, RESTManager):
_obj_cls = ProjectRunner
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(required=("runner_id",))
_list_filters = ("scope", "tag_list")
_types = {"tag_list": types.ListAttribute}
15 changes: 15 additions & 0 deletions gitlab/v4/objects/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from gitlab import types
from gitlab import exceptions as exc
from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import GetWithoutIdMixin, SaveMixin, UpdateMixin
Expand Down Expand Up @@ -35,13 +36,18 @@ class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
"default_snippet_visibility",
"default_group_visibility",
"outbound_local_requests_whitelist",
"disabled_oauth_sign_in_sources",
"domain_whitelist",
"domain_blacklist_enabled",
"domain_blacklist",
"domain_allowlist",
"domain_denylist_enabled",
"domain_denylist",
"external_authorization_service_enabled",
"external_authorization_service_url",
"external_authorization_service_default_label",
"external_authorization_service_timeout",
"import_sources",
"user_oauth_applications",
"after_sign_out_path",
"container_registry_token_expire_delay",
Expand All @@ -65,12 +71,21 @@ class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
"asset_proxy_enabled",
"asset_proxy_url",
"asset_proxy_whitelist",
"asset_proxy_allowlist",
"geo_node_allowed_ips",
"allow_local_requests_from_hooks_and_services",
"allow_local_requests_from_web_hooks_and_services",
"allow_local_requests_from_system_hooks",
),
)
_types = {
"asset_proxy_allowlist": types.ListAttribute,
"disabled_oauth_sign_in_sources": types.ListAttribute,
"domain_allowlist": types.ListAttribute,
"domain_denylist": types.ListAttribute,
"import_sources": types.ListAttribute,
"restricted_visibility_levels": types.ListAttribute,
}

@exc.on_http_error(exc.GitlabUpdateError)
def update(self, id=None, new_data=None, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion gitlab/v4/objects/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ class ProjectUserManager(ListMixin, RESTManager):
_path = "/projects/%(project_id)s/users"
_obj_cls = ProjectUser
_from_parent_attrs = {"project_id": "id"}
_list_filters = ("search",)
_list_filters = ("search", "skip_users")
_types = {"skip_users": types.ListAttribute}


class UserEmail(ObjectDeleteMixin, RESTObject):
Expand Down
4 changes: 4 additions & 0 deletions tools/functional/api/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def test_groups(gl):
assert group3.parent_id == p_id
assert group2.subgroups.list()[0].id == group3.id

filtered_groups = gl.groups.list(skip_groups=[group3.id, group4.id])
assert group3 not in filtered_groups
assert group3 not in filtered_groups

group1.members.create(
{"access_level": gitlab.const.OWNER_ACCESS, "user_id": user.id}
)
Expand Down