Commit c1c4b01d authored by Samuel GAIST's avatar Samuel GAIST

[database][commands] Implement database access information printer

This commands gives an overview about the current
access status of the databases of the beat platform
also giving which user can access them if not public.
parent f7ed9c32
Pipeline #32479 passed with stage
in 16 minutes and 45 seconds
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.web module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import logging
from django.core.management.base import BaseCommand
from ...models import Database
logger = logging.getLogger("beat.web")
class Command(BaseCommand):
help = "Prints the list of databases with access level and user information"
def handle(self, *ignored, **options):
# Setup this command's logging level
global logger
verbosity = int(options["verbosity"])
if verbosity >= 1:
if verbosity == 1:
logger.setLevel(logging.INFO)
elif verbosity >= 2:
logger.setLevel(logging.DEBUG)
self.stdout.write("name, access, user")
for database in Database.objects.all():
db_info = "{}, {}".format(
database.fullname(), database.get_sharing_display()
)
for user in [
"{}: {} {}".format(user.username, user.first_name, user.last_name)
for user in database.all_shared_with_users()
]:
self.stdout.write("{}, {}".format(db_info, user))
else:
self.stdout.write(db_info)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment