[elbe-devel] [PATCH 1/8] elbepack: db: remove del_user()
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Tue Aug 13 13:31:49 CEST 2024
The usermanagement of elbe is being removed.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
docs/elbe-db.rst | 11 -----------
elbepack/commands/db.py | 30 +-----------------------------
elbepack/db.py | 21 ---------------------
3 files changed, 1 insertion(+), 61 deletions(-)
diff --git a/docs/elbe-db.rst b/docs/elbe-db.rst
index ebf1759f30ef..3d9782fd52f4 100644
--- a/docs/elbe-db.rst
+++ b/docs/elbe-db.rst
@@ -22,7 +22,6 @@ SYNOPSIS
elbe db [options] del_project <project_dir>
elbe db [options] print_version_xml <project_dir> <version>
elbe db [options] init
- elbe db [options] del_user <userid>
elbe db [options] set_project_version <project_dir> <version>
elbe db [options] add_user <username>
elbe db [options] list_versions <project_dir>
@@ -59,12 +58,6 @@ OPTIONS
Gives the new user admin privileges. (Boolean variable,
default=False).
---delete-projects
- Delete all projects owned by the user.
-
---quiet
- TODO
-
--user
User name of the project owner.
@@ -86,10 +79,6 @@ COMMANDS
*add_user* <username>
Adds a new user. Options: fullname, password, email, admin=[False].
-*del_user* <userid>
- Deletes user <userid>. Options: delete-projects[=False],
- quiet=[False].
-
*list_projects*
Lists all projects stored in the database.
diff --git a/elbepack/commands/db.py b/elbepack/commands/db.py
index 9d0d34eb1a2a..2c2002fe4f34 100644
--- a/elbepack/commands/db.py
+++ b/elbepack/commands/db.py
@@ -8,7 +8,7 @@ from getpass import getpass
from shutil import copyfileobj
from elbepack.cli import add_argument, add_arguments_from_decorated_function
-from elbepack.db import ElbeDB, ElbeDBError
+from elbepack.db import ElbeDB
@add_argument('--name', default='root')
@@ -36,33 +36,6 @@ def _add_user(args):
db.add_user(args.username, args.fullname, password, args.email, args.admin)
- at add_argument('--delete-projects', dest='delete_projects',
- default=False, action='store_true')
- at add_argument('--quiet', dest='quiet',
- default=False, action='store_true')
- at add_argument('userid', type=int)
-def _del_user(args):
- db = ElbeDB()
-
- projects = db.del_user(args.userid)
-
- if projects:
- if not args.opt.quiet:
- if args.opt.delete_projects:
- print('removing projects owned by the deleted user:')
- else:
- print('keeping projects owned by the deleted user:')
-
- for p in projects:
- if not args.opt.quiet:
- print(f'{p.builddir}: {p.name} [{p.version}] {p.edit}')
- if args.opt.delete_projects:
- try:
- db.del_project(p.builddir)
- except ElbeDBError as e:
- print(f' ==> {e} ')
-
-
def _list_projects(args):
db = ElbeDB()
projects = db.list_projects()
@@ -181,7 +154,6 @@ def _print_version_xml(args):
_actions = {
'init': _init,
'add_user': _add_user,
- 'del_user': _del_user,
'list_projects': _list_projects,
'list_users': _list_users,
'create_project': _create_project,
diff --git a/elbepack/db.py b/elbepack/db.py
index b3f87aa2712c..681a570fdc0a 100644
--- a/elbepack/db.py
+++ b/elbepack/db.py
@@ -769,27 +769,6 @@ class ElbeDB:
if password is not None:
u.pwhash = pbkdf2_sha512.hash(password)
- def del_user(self, userid):
- with session_scope(self.session) as s:
- try:
- u = s.query(User).filter(User.id == userid).one()
- except NoResultFound:
- raise ElbeDBError(f'no user with id {userid}')
-
- # Get a list of all projects owned by the user to delete. Set their
- # owner to nobody and return them to the caller later, so it can
- # decide whether to keep the projects or delete them.
- orphaned_projects = s.query(Project).\
- filter(Project.owner_id == userid).all()
- projectlist = []
- for p in orphaned_projects:
- p.owner_id = None
- projectlist.append(ProjectData(p))
-
- # Now delete the user and return the list
- s.delete(u)
- return projectlist
-
def validate_login(self, name, password):
with session_scope(self.session) as s:
# Find the user with the given name
--
2.46.0
More information about the elbe-devel
mailing list