style: Add advanced and email package mappings in book option package function
style: Implement MongoDB connection and user collection retrieval in server steering style: Add version management methods for advanced and email packages style: Update instance editing functionality for new package options style: Update binary image file in static resources
This commit is contained in:
@@ -1810,8 +1810,11 @@ def book_option_package():
|
||||
package_raw = _sanitize_text(request.form.get("package") or "", 40).lower()
|
||||
package_map = {
|
||||
"starter_package": "Starter-Paket",
|
||||
"advanced_package": "Advanced-Paket",
|
||||
"inventarsystem": "Inventarsystem",
|
||||
"buecherei": "Bücherei",
|
||||
"terminverwaltung": "Terminverwaltung",
|
||||
"emailversand": "E-Mail Versand",
|
||||
"schultraeger": "Schulträger Angebot",
|
||||
"telefonsupport": "Telefonsupport 20/Monat",
|
||||
}
|
||||
|
||||
+171
-1
@@ -1,10 +1,22 @@
|
||||
import os
|
||||
import requests
|
||||
|
||||
from pymongo import MongoClient
|
||||
from bson.objectid import ObjectId
|
||||
import datetime
|
||||
|
||||
_var = "/opt/legendary-octo-garbanzo"
|
||||
_cmd = "manage-tenants.sh"
|
||||
|
||||
MONGO_URI = os.environ.get("MONGO_URI", "mongodb://localhost:27017")
|
||||
MONGO_DB_NAME = os.environ.get("MONGO_DB_NAME", "Invario_Website")
|
||||
|
||||
|
||||
def _get_users_collection():
|
||||
client = MongoClient(MONGO_URI, serverSelectionTimeoutMS=1500)
|
||||
db = client[MONGO_DB_NAME]
|
||||
return client, db["packages"]
|
||||
|
||||
|
||||
def add_dns(name: str, port: int) -> bool:
|
||||
"""
|
||||
Adds the subdomain to the DNS Routes
|
||||
@@ -83,6 +95,120 @@ def execute_script(wd_: str, file_: str, com_: str, com2_: str="None", com3_: st
|
||||
return False
|
||||
return result.stdout
|
||||
|
||||
class versions:
|
||||
"""
|
||||
This will give access to anything like:
|
||||
- Version of the Inventorysystem
|
||||
- Version of the Server
|
||||
|
||||
modules:
|
||||
- inventorysystem()
|
||||
- server()
|
||||
"""
|
||||
def inventorysystem(name: str) -> str:
|
||||
"""
|
||||
Version of the Inventorysystem
|
||||
|
||||
Output:
|
||||
- version -> String
|
||||
"""
|
||||
return instace.edit(name, "inventarsystem")
|
||||
|
||||
def bibliothek(name: str) -> str:
|
||||
"""
|
||||
Version of the Inventorysystem
|
||||
|
||||
Output:
|
||||
- version -> String
|
||||
"""
|
||||
return instace.edit(name, "buecherei")
|
||||
|
||||
def terminplanen(name: str) -> str:
|
||||
"""
|
||||
Version of the Inventorysystem
|
||||
|
||||
Output:
|
||||
- version -> String
|
||||
"""
|
||||
return instace.edit(name, "terminverwaltung")
|
||||
|
||||
def emailversand(name: str) -> str:
|
||||
"""
|
||||
Version of the Inventorysystem
|
||||
|
||||
Output:
|
||||
- version -> String
|
||||
"""
|
||||
return instace.edit(name, "emailversand")
|
||||
|
||||
def starter(name: str) -> str:
|
||||
"""
|
||||
Version of the Inventorysystem
|
||||
|
||||
Output:
|
||||
- version -> String
|
||||
"""
|
||||
return instace.edit(name, "starter")
|
||||
|
||||
def advanced(name: str) -> str:
|
||||
"""
|
||||
Version of the Inventorysystem
|
||||
|
||||
Output:
|
||||
- version -> String
|
||||
"""
|
||||
return instace.edit(name, "advanced")
|
||||
|
||||
def testversion(name: str) -> str:
|
||||
"""
|
||||
Version of the Inventorysystem
|
||||
|
||||
Output:
|
||||
- version -> String
|
||||
"""
|
||||
client = None
|
||||
try:
|
||||
client, packages = _get_users_collection()
|
||||
packages.insert_one(
|
||||
{
|
||||
'client_name': name,
|
||||
'inventarsystem': False,
|
||||
'buecherei': False,
|
||||
'terminverwaltung': False,
|
||||
'emailversand': False,
|
||||
'starter': False,
|
||||
'advanced': False,
|
||||
'registered_on': datetime.datetime.utcnow()
|
||||
}
|
||||
)
|
||||
return True
|
||||
finally:
|
||||
if client:
|
||||
client.close()
|
||||
return instace.edit(name, "starter")
|
||||
|
||||
def _get_auth(name: str) -> int:
|
||||
"""
|
||||
Check if the if it is older than 5 days Test Version
|
||||
|
||||
Output:
|
||||
- days since registration -> int
|
||||
"""
|
||||
client = None
|
||||
try:
|
||||
client, packages = _get_users_collection()
|
||||
package = packages.find_one({'client_name': name}) or {}
|
||||
for key in package:
|
||||
if key == "registered_on":
|
||||
if package[key]:
|
||||
instance_age = (datetime.datetime.utcnow() - package[key]).days
|
||||
else:
|
||||
instance_age = None
|
||||
finally:
|
||||
if client:
|
||||
client.close()
|
||||
return int(instance_age) if int(instance_age) is not None and instance_age <= 5 else False
|
||||
|
||||
|
||||
class instace:
|
||||
"""
|
||||
@@ -125,6 +251,50 @@ class instace:
|
||||
else:
|
||||
return False
|
||||
|
||||
def edit(name: str, module:str) -> bool:
|
||||
"""
|
||||
Edits the name of an instance with the subdomain [name].invario.eu to [new_name].invario.eu
|
||||
|
||||
Input:
|
||||
- name -> String
|
||||
- module -> String (Options: "inventarsystem", "buecherei", "terminverwaltung", "emailversand", "starter", "advanced")
|
||||
|
||||
Output:
|
||||
- bool if the edit works (True: edit worked; False: didnt work)
|
||||
"""
|
||||
if module == "inventarsystem":
|
||||
if execute_script(_var, _cmd, "module", clear_special(name), 'library=off inventory=on'):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
elif module == "buecherei":
|
||||
if execute_script(_var, _cmd, "module", clear_special(name), 'library=on inventory=off'):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
elif module == "terminverwaltung":
|
||||
if execute_script(_var, _cmd, "module", clear_special(name), 'library=off inventory=off'): # -> has to be changed when the module is ready
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
elif module == "emailversand":
|
||||
if execute_script(_var, _cmd, "module", clear_special(name), 'library=off inventory=on'):# -> has to be changed when the module is ready
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
elif module == "starter":
|
||||
if execute_script(_var, _cmd, "module", clear_special(name), 'library=on inventory=on'):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
elif module == "advanced":
|
||||
if execute_script(_var, _cmd, "module", clear_special(name), 'library=on inventory=on'):# -> has to be changed when the module is ready
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def remove(name: str) -> bool:
|
||||
"""
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
Reference in New Issue
Block a user