refac
This commit is contained in:
@@ -152,18 +152,6 @@ class AutomationTable:
|
||||
row = db.get(Automation, id)
|
||||
return AutomationModel.model_validate(row) if row else None
|
||||
|
||||
def get_by_user(
|
||||
self, user_id: str, db: Optional[Session] = None
|
||||
) -> list[AutomationModel]:
|
||||
with get_db_context(db) as db:
|
||||
rows = (
|
||||
db.query(Automation)
|
||||
.filter_by(user_id=user_id)
|
||||
.order_by(Automation.created_at.desc())
|
||||
.all()
|
||||
)
|
||||
return [AutomationModel.model_validate(r) for r in rows]
|
||||
|
||||
def search_automations(
|
||||
self,
|
||||
user_id: str,
|
||||
@@ -206,15 +194,6 @@ class AutomationTable:
|
||||
total=total,
|
||||
)
|
||||
|
||||
def get_all(self, db: Optional[Session] = None) -> list[AutomationModel]:
|
||||
with get_db_context(db) as db:
|
||||
rows = (
|
||||
db.query(Automation)
|
||||
.order_by(Automation.created_at.desc())
|
||||
.all()
|
||||
)
|
||||
return [AutomationModel.model_validate(r) for r in rows]
|
||||
|
||||
def update_by_id(
|
||||
self,
|
||||
id: str,
|
||||
|
||||
@@ -71,22 +71,6 @@ def enrich_automation(
|
||||
)
|
||||
|
||||
|
||||
############################
|
||||
# GetAutomations
|
||||
############################
|
||||
|
||||
|
||||
@router.get('/', response_model=list[AutomationResponse])
|
||||
async def get_automations(
|
||||
request: Request,
|
||||
user=Depends(get_verified_user),
|
||||
db: Session = Depends(get_session),
|
||||
):
|
||||
check_automations_permission(request, user)
|
||||
automations = Automations.get_by_user(user.id, db=db)
|
||||
return [enrich_automation(automation, db, tz=user.timezone) for automation in automations]
|
||||
|
||||
|
||||
############################
|
||||
# GetAutomationItems (paginated)
|
||||
############################
|
||||
@@ -299,15 +283,4 @@ async def get_automation_runs(
|
||||
return AutomationRuns.get_by_automation(id, skip=skip, limit=limit, db=db)
|
||||
|
||||
|
||||
############################
|
||||
# Admin Endpoints
|
||||
############################
|
||||
|
||||
|
||||
@router.get('/admin/all', response_model=list[AutomationModel])
|
||||
async def get_all_automations(
|
||||
request: Request,
|
||||
user=Depends(get_admin_user),
|
||||
db: Session = Depends(get_session),
|
||||
):
|
||||
return Automations.get_all(db=db)
|
||||
|
||||
@@ -49,33 +49,6 @@ export type AutomationResponse = {
|
||||
next_runs: number[] | null;
|
||||
};
|
||||
|
||||
export const getAutomations = async (token: string) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/automations/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
authorization: `Bearer ${token}`
|
||||
}
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err.detail;
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const getAutomationItems = async (
|
||||
token: string,
|
||||
|
||||
Reference in New Issue
Block a user