Skip to content

Commit

Permalink
adding authotization for role admin or visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
danilojezernik committed Aug 26, 2024
1 parent 8b84048 commit 8a4ac5a
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/database/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
kategorija='angular',
podnaslov='Test Podnaslov 1',
datum_vnosa=datetime.datetime.now(),
vsebina='Test Vsebina 1',
vsebina='<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam dictum pellentesque ornare. Integer pulvinar, diam sed consequat pulvinar, justo tortor cursus metus, gravida tincidunt orci sapien vitae orci. Integer id facilisis erat, ac commodo urna. Sed congue ante aliquet magna tempor laoreet. Mauris vel nisl porta, venenatis quam id, consequat est. Praesent vulputate et ipsum a posuere. Vestibulum arcu magna, iaculis sit amet pharetra sodales, aliquet vitae elit. Aenean nec mi urna. Etiam sit amet laoreet quam. Aenean a risus quis diam consectetur volutpat. Nulla facilisi. Proin tempor accumsan risus, vitae vulputate diam aliquet a.</p><p>Quisque accumsan luctus elit vel tempus. Mauris at justo vestibulum, feugiat ipsum sit amet, sollicitudin nisl. Aliquam at tincidunt nunc. Vivamus quis lacinia leo, quis ornare justo. Proin elit nunc, mattis at fermentum a, rutrum eget turpis. Aenean posuere arcu vel ipsum eleifend, sed pharetra risus placerat. Donec sem sapien, mattis ut convallis eget, tincidunt a lacus. Pellentesque vel lectus eros. Vestibulum finibus fringilla ipsum vitae vehicula. Nulla aliquam eleifend bibendum. Donec vitae lacinia odio, a consequat velit. Morbi volutpat condimentum justo, nec tempor dui venenatis ac. Maecenas porttitor enim vel urna condimentum dignissim.</p><p>Suspendisse interdum mauris et ligula aliquet, at gravida nulla maximus. Sed augue arcu, interdum sit amet consectetur non, faucibus vel magna. Quisque ac ex justo. Praesent scelerisque nibh nec lacinia pulvinar. Nullam nisl est, consequat ut dolor at, placerat venenatis risus. Donec aliquet pulvinar ex, nec hendrerit justo pulvinar varius. Pellentesque eget mauris eu purus accumsan cursus eget vel lorem.</p><p>Morbi sed dolor malesuada justo iaculis varius. Donec maximus tempus scelerisque. Mauris in lacus varius, tristique lacus vel, ornare justo. Donec tincidunt, purus sed feugiat fringilla, massa purus suscipit purus, vitae blandit augue sem ut sapien. Nulla at lorem volutpat, rutrum lacus ut, bibendum ex. Interdum et malesuada fames ac ante ipsum primis in faucibus. Duis sagittis mi ut lacus tincidunt, varius venenatis diam congue. Nam blandit orci a nisi porttitor, eget euismod nulla varius. Sed venenatis arcu in scelerisque laoreet. Nam vitae placerat nunc. Phasellus rhoncus erat ut maximus maximus. Curabitur quis consectetur quam.</p><p>Aliquam tincidunt lectus in elit laoreet, ac pretium eros porttitor. Sed et mauris tincidunt, maximus ante sit amet, tristique erat. Maecenas non consectetur nibh, a tempus ipsum. Pellentesque quis nunc non nisi gravida fringilla sed ut quam. Praesent malesuada velit et pharetra placerat. Nam metus diam, vulputate ut venenatis sit amet, consectetur vitae enim. Mauris sed neque luctus, interdum lectus vitae, placerat ante. Vivamus sed ullamcorper tellus. Sed viverra felis metus, quis efficitur dui fermentum in. Pellentesque sed elit vel erat gravida vestibulum vestibulum eget lacus.</p><p>Etiam sed imperdiet tortor. Fusce porta quam lectus, vitae porta metus placerat vel. Vivamus quis porttitor dolor. Aenean sodales turpis ac nulla dictum, laoreet fermentum arcu hendrerit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed pharetra elit quis sem blandit, eu ornare sem mollis. Phasellus eu bibendum est, ac cursus dui. Aenean vel dictum dolor, in condimentum turpis. In hac habitasse platea dictumst. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed aliquam scelerisque eros non congue. Nullam posuere urna ac diam iaculis varius.</p>',
image='test1.jpg'
).dict(by_alias=True),
Blog(
title='Test Naslov 2',
kategorija='angular',
podnaslov='Test Podnaslov 2',
datum_vnosa=datetime.datetime.now(),
vsebina='Test Vsebina 2',
vsebina='<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam dictum pellentesque ornare. Integer pulvinar, diam sed consequat pulvinar, justo tortor cursus metus, gravida tincidunt orci sapien vitae orci. Integer id facilisis erat, ac commodo urna. Sed congue ante aliquet magna tempor laoreet. Mauris vel nisl porta, venenatis quam id, consequat est. Praesent vulputate et ipsum a posuere. Vestibulum arcu magna, iaculis sit amet pharetra sodales, aliquet vitae elit. Aenean nec mi urna. Etiam sit amet laoreet quam. Aenean a risus quis diam consectetur volutpat. Nulla facilisi. Proin tempor accumsan risus, vitae vulputate diam aliquet a.</p><p>Quisque accumsan luctus elit vel tempus. Mauris at justo vestibulum, feugiat ipsum sit amet, sollicitudin nisl. Aliquam at tincidunt nunc. Vivamus quis lacinia leo, quis ornare justo. Proin elit nunc, mattis at fermentum a, rutrum eget turpis. Aenean posuere arcu vel ipsum eleifend, sed pharetra risus placerat. Donec sem sapien, mattis ut convallis eget, tincidunt a lacus. Pellentesque vel lectus eros. Vestibulum finibus fringilla ipsum vitae vehicula. Nulla aliquam eleifend bibendum. Donec vitae lacinia odio, a consequat velit. Morbi volutpat condimentum justo, nec tempor dui venenatis ac. Maecenas porttitor enim vel urna condimentum dignissim.</p><p>Suspendisse interdum mauris et ligula aliquet, at gravida nulla maximus. Sed augue arcu, interdum sit amet consectetur non, faucibus vel magna. Quisque ac ex justo. Praesent scelerisque nibh nec lacinia pulvinar. Nullam nisl est, consequat ut dolor at, placerat venenatis risus. Donec aliquet pulvinar ex, nec hendrerit justo pulvinar varius. Pellentesque eget mauris eu purus accumsan cursus eget vel lorem.</p><p>Morbi sed dolor malesuada justo iaculis varius. Donec maximus tempus scelerisque. Mauris in lacus varius, tristique lacus vel, ornare justo. Donec tincidunt, purus sed feugiat fringilla, massa purus suscipit purus, vitae blandit augue sem ut sapien. Nulla at lorem volutpat, rutrum lacus ut, bibendum ex. Interdum et malesuada fames ac ante ipsum primis in faucibus. Duis sagittis mi ut lacus tincidunt, varius venenatis diam congue. Nam blandit orci a nisi porttitor, eget euismod nulla varius. Sed venenatis arcu in scelerisque laoreet. Nam vitae placerat nunc. Phasellus rhoncus erat ut maximus maximus. Curabitur quis consectetur quam.</p><p>Aliquam tincidunt lectus in elit laoreet, ac pretium eros porttitor. Sed et mauris tincidunt, maximus ante sit amet, tristique erat. Maecenas non consectetur nibh, a tempus ipsum. Pellentesque quis nunc non nisi gravida fringilla sed ut quam. Praesent malesuada velit et pharetra placerat. Nam metus diam, vulputate ut venenatis sit amet, consectetur vitae enim. Mauris sed neque luctus, interdum lectus vitae, placerat ante. Vivamus sed ullamcorper tellus. Sed viverra felis metus, quis efficitur dui fermentum in. Pellentesque sed elit vel erat gravida vestibulum vestibulum eget lacus.</p><p>Etiam sed imperdiet tortor. Fusce porta quam lectus, vitae porta metus placerat vel. Vivamus quis porttitor dolor. Aenean sodales turpis ac nulla dictum, laoreet fermentum arcu hendrerit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed pharetra elit quis sem blandit, eu ornare sem mollis. Phasellus eu bibendum est, ac cursus dui. Aenean vel dictum dolor, in condimentum turpis. In hac habitasse platea dictumst. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed aliquam scelerisque eros non congue. Nullam posuere urna ac diam iaculis varius.</p>',
image='test2.jpg'
).dict(by_alias=True),
Blog(
title='Test Naslov 3',
kategorija='angular',
podnaslov='Test Podnaslov 3',
datum_vnosa=datetime.datetime.now(),
vsebina='Test Vsebina 3',
vsebina='<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam dictum pellentesque ornare. Integer pulvinar, diam sed consequat pulvinar, justo tortor cursus metus, gravida tincidunt orci sapien vitae orci. Integer id facilisis erat, ac commodo urna. Sed congue ante aliquet magna tempor laoreet. Mauris vel nisl porta, venenatis quam id, consequat est. Praesent vulputate et ipsum a posuere. Vestibulum arcu magna, iaculis sit amet pharetra sodales, aliquet vitae elit. Aenean nec mi urna. Etiam sit amet laoreet quam. Aenean a risus quis diam consectetur volutpat. Nulla facilisi. Proin tempor accumsan risus, vitae vulputate diam aliquet a.</p><p>Quisque accumsan luctus elit vel tempus. Mauris at justo vestibulum, feugiat ipsum sit amet, sollicitudin nisl. Aliquam at tincidunt nunc. Vivamus quis lacinia leo, quis ornare justo. Proin elit nunc, mattis at fermentum a, rutrum eget turpis. Aenean posuere arcu vel ipsum eleifend, sed pharetra risus placerat. Donec sem sapien, mattis ut convallis eget, tincidunt a lacus. Pellentesque vel lectus eros. Vestibulum finibus fringilla ipsum vitae vehicula. Nulla aliquam eleifend bibendum. Donec vitae lacinia odio, a consequat velit. Morbi volutpat condimentum justo, nec tempor dui venenatis ac. Maecenas porttitor enim vel urna condimentum dignissim.</p><p>Suspendisse interdum mauris et ligula aliquet, at gravida nulla maximus. Sed augue arcu, interdum sit amet consectetur non, faucibus vel magna. Quisque ac ex justo. Praesent scelerisque nibh nec lacinia pulvinar. Nullam nisl est, consequat ut dolor at, placerat venenatis risus. Donec aliquet pulvinar ex, nec hendrerit justo pulvinar varius. Pellentesque eget mauris eu purus accumsan cursus eget vel lorem.</p><p>Morbi sed dolor malesuada justo iaculis varius. Donec maximus tempus scelerisque. Mauris in lacus varius, tristique lacus vel, ornare justo. Donec tincidunt, purus sed feugiat fringilla, massa purus suscipit purus, vitae blandit augue sem ut sapien. Nulla at lorem volutpat, rutrum lacus ut, bibendum ex. Interdum et malesuada fames ac ante ipsum primis in faucibus. Duis sagittis mi ut lacus tincidunt, varius venenatis diam congue. Nam blandit orci a nisi porttitor, eget euismod nulla varius. Sed venenatis arcu in scelerisque laoreet. Nam vitae placerat nunc. Phasellus rhoncus erat ut maximus maximus. Curabitur quis consectetur quam.</p><p>Aliquam tincidunt lectus in elit laoreet, ac pretium eros porttitor. Sed et mauris tincidunt, maximus ante sit amet, tristique erat. Maecenas non consectetur nibh, a tempus ipsum. Pellentesque quis nunc non nisi gravida fringilla sed ut quam. Praesent malesuada velit et pharetra placerat. Nam metus diam, vulputate ut venenatis sit amet, consectetur vitae enim. Mauris sed neque luctus, interdum lectus vitae, placerat ante. Vivamus sed ullamcorper tellus. Sed viverra felis metus, quis efficitur dui fermentum in. Pellentesque sed elit vel erat gravida vestibulum vestibulum eget lacus.</p><p>Etiam sed imperdiet tortor. Fusce porta quam lectus, vitae porta metus placerat vel. Vivamus quis porttitor dolor. Aenean sodales turpis ac nulla dictum, laoreet fermentum arcu hendrerit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed pharetra elit quis sem blandit, eu ornare sem mollis. Phasellus eu bibendum est, ac cursus dui. Aenean vel dictum dolor, in condimentum turpis. In hac habitasse platea dictumst. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed aliquam scelerisque eros non congue. Nullam posuere urna ac diam iaculis varius.</p>',
image='test3.jpg'
).dict(by_alias=True),
]
1 change: 1 addition & 0 deletions src/database/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
content='Kalkuliranje preprostih izračunov za izračun stopinj',
github='',
website='',
image='',
datum_vnosa=datetime.datetime.now()
).dict(by_alias=True)
]
9 changes: 3 additions & 6 deletions src/database/technology.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,23 @@
Technology(
technology='Angular',
title='Angular interview questions',
subtitle='Angular je framework, ki ga dela Google in je zelo priljubljen. V tem članku bomo pregledali nekaj '
'vprašanj, ki se pogosto pojavljajo na tehničnih razgovorih.',
subtitle='Angular je framework, ki ga dela Google in je zelo priljubljen.',
vsebina='Angular je odprtokodni JavaScriptov ogrodje, ki ga uporabljajo za razvoj enostranskih aplikacij. ',
image='angular1.jpg',
datum_vnosa=datetime.datetime.now(),
).dict(by_alias=True),
Technology(
technology='Vue',
title='Vue interview questions',
subtitle='Vue je framework, ki ga dela Google in je zelo priljubljen. V tem članku bomo pregledali nekaj '
'vprašanj, ki se pogosto pojavljajo na tehničnih razgovorih.',
subtitle='Vue je framework, ki ga dela Google in je zelo priljubljen.',
vsebina='Vue je odprtokodni JavaScriptov ogrodje, ki ga uporabljajo za razvoj enostranskih aplikacij. ',
image='vue2.jpg',
datum_vnosa=datetime.datetime.now(),
).dict(by_alias=True),
Technology(
technology='Typescript',
title='Typescript interview questions',
subtitle='Typescript je framework, ki ga dela Google in je zelo priljubljen. V tem članku bomo pregledali nekaj'
'vprašanj, ki se pogosto pojavljajo na tehničnih razgovorih.',
subtitle='Typescript je framework, ki ga dela Google in je zelo priljubljen.',
vsebina='Typescript je odprtokodni JavaScriptov ogrodje, ki ga uporabljajo za razvoj enostranskih aplikacij. ',
image='typescript2.jpg',
datum_vnosa=datetime.datetime.now(),
Expand Down
16 changes: 16 additions & 0 deletions src/database/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
technology='JavaScript, Python, MongoDB, FastAPI,...',
description='Sem zavzet softvare developer in imam nekaj izkušenj',
hashed_password='$2b$12$/4Ku22NMcxccpiFaIMDJheezk0Q0eDHGyvod3FaToy.BqfaDXM2km',
role='admin',
disabled=False,
confirmed=False,
registered=True,
blog_notification=False,
datum_vnosa=datetime.datetime.now()
).dict(by_alias=True),
User(
username='danitest',
email='[email protected]',
full_name='Danilo Jezernik',
profession='Software inženir',
technology='JavaScript, Python, MongoDB, FastAPI,...',
description='Sem zavzet softvare developer in imam nekaj izkušenj',
hashed_password='$2b$12$/4Ku22NMcxccpiFaIMDJheezk0Q0eDHGyvod3FaToy.BqfaDXM2km',
role='visitor',
disabled=False,
confirmed=False,
registered=True,
Expand Down
1 change: 1 addition & 0 deletions src/domain/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ class Projects(BaseModel):
content: str
github: str
website: str
image: str
datum_vnosa: datetime.datetime = Field(default_factory=datetime.datetime.now)
1 change: 1 addition & 0 deletions src/domain/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class User(BaseModel):
technology: Optional[str] = ''
description: str
hashed_password: str
role: str
confirmed: bool
registered: bool
blog_notification: bool
Expand Down
Binary file added src/media/blogs_media/card-kalika.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/media/projects_media/imports.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface Projects {
content: string;
github: string;
website: string;
image: string;
datum_vnosa: string;
}

Expand Down Expand Up @@ -111,6 +112,7 @@ export interface User {
technology: string;
description: string;
hashed_password: string;
role: string;
confirmed: boolean;
registered: boolean;
blog_notification: boolean;
Expand Down
5 changes: 3 additions & 2 deletions src/routes/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
from fastapi.responses import FileResponse

from src.domain.blog import Blog
from src.domain.user import User
from src.services import db, blog_notification
from src.services.security import get_current_user
from src.services.security import get_current_user, require_role
from src.template import blog_notifications

# Define the root media directory and the subdirectory for media files
Expand Down Expand Up @@ -141,7 +142,7 @@ async def get_blog_by_id_private(_id: str, current_user: str = Depends(get_curre

# This route adds a new blog
@router.post('/', operation_id='add_new_blog_private')
async def add_new_blog(blog: Blog, current_user: str = Depends(get_current_user)) -> Blog | None:
async def add_new_blog(blog: Blog, current_user: User = Depends(require_role('admin'))) -> Blog | None:
"""
Handles the addition of a new blog to the database.
Expand Down
Loading

0 comments on commit 8a4ac5a

Please sign in to comment.