diff --git a/.github/workflows/docker-image_dev_benste.yml b/.github/workflows/docker-image_dev_benste.yml index 1f5234e..a284edc 100644 --- a/.github/workflows/docker-image_dev_benste.yml +++ b/.github/workflows/docker-image_dev_benste.yml @@ -15,9 +15,27 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4.6.1 + with: + python-version: 3.x + + - name: Install Poetry + run: | + pip install poetry + poetry config virtualenvs.create false # Skip creating a virtual environment + env: + POETRY_HOME: ${{ github.workspace }}/.poetry + + - name: Install project dependencies + run: | + poetry install + env: + POETRY_HOME: ${{ github.workspace }}/.poetry + - name: Version from Python run: echo "VERSION=$(python3 ./version.py)" >> $GITHUB_ENV - + - name: SHA_short run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV diff --git a/.github/workflows/docker-image_master.yml b/.github/workflows/docker-image_master.yml index 5121c45..c1804d5 100644 --- a/.github/workflows/docker-image_master.yml +++ b/.github/workflows/docker-image_master.yml @@ -19,6 +19,25 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4.6.1 + with: + python-version: 3.x + + - name: Install Poetry + run: | + pip install poetry + poetry config virtualenvs.create false # Skip creating a virtual environment + env: + POETRY_HOME: ${{ github.workspace }}/.poetry + + - name: Install project dependencies + run: | + poetry install + env: + POETRY_HOME: ${{ github.workspace }}/.poetry + - name: Version from Python run: echo "VVERSION=$(python3 ./version.py)" >> $GITHUB_ENV diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 33ed058..f4d0000 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,9 +10,6 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Version from Python - run: echo "VERSION=$(python3 ./version.py)" >> $GITHUB_ENV - - name: Set up Python uses: actions/setup-python@v4.6.1 with: @@ -36,6 +33,9 @@ jobs: poetry build env: POETRY_HOME: ${{ github.workspace }}/.poetry + + - name: Version from Python + run: echo "VERSION=$(python3 ./version.py)" >> $GITHUB_ENV - name: Create Release uses: ncipollo/release-action@v1.12.0 diff --git a/.vscode/launch.json b/.vscode/launch.json index df7f907..93a59b4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "configurations": [ { "name": "ChurchWebHelper (local)", - "type": "python", + "type": "debugpy", "request": "launch", "module": "church_web_helper", "cwd": "${workspaceFolder}", @@ -16,7 +16,6 @@ "PYTHONUNBUFFERED": "1", "CT_DOMAIN": "https://elkw1610.krz.tools", "COMMUNI_SERVER": "https://api.communiapp.de/rest", - "VERSION": "VS Code Launch config w/o version" }, "args": [ "run", diff --git a/README.md b/README.md index 7a9e970..72d7c29 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,13 @@ version.py is used to define the version number used by any automation 'Docker Compose Up' is using docker-compose.yml and will start a production server including the current version number 'Docker Compose Debug Up' composes a docker container for debugging also including the version number +### nice2know for debugging local docker containers +1. make sure /var/run/docker.sock has group "docker" with rw permissions and user is assigned to group docker +2. docker container IP != local IP - might wanna use the following commands to find the correct IP + - ```docker container list``` + - ```docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}} container_name_or_id``` +default could be http://172.18.0.2:5000 + ## tasks.json does trigger the docker-compose commands used for 2 launch configurations. This is also where the respective ENV vars can be changed. diff --git a/church_web_helper/app.py b/church_web_helper/app.py index 1903aab..3b58207 100644 --- a/church_web_helper/app.py +++ b/church_web_helper/app.py @@ -23,6 +23,8 @@ from dateutil.relativedelta import relativedelta import urllib +import toml + app = Flask(__name__) app.secret_key = os.urandom(16) @@ -40,6 +42,10 @@ if "VERSION" in os.environ.keys(): config["VERSION"] = os.environ["VERSION"] +else: + with open("pyproject.toml", "r") as f: + pyproject_data = toml.load(f) + config["VERSION"] = pyproject_data["tool"]["poetry"]["version"] app.config.update(config) locale.setlocale(locale.LC_TIME, "de_DE.UTF-8") @@ -54,15 +60,23 @@ def index(): @app.before_request def check_session(): - if request.endpoint != "login": - if "ct_api" not in session: - return redirect(url_for("login")) + """Session variable should contain ct_api and communi_api. + If not a redirect to respective login pages should be executed + """ + if request.endpoint != "login_ct" and request.endpoint != "login_communi": + #Check CT Login + if not session.get("ct_api"): + return redirect(url_for("login_ct")) elif not session["ct_api"].who_am_i(): - return redirect(url_for("login")) - - -@app.route("/login_churchtools", methods=["GET", "POST"]) -def login(): + return redirect(url_for("login_ct")) + #Check Communi Login + if not session.get("communi_api"): + return redirect(url_for("login_communi")) + elif not session["communi_api"].who_am_i(): + return redirect(url_for("login_communi")) + +@app.route("/ct/login", methods=["GET", "POST"]) +def login_ct(): """ Update login information for CT :return: @@ -91,7 +105,7 @@ def login(): ) -@app.route("/login_communi", methods=["GET", "POST"]) +@app.route("/communi/login", methods=["GET", "POST"]) def login_communi(): """ Update login information for Communi Login diff --git a/church_web_helper/templates/login_churchtools.html b/church_web_helper/templates/login_churchtools.html index 2711ace..2d1341a 100644 --- a/church_web_helper/templates/login_churchtools.html +++ b/church_web_helper/templates/login_churchtools.html @@ -14,7 +14,7 @@

