Skip to content

Commit

Permalink
minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikonse committed Jan 5, 2022
1 parent 54e56c6 commit 489d1d0
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 25 deletions.
2 changes: 1 addition & 1 deletion abrechnung/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Abrechnung - feature complete payment management and bookkeeping."""

__version__ = "0.4.0"
__version__ = "0.4.1"
2 changes: 2 additions & 0 deletions abrechnung/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ async def run(self):
await revisions.apply_revisions(db_pool=db_pool)
elif self.action == "clean":
await self._clean(db_pool=db_pool)

await db_pool.close()
2 changes: 2 additions & 0 deletions abrechnung/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ async def run(self):
conn, forwarder_id=self.cfg["api"]["id"]
)

await db_pool.close()

async def _register_forwarder(
self, connection: asyncpg.Connection, forwarder_id: str
):
Expand Down
12 changes: 11 additions & 1 deletion abrechnung/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import itertools
import logging
import smtplib
from typing import Optional

import asyncpg

Expand All @@ -16,7 +17,7 @@ def __init__(self, config: Config, **args): # pylint: disable=super-init-not-ca
del args # unused

self.config = config
self.events: asyncio.Queue = asyncio.Queue()
self.events: Optional[asyncio.Queue] = None
self.psql = None
self.mailer = None
self.logger = logging.getLogger(__name__)
Expand All @@ -36,6 +37,11 @@ def __init__(self, config: Config, **args): # pylint: disable=super-init-not-ca
async def run(self):
# just try to connect to the mailing server once
_ = self.get_mailer_instance()
# only initialize the event queue once we are in a proper async context otherwise weird errors happen
self.events = asyncio.Queue()

if self.events is None:
raise RuntimeError("something unexpected happened, self.events is None")

self.psql = await asyncpg.connect(
user=self.config["database"]["user"],
Expand Down Expand Up @@ -96,13 +102,17 @@ def notification_callback(
"""runs whenever we get a psql notification"""
assert connection is self.psql
del pid # unused
if self.events is None:
raise RuntimeError("something unexpected happened, self.events is None")
self.events.put_nowait((channel, payload))

def terminate_callback(self, connection: asyncpg.Connection):
"""runs when the psql connection is closed"""
assert connection is self.psql
self.logger.info("psql connection closed")
# proper way of clearing asyncio queue
if self.events is None:
raise RuntimeError("something unexpected happened, self.events is None")
for _ in range(self.events.qsize()):
self.events.get_nowait()
self.events.task_done()
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion debian/abrechnung.install
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
config/abrechnung.yaml /etc/abrechnung
config/nginx-site /etc/nginx/sites-available/abrechnung
config/nginx/abrechnung /etc/nginx/sites-available/
debian/abrechnung-api.service /lib/systemd/system
debian/abrechnung-mailer.service /lib/systemd/system
debian/abrechnung-db-clean.service /lib/systemd/system
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
abrechnung (0.4.1) stable; urgency=medium

* Abrechnung release 0.4.1

-- Michael Loipführer <[email protected]> Tue, 4 Jan 2022 23:22:24 +0000

abrechnung (0.4.0) stable; urgency=medium

* Abrechnung release 0.4.0
Expand Down
9 changes: 9 additions & 0 deletions docs/requires.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
sphinx-autobuild
sphinx-autodoc-typehints
sphinxcontrib-openapi
aiohttp
aiohttp-cors
asyncpg
bcrypt
pyjwt
PyYAML
marshmallow
schema
email-validator
apispec
webargs
2 changes: 1 addition & 1 deletion docs/usage/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Debian Buster, Bullseye, Bookworm and Sid
-----------------------------------------
This is the recommended installation method as it also installs the prebuilt abrechnung web app.

Simply go to the `github release page <https://github.com/SFTtech/abrechung/releases>`_ and download
Simply go to the `github release page <https://github.com/SFTtech/abrechnung/releases>`_ and download
the latest debian package matching your debian version for the latest release.

Install them via ::
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"aiohttp~=3.7",
"aiohttp~=3.8",
"aiohttp-cors~=0.7",
"asyncpg~=0.21",
"asyncpg~=0.24",
"bcrypt~=3.2",
"pyjwt~=2.2",
"PyYAML~=5.3",
"marshmallow~=3.10",
"marshmallow~=3.14",
"schema",
"email-validator~=1.1",
"apispec",
Expand All @@ -41,9 +41,9 @@ test = [
]
dev = [
"black",
"mypy~=0.910",
"mypy~=0.930",
"types-PyYAML~=5.4",
"pylint~=2.10",
"pylint~=2.12",
]
docs = [
"sphinx",
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/style/EditableField.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const useStyles = makeStyles((theme) => ({
}
}));

export default function EditableField({value, onChange, validate, helperText, onStopEdit, ...props}) {
export default function EditableField({value, onChange, validate, helperText, onStopEdit, canEdit = true, ...props}) {
const [currentValue, setValue] = useState("");
const [editing, setEditing] = useState(false);
const [error, setError] = useState(false);
Expand Down Expand Up @@ -70,7 +70,7 @@ export default function EditableField({value, onChange, validate, helperText, on
onKeyUp={onKeyUp}
{...props}
/>
{editing ? (
{canEdit && editing ? (
<>
<IconButton color="primary" onClick={onSave}>
<Check/>
Expand Down
32 changes: 18 additions & 14 deletions web/src/components/transactions/TransactionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export default function TransactionList({group}) {
<>
<Paper sx={{padding: 2}}>
{userPermissions.can_write && (
<Grid container justifyContent="center">
<IconButton color="primary" onClick={() => setShowCreateDialog(true)}>
<Add/>
</IconButton>
</Grid>
<>
<Grid container justifyContent="center">
<IconButton color="primary" onClick={() => setShowCreateDialog(true)}>
<Add/>
</IconButton>
</Grid>
<Divider variant="middle"/>
</>
)}
<Divider variant="middle"/>
<List>
{transactions.length === 0 ? (
<div className="list-group-item" key={0}>No Transactions</div>
Expand All @@ -35,14 +37,16 @@ export default function TransactionList({group}) {
<TransactionCreateModal group={group} show={showCreateDialog}
onClose={() => setShowCreateDialog(false)}/>
</Paper>
<Fab
color="primary"
aria-label="add"
sx={{position: "absolute", right: 20, bottom: 20}}
onClick={() => setShowCreateDialog(true)}
>
<Add/>
</Fab>
{userPermissions.can_write && (
<Fab
color="primary"
aria-label="add"
sx={{position: "absolute", right: 20, bottom: 20}}
onClick={() => setShowCreateDialog(true)}
>
<Add/>
</Fab>
)}
</>
);
}
4 changes: 4 additions & 0 deletions web/src/pages/groups/GroupDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function GroupDetail({ group }) {
margin="normal"
variant="standard"
value={group.name}
canEdit={userPermissions.can_write}
onChange={name => updateGroup({ name: name })}
/>

Expand All @@ -69,6 +70,7 @@ export default function GroupDetail({ group }) {
margin="normal"
variant="standard"
value={group.description}
canEdit={userPermissions.can_write}
onChange={description => updateGroup({ description: description })}
/>

Expand All @@ -77,6 +79,7 @@ export default function GroupDetail({ group }) {
margin="normal"
variant="standard"
value={group.currency_symbol}
canEdit={userPermissions.can_write}
onChange={currencySymbol => updateGroup({ currencySymbol: currencySymbol })}
/>

Expand All @@ -85,6 +88,7 @@ export default function GroupDetail({ group }) {
margin="normal"
variant="standard"
value={group.terms}
canEdit={userPermissions.can_write}
onChange={terms => updateGroup({ terms: terms })}
/>

Expand Down

0 comments on commit 489d1d0

Please sign in to comment.