Skip to content
Open
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
4 changes: 4 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ Groups
:>json array components: link to associated components; see :http:get:`/api/components/(string:project)/(string:component)/`
:>json array componentlists: link to associated componentlist; see :http:get:`/api/component-lists/(str:slug)/`
:>json str defining_project: link to the defining project, used for :ref:`manage-acl`; see :http:get:`/api/projects/(string:project)/`
:>json array admins: link to associated administrators; see :http:get:`/api/users/(str:username)/`

**Example JSON data:**

Expand All @@ -550,6 +551,9 @@ Groups
"componentlist": "http://example.com/api/component-lists/new/",
"components": [
"http://example.com/api/components/demo/weblate/"
],
"admins": [
"http://example.com/api/users/exampleusername/"
]
}

Expand Down
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Weblate 5.14.1

* Document using Valkey in :ref:`celery` and :ref:`production-cache`.
* Added HTTP environment overview in :ref:`manage-performance`.
* :http:get:`/api/groups/` now includes ``admins``.

.. rubric:: Bug fixes

Expand Down
13 changes: 13 additions & 0 deletions docs/specs/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions weblate/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
super().__init__(**kwargs)
self.lookup_field = lookup_field

def get_url(self, obj, view_name, request: AuthenticatedHttpRequest, format): # noqa: A002

Check failure on line 101 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 3 of "get_url" is incompatible with supertype "rest_framework.relations.HyperlinkedRelatedField"; supertype defines the argument type as "Request"
"""
Given an object, return the URL that hyperlinks to the object.

Expand Down Expand Up @@ -377,7 +377,7 @@
)

id = serializers.IntegerField(read_only=True)
user = serializers.HyperlinkedRelatedField(

Check failure on line 380 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

Need type annotation for "user"
read_only=True, view_name="api:user-detail", lookup_field="username"
)

Expand Down Expand Up @@ -446,7 +446,7 @@
many=True,
read_only=True,
)
componentlists = serializers.HyperlinkedRelatedField(

Check failure on line 449 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

Need type annotation for "componentlists"
view_name="api:componentlist-detail",
lookup_field="slug",
many=True,
Expand All @@ -464,6 +464,12 @@
queryset=Project.objects.none(),
required=False,
)
admins = serializers.HyperlinkedRelatedField(

Check failure on line 467 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

Need type annotation for "admins"
view_name="api:user-detail",
lookup_field="username",
many=True,
read_only=True,
)

class Meta:
model = Group
Expand All @@ -480,6 +486,7 @@
"componentlists",
"components",
"enforced_2fa",
"admins",
)
extra_kwargs = { # noqa: RUF012
"url": {"view_name": "api:group-detail", "lookup_field": "id"},
Expand All @@ -488,7 +495,7 @@
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
user = self.context["request"].user
self.fields["defining_project"].queryset = user.managed_projects

Check failure on line 498 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

"Field[Any, Any, Any, Any]" has no attribute "queryset"


class ProjectSerializer(serializers.ModelSerializer[Project]):
Expand Down Expand Up @@ -565,7 +572,7 @@
def get_attribute(self, instance):
if instance.linked_component:
instance = instance.linked_component
return getattr(instance, self.source)

Check failure on line 575 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 2 to "getattr" has incompatible type "Callable[..., Any] | str | None"; expected "str"


class RepoField(LinkedField):
Expand Down Expand Up @@ -750,7 +757,7 @@
project = kwargs["context"]["project"]

if project is not None:
self.fields["category"].queryset = project.category_set.all()

Check failure on line 760 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

"Field[Any, Any, Any, Any]" has no attribute "queryset"

def validate_enforced_checks(self, value):
if not isinstance(value, list):
Expand Down Expand Up @@ -1052,7 +1059,7 @@
if data["conflicts"] == "replace-approved" and not (
denied := user.has_perm("unit.review", obj)
):
raise serializers.ValidationError({"conflicts": denied.reason})

Check failure on line 1062 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

Item "bool" of "PermissionResult | Literal[False]" has no attribute "reason"

if not (denied := check_upload_method_permissions(user, obj, data["method"])):
hint = "Check your permissions or use different translation object."
Expand Down Expand Up @@ -1194,7 +1201,7 @@
read_only_fields = ("project",)


class UnitLabelsSerializer(serializers.RelatedField, LabelSerializer):

Check failure on line 1204 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

Definition of "many_init" in base class "RelatedField" is incompatible with definition in base class "BaseSerializer"
def get_queryset(self):
"""
List of available labels for an unit.
Expand Down Expand Up @@ -1244,7 +1251,7 @@
language_code = serializers.CharField(
source="translation.language.code", read_only=True
)
source_unit = serializers.HyperlinkedRelatedField(

Check failure on line 1254 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

Need type annotation for "source_unit"
read_only=True, view_name="api:unit-detail"
)
source = PluralField()
Expand Down
Loading