Welcome {{ user.firstName }} {{ user.lastName }}



ReSubmit to change the authenticated user or server {% endif %} -
+
Welcome {{ user.vorname }} {{ user.nachname }} ReSubmit to change the authenticated user or server {% endif %} - +
Functions diff --git a/church_web_helper/templates/navbar.html b/church_web_helper/templates/navbar.html index 93cc4b8..5bbf69e 100644 --- a/church_web_helper/templates/navbar.html +++ b/church_web_helper/templates/navbar.html @@ -31,12 +31,12 @@ diff --git a/docker-compose.debug.yml b/docker-compose.debug.yml index 3e7df29..6f2895c 100644 --- a/docker-compose.debug.yml +++ b/docker-compose.debug.yml @@ -9,7 +9,6 @@ services: ports: - 5000:5000 environment: - - VERSION=${VERSION} - CT_DOMAIN=$CT_DOMAIN - COMMUNI_SERVER=$COMMUNI_SERVER - DEBUG=true diff --git a/docker-compose.yml b/docker-compose.yml index 4d11643..b8568ac 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,5 +8,3 @@ services: dockerfile: ./Dockerfile ports: - 5000:5000 - environment: - - VERSION=${VERSION} diff --git a/generate_pyproj.py b/generate_pyproj.py index 477688e..27b1152 100644 --- a/generate_pyproj.py +++ b/generate_pyproj.py @@ -15,20 +15,29 @@ "version": version, "description": "A python package to make use of ChurchTools API and Communi API with a docker packaged WebUI", "authors": ["bensteUEM"], - "homepage": 'https://github.com/bensteUEM/ChurchWebHelper', + "homepage": "https://github.com/bensteUEM/ChurchWebHelper", "license": "CC-BY-SA", "readme": "README.md", "include": ["templates/*.html", "static/*"], "dependencies": { - "python": "^3.8", - "churchtools-api": {"git": "https://github.com/bensteUEM/ChurchToolsAPI.git", "branch": "master"}, - "communi-api": {"git": "https://github.com/bensteUEM/CommuniAPI.git", "branch": "master"}, + "python": "^3.12", + "churchtools-api": { + "git": "https://github.com/bensteUEM/ChurchToolsAPI.git", + "branch": "master", + }, + "communi-api": { + "git": "https://github.com/bensteUEM/CommuniAPI.git", + "branch": "master", + }, "Flask": "^2.3.2", "Flask-Session": "^0.5.0", "requests": "^2.31.0", "python-docx": "^0.8.11", "gunicorn": "^22.0.0", - "python-dotenv": "^1.0.0" + "python-dotenv": "^1.0.0", + "matplotlib": "^3.9.1", + "pandas": "^2.2.2", + "toml": "^0.10.2", }, "group": { "dev": { @@ -37,16 +46,16 @@ "tomli_w": "^1.0.0", "wheel": "^0.41.2", "setuptools": "^66.1.1", - "autopep8": "^2.0.4" + "autopep8": "^2.0.4", } } - } + }, } }, "build-system": { "requires": ["poetry-core"], - "build-backend": "poetry.core.masonry.api" - } + "build-backend": "poetry.core.masonry.api", + }, } with open("pyproject.toml", "wb") as toml_file: diff --git a/pyproject.toml b/pyproject.toml index 88745f0..43febe7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "church-web-helper" -version = "1.6.1" +version = "1.6.2" description = "A python package to make use of ChurchTools API and Communi API with a docker packaged WebUI" authors = [ "bensteUEM", @@ -23,6 +23,7 @@ gunicorn = "^22.0.0" python-dotenv = "^1.0.0" matplotlib = "^3.9.1" pandas = "^2.2.2" +toml = "^0.10.2" [tool.poetry.dependencies.churchtools-api] git = "https://github.com/bensteUEM/ChurchToolsAPI.git" diff --git a/version.py b/version.py index 4e53248..ad9150d 100644 --- a/version.py +++ b/version.py @@ -1,6 +1,10 @@ import os +import toml + +with open("pyproject.toml", "r") as f: + pyproject_data = toml.load(f) +VERSION = pyproject_data["tool"]["poetry"]["version"] -VERSION = '1.6.1' __version__ = VERSION if __name__ == '__main__':