Esempio n. 1
0
def initialize_reports_overview(database: Database) -> None:
    """Initialize the reports overview if not present in the database."""
    if latest_reports_overview(database):
        logging.info("Skipping initializing reports overview; it already exists")
    else:
        logging.info("Initializing reports overview")
        insert_new_reports_overview(database, dict(title="Reports", subtitle=""))
Esempio n. 2
0
def initialize_reports_overview(database: Database) -> None:
    """Initialize the reports overview if not present in the database."""
    # The coverage measurement of the behave feature tests is unstable. Most of the time it reports the last two lines
    # as covered, sometimes not. It's unclear why. To prevent needless checking of the coverage report coverage
    # measurement of the last two lines and the if-statement has been turned off.
    if latest_reports_overview(database):  # pragma: no-cover behave
        logging.info("Skipping initializing reports overview; it already exists")
    else:
        logging.info("Initializing reports overview")  # pragma: no-cover behave
        insert_new_reports_overview(database, dict(title="Reports", subtitle=""))  # pragma: no-cover behave
Esempio n. 3
0
def get_reports(database: Database):
    """Return the quality reports."""
    date_time = report_date_time()
    data_model = latest_datamodel(database, date_time)
    overview = latest_reports_overview(database, date_time)
    overview["reports"] = []
    recent_measurements = recent_measurements_by_metric_uuid(
        database, date_time)
    for report in latest_reports(database, date_time):
        summarize_report(report, recent_measurements, data_model)
        overview["reports"].append(report)
    hide_credentials(data_model, *overview["reports"])
    return overview
Esempio n. 4
0
 def wrapper(*args, **kwargs):
     """Wrap the route."""
     database = kwargs["database"]
     session_id = str(bottle.request.get_cookie("session_id"))
     session = Session(sessions.find_session(database, session_id))
     if not session.is_valid():
         cls.abort(
             401,
             "%s-access to %s denied: session %s not authenticated",
             context, session_id)
     authorized_users = latest_reports_overview(database).get("editors")
     if not session.is_authorized(authorized_users):
         cls.abort(403,
                   "%s-access to %s denied: session %s not authorized",
                   context, session_id)
     return callback(*args, **kwargs)
Esempio n. 5
0
def post_reports_attribute(reports_attribute: str, database: Database):
    """Set a reports overview attribute."""
    value = dict(bottle.request.json)[reports_attribute]
    overview = latest_reports_overview(database)
    old_value = overview.get(reports_attribute)
    if value == old_value:
        return dict(ok=True)  # Nothing to do
    overview[reports_attribute] = value
    value_change_description = "" if reports_attribute == "layout" else f" from '{old_value}' to '{value}'"
    user = sessions.user(database)
    overview["delta"] = dict(
        email=user["email"],
        description=
        f"{user['user']} changed the {reports_attribute} of the reports overview"
        f"{value_change_description}.")
    return insert_new_reports_overview(database, overview)