Skip to content

Commit

Permalink
updated login references and version varibale #25
Browse files Browse the repository at this point in the history
  • Loading branch information
bensteUEM committed Aug 23, 2024
1 parent 4ebb06b commit b690b1b
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 33 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/docker-image_dev_benste.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ jobs:

- name: Version from Python
run: echo "VERSION=$(python3 ./version.py)" >> $GITHUB_ENV

- name: Set up Python
uses: actions/[email protected]
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: SHA_short
run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/docker-image_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ jobs:
- name: Version from Python
run: echo "VVERSION=$(python3 ./version.py)" >> $GITHUB_ENV

- name: Set up Python
uses: actions/[email protected]
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: SHA_short
run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV

Expand Down
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"configurations": [
{
"name": "ChurchWebHelper (local)",
"type": "python",
"type": "debugpy",
"request": "launch",
"module": "church_web_helper",
"cwd": "${workspaceFolder}",
Expand All @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
32 changes: 23 additions & 9 deletions church_web_helper/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from dateutil.relativedelta import relativedelta
import urllib

import toml

app = Flask(__name__)
app.secret_key = os.urandom(16)

Expand All @@ -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")
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion church_web_helper/templates/login_churchtools.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h2>Welcome {{ user.firstName }} {{ user.lastName }}</h2>
</br></br>
ReSubmit to change the authenticated user or server
{% endif %}
<form action="/login_churchtools" method="POST">
<form action="/ct/login" method="POST">
<div class="form-group">
<label for="ct_domain">Domain:</label>
<input type="text" id="ct_domain" class="form-control" name="ct_domain"
Expand Down
2 changes: 1 addition & 1 deletion church_web_helper/templates/login_communi.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h2>Welcome {{ user.vorname }} {{ user.nachname }}</h2>
ReSubmit to change the authenticated user or server
{% endif %}

<form action="/login_communi" method="POST">
<form action="/communi/login" method="POST">
<div class="form-group">
<label for="communi_server">Communi Server:</label>
<input type="text" id="communi_server" class="form-control" name="communi_server"
Expand Down
4 changes: 2 additions & 2 deletions church_web_helper/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<h2>Functions</h2>
<div class="list-group">
<a class="list-group-item list-group-item-action" href="./login_churchtools">ChurchTools Login</a></li>
<a class="list-group-item list-group-item-action" href="./login_communi">Communi Login</a></li>
<a class="list-group-item list-group-item-action" href="./ct/login">ChurchTools Login</a></li>
<a class="list-group-item list-group-item-action" href="./communi/login">Communi Login</a></li>
<a class="list-group-item list-group-item-action" href="./events">Events</a></li>
<a class="list-group-item list-group-item-action" href="./test">Test page</a></li>
</div>
Expand Down
8 changes: 4 additions & 4 deletions church_web_helper/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
<a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-expanded="false">Logins</a>
<ul class="dropdown-menu dropdown-menu-end">
<li class="nav-item">
<a class="nav-link {% if request.path == '/login_churchtools' %}{% endif %}" aria-current="page"
href="/login_churchtools">ChurchTools Login</a>
<a class="nav-link {% if request.path == '/ct/login' %}{% endif %}" aria-current="page"
href="/ct/login">ChurchTools Login</a>
</li>
<li class="nav-item">
<a class="nav-link {% if request.path == '/login_communi' %}{% endif %}" aria-current="page"
href="/login_communi">Communi Login</a>
<a class="nav-link {% if request.path == '/communi/login' %}{% endif %}" aria-current="page"
href="/communi/login">Communi Login</a>
</li>
</ul>
</li>
Expand Down
1 change: 0 additions & 1 deletion docker-compose.debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
ports:
- 5000:5000
environment:
- VERSION=${VERSION}
- CT_DOMAIN=$CT_DOMAIN
- COMMUNI_SERVER=$COMMUNI_SERVER
- DEBUG=true
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ services:
dockerfile: ./Dockerfile
ports:
- 5000:5000
environment:
- VERSION=${VERSION}
27 changes: 18 additions & 9 deletions generate_pyproj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -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__':
Expand Down

0 comments on commit b690b1b

Please sign in to comment.