mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Fix addressing issue #2005 including tests
This commit is contained in:
1 parent
1d10bda22e
commit
4cf8b79692
9 files changed
+202
-13
No files matched your search
@@ -15,7 +15,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sqlalchemy import Table, Boolean, Column, String, DateTime, ForeignKey, event
|
||||
from sqlalchemy import Table, Boolean, Column, Integer, String, DateTime, ForeignKey, event
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from .base import Base, BaseTable, generate_uuid, GUID
|
||||
@@ -45,6 +45,7 @@ class User(BaseTable):
|
||||
full_name = Column(String)
|
||||
hashed_password = Column(String)
|
||||
last_login = Column(DateTime)
|
||||
token_version = Column(Integer, default=0, nullable=False, server_default="0")
|
||||
is_active = Column(Boolean, default=True)
|
||||
is_superadmin = Column(Boolean, default=False)
|
||||
groups = relationship("UserGroup", secondary=user_group_map, back_populates="users")
|
||||
|
||||
@@ -113,6 +113,18 @@ class UsersRepository(BaseRepository):
|
||||
await self._db_session.refresh(user_db) # force refresh of updated_at value
|
||||
return user_db
|
||||
|
||||
async def logout_user(self, user_id: UUID) -> None:
|
||||
"""
|
||||
Increment token_version to invalidate all existing tokens for the user.
|
||||
"""
|
||||
|
||||
query = update(models.User).\
|
||||
where(models.User.user_id == user_id).\
|
||||
values(token_version=models.User.token_version + 1)
|
||||
|
||||
await self._db_session.execute(query)
|
||||
await self._db_session.commit()
|
||||
|
||||
async def delete_user(self, user_id: UUID) -> bool:
|
||||
"""
|
||||
Delete a user.
|
||||
|
||||
Reference in new issue
Block a user