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

Raw Data API Improvement #238

Closed
wants to merge 48 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
96dc935
Remove back slash
KafayatYusuf Mar 22, 2024
f42a967
Removed backslash
KafayatYusuf Mar 22, 2024
12b3bee
Removed trailing slash at the Auth endpoint
KafayatYusuf Mar 22, 2024
fa4d70d
Added google docstrings to Auth endpoint
KafayatYusuf Mar 22, 2024
ab6232b
Corrected grammatical errors and punctuations
KafayatYusuf Mar 22, 2024
0411b3d
Corrected spelling errors and punctuation
KafayatYusuf Mar 22, 2024
896c6e7
Added status response codes
KafayatYusuf Mar 22, 2024
dee822a
Deleted an import function
KafayatYusuf Mar 22, 2024
8f9a8f3
Removed my client ID and secret
KafayatYusuf Mar 22, 2024
8311cdc
Updated the README Markdown
KafayatYusuf Mar 23, 2024
4961a38
Updated the google docstrings used in classes and functions
KafayatYusuf Mar 23, 2024
38c365d
Updated the manual markdown
KafayatYusuf Mar 23, 2024
1d12047
Fixed indentation error after else
KafayatYusuf Mar 23, 2024
0a82ea4
Created a directory called "error_module" in src folder to import Err…
KafayatYusuf Mar 23, 2024
fd95ee8
Imported ErrorMessage from src
KafayatYusuf Mar 23, 2024
b525565
Imported some libraries in the terminal
KafayatYusuf Mar 23, 2024
bac89c5
Added google docstring to function
KafayatYusuf Mar 23, 2024
979962e
Added docstrings to login endpoint
KafayatYusuf Mar 23, 2024
ebf4cdf
Remove trailing slashes from extract endpoint
KafayatYusuf Mar 23, 2024
db61bfb
Removed trailing slashes in tasks endpoint
KafayatYusuf Mar 23, 2024
20a1697
Removed trailing slash from stats endpoint
KafayatYusuf Mar 23, 2024
43409bb
Removed the trailing slashes that were not taken out from tasks endpo…
KafayatYusuf Mar 23, 2024
193f4f3
Updated status response codes on auth endpoint
KafayatYusuf Mar 23, 2024
1ff73e4
Added docker-compose-config.txt to gitignore so as not make changes t…
KafayatYusuf Mar 24, 2024
905d81e
Cleared osm client id and secret as it was showing from the previous …
KafayatYusuf Mar 24, 2024
1312f95
Removed docker-compose-config from it as it didn't reflect the change…
KafayatYusuf Mar 24, 2024
d25b30f
Changed 200 status response code from 'OK' to 'Successful Response'
KafayatYusuf Mar 24, 2024
685116c
Changed auth login response code from 'OK' to 'Successful Response'
KafayatYusuf Mar 24, 2024
edff361
Removed trailing slash from custom exports endpoint
KafayatYusuf Mar 24, 2024
0ac9718
Removed trailing slash hdx endpoint
KafayatYusuf Mar 24, 2024
e6a776f
Added API description to the app
KafayatYusuf Mar 25, 2024
9bf9417
Added security feature to endpoints
KafayatYusuf Mar 26, 2024
e7a23c9
Updated the security feature
KafayatYusuf Mar 27, 2024
462144c
Corrected manual markdown grammatical speling error
KafayatYusuf Mar 27, 2024
8fdf9a8
Updated json _schema_extra
KafayatYusuf Mar 27, 2024
f0aff07
Updated schema example
KafayatYusuf Mar 27, 2024
3090b5e
Added a non-empty "tags" array
KafayatYusuf Mar 27, 2024
8fb9fea
Shortened operationId to be less than 50 characters
KafayatYusuf Mar 27, 2024
1f41db8
Updated status response codes
KafayatYusuf Mar 28, 2024
7278a4b
I imported the request library and wrote a display message
KafayatYusuf Mar 29, 2024
b5ccf6d
Updated the welcome message
KafayatYusuf Mar 29, 2024
5bb48ea
Added color compose
KafayatYusuf Mar 29, 2024
ab14d53
Changed download_url to downloadUrl
KafayatYusuf Mar 30, 2024
d912924
Included downloadUrl within "result" object
KafayatYusuf Mar 31, 2024
e90512e
Fixed a syntax error
KafayatYusuf Mar 31, 2024
700634b
Added the other keywords to the required property
KafayatYusuf Mar 31, 2024
e027067
Added the missing responses to the responses object
KafayatYusuf Apr 1, 2024
d544ee2
Added an item to the "tags" array
KafayatYusuf Apr 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated the google docstrings used in classes and functions
KafayatYusuf committed Mar 23, 2024
commit 4961a38ab195675ab7e8ac84c72fd2476bc7633d
28 changes: 7 additions & 21 deletions API/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -10,39 +10,32 @@


class UserRole(Enum):
"""
Assigning user roles as integer
"""Assigning user roles as integer"""
ADMIN = 1
STAFF = 2
GUEST = 3
"""


class AuthUser(BaseModel):
"""
Defining fields as attributes
"""Defining fields as attributes"""
id: int
username: str
img_url: Union[str, None]
role: UserRole = Field(default=UserRole.GUEST.value)
"""


osm_auth = Auth(*get_oauth_credentials())


def get_user_from_db(osm_id: int):
"""
Get user's information (osm_id)
"""Get user's information (osm_id)"""
auth = Users()
user = auth.read_user(osm_id)
"""
return user


def get_osm_auth_user(access_token):
"""
Get user's access token
"""Get user's access token"""
try:
user = AuthUser(**osm_auth.deserialize_access_token(access_token))
except Exception as ex:
@@ -51,7 +44,6 @@ def get_osm_auth_user(access_token):
)
db_user = get_user_from_db(user.id)
user.role = db_user["role"]
"""
return user


@@ -61,29 +53,24 @@ def login_required(access_token: str = Header(...)):


def get_optional_user(access_token: str = Header(default=None)) -> AuthUser:
"""
Get user's access token which is optional
"""Get user's access token which is optional"""
if access_token:
return get_osm_auth_user(access_token)
else:
# If no token provided, return a user with limited options or guest user
"""
return AuthUser(id=0, username="guest", img_url=None)


def admin_required(user: AuthUser = Depends(login_required)):
"""
Get admin login details
"""Get admin login details"""
db_user = get_user_from_db(user.id)
if not db_user["role"] is UserRole.ADMIN.value:
raise HTTPException(status_code=403, detail="User is not an admin")
"""
return user


def staff_required(user: AuthUser = Depends(login_required)):
"""
Get staff login details
"""Get staff login details"""
db_user = get_user_from_db(user.id)

# admin is staff too
@@ -92,5 +79,4 @@ def staff_required(user: AuthUser = Depends(login_required)):
or db_user["role"] is UserRole.ADMIN.value
):
raise HTTPException(status_code=403, detail="User is not a staff")
"""
return user