From 5c4c179751ca8230d6b9d29eb73376ea6e1045ca Mon Sep 17 00:00:00 2001 From: danmash Date: Sun, 2 Oct 2022 20:56:58 +0100 Subject: [PATCH 1/2] VERSION 2 release, temporary production links hardcoding --- app/models.py | 2 +- app/sendgrid/templates/user_b_shared_email.py | 2 +- app/sendgrid/templates/welcome_email.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models.py b/app/models.py index 01906f10..266c094f 100644 --- a/app/models.py +++ b/app/models.py @@ -96,7 +96,7 @@ def reset_url(self): _external=True, ).lower() - frontend_base_url = "https://app-frontend-test-001.azurewebsites.net" + frontend_base_url = "https://app.climatemind.org" route_component = "/password-reset/" hard_coded_url = frontend_base_url + route_component + str(self.uuid).lower() return hard_coded_url diff --git a/app/sendgrid/templates/user_b_shared_email.py b/app/sendgrid/templates/user_b_shared_email.py index 27dfa3de..60752c85 100644 --- a/app/sendgrid/templates/user_b_shared_email.py +++ b/app/sendgrid/templates/user_b_shared_email.py @@ -184,7 +184,7 @@ - Login + Login diff --git a/app/sendgrid/templates/welcome_email.py b/app/sendgrid/templates/welcome_email.py index 4791bffb..41d6bdd8 100644 --- a/app/sendgrid/templates/welcome_email.py +++ b/app/sendgrid/templates/welcome_email.py @@ -183,7 +183,7 @@ - Login + Login From cda7e5d572fbdaa27eaaf88fa0904c7527338d1a Mon Sep 17 00:00:00 2001 From: Kameron Rodrigues Date: Sun, 6 Aug 2023 11:33:06 -0700 Subject: [PATCH 2/2] make recaptcha optional and other changes (#498) * Removed flask-selfdoc from project. * Update score_nodes.py added relatedPersonalValues to the GET response of the /feed endpoint to include all the personal values associated with each climate change impact for user's feed. * run linting * optional parameter to skip recaptcha * change spelling * remove timedelta --------- Co-authored-by: Jason Hutson <110316760+HutsonJason@users.noreply.github.com> Co-authored-by: Svenstar74 --- .gitignore | 6 +++--- app/__init__.py | 7 +------ app/account/routes.py | 5 +---- app/alignment/routes.py | 9 --------- app/auth/routes.py | 5 ++--- app/documentation/__init__.py | 5 ----- app/documentation/routes.py | 17 ----------------- app/extensions.py | 2 -- app/feed/routes.py | 3 +-- app/myths/routes.py | 3 --- app/personal_values/routes.py | 2 -- app/post_code/routes.py | 3 --- app/questions/routes.py | 2 -- app/scoring/routes.py | 3 --- app/scoring/score_nodes.py | 5 +++++ app/session/routes.py | 2 -- app/solutions/routes.py | 4 ---- app/subscribe/routes.py | 3 --- requirements/requirements.txt | 1 - 19 files changed, 13 insertions(+), 74 deletions(-) delete mode 100644 app/documentation/__init__.py delete mode 100644 app/documentation/routes.py diff --git a/.gitignore b/.gitignore index 67963ef2..7e714d61 100644 --- a/.gitignore +++ b/.gitignore @@ -58,9 +58,9 @@ docs/_build/ ~* *~ *.pyc - /.idea/ - .idea - .idea/ +/.idea/ +.idea +.idea/ #updated ontology files Climate_Mind_Digraph_Test_Ont.json diff --git a/app/__init__.py b/app/__init__.py index 285d4f83..4c33583c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -4,7 +4,7 @@ from sentry_sdk.integrations.flask import FlaskIntegration from app import models -from app.extensions import db, migrate, login, cache, auto, jwt, limiter +from app.extensions import db, migrate, login, cache, jwt, limiter from config import DevelopmentConfig @@ -17,7 +17,6 @@ def create_app(config_class=DevelopmentConfig): migrate.init_app(app, db) login.init_app(app) cache.init_app(app) - auto.init_app(app) jwt.init_app(app) limiter.init_app(app) @@ -88,10 +87,6 @@ def create_app(config_class=DevelopmentConfig): app.register_blueprint(personal_values_bp) - from app.documentation import bp as documentation_bp - - app.register_blueprint(documentation_bp) - from app.post_code import bp as post_code_bp app.register_blueprint(post_code_bp) diff --git a/app/account/routes.py b/app/account/routes.py index 4df871c5..116e863d 100644 --- a/app/account/routes.py +++ b/app/account/routes.py @@ -7,7 +7,7 @@ from flask_jwt_extended import jwt_required from sqlalchemy.exc import SQLAlchemyError -from app import auto, db, limiter +from app import db, limiter from app.account import bp from app.account.schemas import ( UserChangePasswordSchema, @@ -30,7 +30,6 @@ @bp.route("/quizId", methods=["GET"]) @cross_origin() @jwt_required() -@auto.doc() def current_quizId(): """ Returns the current quizId of a logged in user or standard JWT errors if token not available or expired. @@ -44,7 +43,6 @@ def current_quizId(): @bp.route("/email", methods=["GET"]) @cross_origin() @jwt_required() -@auto.doc() def current_email(): """ Returns the current email address of a logged in user or standard JWT errors if token not available or expired. @@ -58,7 +56,6 @@ def current_email(): @bp.route("/email", methods=["PUT"]) @cross_origin() @jwt_required() -@auto.doc() def update_email(): """ # FIXME: move to /user-account PUT diff --git a/app/alignment/routes.py b/app/alignment/routes.py index a2a0204d..a803bd77 100644 --- a/app/alignment/routes.py +++ b/app/alignment/routes.py @@ -4,7 +4,6 @@ from flask_cors import cross_origin from flask import jsonify -from app import auto from app.alignment import bp from app.common.uuid import validate_uuid, uuidType, check_uuid_in_db from app.user_b.analytics_logging import log_user_b_event, eventType @@ -16,7 +15,6 @@ @bp.route("/alignment", methods=["POST"]) @cross_origin() -@auto.doc() def post_alignment_uuid(): """ Post alignment. After user b has taken the quiz, their results are compared to user a and their @@ -104,7 +102,6 @@ def get_alignment(alignment_scores_uuid): @bp.route("/alignment//shared-impacts", methods=["GET"]) @cross_origin() -@auto.doc() def get_shared_impacts(alignment_scores_uuid): """ Get a list of the shared impacts generated by comparing user A's and user B's quiz scores. @@ -140,7 +137,6 @@ def get_shared_impacts(alignment_scores_uuid): @bp.route("/alignment//shared-solutions", methods=["GET"]) @cross_origin() -@auto.doc() def get_shared_solutions(alignment_scores_uuid): """ Get a list of the shared solutions generated by comparing user A's and user B's quiz scores. @@ -177,7 +173,6 @@ def get_shared_solutions(alignment_scores_uuid): @bp.route("/alignment//shared-impacts", methods=["POST"]) @cross_origin() -@auto.doc() def post_shared_impact_selection(alignment_scores_uuid): """ Records the shared impact that user b has selected to discuss with user a. @@ -227,7 +222,6 @@ def post_shared_impact_selection(alignment_scores_uuid): @bp.route("/alignment//shared-solutions", methods=["POST"]) @cross_origin() -@auto.doc() def post_shared_solution_selection(alignment_scores_uuid): """ Records the shared solutions that user b has selected to discuss with user a. @@ -276,7 +270,6 @@ def post_shared_solution_selection(alignment_scores_uuid): @bp.route("/alignment/shared-impact/", methods=["GET"]) @cross_origin() -@auto.doc() def get_shared_impact_details(impact_iri): """ Gets the details for a shared impact when the user clicks Learn More on the card in their feed. @@ -300,7 +293,6 @@ def get_shared_impact_details(impact_iri): @bp.route("/alignment/shared-solution/", methods=["GET"]) @cross_origin() -@auto.doc() def get_shared_solution_details(solution_iri): """ Gets the details for a shared solution when the user clicks Learn More on the card in their feed. @@ -324,7 +316,6 @@ def get_shared_solution_details(solution_iri): @bp.route("/alignment//summary", methods=["GET"]) @cross_origin() -@auto.doc() def get_alignment_summary(alignment_scores_uuid): """ Gets the alignment summary for user B to see before confirming their consent to share with user A. diff --git a/app/auth/routes.py b/app/auth/routes.py index 378022fb..68ae3b60 100644 --- a/app/auth/routes.py +++ b/app/auth/routes.py @@ -24,7 +24,7 @@ from app.models import Users from app.sendgrid.utils import send_welcome_email -from app import db, auto +from app import db from app import limiter import uuid @@ -46,7 +46,6 @@ def ip_whitelist(): @bp.route("/login", methods=["POST"]) -@auto.doc() @limiter.limit("100/day;50/hour;10/minute;5/second") def login(): """ @@ -77,7 +76,7 @@ def login(): if not user or not user.check_password(password): raise UnauthorizedError(message="Wrong email or password. Try again.") - if not check_if_local(): + if not check_if_local() and not r.get("skipCaptcha", None): # Verify captcha with Google secret_key = os.environ.get("RECAPTCHA_SECRET_KEY") diff --git a/app/documentation/__init__.py b/app/documentation/__init__.py deleted file mode 100644 index 35b093d4..00000000 --- a/app/documentation/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from flask import Blueprint - -bp = Blueprint("documentation", __name__) - -from app.documentation import routes diff --git a/app/documentation/routes.py b/app/documentation/routes.py deleted file mode 100644 index 72794aad..00000000 --- a/app/documentation/routes.py +++ /dev/null @@ -1,17 +0,0 @@ -from app.documentation import bp - -from app import auto -from flask_cors import cross_origin - -""" - -Returns auto-generated API documentation based on the docstrings contained in each -API endpoint. - -""" - - -@bp.route("/documentation") -@cross_origin() -def documentation(): - return auto.html() diff --git a/app/extensions.py b/app/extensions.py index 1b3c3439..21af4fa7 100644 --- a/app/extensions.py +++ b/app/extensions.py @@ -4,7 +4,6 @@ from flask_limiter.util import get_remote_address from flask_login import LoginManager from flask_migrate import Migrate -from flask_selfdoc import Autodoc from flask_sqlalchemy import SQLAlchemy from sqlalchemy import MetaData @@ -24,7 +23,6 @@ login.login_view = "auth.login" login.login_message = "Please log in to access this page." cache = Cache() -auto = Autodoc() jwt = JWTManager() limiter = Limiter( key_func=get_remote_address, default_limits=["1000 per day", "200 per hour"] diff --git a/app/feed/routes.py b/app/feed/routes.py index 35371e38..ee1f7a0c 100644 --- a/app/feed/routes.py +++ b/app/feed/routes.py @@ -9,12 +9,11 @@ from app.models import Scores from flask_cors import cross_origin -from app import db, auto, cache +from app import db, cache @bp.route("/feed", methods=["GET"]) @cross_origin() -@auto.doc() def get_feed(): """ The front-end needs to request personalized climate change effects that are most diff --git a/app/myths/routes.py b/app/myths/routes.py index ccc243cf..c2e75fa4 100644 --- a/app/myths/routes.py +++ b/app/myths/routes.py @@ -6,12 +6,9 @@ MYTH_PROCESSOR = process_myths() -from app import auto - @bp.route("/myths", methods=["GET"]) @cross_origin() -@auto.doc() def get_general_myths(): """ The front-end needs a general myths list and information to serve to user when diff --git a/app/personal_values/routes.py b/app/personal_values/routes.py index 0bd12464..01ef4f3d 100644 --- a/app/personal_values/routes.py +++ b/app/personal_values/routes.py @@ -6,7 +6,6 @@ from app.personal_values import bp from app.models import Scores from app.common.uuid import validate_uuid, uuidType, check_uuid_in_db -from app import auto from app.personal_values.normalize import normalize_scores from flask_cors import cross_origin @@ -16,7 +15,6 @@ @bp.route("/personal_values", methods=["GET"]) @cross_origin() -@auto.doc() def get_personal_values(): """ Users want to know their personal values based on their Schwartz questionnaire diff --git a/app/post_code/routes.py b/app/post_code/routes.py index 79b5f91c..786290e4 100644 --- a/app/post_code/routes.py +++ b/app/post_code/routes.py @@ -6,12 +6,9 @@ from app.errors.errors import InvalidUsageError from flask_cors import cross_origin -from app import auto - @bp.route("/post-code", methods=["POST"]) @cross_origin() -@auto.doc() def post_code(): """ diff --git a/app/questions/routes.py b/app/questions/routes.py index e7ba7e59..07aa032e 100644 --- a/app/questions/routes.py +++ b/app/questions/routes.py @@ -3,14 +3,12 @@ from flask import Response from flask_cors import cross_origin -from app import auto from app.questions import bp from app.questions.utils import get_schwartz_questions_file_data @bp.route("/questions", methods=["GET"]) @cross_origin() -@auto.doc() def get_questions(): """ Returns the list of available schwartz personal value questions that can be diff --git a/app/scoring/routes.py b/app/scoring/routes.py index 7e9219bf..f5c1fb32 100644 --- a/app/scoring/routes.py +++ b/app/scoring/routes.py @@ -12,13 +12,10 @@ from flask_jwt_extended import jwt_required from flask_jwt_extended import current_user -from app import auto - @bp.route("/scores", methods=["POST"]) @cross_origin() @jwt_required(optional=True) -@auto.doc() def user_scores(): """ User scores are used to determine which solutions are best to serve diff --git a/app/scoring/score_nodes.py b/app/scoring/score_nodes.py index 5d04fc50..51b78708 100644 --- a/app/scoring/score_nodes.py +++ b/app/scoring/score_nodes.py @@ -20,6 +20,8 @@ import random from collections import OrderedDict +from app.alignment.utils import get_dashed_personal_values_names_from_vector + class score_nodes: @@ -88,6 +90,9 @@ def simple_scoring(self): localised_acyclic_graph.nodes[node] ), "effectSpecificMythIRIs": self.MYTH_PROCESSOR.get_effect_specific_myths(), + "relatedPersonalValues": get_dashed_personal_values_names_from_vector( + current_node["personal_values_10"] + ), } if any(v is None for v in node_values_associations_10): diff --git a/app/session/routes.py b/app/session/routes.py index 31d14897..325ce85a 100644 --- a/app/session/routes.py +++ b/app/session/routes.py @@ -7,7 +7,6 @@ from flask_jwt_extended import current_user from flask_jwt_extended import jwt_required -from app import auto from app.session import bp from app.session.session_helpers import get_ip_address, store_session @@ -15,7 +14,6 @@ @bp.route("/session", methods=["POST"]) @cross_origin() @jwt_required(optional=True) -@auto.doc() def post_session(): session_uuid = uuid.uuid4() session_created_timestamp = datetime.datetime.now(timezone.utc) diff --git a/app/solutions/routes.py b/app/solutions/routes.py index 8db0057c..c43394d4 100644 --- a/app/solutions/routes.py +++ b/app/solutions/routes.py @@ -9,14 +9,11 @@ import numpy as np import pickle -from app import auto - SOLUTION_PROCESSOR = process_solutions(4, 0.5) @bp.route("/get_actions", methods=["GET"]) @cross_origin() -@auto.doc() def get_actions(): """ The front-end needs to request actions to take against climate change @@ -35,7 +32,6 @@ def get_actions(): @bp.route("/solutions", methods=["GET"]) @cross_origin() -@auto.doc() def get_general_solutions(): """ The front-end needs general solutions list and information to serve to user when diff --git a/app/subscribe/routes.py b/app/subscribe/routes.py index d9387b19..60834039 100644 --- a/app/subscribe/routes.py +++ b/app/subscribe/routes.py @@ -7,12 +7,9 @@ from flask_cors import cross_origin from flask import request -from app import auto - @bp.route("/subscribe", methods=["POST"]) @cross_origin() -@auto.doc() def subscribe(): r = request.get_json(force=True, silent=True) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 6539c7b7..1f92b365 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -29,7 +29,6 @@ Flask-Login==0.5.0 flask-marshmallow==0.14.0 Flask-Migrate==2.5.3 Flask-SQLAlchemy==2.4.4 -Flask-Selfdoc==1.2.3 Flask-Limiter==1.4 limits==1.5.1 future==0.18.2