-
Notifications
You must be signed in to change notification settings - Fork 12
Admin changes rebased #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bdab198
c210c10
c5efe69
1935bd2
195439d
4ff47f6
82050b8
01f93ef
7a97cc9
80d5c0f
8a2c924
99a6d91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| from flask import render_template, redirect, url_for, session, request, jsonify | ||
| from flask_login import LoginManager | ||
| from flask_login import LoginManager, current_user, login_required | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
| from io import StringIO | ||
| from .utils import * | ||
| from .init import logger | ||
| from .url_converters import * | ||
|
|
||
| from functools import wraps | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
|
|
||
| # from .server import User | ||
| from ..server import app, db_session | ||
| from collectoss.application.db.models import User, UserSessionToken | ||
|
|
@@ -38,6 +40,13 @@ def unsupported_method(error): | |
|
|
||
| return render_message("405 - Method not supported", "The resource you are trying to access does not support the request method used"), 405 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
|
|
||
| @app.errorhandler(403) | ||
| def forbidden(error): | ||
| if AUGUR_API_VERSION in str(request.url_rule): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
| return jsonify({"status": "Forbidden"}), 403 | ||
|
|
||
| return render_message("403 - Forbidden", "You do not have permission to view this page"), 403 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
|
|
||
| @app.errorhandler(500) | ||
| def internal_server_error(error): | ||
| if API_VERSION in str(request.path): | ||
|
|
@@ -52,8 +61,21 @@ def internal_server_error(error): | |
| errout.close() | ||
| except Exception as e: | ||
| logger.error(e) | ||
| raise e | ||
|
|
||
| return render_message("500 - Internal Server Error", "An error occurred while trying to service your request. Please try again, and if the issue persists, please file a GitHub issue with the below error message:", error=stacktrace), 500 | ||
| return render_message("500 - Internal Server Error", """An error occurred while trying to service your request. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
| Please try again, and if the error persists, please file a GitHub issue with a description | ||
| of what you were doing before this error occurred accompanied by the below error message:""", error=stacktrace), 500 | ||
|
|
||
| @app.template_filter("escape_ID") | ||
| def escape_HTML_ID(data: str) -> str: | ||
| # Done this way in case we want to add more replacements in the future | ||
| data = data.replace(".", "\\.") | ||
| return data | ||
|
|
||
| @app.template_filter("quoted") | ||
| def quote_surrounded(data: str) -> str: | ||
| return '"' + data + '"' | ||
|
|
||
| @login_manager.unauthorized_handler | ||
| def unauthorized(): | ||
|
|
@@ -98,19 +120,16 @@ def load_user(user_id): | |
| @login_manager.request_loader | ||
| def load_user_request(request): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
| token = get_bearer_token() | ||
|
|
||
| current_time = int(time.time()) | ||
| token = db_session.query(UserSessionToken).filter(UserSessionToken.token == token, UserSessionToken.expiration >= current_time).first() | ||
| if token: | ||
|
|
||
| print("Valid user") | ||
| token = db_session.query(UserSessionToken).filter(UserSessionToken.token == token, UserSessionToken.expiration >= current_time).first() | ||
|
|
||
| if token: | ||
| user = token.user | ||
| user._is_authenticated = True | ||
| user._is_active = True | ||
|
|
||
| return user | ||
|
|
||
| return None | ||
|
|
||
| @app.template_filter('as_datetime') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,16 +3,23 @@ | |
| """ | ||
| import logging | ||
| import math | ||
| import os | ||
| import signal | ||
| from flask import render_template, request, redirect, url_for, session, flash | ||
| from .utils import * | ||
| from augur.api.util import admin_required, development_required | ||
| from flask_login import login_user, logout_user, current_user, login_required | ||
| from sqlalchemy.exc import OperationalError | ||
|
|
||
| from collectoss.application.db.models import User, Repo, ClientApplication | ||
| from .server import LoginException | ||
| from collectoss.application.util import * | ||
| from collectoss.application.db.lib import get_value | ||
| from collectoss.application.config import SystemConfig | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
| from ..server import app, db_session | ||
|
|
||
| from augur.application.db.lib import get_session | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
|
|
@@ -318,6 +325,7 @@ def user_group_view(group = None): | |
| return render_module("user-group-repos-table", title="Repos", repos=data, query_key=query, activePage=params["page"], pages=page_count, offset=pagination_offset, PS="user_group_view", reverse = rev, sorting = params.get("sort"), group=group) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
|
|
||
| @app.route('/error') | ||
| @development_required | ||
| def throw_exception(): | ||
| raise Exception("This Exception intentionally raised") | ||
|
|
||
|
|
@@ -326,6 +334,7 @@ def throw_exception(): | |
| View the admin dashboard. | ||
| """ | ||
| @app.route('/dashboard') | ||
| @admin_required | ||
| def dashboard_view(): | ||
| empty = [ | ||
| { "title": "Placeholder", "settings": [ | ||
|
|
@@ -337,6 +346,14 @@ def dashboard_view(): | |
| ]} | ||
| ] | ||
|
|
||
| backend_config = requestJson("config/get", False) | ||
| backend_config = SystemConfig(logger, db_session).load_config() | ||
|
|
||
| with get_session() as session: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
| try: | ||
| users = session.query(User).all() | ||
| except OperationalError as e: | ||
| # Instruct Gunicorn to reboot workers to resolve database connection instability | ||
| os.kill(os.getpid(), signal.SIGTERM) | ||
| return "reloading" | ||
|
|
||
| return render_template('admin-dashboard.j2', sections = empty, config = backend_config) | ||
| return render_template('admin-dashboard.j2', sections = empty, config = backend_config, users = users) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pylint] reported by reviewdog 🐶
W0611: Unused current_app imported from flask (unused-import)