-
Notifications
You must be signed in to change notification settings - Fork 920
Dev #557
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
base: master
Are you sure you want to change the base?
Dev #557
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||
from rest_framework.generics import GenericAPIView | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
from accounts import swagger_params1 | ||||||||||||||||||||||||||||||||||||||||||||||
from accounts.models import Account, Tags | ||||||||||||||||||||||||||||||||||||||||||||||
from accounts.models import Account | ||||||||||||||||||||||||||||||||||||||||||||||
from accounts.serializer import ( | ||||||||||||||||||||||||||||||||||||||||||||||
AccountCreateSerializer, | ||||||||||||||||||||||||||||||||||||||||||||||
AccountSerializer, | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -29,7 +29,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||
from teams.serializer import TeamsSerializer | ||||||||||||||||||||||||||||||||||||||||||||||
from accounts.tasks import send_email, send_email_to_assigned_user | ||||||||||||||||||||||||||||||||||||||||||||||
from cases.serializer import CaseSerializer | ||||||||||||||||||||||||||||||||||||||||||||||
from common.models import Attachments, Comment, Profile | ||||||||||||||||||||||||||||||||||||||||||||||
from common.models import Attachments, Comment, Profile, Tag | ||||||||||||||||||||||||||||||||||||||||||||||
from leads.models import Lead | ||||||||||||||||||||||||||||||||||||||||||||||
from leads.serializer import LeadSerializer | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -130,7 +130,7 @@ def get_context_data(self, **kwargs): | |||||||||||||||||||||||||||||||||||||||||||||
context["countries"] = COUNTRIES | ||||||||||||||||||||||||||||||||||||||||||||||
context["industries"] = INDCHOICES | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
tags = Tags.objects.all() | ||||||||||||||||||||||||||||||||||||||||||||||
tags = Tag.objects.all() | ||||||||||||||||||||||||||||||||||||||||||||||
tags = TagsSerailizer(tags, many=True).data | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+133
to
134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect serializer name for tags. Below is a suggested fix: - from accounts.serializer import (
- AccountCreateSerializer,
- AccountSerializer,
- EmailSerializer,
- TagsSerailizer,
- ...
- )
+ from accounts.serializer import (
+ AccountCreateSerializer,
+ AccountSerializer,
+ EmailSerializer,
+ TagsSerializer,
+ ...
+ )
...
- tags = TagsSerailizer(tags, many=True).data
+ tags = TagsSerializer(tags, many=True).data 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
context["tags"] = tags | ||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# fastapi_app/main.py | ||
import os | ||
import django | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "crm.settings") | ||
django.setup() | ||
|
||
from fastapi import FastAPI, Response | ||
from apiv2.routers import users, leads, auth, org | ||
from fastapi import Request | ||
|
||
app = FastAPI(title="CRM API", version="1.0.0") | ||
|
||
|
||
@app.middleware("http") | ||
async def log_request(request: Request, call_next): | ||
body = await request.body() | ||
print("Request body:", body) # or use proper logging | ||
# response = await call_next(request) | ||
|
||
org = request.headers.get("org") | ||
if org is None: | ||
# Optionally, handle the missing header (e.g., assign a default or raise an error) | ||
org = "default_org_value" | ||
# Store it in request.state for later access in endpoints | ||
request.state.org = org | ||
response: Response = await call_next(request) | ||
return response | ||
|
||
# Include routers | ||
app.include_router(auth.router, prefix="/api/auth", tags=["Auth"]) | ||
app.include_router(org.router, prefix="/api/org", tags=["Org"]) | ||
app.include_router(users.router, prefix="/api/users", tags=["Users"]) | ||
app.include_router(leads.router, prefix="/api/leads", tags=["Leads"]) | ||
# app.include_router(leads.router, prefix="/api/leads", tags=["Leads"]) | ||
# app.include_router(tasks.router, prefix="/api/tasks", tags=["Tasks"]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# fastapi_app/routers/users.py | ||
from common.models import User # Django model | ||
import requests | ||
from fastapi import APIRouter, HTTPException, Request | ||
from pydantic import BaseModel | ||
from rest_framework_simplejwt.tokens import RefreshToken | ||
from django.contrib.auth.hashers import make_password | ||
from django.contrib.auth.models import BaseUserManager | ||
router = APIRouter() | ||
|
||
class SocialLoginSerializer(BaseModel): | ||
token: str | ||
|
||
@router.post("/google", summary="Login through Google") | ||
def google_login(payload: SocialLoginSerializer, request: Request): | ||
access_token = payload.token | ||
|
||
|
||
# Validate token with Google | ||
print("Google response:", access_token) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove debug print statements. Debug print statements should not be included in production code as they could expose sensitive information and clutter logs. - print("Google response:", access_token)
response = requests.get(
'https://www.googleapis.com/oauth2/v2/userinfo',
params={'access_token': access_token}
)
data = response.json()
- print("Google response data:", data)
if 'error' in data:
raise HTTPException(status_code=400, detail="Invalid or expired Google token") Also applies to: 27-27 |
||
response = requests.get( | ||
'https://www.googleapis.com/oauth2/v2/userinfo', | ||
params={'access_token': access_token} | ||
) | ||
data = response.json() | ||
|
||
print("Google response data:", data) | ||
if 'error' in data: | ||
raise HTTPException(status_code=400, detail="Invalid or expired Google token") | ||
|
||
# Get or create user using Django ORM | ||
try: | ||
user = User.objects.get(email=data['email']) | ||
except User.DoesNotExist: | ||
user = User( | ||
email=data['email'], | ||
profile_pic=data.get('picture', ''), | ||
password=make_password(BaseUserManager().make_random_password()) | ||
) | ||
user.save() | ||
|
||
# Generate JWT tokens using Django's SimpleJWT | ||
token = RefreshToken.for_user(user) | ||
return { | ||
"username": user.email, | ||
"access_token": str(token.access_token), | ||
"refresh_token": str(token), | ||
"user_id": user.id | ||
} | ||
|
||
|
||
|
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.
💡 Verification agent
🧩 Analysis chain
Check for potential serializer field mapping issues
While the model has been updated, it's important to verify that the fields specified in the serializer (
id
,name
,slug
) are all available in the newTag
model. Based on the providedcommon/models.py
snippet, theTag
model has additional fields likecolor
anddescription
that might be useful to include.You may want to run the following command to verify field mapping:
🏁 Script executed:
Length of output: 1313
Action: Update the serializer field mapping for the Tag model.
It appears that the current serializer in
accounts/serializer.py
(lines 16–19) still references("id", "name", "slug")
. However, based on the updatedTag
model incommon/models.py
, the model now includes the fieldsorg
,name
,color
, anddescription
(along with the defaultid
field), and it does not define aslug
field. Please review whether:slug
field is intended to be a computed property (in which case, add the necessary logic in the serializer) or it has been removed in favor of the new fields.color
anddescription
(and possiblyorg
if relevant) in your serializer.Adjusting the serializer to correctly map to the current model is necessary to avoid runtime errors or unintended behavior.