mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-04-01 06:03:39 +00:00
define permissions in views directly
This commit is contained in:
@@ -17,13 +17,16 @@
|
||||
# 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 aiohttp.web import View
|
||||
from typing import Any, Dict, List, Optional
|
||||
from __future__ import annotations
|
||||
|
||||
from aiohttp.web import Request, View
|
||||
from typing import Any, Dict, List, Optional, Type
|
||||
|
||||
from ahriman.core.auth.auth import Auth
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.spawn import Spawn
|
||||
from ahriman.core.status.watcher import Watcher
|
||||
from ahriman.models.user_access import UserAccess
|
||||
|
||||
|
||||
class BaseView(View):
|
||||
@@ -63,6 +66,16 @@ class BaseView(View):
|
||||
validator: Auth = self.request.app["validator"]
|
||||
return validator
|
||||
|
||||
@classmethod
|
||||
async def get_permission(cls: Type[BaseView], request: Request) -> UserAccess:
|
||||
"""
|
||||
retrieve user permission from the request
|
||||
:param request: request object
|
||||
:return: extracted permission
|
||||
"""
|
||||
permission: UserAccess = getattr(cls, f"{request.method.upper()}_PERMISSION", UserAccess.Write)
|
||||
return permission
|
||||
|
||||
async def extract_data(self, list_keys: Optional[List[str]] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
extract json data from either json or form data
|
||||
|
||||
@@ -24,12 +24,15 @@ from typing import Any, Dict
|
||||
from ahriman import version
|
||||
from ahriman.core.auth.helpers import authorized_userid
|
||||
from ahriman.core.util import pretty_datetime
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
class IndexView(BaseView):
|
||||
"""
|
||||
root view
|
||||
:cvar GET_PERMISSION: get permissions of self
|
||||
:cvar HEAD_PERMISSION: head permissions of self
|
||||
|
||||
It uses jinja2 templates for report generation, the following variables are allowed:
|
||||
|
||||
@@ -58,6 +61,8 @@ class IndexView(BaseView):
|
||||
version - ahriman version, string, required
|
||||
"""
|
||||
|
||||
GET_PERMISSION = HEAD_PERMISSION = UserAccess.Safe
|
||||
|
||||
@aiohttp_jinja2.template("build-status.jinja2")
|
||||
async def get(self) -> Dict[str, Any]:
|
||||
"""
|
||||
|
||||
@@ -19,14 +19,18 @@
|
||||
#
|
||||
from aiohttp.web import HTTPFound, Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
class AddView(BaseView):
|
||||
"""
|
||||
add package web view
|
||||
:cvar POST_PERMISSION: post permissions of self
|
||||
"""
|
||||
|
||||
POST_PERMISSION = UserAccess.Write
|
||||
|
||||
async def post(self) -> Response:
|
||||
"""
|
||||
add new package
|
||||
|
||||
@@ -17,18 +17,21 @@
|
||||
# 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 aiohttp.web import Response
|
||||
from aiohttp.web_exceptions import HTTPNoContent
|
||||
from aiohttp.web import HTTPNoContent, Response
|
||||
|
||||
from ahriman.core.auth.auth import Auth
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
class ReloadAuthView(BaseView):
|
||||
"""
|
||||
reload authentication module web view
|
||||
:cvar POST_PERMISSION: post permissions of self
|
||||
"""
|
||||
|
||||
POST_PERMISSION = UserAccess.Write
|
||||
|
||||
async def post(self) -> Response:
|
||||
"""
|
||||
reload authentication module. No parameters supported here
|
||||
|
||||
@@ -19,14 +19,18 @@
|
||||
#
|
||||
from aiohttp.web import HTTPFound, Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
class RemoveView(BaseView):
|
||||
"""
|
||||
remove package web view
|
||||
:cvar POST_PERMISSION: post permissions of self
|
||||
"""
|
||||
|
||||
POST_PERMISSION = UserAccess.Write
|
||||
|
||||
async def post(self) -> Response:
|
||||
"""
|
||||
remove existing packages
|
||||
|
||||
@@ -22,14 +22,19 @@ import aur # type: ignore
|
||||
from aiohttp.web import Response, json_response
|
||||
from typing import Callable, Iterator
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
class SearchView(BaseView):
|
||||
"""
|
||||
AUR search web view
|
||||
:cvar GET_PERMISSION: get permissions of self
|
||||
:cvar HEAD_PERMISSION: head permissions of self
|
||||
"""
|
||||
|
||||
GET_PERMISSION = HEAD_PERMISSION = UserAccess.Read
|
||||
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
search packages in AUR
|
||||
|
||||
@@ -20,14 +20,21 @@
|
||||
from aiohttp.web import HTTPNoContent, Response, json_response
|
||||
|
||||
from ahriman.models.build_status import BuildStatusEnum
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
class AhrimanView(BaseView):
|
||||
"""
|
||||
service status web view
|
||||
:cvar GET_PERMISSION: get permissions of self
|
||||
:cvar HEAD_PERMISSION: head permissions of self
|
||||
:cvar POST_PERMISSION: post permissions of self
|
||||
"""
|
||||
|
||||
GET_PERMISSION = HEAD_PERMISSION = UserAccess.Read
|
||||
POST_PERMISSION = UserAccess.Write
|
||||
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get current service status
|
||||
|
||||
@@ -22,14 +22,22 @@ from aiohttp.web import HTTPNoContent, HTTPNotFound, Response, json_response
|
||||
from ahriman.core.exceptions import UnknownPackage
|
||||
from ahriman.models.build_status import BuildStatusEnum
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
class PackageView(BaseView):
|
||||
"""
|
||||
package base specific web view
|
||||
:cvar DELETE_PERMISSION: delete permissions of self
|
||||
:cvar GET_PERMISSION: get permissions of self
|
||||
:cvar HEAD_PERMISSION: head permissions of self
|
||||
:cvar POST_PERMISSION: post permissions of self
|
||||
"""
|
||||
|
||||
DELETE_PERMISSION = POST_PERMISSION = UserAccess.Write
|
||||
GET_PERMISSION = HEAD_PERMISSION = UserAccess.Read
|
||||
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get current package base status
|
||||
|
||||
@@ -19,14 +19,21 @@
|
||||
#
|
||||
from aiohttp.web import HTTPNoContent, Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
class PackagesView(BaseView):
|
||||
"""
|
||||
global watcher view
|
||||
:cvar GET_PERMISSION: get permissions of self
|
||||
:cvar HEAD_PERMISSION: head permissions of self
|
||||
:cvar POST_PERMISSION: post permissions of self
|
||||
"""
|
||||
|
||||
GET_PERMISSION = HEAD_PERMISSION = UserAccess.Read
|
||||
POST_PERMISSION = UserAccess.Write
|
||||
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get current packages status
|
||||
|
||||
@@ -22,14 +22,19 @@ from aiohttp.web import Response, json_response
|
||||
from ahriman import version
|
||||
from ahriman.models.counters import Counters
|
||||
from ahriman.models.internal_status import InternalStatus
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
class StatusView(BaseView):
|
||||
"""
|
||||
web service status web view
|
||||
:cvar GET_PERMISSION: get permissions of self
|
||||
:cvar HEAD_PERMISSION: head permissions of self
|
||||
"""
|
||||
|
||||
GET_PERMISSION = HEAD_PERMISSION = UserAccess.Read
|
||||
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get current service status
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
from aiohttp.web import HTTPFound, HTTPMethodNotAllowed, HTTPUnauthorized, Response
|
||||
|
||||
from ahriman.core.auth.helpers import remember
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.models.user_identity import UserIdentity
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
@@ -27,8 +28,12 @@ from ahriman.web.views.base import BaseView
|
||||
class LoginView(BaseView):
|
||||
"""
|
||||
login endpoint view
|
||||
:cvar GET_PERMISSION: get permissions of self
|
||||
:cvar POST_PERMISSION: post permissions of self
|
||||
"""
|
||||
|
||||
GET_PERMISSION = POST_PERMISSION = UserAccess.Safe
|
||||
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
OAuth2 response handler
|
||||
|
||||
@@ -20,14 +20,18 @@
|
||||
from aiohttp.web import HTTPFound, Response
|
||||
|
||||
from ahriman.core.auth.helpers import check_authorized, forget
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
class LogoutView(BaseView):
|
||||
"""
|
||||
logout endpoint view
|
||||
:cvar POST_PERMISSION: post permissions of self
|
||||
"""
|
||||
|
||||
POST_PERMISSION = UserAccess.Safe
|
||||
|
||||
async def post(self) -> Response:
|
||||
"""
|
||||
logout user from the service. No parameters supported here
|
||||
|
||||
Reference in New Issue
Block a user