feat(cli) Allow assigning all permissions to one group from cli

This commit is contained in:
Ferdinand Thiessen 2021-11-28 22:23:34 +01:00
parent 2b93404dc0
commit 50632eb333
1 changed files with 21 additions and 17 deletions

View File

@ -5,7 +5,9 @@ import argparse
import sys import sys
import pkg_resources import pkg_resources
from sqlalchemy import exc
from flaschengeist.app import create_app, install_all
from flaschengeist.config import config from flaschengeist.config import config
@ -130,16 +132,12 @@ class InterfaceGenerator:
def install(arguments): def install(arguments):
from flaschengeist.app import create_app, install_all
app = create_app() app = create_app()
with app.app_context(): with app.app_context():
install_all() install_all()
def run(arguments): def run(arguments):
from flaschengeist.app import create_app
app = create_app() app = create_app()
with app.app_context(): with app.app_context():
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=config["FLASCHENGEIST"].get("root", "")) app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=config["FLASCHENGEIST"].get("root", ""))
@ -151,7 +149,6 @@ def run(arguments):
def export(arguments): def export(arguments):
import flaschengeist.models as models import flaschengeist.models as models
from flaschengeist.app import create_app
app = create_app() app = create_app()
with app.app_context(): with app.app_context():
@ -167,16 +164,23 @@ def export(arguments):
gen.write() gen.write()
def ldap_sync(arguments): def ldap(arguments):
from flaschengeist.app import create_app app = create_app()
with app.app_context():
if arguments.set_admin:
from flaschengeist.controller import roleController
from flaschengeist.database import db
role = roleController.get(arguments.set_admin)
role.permissions = roleController.get_permissions()
db.session.commit()
if arguments.sync:
from flaschengeist.controller import userController from flaschengeist.controller import userController
from flaschengeist.plugins.auth_ldap import AuthLDAP from flaschengeist.plugins.auth_ldap import AuthLDAP
from ldap3 import SUBTREE from ldap3 import SUBTREE
app = create_app()
with app.app_context():
auth_ldap: AuthLDAP = app.config.get("FG_PLUGINS").get("auth_ldap") auth_ldap: AuthLDAP = app.config.get("FG_PLUGINS").get("auth_ldap")
if auth_ldap: if auth_ldap is None:
raise Exception("Plugin >auth_ldap< not found")
conn = auth_ldap.ldap.connection conn = auth_ldap.ldap.connection
if not conn: if not conn:
conn = auth_ldap.ldap.connect(auth_ldap.root_dn, auth_ldap.root_secret) conn = auth_ldap.ldap.connect(auth_ldap.root_dn, auth_ldap.root_secret)
@ -185,8 +189,6 @@ def ldap_sync(arguments):
for ldap_user in ldap_users_response: for ldap_user in ldap_users_response:
uid = ldap_user["attributes"]["uid"][0] uid = ldap_user["attributes"]["uid"][0]
userController.find_user(uid) userController.find_user(uid)
exit()
raise Exception("auth_ldap not found")
if __name__ == "__main__": if __name__ == "__main__":
@ -214,8 +216,10 @@ if __name__ == "__main__":
) )
parser_export.add_argument("--plugins", help="Also export plugins (none means all)", nargs="*") parser_export.add_argument("--plugins", help="Also export plugins (none means all)", nargs="*")
parser_ldap_sync = subparsers.add_parser("ldap_sync", help="synch ldap-users with database") parser_ldap = subparsers.add_parser("ldap", help="LDAP helper utils")
parser_ldap_sync.set_defaults(func=ldap_sync) parser_ldap.set_defaults(func=ldap)
parser_ldap.add_argument('--sync', action="store_true", help="Sync ldap-users with database")
parser_ldap.add_argument('--set-admin', type=str, help="Assign all permissions this to group")
args = parser.parse_args() args = parser.parse_args()
args.func(args) args.func(args)