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

differentiate between Unauthorized and Forbidden #29

Open
sveneberth opened this issue Jun 16, 2020 · 1 comment
Open

differentiate between Unauthorized and Forbidden #29

sveneberth opened this issue Jun 16, 2020 · 1 comment
Labels
feature New feature or request invalid This doesn't seem right
Milestone

Comments

@sveneberth
Copy link
Member

sveneberth commented Jun 16, 2020

In several placed in core (especially in the edit-methods) we are currently raising an Unauthorized exception.
But unauthorized means you have submitted no or invalid credentials - If you are logged in and have not the move-/edit-access it's simply just forbidden to you.
So we have to differentiate between not logged in (Unauthorized) and no access (Forbidden).

Originally annotation: https://github.com/viur-framework/viur-core/pull/28/files/dd4287cc596af96f9d39d02c24621339134f098c..1b34887b40e9d3ee6baa71fb4f69771a1a9339f5#r437333030

@sveneberth sveneberth added feature New feature or request invalid This doesn't seem right labels Jun 16, 2020
@sveneberth
Copy link
Member Author

sveneberth commented Sep 6, 2023

Just a draft of how it could be handled in the future:

def can(self, action: str) -> bool:
    if not (user := current.user.get()):
        return Reason.Deny("not loggin'ed", 401)

    if user and user["access"]:
        if not ("root" in user["access"] or f"{self.moduleName}-{action]" in user["access"]):
            return Reason.Deny("missing permissions: root, action-edit", 403)

    if user and not user["has_2fa_enabled"]:
        return Reason.Deny("you have to setup 2FA!")

    return Reason.Allow("You're nice and welcome!")

@Grashalmbeisser Grashalmbeisser added this to the Action-Skels milestone Feb 26, 2024
sveneberth pushed a commit to sveneberth/viur-core that referenced this issue Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants