feed generation and accounts WIP
This commit is contained in:
+39
-16
@@ -30,6 +30,13 @@ async def read_feed(
|
||||
)
|
||||
feed.fill(feed_data)
|
||||
|
||||
groupname = get_groupname_by_feed_id(conn, feed_id)
|
||||
if groupname is None:
|
||||
return HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="No such feed",
|
||||
)
|
||||
|
||||
if not check_membership_exists(conn, current_user.username, groupname) and current_user.role not in settings.settings.admin_roles:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
@@ -39,21 +46,13 @@ async def read_feed(
|
||||
return feed
|
||||
|
||||
|
||||
# maybe to delete
|
||||
@feeds_router.post("/add")
|
||||
async def add_feed(
|
||||
feed_id: int,
|
||||
picture_id: int,
|
||||
value: int,
|
||||
groupname: str,
|
||||
conn: Annotated[connection, Depends(get_db_connection)],
|
||||
current_user: Annotated[User, Depends(get_current_user)]
|
||||
):
|
||||
groupname = get_groupname_by_feed_id(conn, feed_id)
|
||||
if groupname is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="No such feed or feed is not linked to group",
|
||||
)
|
||||
|
||||
group = Group()
|
||||
group_data = get_group(conn, groupname)
|
||||
if group_data is None:
|
||||
@@ -63,26 +62,50 @@ async def add_feed(
|
||||
)
|
||||
group.fill(group_data)
|
||||
|
||||
if value == 0 and group.allow_skips is False:
|
||||
if group.author != current_user.username and current_user.role not in settings.settings.admin_roles:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Skips are disallowed",
|
||||
detail="Not allowed",
|
||||
)
|
||||
return db.create_feed(conn, current_user.username, feed_id, picture_id, value)
|
||||
|
||||
return db.create_feed(conn, groupname, []) # TODO: image list
|
||||
|
||||
|
||||
# maybe to delete
|
||||
@feeds_router.post("/delete")
|
||||
async def delete_feed(
|
||||
username: str,
|
||||
feed_id: int,
|
||||
picture_id: int,
|
||||
conn: Annotated[connection, Depends(get_db_connection)],
|
||||
current_user: Annotated[User, Depends(get_current_user)]
|
||||
):
|
||||
if current_user.role in settings.settings.admin_roles:
|
||||
return db.delete_feed(conn, username, feed_id, picture_id)
|
||||
return db.delete_feed(conn, feed_id)
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Not allowed",
|
||||
)
|
||||
|
||||
|
||||
@feeds_router.post("/reset")
|
||||
async def reset_feed(
|
||||
groupname: str,
|
||||
conn: Annotated[connection, Depends(get_db_connection)],
|
||||
current_user: Annotated[User, Depends(get_current_user)]
|
||||
):
|
||||
group = Group()
|
||||
group_data = get_group(conn, groupname)
|
||||
if group_data is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="No such group",
|
||||
)
|
||||
group.fill(group_data)
|
||||
|
||||
if group.author != current_user.username and current_user.role not in settings.settings.admin_roles:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Not allowed",
|
||||
)
|
||||
|
||||
return db.create_feed(conn, groupname, []) # TODO: image list
|
||||
|
||||
+15
-2
@@ -18,14 +18,12 @@ class User(BaseModel):
|
||||
self.password = params["password"]
|
||||
self.role = params["role"]
|
||||
self.disabled = params["disabled"]
|
||||
self.groups_ids = params["groups_ids"]
|
||||
self.last_seen_at = params["last_seen_at"]
|
||||
self.created_at = params["created_at"]
|
||||
username: str = ""
|
||||
password: str = ""
|
||||
role: str = "user"
|
||||
disabled: bool = False
|
||||
groups_ids: list[str] | None = None
|
||||
last_seen_at: datetime | None = None
|
||||
created_at: datetime | None = None
|
||||
|
||||
@@ -98,3 +96,18 @@ class Feed(BaseModel):
|
||||
groupname: str = ""
|
||||
image_ids: list[int] = []
|
||||
created_at: datetime | None = None
|
||||
|
||||
|
||||
class Account(BaseModel):
|
||||
def fill(self, params):
|
||||
self.id = params["id"]
|
||||
self.platform = params["platform"]
|
||||
self.login = params["login"]
|
||||
self.metadata = params["metadata"]
|
||||
self.created_at = params["created_at"]
|
||||
id: int = -1
|
||||
platform: str = ""
|
||||
login: str = ""
|
||||
password: str = ""
|
||||
metadata: dict = {}
|
||||
created_at: datetime | None = None
|
||||
|
||||
Reference in New Issue
Block a user