Skip to content

Commit

Permalink
fix: Some code clean-up viur-base
Browse files Browse the repository at this point in the history
- File-module cleaned up (uses old current user access, etc.)
- Index-module cleaned up (backup-function is obsolete)
- User-module code clean-up
- renders dummy removes xml
- Updated dependencies and project.json
  • Loading branch information
phorward committed Aug 28, 2024
1 parent df7d92a commit d57cc3d
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 254 deletions.
302 changes: 151 additions & 151 deletions Pipfile.lock

Large diffs are not rendered by default.

43 changes: 11 additions & 32 deletions deploy/modules/file.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
import datetime
from typing import Dict, List
from viur.core import i18n, db, current
from viur.core.modules.file import File

from viur.core import db, utils
from viur.core.modules.file import File as _File

class File(File):

class File(_File):
def getAvailableRootNodes(self, *args, **kwargs):
# Any user who is logged in can see the root-node.
if current.user.get():
repository = self.ensureOwnModuleRootNode()

def getAvailableRootNodes(self, *args, **kwargs) -> List[Dict]:
if utils.getCurrentUser():
repo: db.Entity = self.ensureOwnModuleRootNode()

res = [
{
"name": "Files",
"key": repo.key
}
]
return res
return [{
"name": i18n.translate("Files"),
"key": repository.key
}]

return []

def ensureOwnModuleRootNode(self) -> db.Entity:
"""
Ensures, that general root-node for the current module exists.
If no root-node exists yet, it will be created.
:returns: The entity of the root-node.
"""
key = "rep_module_repo"
kindName = self.viewSkel("node").kindName

return db.GetOrInsert(
db.Key(kindName, key),
creationdate=datetime.datetime.now(),
rootNode=1
)
28 changes: 1 addition & 27 deletions deploy/modules/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import datetime
import logging
from viur.core import current, errors, exposed, utils, Module
from google.cloud.datastore_admin_v1.services.datastore_admin.client import DatastoreAdminClient
from viur.core import current, errors, exposed, Module


class Index(Module):
Expand Down Expand Up @@ -35,26 +32,3 @@ def scriptor(self):
def sitemap_xml(self, *args, **kwargs):
current.request.get().response.headers["Content-Type"] = "text/xml"
return self.render.view({}, tpl="sitemap")

# @tasks.PeriodicTask(24 * 60)
def backup(self, *args, **kwargs):
"""
Backup job kick-off for Google Cloud Storage.
Use the maintenance script setup/enable-backup.sh to configure your project for backups.
"""
if utils.isLocalDevelopmentServer:
logging.info("Backup tool is disabled on local development server")
return

bucket = "backup-dot-%s" % utils.projectID
admin_client = DatastoreAdminClient()
timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")

output_url_prefix = "gs://%s/%s" % (bucket, timestamp)

admin_client.export_entities(
project_id=utils.projectID,
output_url_prefix=output_url_prefix
)

logging.info("Backup queued to be exported to %r", output_url_prefix)
6 changes: 5 additions & 1 deletion deploy/modules/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class User(User):

# Extend default adminInfo to custom adminInfo
adminInfo = User.adminInfo | {
"columns": ["lastname", "firstname", "name"],
"columns": [
"name",
"firstname",
"lastname",
],
"filter": {"orderby": "lastname"},
}
2 changes: 1 addition & 1 deletion deploy/render/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from viur.core.render import admin, html, json, vi, xml
from viur.core.render import admin, html, json, vi
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"admin": {
"command": "viur package install admin",
"kind": "exec",
"version": "4.4.3"
"version": "4.4.6"
},
"npm": {
"command": "build",
Expand Down
41 changes: 0 additions & 41 deletions setup/enable-backup.sh

This file was deleted.

0 comments on commit d57cc3d

Please sign in to comment.