mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
Merge remote-tracking branch 'origin/master' into fix/user-protected-urls
This commit is contained in:
@@ -28,12 +28,12 @@ def heartbeat() -> HeartbeatResponse:
|
||||
|
||||
return {
|
||||
"VERSION": get_version(),
|
||||
"SETUP_WIZARD": len(db_user_handler.get_admin_users()) == 0,
|
||||
"SHOW_SETUP_WIZARD": len(db_user_handler.get_admin_users()) == 0,
|
||||
"ANY_SOURCE_ENABLED": IGDB_API_ENABLED or MOBY_API_ENABLED,
|
||||
"STEAMGRIDDB_ENABLED": STEAMGRIDDB_API_ENABLED,
|
||||
"METADATA_SOURCES": {
|
||||
"IGDB_API_ENABLED": IGDB_API_ENABLED,
|
||||
"MOBY_API_ENABLED": MOBY_API_ENABLED,
|
||||
"STEAMGRIDDB_ENABLED": STEAMGRIDDB_API_ENABLED,
|
||||
},
|
||||
"FS_PLATFORMS": fs_platform_handler.get_platforms(),
|
||||
"WATCHER": {
|
||||
|
||||
@@ -19,14 +19,14 @@ class SchedulerDict(TypedDict):
|
||||
class MetadataSourcesDict(TypedDict):
|
||||
IGDB_API_ENABLED: bool
|
||||
MOBY_API_ENABLED: bool
|
||||
STEAMGRIDDB_ENABLED: bool
|
||||
|
||||
|
||||
class HeartbeatResponse(TypedDict):
|
||||
VERSION: str
|
||||
SETUP_WIZARD: bool
|
||||
SHOW_SETUP_WIZARD: bool
|
||||
WATCHER: WatcherDict
|
||||
SCHEDULER: SchedulerDict
|
||||
ANY_SOURCE_ENABLED: bool
|
||||
METADATA_SOURCES: MetadataSourcesDict
|
||||
STEAMGRIDDB_ENABLED: bool
|
||||
FS_PLATFORMS: list
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Annotated
|
||||
|
||||
@@ -18,7 +19,11 @@ router = APIRouter()
|
||||
@protected_route(
|
||||
router.post,
|
||||
"/users",
|
||||
[] if len(db_user_handler.get_admin_users()) == 0 else ["users.write"],
|
||||
(
|
||||
[]
|
||||
if "pytest" not in sys.modules and len(db_user_handler.get_admin_users()) == 0
|
||||
else ["users.write"]
|
||||
),
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
)
|
||||
def add_user(request: Request, username: str, password: str, role: str) -> UserSchema:
|
||||
@@ -89,7 +94,7 @@ def get_user(request: Request, id: int) -> UserSchema:
|
||||
return user
|
||||
|
||||
|
||||
@protected_route(router.put, "/users/{id}")
|
||||
@protected_route(router.put, "/users/{id}", ["me.write"])
|
||||
def update_user(
|
||||
request: Request, id: int, form_data: Annotated[UserForm, Depends()]
|
||||
) -> UserSchema:
|
||||
@@ -114,7 +119,8 @@ def update_user(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="User not found"
|
||||
)
|
||||
|
||||
if not db_user.id == request.user.id and request.user.role != Role.ADMIN:
|
||||
# Admin users can edit any user, while other users can only edit self
|
||||
if db_user.id != request.user.id and request.user.role != Role.ADMIN:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
|
||||
|
||||
cleaned_data = {}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from decorators.database import begin_session
|
||||
from models.user import Role, User
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.exc import ProgrammingError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .base_handler import DBBaseHandler
|
||||
@@ -43,10 +42,4 @@ class DBUsersHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def get_admin_users(self, session: Session = None) -> list[User]:
|
||||
try:
|
||||
return session.scalars(select(User).filter_by(role=Role.ADMIN)).all()
|
||||
except ProgrammingError as e:
|
||||
if "Table" in str(e.orig) and "doesn't exist" in str(e.orig):
|
||||
return []
|
||||
else:
|
||||
raise ProgrammingError from e
|
||||
return session.scalars(select(User).filter_by(role=Role.ADMIN)).all()
|
||||
|
||||
@@ -23,7 +23,7 @@ onBeforeMount(async () => {
|
||||
.get("/heartbeat")
|
||||
.then(async ({ data: data }) => {
|
||||
heartbeat.set(data);
|
||||
if (heartbeat.value.SETUP_WIZARD) {
|
||||
if (heartbeat.value.SHOW_SETUP_WIZARD) {
|
||||
router.push({ name: "setup" });
|
||||
} else {
|
||||
await userApi
|
||||
|
||||
@@ -9,11 +9,10 @@ import type { WatcherDict } from "./WatcherDict";
|
||||
|
||||
export type HeartbeatResponse = {
|
||||
VERSION: string;
|
||||
SETUP_WIZARD: boolean;
|
||||
SHOW_SETUP_WIZARD: boolean;
|
||||
WATCHER: WatcherDict;
|
||||
SCHEDULER: SchedulerDict;
|
||||
ANY_SOURCE_ENABLED: boolean;
|
||||
METADATA_SOURCES: MetadataSourcesDict;
|
||||
STEAMGRIDDB_ENABLED: boolean;
|
||||
FS_PLATFORMS: Array<any>;
|
||||
};
|
||||
|
||||
@@ -6,4 +6,5 @@
|
||||
export type MetadataSourcesDict = {
|
||||
IGDB_API_ENABLED: boolean;
|
||||
MOBY_API_ENABLED: boolean;
|
||||
STEAMGRIDDB_ENABLED: boolean;
|
||||
};
|
||||
|
||||
@@ -146,7 +146,7 @@ function closeDialog() {
|
||||
<template #append-inner>
|
||||
<v-btn-group rounded="0" divided density="compact">
|
||||
<v-btn
|
||||
:disabled="!heartbeat.value.STEAMGRIDDB_ENABLED"
|
||||
:disabled="!heartbeat.value.METADATA_SOURCES?.STEAMGRIDDB_ENABLED"
|
||||
size="small"
|
||||
class="translucent-dark"
|
||||
@click="
|
||||
|
||||
@@ -144,7 +144,7 @@ function closeDialog() {
|
||||
<template #append-inner>
|
||||
<v-btn-group rounded="0" divided density="compact">
|
||||
<v-btn
|
||||
:disabled="!heartbeat.value.STEAMGRIDDB_ENABLED"
|
||||
:disabled="!heartbeat.value.METADATA_SOURCES?.STEAMGRIDDB_ENABLED"
|
||||
size="small"
|
||||
class="translucent-dark"
|
||||
@click="
|
||||
|
||||
@@ -177,7 +177,7 @@ function closeDialog() {
|
||||
<template #append-inner>
|
||||
<v-btn-group rounded="0" divided density="compact">
|
||||
<v-btn
|
||||
:disabled="!heartbeat.value.STEAMGRIDDB_ENABLED"
|
||||
:disabled="!heartbeat.value.METADATA_SOURCES?.STEAMGRIDDB_ENABLED"
|
||||
size="small"
|
||||
class="translucent-dark"
|
||||
@click="
|
||||
|
||||
@@ -81,7 +81,7 @@ const router = createRouter({
|
||||
|
||||
router.beforeEach((to, from) => {
|
||||
const heartbeat = storeHeartbeat();
|
||||
if (to.name == "setup" && !heartbeat.value.SETUP_WIZARD) {
|
||||
if (to.name == "setup" && !heartbeat.value.SHOW_SETUP_WIZARD) {
|
||||
router.push({ name: "dashboard" });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import router from "@/plugins/router";
|
||||
import axios from "axios";
|
||||
import cookie from "js-cookie";
|
||||
import Cookies from "js-cookie";
|
||||
import { default as cookie, default as Cookies } from "js-cookie";
|
||||
import { debounce } from "lodash";
|
||||
|
||||
const api = axios.create({ baseURL: "/api", timeout: 120000 });
|
||||
@@ -44,6 +43,7 @@ api.interceptors.response.use(
|
||||
}
|
||||
router.push({
|
||||
name: "login",
|
||||
query: { next: router.currentRoute.value.path },
|
||||
});
|
||||
}
|
||||
return Promise.reject(error);
|
||||
|
||||
@@ -20,7 +20,8 @@ async function login() {
|
||||
await identityApi
|
||||
.login(username.value, password.value)
|
||||
.then(() => {
|
||||
router.push({ name: "dashboard" });
|
||||
const next = (router.currentRoute.value.query?.next || "/").toString();
|
||||
router.push(next);
|
||||
})
|
||||
.catch(({ response, message }) => {
|
||||
const errorMessage =
|
||||
|
||||
@@ -32,7 +32,7 @@ const metadataOptions = computed(() => [
|
||||
name: "SteamgridDB",
|
||||
value: "sgdb",
|
||||
logo_path: "/assets/scrappers/sgdb.png",
|
||||
disabled: !heartbeat.value.STEAMGRIDDB_ENABLED,
|
||||
disabled: !heartbeat.value.METADATA_SOURCES?.STEAMGRIDDB_ENABLED,
|
||||
},
|
||||
]);
|
||||
const defaultAdminUser = ref({
|
||||
|
||||
Reference in New Issue
Block a user