mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-04-01 06:03:39 +00:00
feat: add ability to disable specific routes (#119)
This commit is contained in:
@@ -115,6 +115,21 @@ class BaseView(View, CorsViewMixin):
|
||||
permission: UserAccess = getattr(cls, f"{method}_PERMISSION", UserAccess.Full)
|
||||
return permission
|
||||
|
||||
@classmethod
|
||||
def routes(cls, configuration: Configuration) -> list[str]:
|
||||
"""
|
||||
extract routes list for the view
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration instance
|
||||
|
||||
Returns:
|
||||
list[str]: list of routes defined for the view. By default, it tries to read :attr:`ROUTES` option if set
|
||||
and returns empty list otherwise
|
||||
"""
|
||||
del configuration
|
||||
return cls.ROUTES
|
||||
|
||||
@staticmethod
|
||||
def get_non_empty(extractor: Callable[[str], T | None], key: str) -> T:
|
||||
"""
|
||||
|
||||
41
src/ahriman/web/views/status_view_guard.py
Normal file
41
src/ahriman/web/views/status_view_guard.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#
|
||||
# Copyright (c) 2021-2023 ahriman team.
|
||||
#
|
||||
# This file is part of ahriman
|
||||
# (see https://github.com/arcan1s/ahriman).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
class StatusViewGuard:
|
||||
|
||||
ROUTES: list[str]
|
||||
|
||||
@classmethod
|
||||
def routes(cls, configuration: Configuration) -> list[str]:
|
||||
"""
|
||||
extract routes list for the view
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration instance
|
||||
|
||||
Returns:
|
||||
list[str]: list of routes defined for the view. By default, it tries to read :attr:`ROUTES` option if set
|
||||
and returns empty list otherwise
|
||||
"""
|
||||
if configuration.getboolean("web", "service_only", fallback=False):
|
||||
return []
|
||||
return cls.ROUTES
|
||||
@@ -26,9 +26,10 @@ from ahriman.models.changes import Changes
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ChangesSchema, ErrorSchema, PackageNameSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
|
||||
class ChangesView(BaseView):
|
||||
class ChangesView(StatusViewGuard, BaseView):
|
||||
"""
|
||||
package changes web view
|
||||
|
||||
|
||||
@@ -28,9 +28,10 @@ from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, LogsSchema, PackageNameSchema, RepositoryIdSchema, \
|
||||
VersionedLogSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
|
||||
class LogsView(BaseView):
|
||||
class LogsView(StatusViewGuard, BaseView):
|
||||
"""
|
||||
package logs web view
|
||||
|
||||
|
||||
@@ -28,9 +28,10 @@ from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackageNameSchema, PackageStatusSchema, \
|
||||
PackageStatusSimplifiedSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
|
||||
class PackageView(BaseView):
|
||||
class PackageView(StatusViewGuard, BaseView):
|
||||
"""
|
||||
package base specific web view
|
||||
|
||||
|
||||
@@ -28,9 +28,10 @@ from ahriman.models.package import Package
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackageStatusSchema, PaginationSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
|
||||
class PackagesView(BaseView):
|
||||
class PackagesView(StatusViewGuard, BaseView):
|
||||
"""
|
||||
global watcher view
|
||||
|
||||
|
||||
@@ -24,9 +24,10 @@ from aiohttp.web import HTTPNoContent, HTTPNotFound, Response, json_response
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PatchNameSchema, PatchSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
|
||||
class PatchView(BaseView):
|
||||
class PatchView(StatusViewGuard, BaseView):
|
||||
"""
|
||||
package patch web view
|
||||
|
||||
|
||||
@@ -25,9 +25,10 @@ from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackageNameSchema, PatchSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
|
||||
class PatchesView(BaseView):
|
||||
class PatchesView(StatusViewGuard, BaseView):
|
||||
"""
|
||||
package patches web view
|
||||
|
||||
|
||||
@@ -28,9 +28,10 @@ from ahriman.models.internal_status import InternalStatus
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, InternalStatusSchema, StatusSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
|
||||
class StatusView(BaseView):
|
||||
class StatusView(StatusViewGuard, BaseView):
|
||||
"""
|
||||
web service status web view
|
||||
|
||||
|
||||
@@ -24,9 +24,10 @@ from aiohttp.web import Response, json_response
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, LogSchema, PackageNameSchema, PaginationSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
|
||||
class LogsView(BaseView):
|
||||
class LogsView(StatusViewGuard, BaseView):
|
||||
"""
|
||||
package logs web view
|
||||
|
||||
|
||||
Reference in New Issue
Block a user