Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions mflix/api/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from flask_cors import CORS
from flask_jwt_extended import (
jwt_required, get_jwt_claims
jwt_required, get_jwt
)
from mflix.api.user import User
from mflix.api.utils import expect
Expand Down Expand Up @@ -159,13 +159,13 @@ def api_search_movies_faceted():


@movies_api_v1.route('/comment', methods=["POST"])
@jwt_required
@jwt_required()
def api_post_comment():
"""
Posts a comment about a specific movie. Validates the user is logged in by
ensuring a valid JWT is provided
"""
claims = get_jwt_claims()
claims = get_jwt()
user = User.from_claims(claims)
post_data = request.get_json()
try:
Expand All @@ -179,7 +179,7 @@ def api_post_comment():


@movies_api_v1.route('/comment', methods=["PUT"])
@jwt_required
@jwt_required()
def api_update_comment():
"""
Updates a user comment. Validates the user is logged in by ensuring a
Expand All @@ -205,12 +205,12 @@ def api_update_comment():


@movies_api_v1.route('/comment', methods=["DELETE"])
@jwt_required
@jwt_required()
def api_delete_comment():
"""
Delete a comment. Requires a valid JWT
"""
claims = get_jwt_claims()
claims = get_jwt()
user_email = User.from_claims(claims).email
post_data = request.get_json()
try:
Expand Down
29 changes: 10 additions & 19 deletions mflix/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from flask_jwt_extended import (
jwt_required, create_access_token,
get_jwt_claims
get_jwt
)

from flask_cors import CORS
Expand All @@ -21,15 +21,6 @@ def get_bcrypt():
bcrypt = g._bcrypt = current_app.config['BCRYPT']
return bcrypt


def get_jwt():
jwt = getattr(g, '_jwt', None)
if jwt is None:
jwt = g._jwt = current_app.config['JWT']

return jwt


def init_claims_loader():
add_claims = getattr(g, '_add_claims', None)
if add_claims is None:
Expand Down Expand Up @@ -177,9 +168,9 @@ def login():


@user_api_v1.route('/update-preferences', methods=['PUT'])
@jwt_required
@jwt_required()
def save():
claims = get_jwt_claims()
claims = get_jwt()
user = User.from_claims(claims)
body = request.get_json()
prefs = expect(body.get('preferences'), dict, 'preferences')
Expand All @@ -203,9 +194,9 @@ def save():


@user_api_v1.route('/logout', methods=['POST'])
@jwt_required
@jwt_required()
def logout():
claims = get_jwt_claims()
claims = get_jwt()
user = User.from_claims(claims)
try:
logout_user(user.email)
Expand All @@ -223,7 +214,7 @@ def logout():
@user_api_v1.route('/delete', methods=['DELETE'])
@jwt_required
def delete():
claims = get_jwt_claims()
claims = get_jwt()
user = User.from_claims(claims)
try:
password = expect(request.get_json().get('password'), str, 'password')
Expand All @@ -248,9 +239,9 @@ def delete():


@user_api_v1.route('/admin', methods=['GET'])
@jwt_required
@jwt_required()
def is_admin():
claims = get_jwt_claims()
claims = get_jwt()
user = User.from_claims(claims)
try:
if check_admin(user):
Expand All @@ -263,9 +254,9 @@ def is_admin():


@user_api_v1.route('/comment-report', methods=['GET'])
@jwt_required
@jwt_required()
def comment_report():
claims = get_jwt_claims()
claims = get_jwt()
user = User.from_claims(claims)
try:
if check_admin(user):
Expand Down
4 changes: 2 additions & 2 deletions mflix/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,6 @@ def get_configuration():
try:
role_info = db.command({'connectionStatus': 1}).get('authInfo').get(
'authenticatedUserRoles')[0]
return (db.client.max_pool_size, db.client.write_concern, role_info)
return db.client.options.pool_options.max_pool_size, db.client.write_concern, role_info
except IndexError:
return (db.client.max_pool_size, db.client.write_concern, {})
return db.client.options.pool_options.max_pool_size, db.client.write_concern, {}
2 changes: 1 addition & 1 deletion mflix/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_app():
app.register_blueprint(user_api_v1)
jwt = JWTManager(app)

@jwt.user_claims_loader
@jwt.additional_claims_loader
def add_claims(identity):
return {
'user': identity,
Expand Down
22 changes: 9 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
Flask==0.12.4
Flask-Bcrypt==0.7.1
Flask-Login==0.4.0
pymongo==3.7.0
dnspython==1.15.0
pytest==3.3.0
pytest-flask==0.10.0
Flask-Cors==3.0.3
flask-jwt-extended==3.7.0
faker==0.8.13
Flask==2.2.2
Flask-Cors==3.0.10
Flask-Bcrypt==1.0.1
Flask-JWT-Extended==4.4.4
dnspython==2.2.1
jupyter==1.0.0
jupyter-client==5.2.4
jupyter-console==6.0.0
jupyter-core==4.4.0
pymongo==4.2.0
pytest==7.1.3
pytest-flask==1.2.0
python-dateutil==2.8.2