Refactor repeated auth errors

This commit is contained in:
amcmanu3 2024-06-23 19:13:44 -04:00
parent f8884ab93e
commit af11737b48
2 changed files with 13 additions and 10 deletions

View File

@ -41,6 +41,8 @@ SUBPAGE_PERMS = {
"webhooks": EnumPermissionsServer.CONFIG,
}
SCHEDULE_AUTH_ERROR_URL = "/panel/error?error=Unauthorized access To Schedules"
class PanelHandler(BaseHandler):
def get_user_roles(self) -> t.Dict[str, list]:
@ -1147,7 +1149,7 @@ class PanelHandler(BaseHandler):
if not EnumPermissionsServer.SCHEDULE in page_data["user_permissions"]:
if not superuser:
self.redirect("/panel/error?error=Unauthorized access To Schedules")
self.redirect(SCHEDULE_AUTH_ERROR_URL)
return
template = "panel/server_schedule_edit.html"
@ -1245,7 +1247,7 @@ class PanelHandler(BaseHandler):
if not EnumPermissionsServer.SCHEDULE in page_data["user_permissions"]:
if not superuser:
self.redirect("/panel/error?error=Unauthorized access To Schedules")
self.redirect(SCHEDULE_AUTH_ERROR_URL)
return
template = "panel/server_schedule_edit.html"
@ -1317,7 +1319,7 @@ class PanelHandler(BaseHandler):
if EnumPermissionsServer.BACKUP not in page_data["user_permissions"]:
if not superuser:
self.redirect("/panel/error?error=Unauthorized access To Schedules")
self.redirect(SCHEDULE_AUTH_ERROR_URL)
return
template = "panel/server_backup_edit.html"
@ -1376,7 +1378,7 @@ class PanelHandler(BaseHandler):
if EnumPermissionsServer.BACKUP not in page_data["user_permissions"]:
if not superuser:
self.redirect("/panel/error?error=Unauthorized access To Schedules")
self.redirect(SCHEDULE_AUTH_ERROR_URL)
return
template = "panel/server_backup_edit.html"

View File

@ -50,6 +50,7 @@ BASIC_BACKUP_PATCH_SCHEMA = {
"minProperties": 1,
}
ID_MISMATCH = "Server ID backup server ID different"
GENERAL_AUTH_ERROR = "Authorization Error"
class ApiServersServerBackupsBackupIndexHandler(BaseApiHandler):
@ -81,7 +82,7 @@ class ApiServersServerBackupsBackupIndexHandler(BaseApiHandler):
{
"status": "error",
"error": "NOT_AUTHORIZED",
"error_data": "Authorization Error",
"error_data": GENERAL_AUTH_ERROR,
},
)
self.finish_json(200, backup_conf)
@ -114,7 +115,7 @@ class ApiServersServerBackupsBackupIndexHandler(BaseApiHandler):
{
"status": "error",
"error": "NOT_AUTHORIZED",
"error_data": "Authorization Error",
"error_data": GENERAL_AUTH_ERROR,
},
)
@ -156,7 +157,7 @@ class ApiServersServerBackupsBackupIndexHandler(BaseApiHandler):
{
"status": "error",
"error": "NOT_AUTHORIZED",
"error_data": "Authorization Error",
"error_data": GENERAL_AUTH_ERROR,
},
)
backup_config = self.controller.management.get_backup_config(backup_id)
@ -330,7 +331,7 @@ class ApiServersServerBackupsBackupIndexHandler(BaseApiHandler):
{
"status": "error",
"error": "NOT_AUTHORIZED",
"error_data": "Authorization Error",
"error_data": GENERAL_AUTH_ERROR,
},
)
if backup_conf["server_id"]["server_id"] != server_id:
@ -356,7 +357,7 @@ class ApiServersServerBackupsBackupIndexHandler(BaseApiHandler):
{
"status": "error",
"error": "NOT_AUTHORIZED",
"error_data": "Authorization Error",
"error_data": GENERAL_AUTH_ERROR,
},
)
self.controller.management.update_backup_config(backup_id, data)
@ -392,7 +393,7 @@ class ApiServersServerBackupsBackupFilesIndexHandler(BaseApiHandler):
{
"status": "error",
"error": "NOT_AUTHORIZED",
"error_data": "Authorization Error",
"error_data": GENERAL_AUTH_ERROR,
},
)