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

Authenticated markdownfy_view #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vnagendra
Copy link

Added login_required to markdownfy_view method, so it is not unauthenticated.

Fixes: #194

@agusmakmun
Copy link
Owner

agusmakmun commented Mar 10, 2024

Hello @vnagendra thank you for making this changes. To support both conditionals, I think we need to custom the login_required decorator.

from django.conf import settings
from django.contrib.auth.decorators import login_required
from functools import wraps
from django.shortcuts import redirect

def login_required_or_not(view_func):
    """
    Custom decorator to make a Django view required to login or not
    based on the settings.IS_MARTOR_REQUIRED_TO_LOGIN variable.
    """
    @wraps(view_func)
    def wrapped_view(request, *args, **kwargs):
        if settings.IS_MARTOR_REQUIRED_TO_LOGIN:
            return login_required(view_func)(request, *args, **kwargs)
        else:
            return view_func(request, *args, **kwargs)

    return wrapped_view

then in the view:

@login_required_or_not
def markdownfy_view(request):
    ...

in settings.py

IS_MARTOR_REQUIRED_TO_LOGIN = True

Note: above code is not tested yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

markdownfy_view is unauthenticated - Please consider changing it
2 participants