Skip to content

Commit

Permalink
add service view and api check
Browse files Browse the repository at this point in the history
- add service view to admin interface
- add service check on package upload
  • Loading branch information
mreid-tt committed Jan 3, 2024
1 parent e48a3c4 commit bbe6210
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions spkrepo/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
IndexView,
PackageView,
ScreenshotView,
ServiceView,
UserView,
VersionView,
)
Expand Down
26 changes: 25 additions & 1 deletion spkrepo/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@
from wtforms.validators import Regexp

from ..ext import db
from ..models import Architecture, Build, Firmware, Package, Screenshot, User, Version
from ..models import (
Architecture,
Build,
Firmware,
Package,
Screenshot,
Service,
User,
Version,
)
from ..utils import SPK


Expand Down Expand Up @@ -111,6 +120,21 @@ def is_accessible(self):
can_delete = False


class ServiceView(ModelView):
"""View for :class:`~spkrepo.models.Service`"""

def __init__(self, **kwargs):
super(ServiceView, self).__init__(Service, db.session, **kwargs)

# Permissions
def is_accessible(self):
return current_user.is_authenticated and current_user.has_role("package_admin")

can_edit = False

can_delete = False


def screenshot_namegen(obj, file_data):
pattern = "screenshot_%0d%s"
ext = os.path.splitext(file_data.filename)[1]
Expand Down
10 changes: 10 additions & 0 deletions spkrepo/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ def post(self):
if firmware is None:
abort(422, message="Unknown firmware")

# Services
input_install_dep_services = spk.info["install_dep_services"]
if input_install_dep_services:
for info_dep_service in input_install_dep_services.split():
service_name = Service.find(info_dep_service)
if service_name is None:
abort(
422, message="Unknown dependent service: %s" % info_dep_service
)

# Package
create_package = False
package = Package.find(spk.info["package"])
Expand Down

0 comments on commit bbe6210

Please sign in to comment.