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

feat: expose component locked state in component API #13035

Merged
merged 1 commit into from
Nov 15, 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
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,7 @@ Components
:>json string suggestion_voting: :ref:`component-suggestion_voting`
:>json string suggestion_autoaccept: :ref:`component-suggestion_autoaccept`
:>json string push_on_commit: :ref:`component-push_on_commit`
:>json bool locked: Whether component is locked, this field is read-only; see :http:get:`/api/components/(string:project)/(string:component)/lock/`
:>json string commit_pending_age: :ref:`component-commit_pending_age`
:>json string auto_lock_error: :ref:`component-auto_lock_error`
:>json string language_regex: :ref:`component-language_regex`
Expand Down
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Not yet released.
* A shortcut to duplicate a component is now available directly in the menu (:guilabel:`Manage` → :guilabel:`Duplicate Component`)
* Included username when generating :ref:`credits`.
* :ref:`bulk-edit` shows a preview of matched strings.
* :http:get:`/api/components/(string:project)/(string:component)/` exposes component lock state.

**Bug fixes**

Expand Down
2 changes: 2 additions & 0 deletions weblate/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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 85 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / mypy

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

Expand Down Expand Up @@ -273,7 +273,7 @@
return data


class RoleSerializer(serializers.ModelSerializer[Role]):

Check warning on line 276 in weblate/api/serializers.py

View workflow job for this annotation

GitHub Actions / API Lint

[RoleViewSet > RoleSerializer]: could not resolve serializer field "PermissionSerializer()". Defaulting to "string"
permissions = PermissionSerializer(many=True)

class Meta:
Expand Down Expand Up @@ -328,7 +328,7 @@
many=True,
read_only=True,
)
componentlists = serializers.HyperlinkedRelatedField(

Check failure on line 331 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 Down Expand Up @@ -368,7 +368,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 371 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 @@ -432,7 +432,7 @@
def get_attribute(self, instance):
if instance.linked_component:
instance = instance.linked_component
return getattr(instance, self.source)

Check failure on line 435 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 @@ -496,6 +496,7 @@
push_branch = LinkedField(
required=False, allow_blank=True, max_length=BRANCH_LENGTH
)
locked = serializers.BooleanField(read_only=True)

serializer_url_field = MultiFieldHyperlinkedIdentityField

Expand Down Expand Up @@ -595,6 +596,7 @@
"disable_autoshare",
"category",
"linked_component",
"locked",
)
extra_kwargs = {
"url": {
Expand All @@ -613,7 +615,7 @@
project = kwargs["context"]["project"]

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

Check failure on line 618 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 @@ -671,7 +673,7 @@
if "project" in self._context:
result["project"] = self._context["project"]
elif self.instance:
result["project"] = self.instance.project

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

View workflow job for this annotation

GitHub Actions / mypy

Item "Sequence[Component]" of "Component | Sequence[Component]" has no attribute "project"

# Workaround for https://github.com/encode/django-rest-framework/issues/7489
if "category" not in result:
Expand Down Expand Up @@ -703,14 +705,14 @@
if docfile is not None or zipfile is not None:
# Validate name/slug uniqueness, this has to be done prior docfile/zipfile
# extracting
instance.clean_unique_together()

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

View workflow job for this annotation

GitHub Actions / mypy

Item "Sequence[Component]" of "Component | Sequence[Component]" has no attribute "clean_unique_together"

# Handle uploaded files
if docfile is not None:
fake = create_component_from_doc(attrs, docfile)
instance.template = attrs["template"] = fake.template

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

View workflow job for this annotation

GitHub Actions / mypy

Item "Sequence[Component]" of "Component | Sequence[Component]" has no attribute "template"
instance.new_base = attrs["new_base"] = fake.template

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

View workflow job for this annotation

GitHub Actions / mypy

Item "Sequence[Component]" of "Component | Sequence[Component]" has no attribute "new_base"
instance.filemask = attrs["filemask"] = fake.filemask

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

View workflow job for this annotation

GitHub Actions / mypy

Item "Sequence[Component]" of "Component | Sequence[Component]" has no attribute "filemask"
if zipfile is not None:
try:
create_component_from_zip(attrs, zipfile)
Expand Down
Loading