-
Notifications
You must be signed in to change notification settings - Fork 55
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
internal_use_only decorator added and login url changed #229
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
217c8ec
internal_use_only decorator moved to decorators.py and login url changed
deepakdinesh1123 c305d90
frontend build updated and logout view added
deepakdinesh1123 006c8ed
PlatformUserLogoutView updated
deepakdinesh1123 187befb
add: comments and docstring
shahharsh176 a0d224f
fix: change path name
shahharsh176 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,13 @@ | ||
from django.urls import re_path | ||
from django.views.decorators.csrf import csrf_exempt | ||
|
||
from .views import * | ||
from zango.apps.shared.platformauth.views import ( | ||
PlatformUserLoginView, | ||
PlatformUserLogoutView, | ||
) | ||
|
||
|
||
urlpatterns = [ | ||
re_path( | ||
r'^login/', | ||
PlatformUserLoginView.as_view(), | ||
name='platform-login' | ||
), | ||
re_path( | ||
r'^api/v1/login/', | ||
PlatformUserLoginAPIV1.as_view(), | ||
name='platform-api-v1-login' | ||
), | ||
# url( | ||
# regex=r'^api/v1/register-user/', | ||
# view=PlatformUserRegisterAPIV1.as_view(), | ||
# name='platform-api-v1-registeruser' | ||
# ), | ||
re_path( | ||
r'^api/v1/profile/', | ||
PlatformUserProfileAPIV1.as_view(), | ||
name='platform-api-v1-userprofile' | ||
) | ||
|
||
] | ||
re_path(r"^login/", PlatformUserLoginView.as_view(), name="platform-login"), | ||
re_path(r"^logout/", PlatformUserLogoutView.as_view(), name="platform-logout"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ipaddress | ||
|
||
from django.conf import settings | ||
from django.http import Http404 | ||
from ipware.ip import get_client_ip | ||
|
||
|
||
def internal_access_only(f): | ||
""" | ||
Decorator to restrict access to views based on internal IP addresses. | ||
|
||
Args: | ||
f (callable): The view function to decorate. | ||
|
||
Returns: | ||
callable: Decorated view function. | ||
|
||
Raises: | ||
Http404: If the client's IP is not in the list of allowed IPs and the environment is 'staging' or 'prod'. | ||
|
||
""" | ||
|
||
def decorate_view(request, *args, **kwargs): | ||
client_ip, is_routable = get_client_ip(request) | ||
allowed_ips = [ipaddress.ip_network(ip) for ip in settings.INTERNAL_IPS] | ||
if settings.ENV in ["staging", "prod"]: | ||
# Check if the client's IP is not in the allowed IPs | ||
if not any(ipaddress.ip_address(client_ip) in ip for ip in allowed_ips): | ||
# Raise a 404 error if the condition is met | ||
raise Http404 | ||
return f(request, *args, **kwargs) | ||
|
||
return decorate_view |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should enforce internal_ip in a blanket way for all platform endpoints.