Skip to content
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

Martin cedres tabla reservations #547

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ignore all files starting with .
.*

migrations/
# track this file .gitignore (i.e. do NOT ignore it)
!.gitignore
!.github
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ flask-admin = "*"
typing-extensions = "*"
flask-jwt-extended = "==4.6.0"
wtforms = "==3.1.2"
flask-bcrypt = "*"

[requires]
python_version = "3.10"
Expand Down
683 changes: 390 additions & 293 deletions Pipfile.lock

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions src/api/models.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime



db = SQLAlchemy()

class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(120), unique=True, nullable=False)
password = db.Column(db.String(80), unique=False, nullable=False)
is_active = db.Column(db.Boolean(), unique=False, nullable=False)
user_name = db.Column(db.String(50), nullable=False)
email = db.Column(db.String(100), unique=True, nullable=False)
password_hash = db.Column(db.String(255), unique=False, nullable=False)
role = db.Column(db.Enum('user', 'admin', name='role_enum'), default='user', nullable=False)
status = db.Column(db.Enum('activo', 'en_revision', name='role_status'), default='en_revision', nullable=False)
created_at = db.Column(db.DateTime, default=datetime.now(pytz.utc)) # Importe libreria pytz para obtener la hora UTC
updated_at = db.Column(db.DateTime, default=datetime.now(pytz.utc), onupdate=datetime.now(pytz.utc))


def __repr__(self):
return f'<User {self.email}>'
return f'<User {self.user_name}>'

def serialize(self):
return {
"id": self.id,
"username": self.user_name,
"email": self.email,
# do not serialize the password, its a security breach
}
36 changes: 36 additions & 0 deletions src/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,43 @@

# Allow CORS requests to this API
CORS(api)
# Admin
@api.route('/admin/pending-users', methods=['GET'])
@jwt_required()
def get_pending_users():
current_user_id = get_jwt_identity()
current_user = User.query.get(current_user_id)

if current_user.role != 'admin':
return jsonify({"msg": "Unauthorized"}), 403

# Obteniendo usuarios con el estado 'en_revision'
pending_users = User.query.filter_by(status='en_revision').all()
return jsonify([user.serialize() for user in pending_users]), 200

@api.route('/admin/users/<int:user_id>/status', methods=['PATCH'])
@jwt_required()
def update_user_status(user_id):
current_user_id = get_jwt_identity()
current_user = User.query.get(current_user_id)

if not current_user or current_user.role != 'admin':
return jsonify({"error": "Unauthorized"}), 403

user = User.query.get(user_id)
if not user:
return jsonify({"error": "User not found"}), 404

body = request.get_json()
new_status = body.get('status')

if new_status not in ['activo', 'en_revision']:
return jsonify({"error": "Invalid status"}), 400

user.status = new_status
db.session.commit()

return jsonify({"message": "User status updated successfully"}), 200

@api.route('/hello', methods=['POST', 'GET'])
def handle_hello():
Expand Down
1 change: 1 addition & 0 deletions src/front/js/pages/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link } from "react-router-dom";
import { Context } from "../store/appContext";

export const Demo = () => {
// y otro checkpoint del profe aca
const { store, actions } = useContext(Context);

return (
Expand Down
1 change: 1 addition & 0 deletions src/front/js/pages/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useContext } from "react";
import { Context } from "../store/appContext";
import rigoImageUrl from "../../img/rigo-baby.jpg";
import "../../styles/home.css";
//el profe estuvo aqui

export const Home = () => {
const { store, actions } = useContext(Context);
Expand Down