-
Notifications
You must be signed in to change notification settings - Fork 957
Fix: ensure redirect to user group view includes required group path … #3359
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
Changes from all commits
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,34 +1,43 @@ | ||
| from flask import request, jsonify, redirect, url_for, flash, current_app | ||
| import logging | ||
| import re | ||
|
|
||
| from flask import flash, current_app, jsonify, redirect, request, url_for | ||
|
Check warning on line 4 in augur/api/view/api.py
|
||
| from flask_login import current_user, login_required | ||
|
|
||
| from augur.application.db.models import Repo, RepoGroup, UserGroup, UserRepo | ||
|
Check warning on line 7 in augur/api/view/api.py
|
||
| from augur.tasks.frontend import add_github_orgs_and_repos, parse_org_and_repo_name, parse_org_name, add_gitlab_repos | ||
| from .utils import * | ||
| from ..server import app | ||
| from augur.application.db.session import DatabaseSession | ||
|
Check warning on line 8 in augur/api/view/api.py
|
||
| from augur.tasks.frontend import ( | ||
| add_github_orgs_and_repos, | ||
| add_gitlab_repos, | ||
| parse_org_and_repo_name, | ||
| parse_org_name | ||
| ) | ||
|
|
||
| from ..server import app | ||
| from .utils import * | ||
|
|
||
| @app.route('/cache/file/') | ||
| @app.route('/cache/file/<path:file>') | ||
| def cache(file=None): | ||
| if file is None: | ||
| return redirect(url_for('static', filename="cache")) | ||
| return redirect(url_for('static', filename="cache/" + toCacheFilename(file, False))) | ||
|
Check warning on line 24 in augur/api/view/api.py
|
||
|
|
||
|
|
||
| def add_existing_org_to_group(session, user_id, group_name, rg_id): | ||
|
|
||
| logger.info("Adding existing org to group") | ||
|
Check warning on line 29 in augur/api/view/api.py
|
||
|
|
||
| group_id = UserGroup.convert_group_name_to_id(session, user_id, group_name) | ||
| if group_id is None: | ||
| return False | ||
|
|
||
| repos = session.query(Repo).filter(Repo.repo_group_id == rg_id).all() | ||
| logger.info("Length of repos in org: " + str(len(repos))) | ||
|
Check warning on line 36 in augur/api/view/api.py
|
||
| for repo in repos: | ||
| result = UserRepo.insert(session, repo.repo_id, group_id) | ||
| if not result: | ||
| logger.info("Failed to add repo to group") | ||
|
Check warning on line 40 in augur/api/view/api.py
|
||
|
|
||
|
|
||
|
|
||
|
|
@@ -155,21 +164,37 @@ | |
| group = request.args.get("group_name") | ||
| repo = request.args.get("repo_id") | ||
|
|
||
| if not repo: | ||
| flash("No repo id provided") | ||
| if not group: | ||
| flash("No group name provided") | ||
|
|
||
| repo = int(repo) | ||
|
|
||
| if not repo or not group: | ||
MoralCode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if not repo: | ||
| flash("No repo id provided") | ||
| if not group: | ||
| flash("No group name provided") | ||
| # Staying on same page instead of redirecting to settings | ||
| return redirect(url_for("user_group_view", group=group)) | ||
|
|
||
| try: | ||
| repo_id = int(repo) | ||
| except (TypeError, ValueError) as e: | ||
| flash("Invalid repo id provided") | ||
|
Contributor
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. we should probably also print a log message here with the actual exception so the admin of augur knows what specifically happened.
Author
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. updated please check |
||
|
|
||
| logging.error(f"Invalid repo id provided for repo '{repo}'. Error: {e}") | ||
|
|
||
|
|
||
| return redirect(url_for("user_group_view", group=group)) | ||
|
|
||
| result = current_user.remove_repo(group, repo)[0] | ||
| result = current_user.remove_repo(group, repo_id)[0] | ||
|
|
||
| if result: | ||
| flash(f"Successfully removed repo {repo} from group {group}") | ||
| else: | ||
| flash("An error occurred removing repo from group") | ||
|
|
||
| return redirect(url_for("user_group_view") + f"?group={group}") | ||
|
|
||
| return redirect(url_for("user_group_view", group=group)) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| @app.route('/account/application/deauthorize') | ||
| @login_required | ||
|
|
@@ -209,5 +234,5 @@ | |
| """ | ||
| @app.route('/requests/report/wait/<id>') | ||
| def wait_for_report_request(id): | ||
| requestReports(id) | ||
|
Check warning on line 237 in augur/api/view/api.py
|
||
| return jsonify(report_requests[id]) | ||
|
Check warning on line 238 in augur/api/view/api.py
|
||
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.
Was it your editor that reformatted a lot of these imports? I dont see anything crazy wrong just wanted to check where this came from
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.
The pylint check was failing coz of the order of imports. So had to make some tweaks