Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
themanyfaceddemon committed Sep 22, 2024
1 parent 727437c commit 2bc2c89
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 34 deletions.
56 changes: 40 additions & 16 deletions Code/gui/dm_client_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import logging
import shutil
import time
import zipfile
from pathlib import Path
Expand Down Expand Up @@ -117,7 +118,7 @@ async def _create_connect_window(cls):

@classmethod
async def _connect_to_server(cls, sender, app_data, user_data):
if Client._is_connected:
if Client.is_connected():
return

if not user_data and dpg.is_key_down(dpg.mvKey_Control): # For debug
Expand Down Expand Up @@ -207,36 +208,59 @@ async def setup_start_windows(cls) -> None:
)
access = await Client.req_get_data("get_access", None, login=Client.get_login())
dpg.add_viewport_menu_bar(tag="main_bar")

dpg.add_menu_item(label=loc.get_string('cur_login', login=Client.get_login()), parent='main_bar', enabled=False)

dpg.add_menu_item(
label=loc.get_string("cur_login", login=Client.get_login()),
parent="main_bar",
enabled=False,
)

# При всём желании, проверка прав проходит на сервере. Даже не пытайтесь.
if "full_access" in access:
await admin_main_window()

@classmethod
async def download_content_from_server(cls) -> None:
anser = await Client.req_get_data("download_server_conent", "download")
if anser != "done":
logging.error(anser)
return

file_path = (
Path(ROOT_PATH)
/ "Content"
/ "Servers"
/ Client.get_server_name()
/ "server_contet.zip"
)
extract_path = (
server_content_path: Path = (
Path(ROOT_PATH) / "Content" / "Servers" / Client.get_server_name()
)
local_hash_path = server_content_path / "content_hash"

if local_hash_path.exists():
with local_hash_path.open("r") as file:
local_hash = file.read().strip()
else:
local_hash = None

server_hash = await Client.req_get_data("get_server_content_hash", None)

if local_hash == server_hash:
return

else:
if server_content_path.exists():
for item in server_content_path.iterdir():
if item.is_file():
item.unlink()
elif item.is_dir():
shutil.rmtree(item)

answer = await Client.req_get_data("download_server_content", None)
if answer != "done":
logging.error(f"Error while download content: {answer}")
return

file_path = server_content_path / "server_content.zip"
extract_path = server_content_path

with zipfile.ZipFile(file_path, "r") as zip_ref:
zip_ref.extractall(extract_path)

file_path.unlink()

with local_hash_path.open("w") as file:
file.write(server_hash)

@classmethod
def run(cls):
cls._dpg_async.run()
Expand Down
13 changes: 9 additions & 4 deletions Code/gui/windows/admin/manage_server_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
from systems.loc import Localization as loc


async def manage_server_settings():
if dpg.does_item_exist("manage_server_settings"):
dpg.focus_item("manage_server_settings")
async def manage_server_settings(sender, app_data, user_data) -> None:
if dpg.does_item_exist("manage_server_settings_window"):
dpg.focus_item("manage_server_settings_window")
return

with dpg.window(
label=loc.get_string("manage_server_settings_lable"),
tag="manage_server_settings",
tag="manage_server_settings_window",
width=400,
height=200,
on_close=_on_close
):
pass

def _on_close():
if dpg.does_item_exist("manage_server_settings_window"):
dpg.delete_item("manage_server_settings_window")
13 changes: 9 additions & 4 deletions Code/gui/windows/admin/manage_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
from systems.loc import Localization as loc


async def manage_users():
if dpg.does_item_exist("manage_users"):
dpg.focus_item("manage_users")
async def manage_users(sender, app_data, user_data) -> None:
if dpg.does_item_exist("manage_users_window"):
dpg.focus_item("manage_users_window")
return

with dpg.window(
label=loc.get_string("manage_users_lable"),
tag="manage_users",
tag="manage_users_window",
width=400,
height=200,
on_close=_on_close
):
pass

def _on_close():
if dpg.does_item_exist("manage_users_window"):
dpg.delete_item("manage_users_window")
22 changes: 14 additions & 8 deletions Code/gui/windows/admin/user_access_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@
from systems.loc import Localization as loc


async def user_access_control() -> None:
if dpg.does_item_exist("user_access_control"):
dpg.focus_item("user_access_control")
async def user_access_control(sender, app_data, user_data) -> None:
if dpg.does_item_exist("user_access_control_window"):
dpg.focus_item("user_access_control_window")
return

with dpg.window(
label=loc.get_string("user_access_control_lable"),
tag="user_access_control",
tag="user_access_control_window",
width=400,
height=200,
on_close=_on_close
):
users: list = await Client.req_get_data("get_all_users", None)

with dpg.group(horizontal=True):
with dpg.child_window(width=100, autosize_y=True):
dpg.add_text(loc.get_string("users_control_logins"))
with dpg.child_window(width=200, autosize_y=True):
dpg.add_text(loc.get_string("users_control_logins"), wrap=0)
for user in users:
dpg.add_button(
label=user, callback=load_user_access, user_data=user
)

with dpg.child_window(
width=300, tag="access_rights_admin", autosize_y=True, autosize_x=True
width=200, tag="access_rights_admin", autosize_y=True, autosize_x=True
):
dpg.add_text(loc.get_string("user_control_access_control"), wrap=0)
with dpg.group(tag="access_group"):
Expand Down Expand Up @@ -69,7 +70,7 @@ async def load_user_access(sender, app_data, user_data):
)

with dpg.tooltip(uuid_text):
dpg.add_text(loc.get_string(f"desc-{access_key}"), wrap=0)
dpg.add_text(loc.get_string(f"desc-{access_key}"), wrap=300)

dpg.add_spacer(width=0, height=10)

Expand All @@ -87,3 +88,8 @@ async def toggle_access(sender, app_data, user_data):

except Exception as e:
logging.error(f"Failed to update access for {user_id}: {e}")


def _on_close():
if dpg.does_item_exist("user_access_control_window"):
dpg.delete_item("user_access_control_window")
Loading

0 comments on commit 2bc2c89

Please sign in to comment.