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: Evaluate x-viur-bonelist on default viewSkel() (light-version) #1415

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

phorward
Copy link
Member

This is a lighter version of #1384, integrating the feature only for Singleton and List.

This is a lighter version of viur-framework#1384, integrating the feature only for `Singleton` and `List`.
@phorward phorward added feature New feature or request Priority: High After critical issues are fixed, these should be dealt with before any further issues. main labels Feb 17, 2025
@phorward phorward added this to the ViUR-core v3.7 milestone Feb 17, 2025
ArneGudermann
ArneGudermann previously approved these changes Feb 18, 2025
@@ -110,6 +112,46 @@ def baseSkel(self, *args, **kwargs) -> SkeletonInstance:
"""
return self._resolveSkelCls(*args, **kwargs)()

def skel(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've in a project already a custom quick & dirty solution, based on #1384.

    def skel_from_header(
        self,
        *args,
        bones_exclude: tuple[str, ...] | t.List[str] = (),
        **kwargs,
    ) -> SkeletonInstance:
        X_VIUR_BONELIST: t.Final[str] = "X-VIUR-BONELIST"

        skel_cls = self._resolveSkelCls(**kwargs)
        bones = set()

        if bonelist := current.request.get().request.headers.get(X_VIUR_BONELIST):
            if "*" not in skel_cls.subSkels:  # a named star-subskel "*"" must exist!
                raise errors.BadRequest(f"Use of {X_VIUR_BONELIST!r} requires for a star-subskel")
            bones |= {bone.strip() for bone in bonelist.split(",")}

        bones.difference_update(bones_exclude)

        if bones:  # Return a subskel?
            log.debug(f"{current.request.get().response.vary=}")
            current.request.get().response.vary = (X_VIUR_BONELIST, *(current.request.get().response.vary or ()))
            # When coming from outside of a request, "*" is always involved.
            return skel_cls.subskel("*", bones=bones)

        elif bones_exclude:  # Return full skel, without generally excluded bones
            bones.update(skel_cls.__boneMap__.keys())
            bones.difference_update(bones_exclude)
            return skel_cls(bones=bones)

        # Otherwise, return full skeleton
        return skel_cls()

Can you please integrate the bones_exclude param and the vary header in your method too?

@@ -110,6 +112,46 @@ def baseSkel(self, *args, **kwargs) -> SkeletonInstance:
"""
return self._resolveSkelCls(*args, **kwargs)()

def skel(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you implement this directly in baseSkel? Now you have to customize every call (baseSkel() --> skel()). If you would implement this in baseSkel, all calls could remain the same and you would be more backwards compatible.

With yet another *skel method, it only gets more complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request main Priority: High After critical issues are fixed, these should be dealt with before any further issues.
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants