Skip to content

Commit 4abd3d2

Browse files
committed
fix: node user email format
1 parent e5ae7de commit 4abd3d2

7 files changed

Lines changed: 50 additions & 37 deletions

File tree

app/db/crud/admin.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,15 @@ async def delete_admin_notification_reminders(
517517

518518
async def get_active_to_limited_admins(db: AsyncSession) -> list[Admin]:
519519
"""Return ALL active admins that have exceeded their data_limit (for status flip)."""
520-
stmt = select(Admin).options(selectinload(Admin.role)).where(
521-
Admin.status == AdminStatus.active,
522-
Admin.data_limit.isnot(None),
523-
Admin.data_limit > 0,
524-
Admin.used_traffic >= Admin.data_limit,
520+
stmt = (
521+
select(Admin)
522+
.options(selectinload(Admin.role))
523+
.where(
524+
Admin.status == AdminStatus.active,
525+
Admin.data_limit.isnot(None),
526+
Admin.data_limit > 0,
527+
Admin.used_traffic >= Admin.data_limit,
528+
)
525529
)
526530
return list((await db.execute(stmt)).scalars().all())
527531

app/models/host.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,9 @@ class NoiseSettings(BaseModel):
6363

6464

6565
class XMuxSettings(BaseModel):
66-
max_concurrency: str | None = Field(
67-
None, pattern=r"^\d{1,16}(-\d{1,16})?$", serialization_alias="maxConcurrency"
68-
)
69-
max_connections: str | None = Field(
70-
None, pattern=r"^\d{1,16}(-\d{1,16})?$", serialization_alias="maxConnections"
71-
)
72-
c_max_reuse_times: str | None = Field(
73-
None, pattern=r"^\d{1,16}(-\d{1,16})?$", serialization_alias="cMaxReuseTimes"
74-
)
66+
max_concurrency: str | None = Field(None, pattern=r"^\d{1,16}(-\d{1,16})?$", serialization_alias="maxConcurrency")
67+
max_connections: str | None = Field(None, pattern=r"^\d{1,16}(-\d{1,16})?$", serialization_alias="maxConnections")
68+
c_max_reuse_times: str | None = Field(None, pattern=r"^\d{1,16}(-\d{1,16})?$", serialization_alias="cMaxReuseTimes")
7569
h_max_reusable_secs: str | None = Field(
7670
None, pattern=r"^\d{1,16}(-\d{1,16})?$", serialization_alias="hMaxReusableSecs"
7771
)

app/models/subscription.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ class XHTTPTransportConfig(BaseTransportConfig):
104104
sc_min_posts_interval_ms: str | None = Field(
105105
None, serialization_alias="scMinPostsIntervalMs", pattern=r"^\d{1,16}(?:-\d{1,16})?$"
106106
)
107-
x_padding_bytes: str | None = Field(
108-
None, serialization_alias="xPaddingBytes", pattern=r"^\d{1,16}(?:-\d{1,16})?$"
109-
)
107+
x_padding_bytes: str | None = Field(None, serialization_alias="xPaddingBytes", pattern=r"^\d{1,16}(?:-\d{1,16})?$")
110108
x_padding_obfs_mode: bool | None = Field(None, serialization_alias="xPaddingObfsMode")
111109
x_padding_key: str | None = Field(None, serialization_alias="xPaddingKey")
112110
x_padding_header: str | None = Field(None, serialization_alias="xPaddingHeader")

app/operation/admin.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,16 @@ async def _modify_admin(
107107
)
108108

109109
if is_owner_target and modified_admin.role_id is not None and modified_admin.role_id != db_admin.role_id:
110-
await self.raise_error(message="Owner role cannot be changed via this endpoint. Use the setup flow.", code=403)
110+
await self.raise_error(
111+
message="Owner role cannot be changed via this endpoint. Use the setup flow.", code=403
112+
)
111113

112-
if not current_admin.is_owner and is_self and modified_admin.role_id is not None and modified_admin.role_id != db_admin.role_id:
114+
if (
115+
not current_admin.is_owner
116+
and is_self
117+
and modified_admin.role_id is not None
118+
and modified_admin.role_id != db_admin.role_id
119+
):
113120
await self.raise_error(message="You're not allowed to change your own role.", code=403)
114121

115122
if not current_admin.is_owner and is_self:

app/operation/node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ async def _get_user_online_stats_local(self, db: AsyncSession, node_id: int, use
839839
await self.raise_error(message="Node not found", code=404)
840840

841841
try:
842-
stats = await node.get_user_online_stats(email=f"{db_user.id}.{db_user.username}")
842+
stats = await node.get_user_online_stats(email=f"{db_user.id}")
843843
except NodeAPIError as e:
844844
await self.raise_error(message=e.detail, code=e.code)
845845

@@ -880,7 +880,7 @@ async def _get_user_ip_list_all_local(self, db: AsyncSession, username: str) ->
880880
await self.raise_error(message="User not found", code=404)
881881

882882
nodes = await node_manager.get_healthy_nodes()
883-
email = f"{db_user.id}.{db_user.username}"
883+
email = f"{db_user.id}"
884884

885885
ip_list_tasks = {id: asyncio.create_task(self._get_node_user_ip_list_safe(id, email)) for id, _ in nodes}
886886

app/operation/user.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
from app.db.models import User, UserStatus, UserTemplate
5656
from app.models.admin import AdminDetails
5757
from app.models.proxy import ProxyTable
58-
from app.models.settings import HWIDSettings
5958
from app.models.stats import (
6059
Period,
6160
UserCountMetric,
@@ -545,8 +544,10 @@ async def create_user(
545544
await self.raise_error(
546545
message=f"HWID limit cannot be less than {effective_hwid_conf.min_limit}", code=400, db=db
547546
)
548-
if effective_hwid_conf.max_limit is not None and effective_hwid_conf.max_limit > 0 and (
549-
new_user.hwid_limit > effective_hwid_conf.max_limit or new_user.hwid_limit == 0
547+
if (
548+
effective_hwid_conf.max_limit is not None
549+
and effective_hwid_conf.max_limit > 0
550+
and (new_user.hwid_limit > effective_hwid_conf.max_limit or new_user.hwid_limit == 0)
550551
):
551552
await self.raise_error(
552553
message=f"HWID limit cannot exceed {effective_hwid_conf.max_limit}", code=400, db=db
@@ -643,12 +644,17 @@ async def _prepare_modified_user(
643644
admin.role.hwid if admin.role is not None else None,
644645
)
645646
if effective_hwid_conf is not None:
646-
if effective_hwid_conf.min_limit is not None and modified_user.hwid_limit < effective_hwid_conf.min_limit:
647+
if (
648+
effective_hwid_conf.min_limit is not None
649+
and modified_user.hwid_limit < effective_hwid_conf.min_limit
650+
):
647651
await self.raise_error(
648652
message=f"HWID limit cannot be less than {effective_hwid_conf.min_limit}", code=400, db=db
649653
)
650-
if effective_hwid_conf.max_limit is not None and effective_hwid_conf.max_limit > 0 and (
651-
modified_user.hwid_limit > effective_hwid_conf.max_limit or modified_user.hwid_limit == 0
654+
if (
655+
effective_hwid_conf.max_limit is not None
656+
and effective_hwid_conf.max_limit > 0
657+
and (modified_user.hwid_limit > effective_hwid_conf.max_limit or modified_user.hwid_limit == 0)
652658
):
653659
await self.raise_error(
654660
message=f"HWID limit cannot exceed {effective_hwid_conf.max_limit}", code=400, db=db

tests/api/test_user.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,11 +1267,13 @@ def test_xray_subscription_uses_host_specific_template_override(access_token):
12671267
access_token,
12681268
name=unique_name("xray_host_override_template"),
12691269
template_type="xray_subscription",
1270-
content=json.dumps({
1271-
"log": {"loglevel": "warning"},
1272-
"inbounds": [{"tag": "placeholder", "protocol": "vmess", "settings": {"clients": []}}],
1273-
"outbounds": [{"tag": "template-marker", "protocol": "freedom", "settings": {}}],
1274-
}),
1270+
content=json.dumps(
1271+
{
1272+
"log": {"loglevel": "warning"},
1273+
"inbounds": [{"tag": "placeholder", "protocol": "vmess", "settings": {"clients": []}}],
1274+
"outbounds": [{"tag": "template-marker", "protocol": "freedom", "settings": {}}],
1275+
}
1276+
),
12751277
)
12761278

12771279
host_response = client.post(
@@ -1337,11 +1339,13 @@ def test_xray_subscription_template_override_isolated_per_host(access_token):
13371339
access_token,
13381340
name=unique_name("xray_host_isolated_template"),
13391341
template_type="xray_subscription",
1340-
content=json.dumps({
1341-
"log": {"loglevel": "warning"},
1342-
"inbounds": [{"tag": "placeholder", "protocol": "vmess", "settings": {"clients": []}}],
1343-
"outbounds": [{"tag": "template-marker", "protocol": "freedom", "settings": {}}],
1344-
}),
1342+
content=json.dumps(
1343+
{
1344+
"log": {"loglevel": "warning"},
1345+
"inbounds": [{"tag": "placeholder", "protocol": "vmess", "settings": {"clients": []}}],
1346+
"outbounds": [{"tag": "template-marker", "protocol": "freedom", "settings": {}}],
1347+
}
1348+
),
13451349
)
13461350

13471351
first_host_response = client.post(

0 commit comments

Comments
 (0)