Skip to content

Commit

Permalink
renaming for matching
Browse files Browse the repository at this point in the history
Signed-off-by: Alex <[email protected]>

#744
  • Loading branch information
agmes4 committed Sep 17, 2024
1 parent 00eceea commit 4e1f238
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pycroft/model/mpsk_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MPSKClient(IntegerIdModel):
owner_id: Mapped[int | None] = mapped_column(
ForeignKey(User.id, ondelete="CASCADE"), index=True
)
owner: Mapped[User] = relationship(User, back_populates="mspks")
owner: Mapped[User] = relationship(User, back_populates="mpsks")
mac: Mapped[mac_address] = mapped_column(unique=True)

@validates("mac")
Expand Down
2 changes: 1 addition & 1 deletion pycroft/model/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class User(BaseUser, UserMixin):
back_populates="owner", cascade="all, delete-orphan"
)

mspks: Mapped[list[MPSKClient]] = relationship(
mpsks: Mapped[list[MPSKClient]] = relationship(
back_populates="owner", cascade="all, delete-orphan"
)

Expand Down
1 change: 1 addition & 0 deletions tests/factories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SwitchFactory,
SwitchPortFactory,
)
from .mpsk import MPSKFactory, BareMPSKFactory
from .net import SubnetFactory, VLANFactory
from .property import (
PropertyGroupFactory,
Expand Down
32 changes: 16 additions & 16 deletions web/blueprints/mpskclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pycroft.exc import PycroftException
from pycroft.helpers.net import mac_regex, get_interface_manufacturer
from pycroft.lib import mpsk_client as lib_mspk
from pycroft.lib import mpsk_client as lib_mpsk
from pycroft.lib.net import get_subnets_for_room
from pycroft.lib.facilities import get_room
from pycroft.model import session
Expand All @@ -22,18 +22,18 @@
from web.blueprints.host.forms import InterfaceForm, HostForm
from web.blueprints.host.tables import InterfaceTable, HostTable, HostRow, InterfaceRow
from web.blueprints.mpskclient.forms import WiFiInterfaceForm
from web.blueprints.mpskclient.tables import MSPKRow
from web.blueprints.mpskclient.tables import MPSKRow
from web.table.table import TableResponse, BtnColResponse, LinkColResponse

bp = Blueprint("wifi-mpsk", __name__)
access = BlueprintAccess(bp, required_properties=["user_show"])


def get_mpsk_client_or_404(mspk_id: int) -> MPSKClient:
if (mspk := session.session.get(MPSKClient, mspk_id)) is None:
def get_mpsk_client_or_404(mpsk_id: int) -> MPSKClient:
if (mpsk := session.session.get(MPSKClient, mpsk_id)) is None:
flash("Host existiert nicht.", "error")
abort(404)
return mspk
return mpsk


@bp.route("/create", methods=["GET", "POST"])
Expand All @@ -46,7 +46,7 @@ def default_response() -> ResponseReturnValue:
form_args = {"form": form, "cancel_to": url_for("user.user_show", user_id=user.id)}

return render_template(
"generic_form.html", page_title="MSPK Client erstellen", form_args=form_args, form=form
"generic_form.html", page_title="MPSK Client erstellen", form_args=form_args, form=form
)

if not form.is_submitted():
Expand All @@ -61,13 +61,13 @@ def default_response() -> ResponseReturnValue:
owner = session.session.get(User, form.owner_id.data)
with abort_on_error(default_response), session.session.begin_nested():

host = lib_mspk.mpsk_client_create(
host = lib_mpsk.mpsk_client_create(
owner, form.name.data, form.mac.data, processor=current_user
)
session.session.commit()

flash("MPSK Client erfolgreich erstellt.", "success")
return redirect(url_for("user.user_show", user_id=host.owner.id, _anchor="mspks"))
return redirect(url_for("user.user_show", user_id=host.owner.id, _anchor="mpsks"))


@bp.route("/<int:mpsk_id>/delete", methods=["GET", "POST"])
Expand All @@ -93,11 +93,11 @@ def default_response() -> ResponseReturnValue:
return default_response()

with abort_on_error(default_response), session.session.begin_nested():
lib_mspk.mpsk_delete(mpsk, current_user)
lib_mpsk.mpsk_delete(mpsk, current_user)
session.session.commit()

flash("MPSK Client erfolgreich gelöscht.", "success")
return redirect(url_for("user.user_show", user_id=owner.id, _anchor="mspks"))
return redirect(url_for("user.user_show", user_id=owner.id, _anchor="mpsks"))


@bp.route("/<int:mpsk_id>/edit", methods=["GET", "POST"])
Expand All @@ -118,26 +118,26 @@ def default_response() -> ResponseReturnValue:
return default_response()

with abort_on_error(default_response), session.session.begin_nested():
lib_mspk.mpsk_edit(mpsk, mpsk.owner, form.name.data, form.mac.data, current_user)
lib_mpsk.mpsk_edit(mpsk, mpsk.owner, form.name.data, form.mac.data, current_user)
session.session.commit()
flash("MPSK Client erfolgreich bearbeitet.", "success")
return redirect(url_for("user.user_show", user_id=mpsk.owner_id, _anchor="mspks"))
return redirect(url_for("user.user_show", user_id=mpsk.owner_id, _anchor="mpsks"))


@bp.route("/<int:user_id>")
def user_clients_json(user_id: int) -> ResponseReturnValue:
user = get_user_or_404(user_id)
# TODO: Importend when the for the returning of actual mpsk mac addresses for MPSK devices
# return ""
return TableResponse[MSPKRow](
items=[_mspk_row(mpsk, user_id) for mpsk in user.mspks]
return TableResponse[MPSKRow](
items=[_mpsk_row(mpsk, user_id) for mpsk in user.mpsks]
).model_dump()


def _mspk_row(client, user_id: int) -> MSPKRow:
def _mpsk_row(client, user_id: int) -> MPSKRow:
# println(f"{client}")
# client = get_wlan_host_or_404(client)
return MSPKRow(
return MPSKRow(
id=client.id,
name=client.name,
mac=client.mac,
Expand Down
2 changes: 1 addition & 1 deletion web/blueprints/mpskclient/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def toolbar(self) -> HasDunderStr | None:
return button_toolbar("Client", href)


class MSPKRow(BaseModel):
class MPSKRow(BaseModel):
name: str | None = None
mac: str
actions: list[BtnColResponse]
Expand Down

0 comments on commit 4e1f238

Please sign in to comment.