You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by ar...@apache.org on 2026/05/26 12:15:42 UTC
(tooling-trusted-releases) branch arm updated (2b6a907f -> 19091392)
This is an automated email from the ASF dual-hosted git repository.
alitheg pushed a change to branch arm
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
discard 2b6a907f List user sessions
new 19091392 List user sessions
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (2b6a907f)
\
N -- N -- N refs/heads/arm (19091392)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
tests/unit/test_sessions.py | 4 ++++
1 file changed, 4 insertions(+)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org
(tooling-trusted-releases) 01/01: List user sessions
Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alitheg pushed a commit to branch arm
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
commit 19091392a679405dee35f70e04b5c9da1b7e659e
Author: Alastair McFarlane <ar...@apache.org>
AuthorDate: Tue May 26 13:07:53 2026 +0100
List user sessions
---
atr/admin/__init__.py | 1 +
atr/db/__init__.py | 8 ++++
atr/get/user.py | 49 +++++++++++++++++++++++++
atr/models/sql.py | 1 +
atr/sessions.py | 3 +-
atr/storage/readers/user.py | 7 ++++
atr/templates/includes/topnav.html | 4 ++
migrations/versions/0086_2026.05.26_a69c86b6.py | 27 ++++++++++++++
tests/unit/test_sessions.py | 4 ++
9 files changed, 103 insertions(+), 1 deletion(-)
diff --git a/atr/admin/__init__.py b/atr/admin/__init__.py
index 3dcb03a1..71a45001 100644
--- a/atr/admin/__init__.py
+++ b/atr/admin/__init__.py
@@ -209,6 +209,7 @@ async def browse_as_post(
projects=sorted(set(committer.projects)),
mfa=session.session.mfa,
admin_uid=admin_id,
+ ip_address=quart.request.remote_addr,
)
)
log.auth_event("impersonate", admin_id, as_user=committer.uid)
diff --git a/atr/db/__init__.py b/atr/db/__init__.py
index 2f4b801e..4303d9ce 100644
--- a/atr/db/__init__.py
+++ b/atr/db/__init__.py
@@ -988,6 +988,14 @@ class Session(sqlalchemy.ext.asyncio.AsyncSession):
return Query(self, query)
+ def usersession(self, uid: Opt[str] = NOT_SET) -> Query[sql.UserSession]:
+ query = sqlmodel.select(sql.UserSession)
+
+ if is_defined(uid):
+ query = query.where(sql.UserSession.uid == uid)
+
+ return Query(self, query)
+
def workflow_ssh_key(
self,
fingerprint: Opt[str] = NOT_SET,
diff --git a/atr/get/user.py b/atr/get/user.py
index 6d3da83a..0f5a2607 100644
--- a/atr/get/user.py
+++ b/atr/get/user.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
+import datetime
from typing import Literal
import quart
@@ -23,6 +24,7 @@ import atr.blueprints.get as get
import atr.config as config
import atr.form as form
import atr.htm as htm
+import atr.models.sql as sql
import atr.shared as shared
import atr.storage as storage
import atr.template as template
@@ -122,6 +124,53 @@ async def preferences(session: web.Committer, _user_preferences: Literal["user/p
return await template.blank("User preferences", content=block.collect())
+@get.typed
+async def sessions(_session: web.Committer, _user_sessions: Literal["user/sessions"]) -> str:
+ """
+ URL: /user/sessions
+ """
+
+ sessions: list[sql.UserSession] = []
+ async with storage.read_as_foundation_committer() as rafc:
+ sessions = sorted(await rafc.user.user_sessions(), key=lambda s: s.last_account_check or s.cts, reverse=True)
+
+ block = htm.Block()
+ block.h1["User sessions"]
+ block.p["Below is a list of your recent sessions"]
+
+ card = htm.Block(htm.div, classes=".card.mb-4")
+ card.div(".card-header.d-flex.justify-content-between.align-items-center")[htm.h3(".mb-0")["Sessions"]]
+
+ tbody = htm.Block(htm.tbody)
+ for session in sessions:
+ tbody.tr[
+ htm.td[session.uid],
+ htm.td[datetime.datetime.fromtimestamp(session.cts).strftime("%Y-%m-%d %H:%M:%S")],
+ htm.td[datetime.datetime.fromtimestamp(session.last_account_check).strftime("%Y-%m-%d %H:%M:%S")]
+ if session.last_account_check
+ else "",
+ htm.td[session.ip_address or "unknown"],
+ ]
+
+ card.div(".card-body")[
+ htm.div(".table-responsive")[
+ htm.table(".table.table-striped")[
+ htm.thead[
+ htm.tr[
+ htm.th["User ID"],
+ htm.th["Created"],
+ htm.th["Last verified"],
+ htm.th["IP Address"],
+ ]
+ ],
+ tbody.collect(),
+ ]
+ ]
+ ]
+ block.append(card)
+ return await template.blank("User sessions", content=block.collect())
+
+
@get.typed
async def tally(_session: web.Committer, _user_tally: Literal["user/tally"]) -> str:
"""
diff --git a/atr/models/sql.py b/atr/models/sql.py
index ff6e28c5..1cd51eef 100644
--- a/atr/models/sql.py
+++ b/atr/models/sql.py
@@ -703,6 +703,7 @@ class UserSession(sqlmodel.SQLModel, table=True):
)
mfa: bool = sqlmodel.Field(default=False)
is_role: bool = sqlmodel.Field(default=False)
+ ip_address: str | None = sqlmodel.Field(nullable=True)
admin_uid: str | None = sqlmodel.Field(default=None, index=True)
last_account_check: float | None = sqlmodel.Field(default=None)
downgrade_admin_to_user: bool = sqlmodel.Field(default=False)
diff --git a/atr/sessions.py b/atr/sessions.py
index 2fa2c6f3..cab71f0d 100644
--- a/atr/sessions.py
+++ b/atr/sessions.py
@@ -140,8 +140,9 @@ def _prepare_session_data(session_data: dict[str, Any]) -> dict[str, Any]:
class Store:
async def create(self, hsid: str, session_data: dict[str, Any]) -> None:
prepared = _prepare_session_data(session_data)
+ ip_address = quart.request.remote_addr
now = time.time()
- user_session = sql.UserSession(sid_hash=hsid, cts=now, uts=now, **prepared)
+ user_session = sql.UserSession(sid_hash=hsid, cts=now, uts=now, ip_address=ip_address, **prepared)
async with db.session() as data:
data.add(user_session)
await data.commit()
diff --git a/atr/storage/readers/user.py b/atr/storage/readers/user.py
index 8132e995..06987dc4 100644
--- a/atr/storage/readers/user.py
+++ b/atr/storage/readers/user.py
@@ -48,3 +48,10 @@ class FoundationCommitter(GeneralPublic):
raise ValueError("Not authorized")
user = await self.__data.user(asf_uid=asf_uid).get()
return user
+
+ async def user_sessions(self) -> list[sql.UserSession]:
+ asf_uid = self.__asf_uid
+ if asf_uid is None:
+ raise ValueError("Not authorized")
+ user = await self.__data.usersession(uid=asf_uid).all()
+ return list(user)
diff --git a/atr/templates/includes/topnav.html b/atr/templates/includes/topnav.html
index d782a0a1..5466117b 100644
--- a/atr/templates/includes/topnav.html
+++ b/atr/templates/includes/topnav.html
@@ -134,6 +134,10 @@
<a class="dropdown-item" href="{{ as_url(get.user.preferences) }}"><i class="bi bi-gear"></i>
Preferences</a>
</li>
+ <li>
+ <a class="dropdown-item" href="{{ as_url(get.user.sessions) }}"><i class="bi bi-shield-lock"></i>
+ Sessions</a>
+ </li>
</ul>
</li>
{% endif %}
diff --git a/migrations/versions/0086_2026.05.26_a69c86b6.py b/migrations/versions/0086_2026.05.26_a69c86b6.py
new file mode 100644
index 00000000..29949af3
--- /dev/null
+++ b/migrations/versions/0086_2026.05.26_a69c86b6.py
@@ -0,0 +1,27 @@
+"""session IPs
+
+Revision ID: 0086_2026.05.26_a69c86b6
+Revises: 0085_2025.05.19_9d086f7e
+Create Date: 2026-05-26 11:44:54.320807+00:00
+"""
+
+from collections.abc import Sequence
+
+import sqlalchemy as sa
+from alembic import op
+
+# Revision identifiers, used by Alembic
+revision: str = "0086_2026.05.26_a69c86b6"
+down_revision: str | None = "0085_2025.05.19_9d086f7e"
+branch_labels: str | Sequence[str] | None = None
+depends_on: str | Sequence[str] | None = None
+
+
+def upgrade() -> None:
+ with op.batch_alter_table("usersession", schema=None) as batch_op:
+ batch_op.add_column(sa.Column("ip_address", sa.String(), nullable=True))
+
+
+def downgrade() -> None:
+ with op.batch_alter_table("usersession", schema=None) as batch_op:
+ batch_op.drop_column("ip_address")
diff --git a/tests/unit/test_sessions.py b/tests/unit/test_sessions.py
index 344fc12a..33fab4e1 100644
--- a/tests/unit/test_sessions.py
+++ b/tests/unit/test_sessions.py
@@ -43,6 +43,10 @@ async def store(monkeypatch):
monkeypatch.setattr(sessions.config, "get", lambda: _MOCK_CONFIG)
+ mock_request = mock.MagicMock()
+ mock_request.remote_addr = "127.0.0.1"
+ monkeypatch.setattr("quart.request", mock_request)
+
global _COUNTER
_COUNTER = 0
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org